annotate libcxxabi/test/catch_ptr.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 c4bab56944e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents: 221
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
anatofuz
parents:
diff changeset
9 /*
anatofuz
parents:
diff changeset
10 This test checks that adjustedPtr is correct as there exist offsets in this
anatofuz
parents:
diff changeset
11 object for the various subobjects, all of which have a unique id_ to
anatofuz
parents:
diff changeset
12 check against. It also checks that virtual bases work properly
anatofuz
parents:
diff changeset
13 */
anatofuz
parents:
diff changeset
14
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 // UNSUPPORTED: no-exceptions
150
anatofuz
parents:
diff changeset
16
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
17 // Compilers emit warnings about exceptions of type 'Child' being caught by
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
18 // an earlier handler of type 'Base'. Congrats, you've just diagnosed the
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
19 // behavior under test.
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
20 // ADDITIONAL_COMPILE_FLAGS: -Wno-exceptions
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21
150
anatofuz
parents:
diff changeset
22 #include <exception>
anatofuz
parents:
diff changeset
23 #include <stdlib.h>
anatofuz
parents:
diff changeset
24 #include <assert.h>
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 struct B
anatofuz
parents:
diff changeset
27 {
anatofuz
parents:
diff changeset
28 static int count;
anatofuz
parents:
diff changeset
29 int id_;
anatofuz
parents:
diff changeset
30 explicit B(int id) : id_(id) {count++;}
anatofuz
parents:
diff changeset
31 B(const B& a) : id_(a.id_) {count++;}
anatofuz
parents:
diff changeset
32 ~B() {count--;}
anatofuz
parents:
diff changeset
33 };
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 int B::count = 0;
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 struct C1
anatofuz
parents:
diff changeset
38 : virtual B
anatofuz
parents:
diff changeset
39 {
anatofuz
parents:
diff changeset
40 static int count;
anatofuz
parents:
diff changeset
41 int id_;
anatofuz
parents:
diff changeset
42 explicit C1(int id) : B(id-2), id_(id) {count++;}
anatofuz
parents:
diff changeset
43 C1(const C1& a) : B(a.id_-2), id_(a.id_) {count++;}
anatofuz
parents:
diff changeset
44 ~C1() {count--;}
anatofuz
parents:
diff changeset
45 };
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 int C1::count = 0;
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 struct C2
anatofuz
parents:
diff changeset
50 : virtual private B
anatofuz
parents:
diff changeset
51 {
anatofuz
parents:
diff changeset
52 static int count;
anatofuz
parents:
diff changeset
53 int id_;
anatofuz
parents:
diff changeset
54 explicit C2(int id) : B(id-2), id_(id) {count++;}
anatofuz
parents:
diff changeset
55 C2(const C2& a) : B(a.id_-2), id_(a.id_) {count++;}
anatofuz
parents:
diff changeset
56 ~C2() {count--;}
anatofuz
parents:
diff changeset
57 };
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 int C2::count = 0;
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 struct A
anatofuz
parents:
diff changeset
62 : C1, C2
anatofuz
parents:
diff changeset
63 {
anatofuz
parents:
diff changeset
64 static int count;
anatofuz
parents:
diff changeset
65 int id_;
anatofuz
parents:
diff changeset
66 explicit A(int id) : B(id+3), C1(id-1), C2(id-2), id_(id) {count++;}
anatofuz
parents:
diff changeset
67 A(const A& a) : B(a.id_+3), C1(a.id_-1), C2(a.id_-2), id_(a.id_) {count++;}
anatofuz
parents:
diff changeset
68 ~A() {count--;}
anatofuz
parents:
diff changeset
69 };
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 int A::count = 0;
anatofuz
parents:
diff changeset
72
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
73 A global_a(5);
150
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 void f1()
anatofuz
parents:
diff changeset
76 {
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
77 throw &global_a;
150
anatofuz
parents:
diff changeset
78 assert(false);
anatofuz
parents:
diff changeset
79 }
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 void f2()
anatofuz
parents:
diff changeset
82 {
anatofuz
parents:
diff changeset
83 try
anatofuz
parents:
diff changeset
84 {
anatofuz
parents:
diff changeset
85 f1();
anatofuz
parents:
diff changeset
86 assert(false);
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88 catch (const A* a) // can catch A
anatofuz
parents:
diff changeset
89 {
anatofuz
parents:
diff changeset
90 assert(a->id_ == 5);
anatofuz
parents:
diff changeset
91 assert(static_cast<const C1*>(a)->id_ == 4);
anatofuz
parents:
diff changeset
92 assert(static_cast<const C2*>(a)->id_ == 3);
anatofuz
parents:
diff changeset
93 assert(static_cast<const B*>(a)->id_ == 8);
anatofuz
parents:
diff changeset
94 throw;
anatofuz
parents:
diff changeset
95 }
anatofuz
parents:
diff changeset
96 catch (const C1*)
anatofuz
parents:
diff changeset
97 {
anatofuz
parents:
diff changeset
98 assert(false);
anatofuz
parents:
diff changeset
99 }
anatofuz
parents:
diff changeset
100 catch (const C2*)
anatofuz
parents:
diff changeset
101 {
anatofuz
parents:
diff changeset
102 assert(false);
anatofuz
parents:
diff changeset
103 }
anatofuz
parents:
diff changeset
104 catch (const B*)
anatofuz
parents:
diff changeset
105 {
anatofuz
parents:
diff changeset
106 assert(false);
anatofuz
parents:
diff changeset
107 }
anatofuz
parents:
diff changeset
108 }
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 void f3()
anatofuz
parents:
diff changeset
111 {
anatofuz
parents:
diff changeset
112 try
anatofuz
parents:
diff changeset
113 {
anatofuz
parents:
diff changeset
114 f2();
anatofuz
parents:
diff changeset
115 assert(false);
anatofuz
parents:
diff changeset
116 }
anatofuz
parents:
diff changeset
117 catch (const B* a) // can catch B
anatofuz
parents:
diff changeset
118 {
anatofuz
parents:
diff changeset
119 assert(static_cast<const B*>(a)->id_ == 8);
anatofuz
parents:
diff changeset
120 throw;
anatofuz
parents:
diff changeset
121 }
anatofuz
parents:
diff changeset
122 catch (const C1* c1)
anatofuz
parents:
diff changeset
123 {
anatofuz
parents:
diff changeset
124 assert(false);
anatofuz
parents:
diff changeset
125 }
anatofuz
parents:
diff changeset
126 catch (const C2*)
anatofuz
parents:
diff changeset
127 {
anatofuz
parents:
diff changeset
128 assert(false);
anatofuz
parents:
diff changeset
129 }
anatofuz
parents:
diff changeset
130 }
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 void f4()
anatofuz
parents:
diff changeset
133 {
anatofuz
parents:
diff changeset
134 try
anatofuz
parents:
diff changeset
135 {
anatofuz
parents:
diff changeset
136 f3();
anatofuz
parents:
diff changeset
137 assert(false);
anatofuz
parents:
diff changeset
138 }
anatofuz
parents:
diff changeset
139 catch (const C2* c2) // can catch C2
anatofuz
parents:
diff changeset
140 {
anatofuz
parents:
diff changeset
141 assert(c2->id_ == 3);
anatofuz
parents:
diff changeset
142 throw;
anatofuz
parents:
diff changeset
143 }
anatofuz
parents:
diff changeset
144 catch (const B* a)
anatofuz
parents:
diff changeset
145 {
anatofuz
parents:
diff changeset
146 assert(false);
anatofuz
parents:
diff changeset
147 }
anatofuz
parents:
diff changeset
148 catch (const C1*)
anatofuz
parents:
diff changeset
149 {
anatofuz
parents:
diff changeset
150 assert(false);
anatofuz
parents:
diff changeset
151 }
anatofuz
parents:
diff changeset
152 }
anatofuz
parents:
diff changeset
153
anatofuz
parents:
diff changeset
154 void f5()
anatofuz
parents:
diff changeset
155 {
anatofuz
parents:
diff changeset
156 try
anatofuz
parents:
diff changeset
157 {
anatofuz
parents:
diff changeset
158 f4();
anatofuz
parents:
diff changeset
159 assert(false);
anatofuz
parents:
diff changeset
160 }
anatofuz
parents:
diff changeset
161 catch (const C1* c1) // can catch C1
anatofuz
parents:
diff changeset
162 {
anatofuz
parents:
diff changeset
163 assert(c1->id_ == 4);
anatofuz
parents:
diff changeset
164 assert(static_cast<const B*>(c1)->id_ == 8);
anatofuz
parents:
diff changeset
165 throw;
anatofuz
parents:
diff changeset
166 }
anatofuz
parents:
diff changeset
167 catch (const B* a)
anatofuz
parents:
diff changeset
168 {
anatofuz
parents:
diff changeset
169 assert(false);
anatofuz
parents:
diff changeset
170 }
anatofuz
parents:
diff changeset
171 catch (const C2*)
anatofuz
parents:
diff changeset
172 {
anatofuz
parents:
diff changeset
173 assert(false);
anatofuz
parents:
diff changeset
174 }
anatofuz
parents:
diff changeset
175 }
anatofuz
parents:
diff changeset
176
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
177 int main(int, char**)
150
anatofuz
parents:
diff changeset
178 {
anatofuz
parents:
diff changeset
179 try
anatofuz
parents:
diff changeset
180 {
anatofuz
parents:
diff changeset
181 f5();
anatofuz
parents:
diff changeset
182 assert(false);
anatofuz
parents:
diff changeset
183 }
anatofuz
parents:
diff changeset
184 catch (...)
anatofuz
parents:
diff changeset
185 {
anatofuz
parents:
diff changeset
186 }
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
187
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
188 return 0;
150
anatofuz
parents:
diff changeset
189 }