Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / libcxxabi / test / inherited_exception.pass.cpp
blob784637621697ff5400901c2dbab7d336c9c969b9
1 //===--------------------- inherited_exception.cpp ------------------------===//
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: libcxxabi-no-exceptions
29 // Clang emits warnings about exceptions of type 'Child' being caught by
30 // an earlier handler of type 'Base'. Congrats clang, you've just
31 // diagnosed the behavior under test.
32 #if defined(__clang__)
33 #pragma clang diagnostic ignored "-Wexceptions"
34 #endif
36 #include <assert.h>
38 struct Base {
39 int b1;
42 struct Base2 {
43 int b2;
46 struct Child : public Base, public Base2 {
47 int c;
50 void f1() {
51 Child child;
52 child.b1 = 10;
53 child.b2 = 11;
54 child.c = 12;
55 throw child;
58 void f2() {
59 Child child;
60 child.b1 = 10;
61 child.b2 = 11;
62 child.c = 12;
63 throw static_cast<Base2&>(child);
66 void f3() {
67 static Child child;
68 child.b1 = 10;
69 child.b2 = 11;
70 child.c = 12;
71 throw static_cast<Base2*>(&child);
74 int main()
76 try
78 f1();
79 assert(false);
81 catch (const Child& c)
83 assert(true);
85 catch (const Base& b)
87 assert(false);
89 catch (...)
91 assert(false);
94 try
96 f1();
97 assert(false);
99 catch (const Base& c)
101 assert(true);
103 catch (const Child& b)
105 assert(false);
107 catch (...)
109 assert(false);
114 f1();
115 assert(false);
117 catch (const Base2& c)
119 assert(true);
121 catch (const Child& b)
123 assert(false);
125 catch (...)
127 assert(false);
132 f2();
133 assert(false);
135 catch (const Child& c)
137 assert(false);
139 catch (const Base& b)
141 assert(false);
143 catch (const Base2& b)
145 assert(true);
147 catch (...)
149 assert(false);
154 f3();
155 assert(false);
157 catch (const Base* c)
159 assert(false);
161 catch (const Child* b)
163 assert(false);
165 catch (const Base2* c)
167 assert(true);
169 catch (...)
171 assert(false);