Nico Weber | cfbfdd9 | 2013-12-05 21:54:49 +0000 | [diff] [blame] | 1 | //===--------------------- catch_const_pointer_nullptr.cpp ----------------===// |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 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 | |||||
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
11 | |||||
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 12 | #include <cassert> |
13 | |||||
Eric Fiselier | df448d8 | 2016-06-15 19:07:19 +0000 | [diff] [blame] | 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 | |||||
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 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 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 32 | catch (A* p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 33 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 34 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 35 | } |
36 | catch (const A*) | ||||
37 | { | ||||
38 | assert(false); | ||||
39 | } | ||||
40 | } | ||||
41 | |||||
42 | |||||
43 | void test2() | ||||
44 | { | ||||
45 | try | ||||
46 | { | ||||
47 | throw nullptr; | ||||
48 | assert(false); | ||||
49 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 50 | catch (const A* p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 51 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 52 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 53 | } |
54 | catch (A*) | ||||
55 | { | ||||
56 | assert(false); | ||||
57 | } | ||||
58 | } | ||||
59 | |||||
60 | void test3() | ||||
61 | { | ||||
62 | try | ||||
63 | { | ||||
64 | throw nullptr; | ||||
65 | assert(false); | ||||
66 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 67 | catch (const A* const p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 68 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 69 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 70 | } |
71 | catch (A*) | ||||
72 | { | ||||
73 | assert(false); | ||||
74 | } | ||||
75 | } | ||||
76 | |||||
77 | void test4() | ||||
78 | { | ||||
79 | try | ||||
80 | { | ||||
81 | throw nullptr; | ||||
82 | assert(false); | ||||
83 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 84 | catch (A* p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 85 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 86 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 87 | } |
Marshall Clow | c22004f | 2013-12-04 05:39:55 +0000 | [diff] [blame] | 88 | catch (const A* const) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 89 | { |
90 | assert(false); | ||||
91 | } | ||||
92 | } | ||||
93 | |||||
94 | void test5() | ||||
95 | { | ||||
96 | try | ||||
97 | { | ||||
98 | throw nullptr; | ||||
99 | assert(false); | ||||
100 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 101 | catch (A const* p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 102 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 103 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 104 | } |
105 | catch (A*) | ||||
106 | { | ||||
107 | assert(false); | ||||
108 | } | ||||
109 | } | ||||
110 | |||||
111 | void test6() | ||||
112 | { | ||||
113 | try | ||||
114 | { | ||||
115 | throw nullptr; | ||||
116 | assert(false); | ||||
117 | } | ||||
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 118 | catch (A* p) |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 119 | { |
Richard Smith | 081ea86 | 2016-07-19 20:19:37 +0000 | [diff] [blame] | 120 | assert(!p); |
Marshall Clow | cf95bab | 2012-02-01 22:27:24 +0000 | [diff] [blame] | 121 | } |
122 | catch (A const*) | ||||
123 | { | ||||
124 | assert(false); | ||||
125 | } | ||||
126 | } | ||||
127 | |||||
128 | |||||
129 | #else | ||||
130 | |||||
131 | void test1() {} | ||||
132 | void test2() {} | ||||
133 | void test3() {} | ||||
134 | void test4() {} | ||||
135 | void test5() {} | ||||
136 | void test6() {} | ||||
137 | |||||
138 | #endif | ||||
139 | |||||
140 | int main() | ||||
141 | { | ||||
142 | test1(); | ||||
143 | test2(); | ||||
144 | test3(); | ||||
145 | test4(); | ||||
146 | test5(); | ||||
147 | test6(); | ||||
148 | } |