1 //===---------------------- catch_class_04.cpp ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 This test checks that adjustedPtr is correct as there exist offsets in this
12 object for the various subobjects, all of which have a unique id_ to
13 check against. It also checks that virtual bases work properly
24 explicit B(int id
) : id_(id
) {count
++;}
25 B(const B
& a
) : id_(a
.id_
) {count
++;}
36 explicit C1(int id
) : B(id
-2), id_(id
) {count
++;}
37 C1(const C1
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
48 explicit C2(int id
) : B(id
-2), id_(id
) {count
++;}
49 C2(const C2
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
60 explicit A(int id
) : C1(id
-1), C2(id
-2), B(id
+3), id_(id
) {count
++;}
61 A(const A
& a
) : C1(a
.id_
-1), C2(a
.id_
-2), B(a
.id_
+3), id_(a
.id_
) {count
++;}
69 assert(A::count
== 0);
70 assert(C1::count
== 0);
71 assert(C2::count
== 0);
72 assert(B::count
== 0);
74 assert(A::count
== 1);
75 assert(C1::count
== 1);
76 assert(C2::count
== 1);
77 assert(B::count
== 1);
80 assert(static_cast<C1
&>(a
).id_
== 4);
81 assert(static_cast<C2
&>(a
).id_
== 3);
82 assert(static_cast<B
&>(a
).id_
== 8);
91 assert(A::count
== 0);
92 assert(C1::count
== 0);
93 assert(C2::count
== 0);
94 assert(B::count
== 0);
98 catch (const A
& a
) // can catch A
101 assert(static_cast<const C1
&>(a
).id_
== 4);
102 assert(static_cast<const C2
&>(a
).id_
== 3);
103 assert(static_cast<const B
&>(a
).id_
== 8);
124 assert(A::count
== 0);
125 assert(C1::count
== 0);
126 assert(C2::count
== 0);
127 assert(B::count
== 0);
131 catch (const B
& a
) // can catch B
133 assert(static_cast<const B
&>(a
).id_
== 8);
150 assert(A::count
== 0);
151 assert(C1::count
== 0);
152 assert(C2::count
== 0);
153 assert(B::count
== 0);
157 catch (const C2
& c2
) // can catch C2
162 catch (const B
& a
) // can not catch B (ambiguous base)
176 assert(A::count
== 0);
177 assert(C1::count
== 0);
178 assert(C2::count
== 0);
179 assert(B::count
== 0);
183 catch (const C1
& c1
) // can catch C1
186 assert(static_cast<const B
&>(c1
).id_
== 8);
209 assert(A::count
== 0);
210 assert(C1::count
== 0);
211 assert(C2::count
== 0);
212 assert(B::count
== 0);