annotate libcxxabi/test/dynamic_cast.pass.cpp @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
1 //===----------------------------------------------------------------------===//
150
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9 // PR33425 and PR33487 are not fixed until the dylib shipped with macOS 10.15
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
10 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.14
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 // PR33439 isn't fixed until the dylib shipped with macOS 10.14
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
13 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12|13}}
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
14
150
anatofuz
parents:
diff changeset
15 #include <cassert>
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 // This test explicitly tests dynamic cast with types that have inaccessible
anatofuz
parents:
diff changeset
18 // bases.
anatofuz
parents:
diff changeset
19 #if defined(__clang__)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20 # pragma clang diagnostic ignored "-Winaccessible-base"
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
21 #elif defined(__GNUC__)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
22 # pragma GCC diagnostic ignored "-Winaccessible-base"
150
anatofuz
parents:
diff changeset
23 #endif
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 typedef char Pad1[43981];
anatofuz
parents:
diff changeset
26 typedef char Pad2[34981];
anatofuz
parents:
diff changeset
27 typedef char Pad3[93481];
anatofuz
parents:
diff changeset
28 typedef char Pad4[13489];
anatofuz
parents:
diff changeset
29 typedef char Pad5[81349];
anatofuz
parents:
diff changeset
30 typedef char Pad6[34819];
anatofuz
parents:
diff changeset
31 typedef char Pad7[3489];
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 namespace t1
anatofuz
parents:
diff changeset
34 {
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 // PR33425
anatofuz
parents:
diff changeset
37 struct C3 { virtual ~C3() {} Pad1 _; };
anatofuz
parents:
diff changeset
38 struct C5 : protected virtual C3 { Pad2 _; };
anatofuz
parents:
diff changeset
39 struct C6 : virtual C5 { Pad3 _; };
anatofuz
parents:
diff changeset
40 struct C7 : virtual C3 { Pad4 _; };
anatofuz
parents:
diff changeset
41 struct C9 : C6, C7 { Pad5 _; };
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 C9 c9;
anatofuz
parents:
diff changeset
44 C3 *c3 = &c9;
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 void test()
anatofuz
parents:
diff changeset
47 {
anatofuz
parents:
diff changeset
48 assert(dynamic_cast<C3*>(c3) == static_cast<C3*>(&c9));
anatofuz
parents:
diff changeset
49 assert(dynamic_cast<C5*>(c3) == static_cast<C5*>(&c9));
anatofuz
parents:
diff changeset
50 assert(dynamic_cast<C6*>(c3) == static_cast<C6*>(&c9));
anatofuz
parents:
diff changeset
51 assert(dynamic_cast<C7*>(c3) == static_cast<C7*>(&c9));
anatofuz
parents:
diff changeset
52 assert(dynamic_cast<C9*>(c3) == static_cast<C9*>(&c9));
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 } // t1
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 namespace t2
anatofuz
parents:
diff changeset
58 {
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 // PR33425
anatofuz
parents:
diff changeset
61 struct Src { virtual ~Src() {} Pad1 _; };
anatofuz
parents:
diff changeset
62 struct Mask : protected virtual Src { Pad2 _; };
anatofuz
parents:
diff changeset
63 struct Dest : Mask { Pad3 _; };
anatofuz
parents:
diff changeset
64 struct Root : Dest, virtual Src { Pad4 _; };
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 Root root;
anatofuz
parents:
diff changeset
67 Src *src = &root;
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 void test()
anatofuz
parents:
diff changeset
70 {
anatofuz
parents:
diff changeset
71 assert(dynamic_cast<Src*>(src) == static_cast<Src*>(&root));
anatofuz
parents:
diff changeset
72 assert(dynamic_cast<Mask*>(src) == static_cast<Mask*>(&root));
anatofuz
parents:
diff changeset
73 assert(dynamic_cast<Dest*>(src) == static_cast<Dest*>(&root));
anatofuz
parents:
diff changeset
74 assert(dynamic_cast<Root*>(src) == static_cast<Root*>(&root));
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 } // t2
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 namespace t3
anatofuz
parents:
diff changeset
80 {
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 // PR33487
anatofuz
parents:
diff changeset
83 struct Class1 { virtual ~Class1() {} Pad1 _; };
anatofuz
parents:
diff changeset
84 struct Shared : virtual Class1 { Pad2 _; };
anatofuz
parents:
diff changeset
85 struct Class6 : virtual Shared { Pad3 _; };
anatofuz
parents:
diff changeset
86 struct Left : Class6 { Pad4 _; };
anatofuz
parents:
diff changeset
87 struct Right : Class6 { Pad5 _; };
anatofuz
parents:
diff changeset
88 struct Main : Left, Right { Pad6 _; };
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 Main m;
anatofuz
parents:
diff changeset
91 Class1 *c1 = &m;
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 void test()
anatofuz
parents:
diff changeset
94 {
anatofuz
parents:
diff changeset
95 assert(dynamic_cast<Class1*>(c1) == static_cast<Class1*>(&m));
anatofuz
parents:
diff changeset
96 assert(dynamic_cast<Shared*>(c1) == static_cast<Shared*>(&m));
anatofuz
parents:
diff changeset
97 assert(dynamic_cast<Class6*>(c1) == 0);
anatofuz
parents:
diff changeset
98 assert(dynamic_cast<Left*>(c1) == static_cast<Left*>(&m));
anatofuz
parents:
diff changeset
99 assert(dynamic_cast<Right*>(c1) == static_cast<Right*>(&m));
anatofuz
parents:
diff changeset
100 assert(dynamic_cast<Main*>(c1) == static_cast<Main*>(&m));
anatofuz
parents:
diff changeset
101 }
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 } // t3
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 namespace t4
anatofuz
parents:
diff changeset
106 {
anatofuz
parents:
diff changeset
107
anatofuz
parents:
diff changeset
108 // PR33439
anatofuz
parents:
diff changeset
109 struct C2 { virtual ~C2() {} Pad1 _; };
anatofuz
parents:
diff changeset
110 struct C3 { virtual ~C3() {} Pad2 _; };
anatofuz
parents:
diff changeset
111 struct C4 : C3 { Pad3 _; };
anatofuz
parents:
diff changeset
112 struct C8 : C2, virtual C4 { Pad4 _; };
anatofuz
parents:
diff changeset
113 struct C9 : C4, C8 { Pad5 _; };
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 C9 c9;
anatofuz
parents:
diff changeset
116 C2 *c2 = &c9;
anatofuz
parents:
diff changeset
117
anatofuz
parents:
diff changeset
118 void test()
anatofuz
parents:
diff changeset
119 {
anatofuz
parents:
diff changeset
120 assert(dynamic_cast<C2*>(c2) == static_cast<C2*>(&c9));
anatofuz
parents:
diff changeset
121 assert(dynamic_cast<C3*>(c2) == 0);
anatofuz
parents:
diff changeset
122 assert(dynamic_cast<C4*>(c2) == 0);
anatofuz
parents:
diff changeset
123 assert(dynamic_cast<C8*>(c2) == static_cast<C8*>(&c9));
anatofuz
parents:
diff changeset
124 assert(dynamic_cast<C9*>(c2) == static_cast<C9*>(&c9));
anatofuz
parents:
diff changeset
125 }
anatofuz
parents:
diff changeset
126
anatofuz
parents:
diff changeset
127 } // t4
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 namespace t5
anatofuz
parents:
diff changeset
130 {
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 // PR33439
anatofuz
parents:
diff changeset
133 struct Dummy { virtual ~Dummy() {} Pad1 _; };
anatofuz
parents:
diff changeset
134 struct Src { virtual ~Src() {} Pad2 _; };
anatofuz
parents:
diff changeset
135 struct Dest : Dummy { Pad3 _; };
anatofuz
parents:
diff changeset
136 struct A1 : Dest { Pad4 _; };
anatofuz
parents:
diff changeset
137 struct A2 : Dest { Pad5 _; };
anatofuz
parents:
diff changeset
138 struct Root : Src, A1, A2 { Pad6 _; };
anatofuz
parents:
diff changeset
139
anatofuz
parents:
diff changeset
140 Root root;
anatofuz
parents:
diff changeset
141 Src *src = &root;
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 void test()
anatofuz
parents:
diff changeset
144 {
anatofuz
parents:
diff changeset
145 assert(dynamic_cast<Dummy*>(src) == 0);
anatofuz
parents:
diff changeset
146 assert(dynamic_cast<Src*>(src) == static_cast<Src*>(&root));
anatofuz
parents:
diff changeset
147 assert(dynamic_cast<Dest*>(src) == 0);
anatofuz
parents:
diff changeset
148 assert(dynamic_cast<A1*>(src) == static_cast<A1*>(&root));
anatofuz
parents:
diff changeset
149 assert(dynamic_cast<A2*>(src) == static_cast<A2*>(&root));
anatofuz
parents:
diff changeset
150 }
anatofuz
parents:
diff changeset
151
anatofuz
parents:
diff changeset
152 } // t5
anatofuz
parents:
diff changeset
153
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
154 int main(int, char**)
150
anatofuz
parents:
diff changeset
155 {
anatofuz
parents:
diff changeset
156 t1::test();
anatofuz
parents:
diff changeset
157 t2::test();
anatofuz
parents:
diff changeset
158 t3::test();
anatofuz
parents:
diff changeset
159 t4::test();
anatofuz
parents:
diff changeset
160 t5::test();
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
161
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
162 return 0;
150
anatofuz
parents:
diff changeset
163 }