1 //===--------------------- catch_pointer_nullptr.cpp ----------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03
11 
12 #include <cassert>
13 #include <cstdlib>
14 
15 struct A {};
16 
17 void test1()
18 {
19     try
20     {
21         throw nullptr;
22         assert(false);
23     }
24     catch (int*)
25     {
26     }
27     catch (long*)
28     {
29         assert(false);
30     }
31 }
32 
33 void test2()
34 {
35     try
36     {
37         throw nullptr;
38         assert(false);
39     }
40     catch (A*)
41     {
42     }
43     catch (int*)
44     {
45         assert(false);
46     }
47 }
48 
49 template <class Catch>
50 void catch_nullptr_test() {
51   try {
52     throw nullptr;
53     assert(false);
54   } catch (Catch) {
55     // nothing todo
56   } catch (...) {
57     assert(false);
58   }
59 }
60 
61 
62 int main()
63 {
64   // catch naked nullptrs
65   test1();
66   test2();
67 
68   catch_nullptr_test<int*>();
69   catch_nullptr_test<int**>();
70   catch_nullptr_test<int A::*>();
71   catch_nullptr_test<const int A::*>();
72   catch_nullptr_test<int A::**>();
73 }
74