1 //===---------------------- catch_class_04.cpp ----------------------------===//
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: libcxxabi-no-exceptions
21 // Clang emits warnings about exceptions of type 'Child' being caught by
22 // an earlier handler of type 'Base'. Congrats clang, you've just
23 // diagnosed the behavior under test.
24 #if defined(__clang__)
25 #pragma clang diagnostic ignored "-Wexceptions"
32 explicit B(int id
) : id_(id
) {count
++;}
33 B(const B
& a
) : id_(a
.id_
) {count
++;}
44 explicit C1(int id
) : B(id
-2), id_(id
) {count
++;}
45 C1(const C1
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
56 explicit C2(int id
) : B(id
-2), id_(id
) {count
++;}
57 C2(const C2
& a
) : B(a
.id_
-2), id_(a
.id_
) {count
++;}
68 explicit A(int id
) : B(id
+3), C1(id
-1), C2(id
-2), id_(id
) {count
++;}
69 A(const A
& a
) : B(a
.id_
+3), C1(a
.id_
-1), C2(a
.id_
-2), id_(a
.id_
) {count
++;}
90 catch (const A
* a
) // can catch A
93 assert(static_cast<const C1
*>(a
)->id_
== 4);
94 assert(static_cast<const C2
*>(a
)->id_
== 3);
95 assert(static_cast<const B
*>(a
)->id_
== 8);
119 catch (const B
* a
) // can catch B
121 assert(static_cast<const B
*>(a
)->id_
== 8);
141 catch (const C2
* c2
) // can catch C2
143 assert(c2
->id_
== 3);
163 catch (const C1
* c1
) // can catch C1
165 assert(c1
->id_
== 4);
166 assert(static_cast<const B
*>(c1
)->id_
== 8);