1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
10 This test checks that adjustedPtr is correct as there exist offsets in this
11 object for the various subobjects, all of which have a unique id_ to
12 check against. It also checks that virtual bases work properly
15 // UNSUPPORTED: no-exceptions
17 // Compilers emit warnings about exceptions of type 'Child' being caught by
18 // an earlier handler of type 'Base'. Congrats, you've just diagnosed the
19 // behavior under test.
20 // ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
30 explicit B(int id
) : id_(id
) {count
++;}
31 B(const B
& a
) : id_(a
.id_
) {count
++;}
42 explicit C1(int id
) : B(id
-2), id_(id
) {count
++;}
43 C1(const C1
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
54 explicit C2(int id
) : B(id
-2), id_(id
) {count
++;}
55 C2(const C2
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
66 explicit A(int id
) : B(id
+3), C1(id
-1), C2(id
-2), id_(id
) {count
++;}
67 A(const A
& a
) : B(a
.id_
+3), C1(a
.id_
-1), C2(a
.id_
-2), id_(a
.id_
) {count
++;}
75 assert(A::count
== 0);
76 assert(C1::count
== 0);
77 assert(C2::count
== 0);
78 assert(B::count
== 0);
80 assert(A::count
== 1);
81 assert(C1::count
== 1);
82 assert(C2::count
== 1);
83 assert(B::count
== 1);
86 assert(static_cast<C1
&>(a
).id_
== 4);
87 assert(static_cast<C2
&>(a
).id_
== 3);
88 assert(static_cast<B
&>(a
).id_
== 8);
97 assert(A::count
== 0);
98 assert(C1::count
== 0);
99 assert(C2::count
== 0);
100 assert(B::count
== 0);
104 catch (const A
& a
) // can catch A
107 assert(static_cast<const C1
&>(a
).id_
== 4);
108 assert(static_cast<const C2
&>(a
).id_
== 3);
109 assert(static_cast<const B
&>(a
).id_
== 8);
130 assert(A::count
== 0);
131 assert(C1::count
== 0);
132 assert(C2::count
== 0);
133 assert(B::count
== 0);
137 catch (const B
& a
) // can catch B
139 assert(static_cast<const B
&>(a
).id_
== 8);
156 assert(A::count
== 0);
157 assert(C1::count
== 0);
158 assert(C2::count
== 0);
159 assert(B::count
== 0);
163 catch (const C2
& c2
) // can catch C2
168 catch (const B
& a
) // can not catch B (ambiguous base)
182 assert(A::count
== 0);
183 assert(C1::count
== 0);
184 assert(C2::count
== 0);
185 assert(B::count
== 0);
189 catch (const C1
& c1
) // can catch C1
192 assert(static_cast<const B
&>(c1
).id_
== 8);
205 int main(int, char**)
215 assert(A::count
== 0);
216 assert(C1::count
== 0);
217 assert(C2::count
== 0);
218 assert(B::count
== 0);