1//===----------------------------------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include <cassert>
10#include "support/timer.h"
11
12// This test explicitly tests dynamic cast with types that have inaccessible
13// bases.
14#if defined(__clang__)
15# pragma clang diagnostic ignored "-Winaccessible-base"
16#elif defined(__GNUC__)
17# pragma GCC diagnostic ignored "-Winaccessible-base"
18#endif
19
20namespace t1
21{
22
23struct A1
24{
25 char _[43981];
26 virtual ~A1() {}
27
28 A1* getA1() {return this;}
29};
30
31struct A2
32{
33 char _[34981];
34 virtual ~A2() {}
35
36 A2* getA2() {return this;}
37};
38
39struct A3
40 : public virtual A1,
41 private A2
42{
43 char _[93481];
44 virtual ~A3() {}
45
46 A1* getA1() {return A1::getA1();}
47 A2* getA2() {return A2::getA2();}
48 A3* getA3() {return this;}
49};
50
51struct A4
52 : public A3,
53 public A2
54{
55 char _[13489];
56 virtual ~A4() {}
57
58 t1::A1* getA1() {return A3::getA1();}
59 A2* getA2() {return A3::getA2();}
60 A3* getA3() {return A3::getA3();}
61 A4* getA4() {return this;}
62};
63
64struct A5
65 : public A4,
66 public A3
67{
68 char _[13489];
69 virtual ~A5() {}
70
71 t1::A1* getA1() {return A4::getA1();}
72 A2* getA2() {return A4::getA2();}
73 A3* getA3() {return A4::getA3();}
74 A4* getA4() {return A4::getA4();}
75 A5* getA5() {return this;}
76};
77
78void test()
79{
80 A1 a1;
81 A2 a2;
82 A3 a3;
83 A4 a4;
84 A5 a5;
85
86 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
87 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
88 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
89 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
90 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
91 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
92 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
93 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
94 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
95 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
96 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
97 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
98 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
99 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
100
101 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
102 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
103 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
104 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
105// assert(dynamic_cast<A2*>(a3.getA3()) == 0); // cast to private base
106 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
107 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
108// assert(dynamic_cast<A2*>(a4.getA3()) == 0); // cast to private base
109// assert(dynamic_cast<A2*>(a4.getA4()) == 0); // cast to ambiguous base
110 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
111 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
112// assert(dynamic_cast<A2*>(a5.getA3()) == 0); // cast to private base
113// assert(dynamic_cast<A2*>(a5.getA4()) == 0); // cast to ambiguous base
114// assert(dynamic_cast<A2*>(a5.getA5()) == 0); // cast to ambiguous base
115
116 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
117 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
118 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
119 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
120 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
121 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
122 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
123 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
124 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
125 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
126 assert(dynamic_cast<A3*>(a5.getA2()) == 0);
127 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
128 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
129// assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
130
131 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
132 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
133 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
134 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
135 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
136 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
137 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
138 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
139 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
140 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
141 assert(dynamic_cast<A4*>(a5.getA2()) == 0);
142 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
143 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
144 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
145
146 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
147 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
148 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
149 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
150 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
151 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
152 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
153 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
154 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
155 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
156 assert(dynamic_cast<A5*>(a5.getA2()) == 0);
157 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
158 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
159 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
160}
161
162} // t1
163
164namespace t2
165{
166
167struct A1
168{
169 char _[43981];
170 virtual ~A1() {}
171
172 A1* getA1() {return this;}
173};
174
175struct A2
176{
177 char _[34981];
178 virtual ~A2() {}
179
180 A2* getA2() {return this;}
181};
182
183struct A3
184 : public virtual A1,
185 public A2
186{
187 char _[93481];
188 virtual ~A3() {}
189
190 A1* getA1() {return A1::getA1();}
191 A2* getA2() {return A2::getA2();}
192 A3* getA3() {return this;}
193};
194
195struct A4
196 : public A3,
197 public A2
198{
199 char _[13489];
200 virtual ~A4() {}
201
202 t2::A1* getA1() {return A3::getA1();}
203 A2* getA2() {return A3::getA2();}
204 A3* getA3() {return A3::getA3();}
205 A4* getA4() {return this;}
206};
207
208struct A5
209 : public A4,
210 public A3
211{
212 char _[13489];
213 virtual ~A5() {}
214
215 t2::A1* getA1() {return A4::getA1();}
216 A2* getA2() {return A4::getA2();}
217 A3* getA3() {return A4::getA3();}
218 A4* getA4() {return A4::getA4();}
219 A5* getA5() {return this;}
220};
221
222void test()
223{
224 A1 a1;
225 A2 a2;
226 A3 a3;
227 A4 a4;
228 A5 a5;
229
230 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
231 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
232 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
233 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
234 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
235 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
236 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
237 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
238 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
239 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
240 assert(dynamic_cast<A1*>(a5.getA2()) == a5.getA1());
241 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
242 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
243 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
244
245 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
246 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
247 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
248 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
249 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
250 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
251 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
252 assert(dynamic_cast<A2*>(a4.getA3()) == a4.getA2());
253// assert(dynamic_cast<A2*>(a4.getA4()) == 0); // cast to ambiguous base
254 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
255 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
256 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
257// assert(dynamic_cast<A2*>(a5.getA4()) == 0); // cast to ambiguous base
258// assert(dynamic_cast<A2*>(a5.getA5()) == 0); // cast to ambiguous base
259
260 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
261 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
262 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
263 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
264 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
265 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
266 assert(dynamic_cast<A3*>(a4.getA2()) == a4.getA3());
267 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
268 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
269 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
270 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
271 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
272 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
273// assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
274
275 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
276 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
277 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
278 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
279 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
280 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
281 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
282 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
283 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
284 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
285 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
286 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
287 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
288 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
289
290 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
291 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
292 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
293 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
294 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
295 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
296 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
297 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
298 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
299 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
300 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
301 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
302 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
303 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
304}
305
306} // t2
307
308namespace t3
309{
310
311struct A1
312{
313 char _[43981];
314 virtual ~A1() {}
315
316 A1* getA1() {return this;}
317};
318
319struct A2
320{
321 char _[34981];
322 virtual ~A2() {}
323
324 A2* getA2() {return this;}
325};
326
327struct A3
328 : public A1,
329 public virtual A2
330{
331 char _[93481];
332 virtual ~A3() {}
333
334 A1* getA1() {return A1::getA1();}
335 A2* getA2() {return A2::getA2();}
336 A3* getA3() {return this;}
337};
338
339struct A4
340 : public A1,
341 public virtual A2
342{
343 char _[13489];
344 virtual ~A4() {}
345
346 A1* getA1() {return A1::getA1();}
347 A2* getA2() {return A2::getA2();}
348 A4* getA4() {return this;}
349};
350
351struct A5
352 : public A3,
353 public A4
354{
355 char _[41389];
356 virtual ~A5() {}
357
358 A1* getA14() {return A4::getA1();}
359 A1* getA13() {return A3::getA1();}
360 A2* getA2() {return A4::getA2();}
361 A3* getA3() {return A3::getA3();}
362 A4* getA4() {return A4::getA4();}
363 A5* getA5() {return this;}
364};
365
366void test()
367{
368 A1 a1;
369 A2 a2;
370 A3 a3;
371 A4 a4;
372 A5 a5;
373
374 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
375 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
376 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
377 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
378 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
379 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
380 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
381 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
382 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
383 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
384 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
385 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
386 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
387
388 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
389 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
390 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
391 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
392 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
393 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
394 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
395 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
396 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
397 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
398 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
399 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
400 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
401 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
402
403 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
404 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
405 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
406 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
407 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
408 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
409 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
410 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
411 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
412 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
413 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
414 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
415 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
416 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
417
418 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
419 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
420 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
421 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
422 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
423 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
424 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
425 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
426 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
427 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
428 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
429 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
430 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
431 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
432
433 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
434 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
435 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
436 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
437 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
438 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
439 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
440 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
441 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
442 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
443 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
444 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
445 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
446 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
447}
448
449} // t3
450
451namespace t4
452{
453
454struct A1
455{
456 char _[43981];
457 virtual ~A1() {}
458
459 A1* getA1() {return this;}
460};
461
462struct A2
463{
464 char _[34981];
465 virtual ~A2() {}
466
467 A2* getA2() {return this;}
468};
469
470struct A3
471 : protected A1,
472 public virtual A2
473{
474 char _[93481];
475 virtual ~A3() {}
476
477 A1* getA1() {return A1::getA1();}
478 A2* getA2() {return A2::getA2();}
479 A3* getA3() {return this;}
480};
481
482struct A4
483 : public A1,
484 public virtual A2
485{
486 char _[13489];
487 virtual ~A4() {}
488
489 A1* getA1() {return A1::getA1();}
490 A2* getA2() {return A2::getA2();}
491 A4* getA4() {return this;}
492};
493
494struct A5
495 : public A3,
496 public A4
497{
498 char _[41389];
499 virtual ~A5() {}
500
501 A1* getA14() {return A4::getA1();}
502 A1* getA13() {return A3::getA1();}
503 A2* getA2() {return A4::getA2();}
504 A3* getA3() {return A3::getA3();}
505 A4* getA4() {return A4::getA4();}
506 A5* getA5() {return this;}
507};
508
509void test()
510{
511 A1 a1;
512 A2 a2;
513 A3 a3;
514 A4 a4;
515 A5 a5;
516
517 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
518 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
519 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
520 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
521// assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1()); // cast to protected base
522 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
523 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
524 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
525 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
526 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
527 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
528// assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13()); // cast to protected base
529 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
530
531 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
532 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
533 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
534 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
535 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
536 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
537 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
538 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
539 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
540 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
541 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
542 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
543 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
544 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
545
546 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
547 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
548 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
549 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
550 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
551 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
552 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
553 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
554 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
555 assert(dynamic_cast<A3*>(a5.getA13()) == 0);
556 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
557 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
558 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
559 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
560
561 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
562 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
563 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
564 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
565 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
566 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
567 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
568 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
569 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
570 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
571 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
572 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
573 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
574 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
575
576 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
577 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
578 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
579 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
580 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
581 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
582 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
583 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
584 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
585 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
586 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
587 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
588 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
589 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
590}
591
592} // t4
593
594namespace t5
595{
596
597struct A1
598{
599 char _[43981];
600 virtual ~A1() {}
601
602 A1* getA1() {return this;}
603};
604
605struct A2
606{
607 char _[34981];
608 virtual ~A2() {}
609
610 A2* getA2() {return this;}
611};
612
613struct A3
614 : public A1,
615 protected virtual A2
616{
617 char _[93481];
618 virtual ~A3() {}
619
620 A1* getA1() {return A1::getA1();}
621 A2* getA2() {return A2::getA2();}
622 A3* getA3() {return this;}
623};
624
625struct A4
626 : public A1,
627 public virtual A2
628{
629 char _[13489];
630 virtual ~A4() {}
631
632 A1* getA1() {return A1::getA1();}
633 A2* getA2() {return A2::getA2();}
634 A4* getA4() {return this;}
635};
636
637struct A5
638 : public A3,
639 public A4
640{
641 char _[41389];
642 virtual ~A5() {}
643
644 A1* getA14() {return A4::getA1();}
645 A1* getA13() {return A3::getA1();}
646 A2* getA2() {return A4::getA2();}
647 A3* getA3() {return A3::getA3();}
648 A4* getA4() {return A4::getA4();}
649 A5* getA5() {return this;}
650};
651
652void test()
653{
654 A1 a1;
655 A2 a2;
656 A3 a3;
657 A4 a4;
658 A5 a5;
659
660 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
661 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
662 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
663 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
664 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
665 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
666 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
667 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
668 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
669 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
670 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
671 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
672 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
673
674 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
675 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
676 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
677 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
678// assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2()); // cast to protected base
679 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
680 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
681 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
682 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
683 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
684 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
685// assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2()); // cast to protected base
686 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
687 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
688
689 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
690 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
691 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
692 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
693 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
694 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
695 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
696 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
697 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
698 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
699 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
700 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
701 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
702 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
703
704 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
705 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
706 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
707 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
708 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
709 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
710 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
711 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
712 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
713 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
714 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
715 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
716 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
717 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
718
719 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
720 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
721 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
722 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
723 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
724 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
725 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
726 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
727 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
728 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
729 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
730 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
731 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
732 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
733}
734
735} // t5
736
737namespace t6
738{
739
740struct A1
741{
742 char _[43981];
743 virtual ~A1() {}
744
745 A1* getA1() {return this;}
746};
747
748struct A2
749{
750 char _[34981];
751 virtual ~A2() {}
752
753 A2* getA2() {return this;}
754};
755
756struct A3
757 : public A1,
758 public virtual A2
759{
760 char _[93481];
761 virtual ~A3() {}
762
763 A1* getA1() {return A1::getA1();}
764 A2* getA2() {return A2::getA2();}
765 A3* getA3() {return this;}
766};
767
768struct A4
769 : protected A1,
770 public virtual A2
771{
772 char _[13489];
773 virtual ~A4() {}
774
775 A1* getA1() {return A1::getA1();}
776 A2* getA2() {return A2::getA2();}
777 A4* getA4() {return this;}
778};
779
780struct A5
781 : public A3,
782 public A4
783{
784 char _[41389];
785 virtual ~A5() {}
786
787 A1* getA14() {return A4::getA1();}
788 A1* getA13() {return A3::getA1();}
789 A2* getA2() {return A4::getA2();}
790 A3* getA3() {return A3::getA3();}
791 A4* getA4() {return A4::getA4();}
792 A5* getA5() {return this;}
793};
794
795void test()
796{
797 A1 a1;
798 A2 a2;
799 A3 a3;
800 A4 a4;
801 A5 a5;
802
803 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
804 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
805 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
806 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
807 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
808 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
809 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
810// assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1()); // cast to protected base
811 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
812 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
813 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
814 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
815// assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14()); // cast to protected base
816
817 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
818 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
819 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
820 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
821 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
822 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
823 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
824 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
825 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
826 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
827 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
828 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
829 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
830 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
831
832 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
833 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
834 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
835 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
836 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
837 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
838 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
839 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
840 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
841 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
842 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
843 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
844 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
845 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
846
847 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
848 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
849 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
850 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
851 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
852 assert(dynamic_cast<A4*>(a4.getA1()) == 0);
853 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
854 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
855 assert(dynamic_cast<A4*>(a5.getA14()) == 0);
856 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
857 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
858 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
859 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
860 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
861
862 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
863 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
864 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
865 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
866 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
867 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
868 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
869 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
870 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
871 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
872 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
873 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
874 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
875 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
876}
877
878} // t6
879
880namespace t7
881{
882
883struct A1
884{
885 char _[43981];
886 virtual ~A1() {}
887
888 A1* getA1() {return this;}
889};
890
891struct A2
892{
893 char _[34981];
894 virtual ~A2() {}
895
896 A2* getA2() {return this;}
897};
898
899struct A3
900 : public A1,
901 public virtual A2
902{
903 char _[93481];
904 virtual ~A3() {}
905
906 A1* getA1() {return A1::getA1();}
907 A2* getA2() {return A2::getA2();}
908 A3* getA3() {return this;}
909};
910
911struct A4
912 : public A1,
913 protected virtual A2
914{
915 char _[13489];
916 virtual ~A4() {}
917
918 A1* getA1() {return A1::getA1();}
919 A2* getA2() {return A2::getA2();}
920 A4* getA4() {return this;}
921};
922
923struct A5
924 : public A3,
925 public A4
926{
927 char _[41389];
928 virtual ~A5() {}
929
930 A1* getA14() {return A4::getA1();}
931 A1* getA13() {return A3::getA1();}
932 A2* getA2() {return A4::getA2();}
933 A3* getA3() {return A3::getA3();}
934 A4* getA4() {return A4::getA4();}
935 A5* getA5() {return this;}
936};
937
938void test()
939{
940 A1 a1;
941 A2 a2;
942 A3 a3;
943 A4 a4;
944 A5 a5;
945
946 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
947 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
948 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
949 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
950 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
951 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
952 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
953 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
954 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
955 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
956 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
957 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
958 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
959
960 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
961 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
962 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
963 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
964 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
965 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
966 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
967// assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2()); // cast to protected base
968 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
969 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
970 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
971 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
972// assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2()); // cast to protected base
973 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
974
975 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
976 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
977 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
978 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
979 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
980 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
981 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
982 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
983 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
984 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
985 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
986 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
987 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
988 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
989
990 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
991 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
992 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
993 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
994 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
995 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
996 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
997 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
998 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
999 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
1000 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1001 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
1002 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1003 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
1004
1005 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1006 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1007 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1008 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1009 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1010 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1011 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1012 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1013 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1014 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1015 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1016 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1017 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1018 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1019}
1020
1021} // t7
1022
1023namespace t8
1024{
1025
1026struct A1
1027{
1028 char _[43981];
1029 virtual ~A1() {}
1030
1031 A1* getA1() {return this;}
1032};
1033
1034struct A2
1035{
1036 char _[34981];
1037 virtual ~A2() {}
1038
1039 A2* getA2() {return this;}
1040};
1041
1042struct A3
1043 : public A1,
1044 public virtual A2
1045{
1046 char _[93481];
1047 virtual ~A3() {}
1048
1049 A1* getA1() {return A1::getA1();}
1050 A2* getA2() {return A2::getA2();}
1051 A3* getA3() {return this;}
1052};
1053
1054struct A4
1055 : public A1,
1056 public virtual A2
1057{
1058 char _[13489];
1059 virtual ~A4() {}
1060
1061 A1* getA1() {return A1::getA1();}
1062 A2* getA2() {return A2::getA2();}
1063 A4* getA4() {return this;}
1064};
1065
1066struct A5
1067 : protected A3,
1068 public A4
1069{
1070 char _[41389];
1071 virtual ~A5() {}
1072
1073 A1* getA14() {return A4::getA1();}
1074 A1* getA13() {return A3::getA1();}
1075 A2* getA2() {return A4::getA2();}
1076 A3* getA3() {return A3::getA3();}
1077 A4* getA4() {return A4::getA4();}
1078 A5* getA5() {return this;}
1079};
1080
1081void test()
1082{
1083 A1 a1;
1084 A2 a2;
1085 A3 a3;
1086 A4 a4;
1087 A5 a5;
1088
1089 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1090 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1091 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1092 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1093 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1094 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1095 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1096 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1097 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1098 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1099 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1100 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1101 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1102
1103 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1104 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1105 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1106 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1107 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1108 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1109 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1110 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1111 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
1112 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
1113 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1114 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1115 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1116 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1117
1118 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1119 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1120 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1121 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1122 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1123 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1124 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1125 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1126 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1127 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1128 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1129 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1130 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1131// assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3()); // cast to protected base
1132
1133 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1134 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1135 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1136 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1137 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1138 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1139 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1140 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1141 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1142 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1143 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1144 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1145 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1146 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
1147
1148 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1149 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1150 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1151 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1152 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1153 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1154 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1155 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1156 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1157 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
1158 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1159 assert(dynamic_cast<A5*>(a5.getA3()) == 0);
1160 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1161 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1162}
1163
1164} // t8
1165
1166namespace t9
1167{
1168
1169struct A1
1170{
1171 char _[43981];
1172 virtual ~A1() {}
1173
1174 A1* getA1() {return this;}
1175};
1176
1177struct A2
1178{
1179 char _[34981];
1180 virtual ~A2() {}
1181
1182 A2* getA2() {return this;}
1183};
1184
1185struct A3
1186 : public A1,
1187 public virtual A2
1188{
1189 char _[93481];
1190 virtual ~A3() {}
1191
1192 A1* getA1() {return A1::getA1();}
1193 A2* getA2() {return A2::getA2();}
1194 A3* getA3() {return this;}
1195};
1196
1197struct A4
1198 : public A1,
1199 public virtual A2
1200{
1201 char _[13489];
1202 virtual ~A4() {}
1203
1204 A1* getA1() {return A1::getA1();}
1205 A2* getA2() {return A2::getA2();}
1206 A4* getA4() {return this;}
1207};
1208
1209struct A5
1210 : public A3,
1211 protected A4
1212{
1213 char _[41389];
1214 virtual ~A5() {}
1215
1216 A1* getA14() {return A4::getA1();}
1217 A1* getA13() {return A3::getA1();}
1218 A2* getA2() {return A4::getA2();}
1219 A3* getA3() {return A3::getA3();}
1220 A4* getA4() {return A4::getA4();}
1221 A5* getA5() {return this;}
1222};
1223
1224void test()
1225{
1226 A1 a1;
1227 A2 a2;
1228 A3 a3;
1229 A4 a4;
1230 A5 a5;
1231
1232 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1233 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1234 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1235 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1236 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1237 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1238 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1239 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1240 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1241 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1242 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1243 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1244 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1245
1246 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1247 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1248 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1249 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1250 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1251 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1252 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1253 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1254 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
1255 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
1256 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1257 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1258 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1259 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1260
1261 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1262 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1263 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1264 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1265 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1266 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1267 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1268 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1269 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1270 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1271 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1272 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1273 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1274 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
1275
1276 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1277 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1278 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1279 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1280 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1281 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1282 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1283 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1284 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1285 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1286 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1287 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1288 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1289// assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4()); // cast to protected base
1290
1291 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1292 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1293 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1294 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1295 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1296 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1297 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1298 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1299 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
1300 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1301 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1302 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1303 assert(dynamic_cast<A5*>(a5.getA4()) == 0);
1304 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1305}
1306
1307} // t9
1308
1309
1310int main(int, char**)
1311{
1312 timer t;
1313 t1::test();
1314 t2::test();
1315 t3::test();
1316 t4::test();
1317 t5::test();
1318 t6::test();
1319 t7::test();
1320 t8::test();
1321 t9::test();
1322
1323 return 0;
1324}
1325

source code of libcxxabi/test/dynamic_cast5.pass.cpp