blob: 763e26a434f694a6115bb2af14ae4943a27b205d [file] [log] [blame]
Jonathan Roelofs72a15cd2014-06-03 21:50:11 +00001//===--------------------- inherited_exception.cpp ------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This test case checks specifically the cases under C++ ABI 15.3.1, and 15.3.2
11//
12// C++ ABI 15.3:
13// A handler is a match for an exception object of type E if
14// / * The handler is of type cv T or cv T& and E and T are the same type \
15// | (ignoring the top-level cv-qualifiers), or |
16// | * the handler is of type cv T or cv T& and T is an unambiguous base |
17// \ class of E, or /
18// * the handler is of type cv1 T* cv2 and E is a pointer type that can
19// be converted to the type of the handler by either or both of
20// o a standard pointer conversion (4.10 [conv.ptr]) not involving
21// conversions to private or protected or ambiguous classes
22// o a qualification conversion
23// * the handler is a pointer or pointer to member type and E is
24// std::nullptr_t
25//
26//===----------------------------------------------------------------------===//
27
Asiri Rathnayake57e446d2016-05-31 12:01:32 +000028// UNSUPPORTED: libcxxabi-no-exceptions
29
Jonathan Roelofs72a15cd2014-06-03 21:50:11 +000030#include <assert.h>
31
32struct Base {
33 int b1;
34};
35
36struct Base2 {
37 int b2;
38};
39
40struct Child : public Base, public Base2 {
41 int c;
42};
43
44void f1() {
45 Child child;
46 child.b1 = 10;
47 child.b2 = 11;
48 child.c = 12;
49 throw child;
50}
51
52void f2() {
53 Child child;
54 child.b1 = 10;
55 child.b2 = 11;
56 child.c = 12;
57 throw static_cast<Base2&>(child);
58}
59
60void f3() {
Eric Fiseliera3158652014-11-21 01:53:51 +000061 static Child child;
62 child.b1 = 10;
63 child.b2 = 11;
64 child.c = 12;
65 throw static_cast<Base2*>(&child);
Jonathan Roelofs72a15cd2014-06-03 21:50:11 +000066}
67
68int main()
69{
70 try
71 {
72 f1();
73 assert(false);
74 }
75 catch (const Child& c)
76 {
77 assert(true);
78 }
79 catch (const Base& b)
80 {
81 assert(false);
82 }
83 catch (...)
84 {
85 assert(false);
86 }
87
88 try
89 {
90 f1();
91 assert(false);
92 }
93 catch (const Base& c)
94 {
95 assert(true);
96 }
97 catch (const Child& b)
98 {
99 assert(false);
100 }
101 catch (...)
102 {
103 assert(false);
104 }
105
106 try
107 {
108 f1();
109 assert(false);
110 }
111 catch (const Base2& c)
112 {
113 assert(true);
114 }
115 catch (const Child& b)
116 {
117 assert(false);
118 }
119 catch (...)
120 {
121 assert(false);
122 }
123
124 try
125 {
126 f2();
127 assert(false);
128 }
129 catch (const Child& c)
130 {
131 assert(false);
132 }
133 catch (const Base& b)
134 {
135 assert(false);
136 }
137 catch (const Base2& b)
138 {
139 assert(true);
140 }
141 catch (...)
142 {
143 assert(false);
144 }
145
146 try
147 {
148 f3();
149 assert(false);
150 }
151 catch (const Base* c)
152 {
153 assert(false);
154 }
155 catch (const Child* b)
156 {
157 assert(false);
158 }
159 catch (const Base2* c)
160 {
161 assert(true);
162 }
163 catch (...)
164 {
165 assert(false);
166 }
167}