[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / test / catch_const_pointer_nullptr.pass.cpp
bloba0d1f36f050f05e9865c6af8bc7c66b5c175ff74
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 #include <cassert>
13 // Clang emits warnings about exceptions of type 'Child' being caught by
14 // an earlier handler of type 'Base'. Congrats clang, you've just
15 // diagnosed the behavior under test.
16 #if defined(__clang__)
17 #pragma clang diagnostic ignored "-Wexceptions"
18 #endif
20 #if __has_feature(cxx_nullptr)
22 struct A {};
24 void test1()
26 try
28 throw nullptr;
29 assert(false);
31 catch (A* p)
33 assert(!p);
35 catch (const A*)
37 assert(false);
42 void test2()
44 try
46 throw nullptr;
47 assert(false);
49 catch (const A* p)
51 assert(!p);
53 catch (A*)
55 assert(false);
59 void test3()
61 try
63 throw nullptr;
64 assert(false);
66 catch (const A* const p)
68 assert(!p);
70 catch (A*)
72 assert(false);
76 void test4()
78 try
80 throw nullptr;
81 assert(false);
83 catch (A* p)
85 assert(!p);
87 catch (const A* const)
89 assert(false);
93 void test5()
95 try
97 throw nullptr;
98 assert(false);
100 catch (A const* p)
102 assert(!p);
104 catch (A*)
106 assert(false);
110 void test6()
114 throw nullptr;
115 assert(false);
117 catch (A* p)
119 assert(!p);
121 catch (A const*)
123 assert(false);
128 #else
130 void test1() {}
131 void test2() {}
132 void test3() {}
133 void test4() {}
134 void test5() {}
135 void test6() {}
137 #endif
139 int main(int, char**) {
140 test1();
141 test2();
142 test3();
143 test4();
144 test5();
145 test6();
147 return 0;