[M68k] always use movem for register spills (#106715)
[llvm-project.git] / libcxxabi / test / catch_ptr_02.pass.cpp
blob3662464ce43fdce4eb1b07b8fafe7d2f11a39030
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 #include <cassert>
17 #include <stdint.h>
19 #if __cplusplus < 201103L
20 #define DISABLE_NULLPTR_TESTS
21 #endif
23 struct A {};
24 A a;
25 const A ca = A();
27 void test1 ()
29 try
31 throw &a;
32 assert(false);
34 catch ( const A* )
37 catch ( A *)
39 assert (false);
43 void test2 ()
45 try
47 throw &a;
48 assert(false);
50 catch ( A* )
53 catch ( const A *)
55 assert (false);
59 void test3 ()
61 try
63 throw &ca;
64 assert(false);
66 catch ( const A* )
69 catch ( A *)
71 assert (false);
75 void test4 ()
77 try
79 throw &ca;
80 assert(false);
82 catch ( A *)
84 assert (false);
86 catch ( const A* )
91 struct base1 {int x;};
92 struct base2 {int x;};
93 struct derived : base1, base2 {};
95 void test5 ()
97 try
99 throw (derived*)0;
100 assert(false);
102 catch (base2 *p) {
103 assert (p == 0);
105 catch (...)
107 assert (false);
111 void test6 ()
113 #if !defined(DISABLE_NULLPTR_TESTS)
116 throw nullptr;
117 assert(false);
119 catch (base2 *p) {
120 assert (p == nullptr);
122 catch (...)
124 assert (false);
126 #endif
129 void test7 ()
133 throw (derived*)12;
134 assert(false);
136 catch (base2 *p) {
137 assert ((uintptr_t)p == 12+sizeof(base1));
139 catch (...)
141 assert (false);
146 struct vBase {};
147 struct vDerived : virtual public vBase {};
149 void test8 ()
151 vDerived derived;
154 throw &derived;
155 assert(false);
157 catch (vBase *p) {
158 assert(p != 0);
160 catch (...)
162 assert (false);
166 void test9 ()
168 #if !defined(DISABLE_NULLPTR_TESTS)
171 throw nullptr;
172 assert(false);
174 catch (vBase *p) {
175 assert(p == 0);
177 catch (...)
179 assert (false);
181 #endif
184 void test10 ()
188 throw (vDerived*)0;
189 assert(false);
191 catch (vBase *p) {
192 assert(p == 0);
194 catch (...)
196 assert (false);
200 int main(int, char**)
202 test1();
203 test2();
204 test3();
205 test4();
206 test5();
207 test6();
208 test7();
209 test8();
210 test9();
211 test10();
213 return 0;