[ARM] Stop gluing ALU nodes to branches / selects (#116970)
[llvm-project.git] / libcxxabi / test / inherited_exception.pass.cpp
blobdc00a573c96ef69952d7283baf1c6385da3f65c9
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 //===----------------------------------------------------------------------===//
8 //
9 // This test case checks specifically the cases under C++ ABI 15.3.1, and 15.3.2
11 // C++ ABI 15.3:
12 // A handler is a match for an exception object of type E if
13 // > * The handler is of type cv T or cv T& and E and T are the same type <
14 // > (ignoring the top-level cv-qualifiers), or <
15 // > * the handler is of type cv T or cv T& and T is an unambiguous base <
16 // > class of E, or <
17 // * the handler is of type cv1 T* cv2 and E is a pointer type that can
18 // be converted to the type of the handler by either or both of
19 // o a standard pointer conversion (4.10 [conv.ptr]) not involving
20 // conversions to private or protected or ambiguous classes
21 // o a qualification conversion
22 // * the handler is a pointer or pointer to member type and E is
23 // std::nullptr_t
25 //===----------------------------------------------------------------------===//
27 // UNSUPPORTED: no-exceptions
29 // Compilers emit warnings about exceptions of type 'Child' being caught by
30 // an earlier handler of type 'Base'. Congrats, you've just diagnosed the
31 // behavior under test.
32 // ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
34 #include <assert.h>
36 struct Base {
37 int b1;
40 struct Base2 {
41 int b2;
44 struct Child : public Base, public Base2 {
45 int c;
48 void f1() {
49 Child child;
50 child.b1 = 10;
51 child.b2 = 11;
52 child.c = 12;
53 throw child;
56 void f2() {
57 Child child;
58 child.b1 = 10;
59 child.b2 = 11;
60 child.c = 12;
61 throw static_cast<Base2&>(child);
64 void f3() {
65 static Child child;
66 child.b1 = 10;
67 child.b2 = 11;
68 child.c = 12;
69 throw static_cast<Base2*>(&child);
72 int main(int, char**)
74 try
76 f1();
77 assert(false);
79 catch (const Child& c)
81 assert(true);
83 catch (const Base& b)
85 assert(false);
87 catch (...)
89 assert(false);
92 try
94 f1();
95 assert(false);
97 catch (const Base& c)
99 assert(true);
101 catch (const Child& b)
103 assert(false);
105 catch (...)
107 assert(false);
112 f1();
113 assert(false);
115 catch (const Base2& c)
117 assert(true);
119 catch (const Child& b)
121 assert(false);
123 catch (...)
125 assert(false);
130 f2();
131 assert(false);
133 catch (const Child& c)
135 assert(false);
137 catch (const Base& b)
139 assert(false);
141 catch (const Base2& b)
143 assert(true);
145 catch (...)
147 assert(false);
152 f3();
153 assert(false);
155 catch (const Base* c)
157 assert(false);
159 catch (const Child* b)
161 assert(false);
163 catch (const Base2* c)
165 assert(true);
167 catch (...)
169 assert(false);
172 return 0;