[flang] Lower procedure pointer components (#75453)
[llvm-project.git] / libcxxabi / test / catch_ptr_02.pass.cpp
blobc7ef28a976f88390b9475e5e425b480a35bc5b65
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 // Compilers emit warnings about exceptions of type 'Child' being caught by
12 // an earlier handler of type 'Base'. Congrats, you've just diagnosed the
13 // behavior under test.
14 // ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
16 // The fix for PR17222 made it in the dylib for macOS 10.10
17 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.9
19 #include <cassert>
20 #include <stdint.h>
22 #if __cplusplus < 201103L
23 #define DISABLE_NULLPTR_TESTS
24 #endif
26 struct A {};
27 A a;
28 const A ca = A();
30 void test1 ()
32 try
34 throw &a;
35 assert(false);
37 catch ( const A* )
40 catch ( A *)
42 assert (false);
46 void test2 ()
48 try
50 throw &a;
51 assert(false);
53 catch ( A* )
56 catch ( const A *)
58 assert (false);
62 void test3 ()
64 try
66 throw &ca;
67 assert(false);
69 catch ( const A* )
72 catch ( A *)
74 assert (false);
78 void test4 ()
80 try
82 throw &ca;
83 assert(false);
85 catch ( A *)
87 assert (false);
89 catch ( const A* )
94 struct base1 {int x;};
95 struct base2 {int x;};
96 struct derived : base1, base2 {};
98 void test5 ()
102 throw (derived*)0;
103 assert(false);
105 catch (base2 *p) {
106 assert (p == 0);
108 catch (...)
110 assert (false);
114 void test6 ()
116 #if !defined(DISABLE_NULLPTR_TESTS)
119 throw nullptr;
120 assert(false);
122 catch (base2 *p) {
123 assert (p == nullptr);
125 catch (...)
127 assert (false);
129 #endif
132 void test7 ()
136 throw (derived*)12;
137 assert(false);
139 catch (base2 *p) {
140 assert ((uintptr_t)p == 12+sizeof(base1));
142 catch (...)
144 assert (false);
149 struct vBase {};
150 struct vDerived : virtual public vBase {};
152 void test8 ()
154 vDerived derived;
157 throw &derived;
158 assert(false);
160 catch (vBase *p) {
161 assert(p != 0);
163 catch (...)
165 assert (false);
169 void test9 ()
171 #if !defined(DISABLE_NULLPTR_TESTS)
174 throw nullptr;
175 assert(false);
177 catch (vBase *p) {
178 assert(p == 0);
180 catch (...)
182 assert (false);
184 #endif
187 void test10 ()
191 throw (vDerived*)0;
192 assert(false);
194 catch (vBase *p) {
195 assert(p == 0);
197 catch (...)
199 assert (false);
203 int main(int, char**)
205 test1();
206 test2();
207 test3();
208 test4();
209 test5();
210 test6();
211 test7();
212 test8();
213 test9();
214 test10();
216 return 0;