1 //===--------------------- catch_const_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: libcxxabi-no-exceptions
11 
12 #include <cassert>
13 
14 // Clang emits  warnings about exceptions of type 'Child' being caught by
15 // an earlier handler of type 'Base'. Congrats clang, you've just
16 // diagnosed the behavior under test.
17 #if defined(__clang__)
18 #pragma clang diagnostic ignored "-Wexceptions"
19 #endif
20 
21 #if __has_feature(cxx_nullptr)
22 
23 struct A {};
24 
25 void test1()
26 {
27     try
28     {
29         throw nullptr;
30         assert(false);
31     }
32     catch (A*)
33     {
34     }
35     catch (const A*)
36     {
37         assert(false);
38     }
39 }
40 
41 
42 void test2()
43 {
44     try
45     {
46         throw nullptr;
47         assert(false);
48     }
49     catch (const A*)
50     {
51     }
52     catch (A*)
53     {
54         assert(false);
55     }
56 }
57 
58 void test3()
59 {
60     try
61     {
62         throw nullptr;
63         assert(false);
64     }
65     catch (const A* const)
66     {
67     }
68     catch (A*)
69     {
70         assert(false);
71     }
72 }
73 
74 void test4()
75 {
76     try
77     {
78         throw nullptr;
79         assert(false);
80     }
81     catch (A*)
82     {
83     }
84     catch (const A* const)
85     {
86         assert(false);
87     }
88 }
89 
90 void test5()
91 {
92     try
93     {
94         throw nullptr;
95         assert(false);
96     }
97     catch (A const*)
98     {
99     }
100     catch (A*)
101     {
102         assert(false);
103     }
104 }
105 
106 void test6()
107 {
108     try
109     {
110         throw nullptr;
111         assert(false);
112     }
113     catch (A*)
114     {
115     }
116     catch (A const*)
117     {
118         assert(false);
119     }
120 }
121 
122 
123 #else
124 
125 void test1() {}
126 void test2() {}
127 void test3() {}
128 void test4() {}
129 void test5() {}
130 void test6() {}
131 
132 #endif
133 
134 int main()
135 {
136     test1();
137     test2();
138     test3();
139     test4();
140     test5();
141     test6();
142 }
143