1 //===------------------------- dynamic_cast3.cpp --------------------------===//
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 // XFAIL: gcc-7, gcc-8, gcc-9
10
11 #include <cassert>
12 #include "support/timer.h"
13
14 // This test explicitly tests dynamic cast with types that have inaccessible
15 // bases.
16 #if defined(__clang__)
17 # pragma clang diagnostic ignored "-Winaccessible-base"
18 #elif defined(__GNUC__) && (__GNUC__ >= 10)
19 # pragma GCC diagnostic ignored "-Winaccessible-base"
20 #endif
21
22 /*
23
24 A1 A2 A3
25
26 */
27
28 namespace t1
29 {
30
31 struct A1
32 {
33 char _[43981];
~A1t1::A134 virtual ~A1() {}
35
getA1t1::A136 A1* getA1() {return this;}
37 };
38
39 struct A2
40 {
41 char _[34981];
~A2t1::A242 virtual ~A2() {}
43
getA2t1::A244 A2* getA2() {return this;}
45 };
46
47 struct A3
48 {
49 char _[93481];
~A3t1::A350 virtual ~A3() {}
51
getA3t1::A352 A3* getA3() {return this;}
53 };
54
test()55 void test()
56 {
57 A1 a1;
58 A2 a2;
59 A3 a3;
60 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
61 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
62 assert(dynamic_cast<A1*>(a3.getA3()) == 0);
63 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
64 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
65 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
66 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
67 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
68 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
69 }
70
71 } // t1
72
73 /*
74
75 A1 A2
76 |
77 A3
78
79 */
80
81 namespace t2
82 {
83
84 struct A1
85 {
86 char _[43981];
~A1t2::A187 virtual ~A1() {}
88
getA1t2::A189 A1* getA1() {return this;}
90 };
91
92 struct A2
93 {
94 char _[34981];
~A2t2::A295 virtual ~A2() {}
96
getA2t2::A297 A2* getA2() {return this;}
98 };
99
100 struct A3
101 : public A1
102 {
103 char _[93481];
~A3t2::A3104 virtual ~A3() {}
105
getA3t2::A3106 A3* getA3() {return this;}
107 };
108
test()109 void test()
110 {
111 A1 a1;
112 A2 a2;
113 A3 a3;
114 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
115 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
116 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
117 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
118
119 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
120 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
121 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
122 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
123
124 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
125 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
126 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
127 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
128 }
129
130 } // t2
131
132 namespace t3
133 {
134
135 struct A1
136 {
137 char _[43981];
~A1t3::A1138 virtual ~A1() {}
139
getA1t3::A1140 A1* getA1() {return this;}
141 };
142
143 struct A2
144 {
145 char _[34981];
~A2t3::A2146 virtual ~A2() {}
147
getA2t3::A2148 A2* getA2() {return this;}
149 };
150
151 struct A3
152 : public virtual A1
153 {
154 char _[93481];
~A3t3::A3155 virtual ~A3() {}
156
getA3t3::A3157 A3* getA3() {return this;}
158 };
159
test()160 void test()
161 {
162 A1 a1;
163 A2 a2;
164 A3 a3;
165 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
166 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
167 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
168 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
169
170 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
171 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
172 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
173 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
174
175 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
176 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
177 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
178 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
179 }
180
181 } // t3
182
183 namespace t4
184 {
185
186 struct A1
187 {
188 char _[43981];
~A1t4::A1189 virtual ~A1() {}
190
getA1t4::A1191 A1* getA1() {return this;}
192 };
193
194 struct A2
195 {
196 char _[34981];
~A2t4::A2197 virtual ~A2() {}
198
getA2t4::A2199 A2* getA2() {return this;}
200 };
201
202 struct A3
203 : private A1
204 {
205 char _[93481];
~A3t4::A3206 virtual ~A3() {}
207
getA1t4::A3208 A1* getA1() {return this;}
getA3t4::A3209 A3* getA3() {return this;}
210 };
211
test()212 void test()
213 {
214 A1 a1;
215 A2 a2;
216 A3 a3;
217 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
218 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
219 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
220
221 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
222 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
223 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
224 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
225
226 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
227 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
228 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
229 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
230 }
231
232 } // t4
233
234 namespace t5
235 {
236
237 struct A1
238 {
239 char _[43981];
~A1t5::A1240 virtual ~A1() {}
241
getA1t5::A1242 A1* getA1() {return this;}
243 };
244
245 struct A2
246 {
247 char _[34981];
~A2t5::A2248 virtual ~A2() {}
249
getA2t5::A2250 A2* getA2() {return this;}
251 };
252
253 struct A3
254 : private virtual A1
255 {
256 char _[93481];
~A3t5::A3257 virtual ~A3() {}
258
getA1t5::A3259 A1* getA1() {return this;}
getA3t5::A3260 A3* getA3() {return this;}
261 };
262
test()263 void test()
264 {
265 A1 a1;
266 A2 a2;
267 A3 a3;
268 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
269 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
270 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
271
272 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
273 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
274 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
275 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
276
277 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
278 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
279 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
280 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
281 }
282
283 } // t5
284
285 /*
286
287 A1 A2
288 \ /
289 A3
290
291 */
292
293 namespace t6
294 {
295
296 struct A1
297 {
298 char _[43981];
~A1t6::A1299 virtual ~A1() {}
300
getA1t6::A1301 A1* getA1() {return this;}
302 };
303
304 struct A2
305 {
306 char _[34981];
~A2t6::A2307 virtual ~A2() {}
308
getA2t6::A2309 A2* getA2() {return this;}
310 };
311
312 struct A3
313 : public A1,
314 public A2
315 {
316 char _[93481];
~A3t6::A3317 virtual ~A3() {}
318
getA1t6::A3319 A1* getA1() {return this;}
getA2t6::A3320 A2* getA2() {return this;}
getA3t6::A3321 A3* getA3() {return this;}
322 };
323
test()324 void test()
325 {
326 A1 a1;
327 A2 a2;
328 A3 a3;
329 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
330 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
331 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
332 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
333 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
334
335 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
336 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
337 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
338 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
339 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
340
341 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
342 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
343 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
344 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
345 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
346 }
347
348 } // t6
349
350 namespace t7
351 {
352
353 struct A1
354 {
355 char _[43981];
~A1t7::A1356 virtual ~A1() {}
357
getA1t7::A1358 A1* getA1() {return this;}
359 };
360
361 struct A2
362 {
363 char _[34981];
~A2t7::A2364 virtual ~A2() {}
365
getA2t7::A2366 A2* getA2() {return this;}
367 };
368
369 struct A3
370 : public virtual A1,
371 public A2
372 {
373 char _[93481];
~A3t7::A3374 virtual ~A3() {}
375
getA1t7::A3376 A1* getA1() {return this;}
getA2t7::A3377 A2* getA2() {return this;}
getA3t7::A3378 A3* getA3() {return this;}
379 };
380
test()381 void test()
382 {
383 A1 a1;
384 A2 a2;
385 A3 a3;
386 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
387 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
388 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
389 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
390 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
391
392 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
393 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
394 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
395 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
396 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
397
398 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
399 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
400 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
401 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
402 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
403 }
404
405 } // t7
406
407 namespace t8
408 {
409
410 struct A1
411 {
412 char _[43981];
~A1t8::A1413 virtual ~A1() {}
414
getA1t8::A1415 A1* getA1() {return this;}
416 };
417
418 struct A2
419 {
420 char _[34981];
~A2t8::A2421 virtual ~A2() {}
422
getA2t8::A2423 A2* getA2() {return this;}
424 };
425
426 struct A3
427 : private A1,
428 public A2
429 {
430 char _[93481];
~A3t8::A3431 virtual ~A3() {}
432
getA1t8::A3433 A1* getA1() {return this;}
getA2t8::A3434 A2* getA2() {return this;}
getA3t8::A3435 A3* getA3() {return this;}
436 };
437
test()438 void test()
439 {
440 A1 a1;
441 A2 a2;
442 A3 a3;
443 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
444 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
445 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
446 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
447
448 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
449 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
450 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
451 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
452 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
453
454 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
455 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
456 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
457 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
458 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
459 }
460
461 } // t8
462
463 namespace t9
464 {
465
466 struct A1
467 {
468 char _[43981];
~A1t9::A1469 virtual ~A1() {}
470
getA1t9::A1471 A1* getA1() {return this;}
472 };
473
474 struct A2
475 {
476 char _[34981];
~A2t9::A2477 virtual ~A2() {}
478
getA2t9::A2479 A2* getA2() {return this;}
480 };
481
482 struct A3
483 : private virtual A1,
484 public A2
485 {
486 char _[93481];
~A3t9::A3487 virtual ~A3() {}
488
getA1t9::A3489 A1* getA1() {return this;}
getA2t9::A3490 A2* getA2() {return this;}
getA3t9::A3491 A3* getA3() {return this;}
492 };
493
test()494 void test()
495 {
496 A1 a1;
497 A2 a2;
498 A3 a3;
499 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
500 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
501 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
502 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
503
504 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
505 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
506 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
507 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
508 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
509
510 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
511 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
512 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
513 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
514 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
515 }
516
517 } // t9
518
519 namespace t10
520 {
521
522 struct A1
523 {
524 char _[43981];
~A1t10::A1525 virtual ~A1() {}
526
getA1t10::A1527 A1* getA1() {return this;}
528 };
529
530 struct A2
531 {
532 char _[34981];
~A2t10::A2533 virtual ~A2() {}
534
getA2t10::A2535 A2* getA2() {return this;}
536 };
537
538 struct A3
539 : public virtual A1,
540 public virtual A2
541 {
542 char _[93481];
~A3t10::A3543 virtual ~A3() {}
544
getA1t10::A3545 A1* getA1() {return this;}
getA2t10::A3546 A2* getA2() {return this;}
getA3t10::A3547 A3* getA3() {return this;}
548 };
549
test()550 void test()
551 {
552 A1 a1;
553 A2 a2;
554 A3 a3;
555 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
556 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
557 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
558 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
559 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
560
561 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
562 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
563 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
564 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
565 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
566
567 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
568 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
569 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
570 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
571 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
572 }
573
574 } // t10
575
576 namespace t11
577 {
578
579 struct A1
580 {
581 char _[43981];
~A1t11::A1582 virtual ~A1() {}
583
getA1t11::A1584 A1* getA1() {return this;}
585 };
586
587 struct A2
588 {
589 char _[34981];
~A2t11::A2590 virtual ~A2() {}
591
getA2t11::A2592 A2* getA2() {return this;}
593 };
594
595 struct A3
596 : private A1,
597 public virtual A2
598 {
599 char _[93481];
~A3t11::A3600 virtual ~A3() {}
601
getA1t11::A3602 A1* getA1() {return this;}
getA2t11::A3603 A2* getA2() {return this;}
getA3t11::A3604 A3* getA3() {return this;}
605 };
606
test()607 void test()
608 {
609 A1 a1;
610 A2 a2;
611 A3 a3;
612 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
613 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
614 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
615 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
616
617 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
618 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
619 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
620 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
621 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
622
623 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
624 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
625 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
626 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
627 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
628 }
629
630 } // t11
631
632 namespace t12
633 {
634
635 struct A1
636 {
637 char _[43981];
~A1t12::A1638 virtual ~A1() {}
639
getA1t12::A1640 A1* getA1() {return this;}
641 };
642
643 struct A2
644 {
645 char _[34981];
~A2t12::A2646 virtual ~A2() {}
647
getA2t12::A2648 A2* getA2() {return this;}
649 };
650
651 struct A3
652 : private virtual A1,
653 public virtual A2
654 {
655 char _[93481];
~A3t12::A3656 virtual ~A3() {}
657
getA1t12::A3658 A1* getA1() {return this;}
getA2t12::A3659 A2* getA2() {return this;}
getA3t12::A3660 A3* getA3() {return this;}
661 };
662
test()663 void test()
664 {
665 A1 a1;
666 A2 a2;
667 A3 a3;
668 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
669 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
670 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
671 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
672
673 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
674 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
675 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
676 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
677 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
678
679 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
680 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
681 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
682 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
683 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
684 }
685
686 } // t12
687
688 namespace t13
689 {
690
691 struct A1
692 {
693 char _[43981];
~A1t13::A1694 virtual ~A1() {}
695
getA1t13::A1696 A1* getA1() {return this;}
697 };
698
699 struct A2
700 {
701 char _[34981];
~A2t13::A2702 virtual ~A2() {}
703
getA2t13::A2704 A2* getA2() {return this;}
705 };
706
707 struct A3
708 : private A1,
709 private A2
710 {
711 char _[93481];
~A3t13::A3712 virtual ~A3() {}
713
getA1t13::A3714 A1* getA1() {return this;}
getA2t13::A3715 A2* getA2() {return this;}
getA3t13::A3716 A3* getA3() {return this;}
717 };
718
test()719 void test()
720 {
721 A1 a1;
722 A2 a2;
723 A3 a3;
724 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
725 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
726 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
727 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
728
729 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
730 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
731 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
732 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
733
734 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
735 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
736 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
737 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
738 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
739 }
740
741 } // t13
742
743 namespace t14
744 {
745
746 struct A1
747 {
748 char _[43981];
~A1t14::A1749 virtual ~A1() {}
750
getA1t14::A1751 A1* getA1() {return this;}
752 };
753
754 struct A2
755 {
756 char _[34981];
~A2t14::A2757 virtual ~A2() {}
758
getA2t14::A2759 A2* getA2() {return this;}
760 };
761
762 struct A3
763 : private virtual A1,
764 private A2
765 {
766 char _[93481];
~A3t14::A3767 virtual ~A3() {}
768
getA1t14::A3769 A1* getA1() {return this;}
getA2t14::A3770 A2* getA2() {return this;}
getA3t14::A3771 A3* getA3() {return this;}
772 };
773
test()774 void test()
775 {
776 A1 a1;
777 A2 a2;
778 A3 a3;
779 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
780 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
781 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
782 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
783
784 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
785 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
786 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
787 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
788
789 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
790 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
791 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
792 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
793 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
794 }
795
796 } // t14
797
798 namespace t15
799 {
800
801 struct A1
802 {
803 char _[43981];
~A1t15::A1804 virtual ~A1() {}
805
getA1t15::A1806 A1* getA1() {return this;}
807 };
808
809 struct A2
810 {
811 char _[34981];
~A2t15::A2812 virtual ~A2() {}
813
getA2t15::A2814 A2* getA2() {return this;}
815 };
816
817 struct A3
818 : private virtual A1,
819 private virtual A2
820 {
821 char _[93481];
~A3t15::A3822 virtual ~A3() {}
823
getA1t15::A3824 A1* getA1() {return this;}
getA2t15::A3825 A2* getA2() {return this;}
getA3t15::A3826 A3* getA3() {return this;}
827 };
828
test()829 void test()
830 {
831 A1 a1;
832 A2 a2;
833 A3 a3;
834 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
835 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
836 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
837 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
838
839 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
840 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
841 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
842 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
843
844 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
845 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
846 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
847 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
848 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
849 }
850
851 } // t15
852
853 /*
854
855 A1
856 |
857 A2
858 |
859 A3
860
861 */
862
863 namespace t16
864 {
865
866 struct A1
867 {
868 char _[43981];
~A1t16::A1869 virtual ~A1() {}
870
getA1t16::A1871 A1* getA1() {return this;}
872 };
873
874 struct A2
875 : public A1
876 {
877 char _[34981];
~A2t16::A2878 virtual ~A2() {}
879
getA1t16::A2880 A1* getA1() {return this;}
getA2t16::A2881 A2* getA2() {return this;}
882 };
883
884 struct A3
885 : public A2
886 {
887 char _[93481];
~A3t16::A3888 virtual ~A3() {}
889
getA1t16::A3890 A1* getA1() {return this;}
getA2t16::A3891 A2* getA2() {return this;}
getA3t16::A3892 A3* getA3() {return this;}
893 };
894
test()895 void test()
896 {
897 A1 a1;
898 A2 a2;
899 A3 a3;
900 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
901 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
902 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
903 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
904 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
905 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
906
907 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
908 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
909 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
910 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
911 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
912 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
913
914 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
915 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
916 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
917 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
918 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
919 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
920 }
921
922 } // t16
923
924 namespace t17
925 {
926
927 struct A1
928 {
929 char _[43981];
~A1t17::A1930 virtual ~A1() {}
931
getA1t17::A1932 A1* getA1() {return this;}
933 };
934
935 struct A2
936 : public virtual A1
937 {
938 char _[34981];
~A2t17::A2939 virtual ~A2() {}
940
getA1t17::A2941 A1* getA1() {return this;}
getA2t17::A2942 A2* getA2() {return this;}
943 };
944
945 struct A3
946 : public A2
947 {
948 char _[93481];
~A3t17::A3949 virtual ~A3() {}
950
getA1t17::A3951 A1* getA1() {return this;}
getA2t17::A3952 A2* getA2() {return this;}
getA3t17::A3953 A3* getA3() {return this;}
954 };
955
test()956 void test()
957 {
958 A1 a1;
959 A2 a2;
960 A3 a3;
961 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
962 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
963 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
964 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
965 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
966 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
967
968 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
969 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
970 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
971 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
972 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
973 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
974
975 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
976 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
977 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
978 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
979 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
980 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
981 }
982
983 } // t17
984
985 namespace t18
986 {
987
988 struct A1
989 {
990 char _[43981];
~A1t18::A1991 virtual ~A1() {}
992
getA1t18::A1993 A1* getA1() {return this;}
994 };
995
996 struct A2
997 : private A1
998 {
999 char _[34981];
~A2t18::A21000 virtual ~A2() {}
1001
getA1t18::A21002 A1* getA1() {return this;}
getA2t18::A21003 A2* getA2() {return this;}
1004 };
1005
1006 struct A3
1007 : public A2
1008 {
1009 char _[93481];
~A3t18::A31010 virtual ~A3() {}
1011
getA2t18::A31012 A2* getA2() {return this;}
getA3t18::A31013 A3* getA3() {return this;}
1014 };
1015
test()1016 void test()
1017 {
1018 A1 a1;
1019 A2 a2;
1020 A3 a3;
1021 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1022 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1023 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1024
1025 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1026 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1027 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1028 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1029 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1030 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1031
1032 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1033 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1034 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1035 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1036 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1037 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1038 }
1039
1040 } // t18
1041
1042 namespace t19
1043 {
1044
1045 struct A1
1046 {
1047 char _[43981];
~A1t19::A11048 virtual ~A1() {}
1049
getA1t19::A11050 A1* getA1() {return this;}
1051 };
1052
1053 struct A2
1054 : protected virtual A1
1055 {
1056 char _[34981];
~A2t19::A21057 virtual ~A2() {}
1058
getA1t19::A21059 A1* getA1() {return this;}
getA2t19::A21060 A2* getA2() {return this;}
1061 };
1062
1063 struct A3
1064 : public A2
1065 {
1066 char _[93481];
~A3t19::A31067 virtual ~A3() {}
1068
getA2t19::A31069 A2* getA2() {return this;}
getA3t19::A31070 A3* getA3() {return this;}
1071 };
1072
test()1073 void test()
1074 {
1075 A1 a1;
1076 A2 a2;
1077 A3 a3;
1078 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1079 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1080 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1081
1082 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1083 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1084 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1085 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1086 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1087 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1088
1089 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1090 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1091 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1092 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1093 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1094 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1095 }
1096
1097 } // t19
1098
1099 namespace t20
1100 {
1101
1102 struct A1
1103 {
1104 char _[43981];
~A1t20::A11105 virtual ~A1() {}
1106
getA1t20::A11107 A1* getA1() {return this;}
1108 };
1109
1110 struct A2
1111 : public virtual A1
1112 {
1113 char _[34981];
~A2t20::A21114 virtual ~A2() {}
1115
getA1t20::A21116 A1* getA1() {return this;}
getA2t20::A21117 A2* getA2() {return this;}
1118 };
1119
1120 struct A3
1121 : public virtual A2
1122 {
1123 char _[93481];
~A3t20::A31124 virtual ~A3() {}
1125
getA1t20::A31126 A1* getA1() {return this;}
getA2t20::A31127 A2* getA2() {return this;}
getA3t20::A31128 A3* getA3() {return this;}
1129 };
1130
test()1131 void test()
1132 {
1133 A1 a1;
1134 A2 a2;
1135 A3 a3;
1136 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1137 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1138 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1139 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1140 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1141 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1142
1143 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1144 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1145 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1146 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1147 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1148 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1149
1150 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1151 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1152 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1153 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1154 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1155 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1156 }
1157
1158 } // t20
1159
1160 namespace t21
1161 {
1162
1163 struct A1
1164 {
1165 char _[43981];
~A1t21::A11166 virtual ~A1() {}
1167
getA1t21::A11168 A1* getA1() {return this;}
1169 };
1170
1171 struct A2
1172 : private A1
1173 {
1174 char _[34981];
~A2t21::A21175 virtual ~A2() {}
1176
getA1t21::A21177 A1* getA1() {return this;}
getA2t21::A21178 A2* getA2() {return this;}
1179 };
1180
1181 struct A3
1182 : public virtual A2
1183 {
1184 char _[93481];
~A3t21::A31185 virtual ~A3() {}
1186
getA2t21::A31187 A2* getA2() {return this;}
getA3t21::A31188 A3* getA3() {return this;}
1189 };
1190
test()1191 void test()
1192 {
1193 A1 a1;
1194 A2 a2;
1195 A3 a3;
1196 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1197 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1198 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1199
1200 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1201 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1202 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1203 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1204 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1205 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1206
1207 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1208 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1209 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1210 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1211 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1212 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1213 }
1214
1215 } // t21
1216
1217 namespace t22
1218 {
1219
1220 struct A1
1221 {
1222 char _[43981];
~A1t22::A11223 virtual ~A1() {}
1224
getA1t22::A11225 A1* getA1() {return this;}
1226 };
1227
1228 struct A2
1229 : protected virtual A1
1230 {
1231 char _[34981];
~A2t22::A21232 virtual ~A2() {}
1233
getA1t22::A21234 A1* getA1() {return this;}
getA2t22::A21235 A2* getA2() {return this;}
1236 };
1237
1238 struct A3
1239 : public virtual A2
1240 {
1241 char _[93481];
~A3t22::A31242 virtual ~A3() {}
1243
getA2t22::A31244 A2* getA2() {return this;}
getA3t22::A31245 A3* getA3() {return this;}
1246 };
1247
test()1248 void test()
1249 {
1250 A1 a1;
1251 A2 a2;
1252 A3 a3;
1253 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1254 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1255 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1256
1257 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1258 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1259 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1260 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1261 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1262 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1263
1264 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1265 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1266 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1267 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1268 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1269 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1270 }
1271
1272 } // t22
1273
1274 namespace t23
1275 {
1276
1277 struct A1
1278 {
1279 char _[43981];
~A1t23::A11280 virtual ~A1() {}
1281
getA1t23::A11282 A1* getA1() {return this;}
1283 };
1284
1285 struct A2
1286 : private A1
1287 {
1288 char _[34981];
~A2t23::A21289 virtual ~A2() {}
1290
getA1t23::A21291 A1* getA1() {return this;}
getA2t23::A21292 A2* getA2() {return this;}
1293 };
1294
1295 struct A3
1296 : private A2
1297 {
1298 char _[93481];
~A3t23::A31299 virtual ~A3() {}
1300
getA1t23::A31301 t23::A1* getA1() {return A2::getA1();}
getA2t23::A31302 A2* getA2() {return this;}
getA3t23::A31303 A3* getA3() {return this;}
1304 };
1305
test()1306 void test()
1307 {
1308 A1 a1;
1309 A2 a2;
1310 A3 a3;
1311 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1312 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1313 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1314
1315 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1316 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1317 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1318 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1319 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1320
1321 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1322 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1323 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1324 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1325 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1326 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1327 }
1328
1329 } // t23
1330
1331 namespace t24
1332 {
1333
1334 struct A1
1335 {
1336 char _[43981];
~A1t24::A11337 virtual ~A1() {}
1338
getA1t24::A11339 A1* getA1() {return this;}
1340 };
1341
1342 struct A2
1343 : protected virtual A1
1344 {
1345 char _[34981];
~A2t24::A21346 virtual ~A2() {}
1347
getA1t24::A21348 A1* getA1() {return this;}
getA2t24::A21349 A2* getA2() {return this;}
1350 };
1351
1352 struct A3
1353 : private A2
1354 {
1355 char _[93481];
~A3t24::A31356 virtual ~A3() {}
1357
getA1t24::A31358 t24::A1* getA1() {return A2::getA1();}
getA2t24::A31359 A2* getA2() {return this;}
getA3t24::A31360 A3* getA3() {return this;}
1361 };
1362
test()1363 void test()
1364 {
1365 A1 a1;
1366 A2 a2;
1367 A3 a3;
1368 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1369 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1370 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1371
1372 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1373 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1374 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1375 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1376 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1377
1378 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1379 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1380 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1381 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1382 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1383 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1384 }
1385
1386 } // t24
1387
1388 namespace t25
1389 {
1390
1391 struct A1
1392 {
1393 char _[43981];
~A1t25::A11394 virtual ~A1() {}
1395
getA1t25::A11396 A1* getA1() {return this;}
1397 };
1398
1399 struct A2
1400 : protected virtual A1
1401 {
1402 char _[34981];
~A2t25::A21403 virtual ~A2() {}
1404
getA1t25::A21405 A1* getA1() {return this;}
getA2t25::A21406 A2* getA2() {return this;}
1407 };
1408
1409 struct A3
1410 : private virtual A2
1411 {
1412 char _[93481];
~A3t25::A31413 virtual ~A3() {}
1414
getA1t25::A31415 t25::A1* getA1() {return A2::getA1();}
getA2t25::A31416 A2* getA2() {return this;}
getA3t25::A31417 A3* getA3() {return this;}
1418 };
1419
test()1420 void test()
1421 {
1422 A1 a1;
1423 A2 a2;
1424 A3 a3;
1425 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1426 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1427 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1428
1429 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1430 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1431 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1432 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1433 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1434
1435 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1436 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1437 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1438 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1439 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1440 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1441 }
1442
1443 } // t25
1444
1445 /*
1446
1447 A1 A1
1448 | |
1449 A2 |
1450 \ |
1451 A3
1452
1453 */
1454
1455 namespace t26
1456 {
1457
1458 struct A1
1459 {
1460 char _[43981];
~A1t26::A11461 virtual ~A1() {}
1462
getA1t26::A11463 A1* getA1() {return this;}
1464 };
1465
1466 struct A2
1467 : public A1
1468 {
1469 char _[34981];
~A2t26::A21470 virtual ~A2() {}
1471
getA1t26::A21472 A1* getA1() {return this;}
getA2t26::A21473 A2* getA2() {return this;}
1474 };
1475
1476 struct A3
1477 : public A1,
1478 public A2
1479 {
1480 char _[93481];
~A3t26::A31481 virtual ~A3() {}
1482
getA12t26::A31483 A1* getA12() {return A2::getA1();}
getA2t26::A31484 A2* getA2() {return this;}
getA3t26::A31485 A3* getA3() {return this;}
1486 };
1487
test()1488 void test()
1489 {
1490 A1 a1;
1491 A2 a2;
1492 A3 a3;
1493 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1494 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1495 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1496 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1497 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1498
1499 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1500 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1501 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1502 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1503 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1504 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1505
1506 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1507 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1508 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1509 assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1510 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1511 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1512 }
1513
1514 } // t26
1515
1516 namespace t27
1517 {
1518
1519 struct A1
1520 {
1521 char _[43981];
~A1t27::A11522 virtual ~A1() {}
1523
getA1t27::A11524 A1* getA1() {return this;}
1525 };
1526
1527 struct A2
1528 : private A1
1529 {
1530 char _[34981];
~A2t27::A21531 virtual ~A2() {}
1532
getA1t27::A21533 A1* getA1() {return this;}
getA2t27::A21534 A2* getA2() {return this;}
1535 };
1536
1537 struct A3
1538 : public A1,
1539 public A2
1540 {
1541 char _[93481];
~A3t27::A31542 virtual ~A3() {}
1543
getA12t27::A31544 A1* getA12() {return A2::getA1();}
getA2t27::A31545 A2* getA2() {return this;}
getA3t27::A31546 A3* getA3() {return this;}
1547 };
1548
test()1549 void test()
1550 {
1551 A1 a1;
1552 A2 a2;
1553 A3 a3;
1554 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1555 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1556 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1557
1558 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1559 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1560 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1561 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1562 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1563 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1564
1565 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1566 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1567 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1568 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1569 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1570 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1571 }
1572
1573 } // t27
1574
1575 namespace t28
1576 {
1577
1578 struct A1
1579 {
1580 char _[43981];
~A1t28::A11581 virtual ~A1() {}
1582
getA1t28::A11583 A1* getA1() {return this;}
1584 };
1585
1586 struct A2
1587 : public A1
1588 {
1589 char _[34981];
~A2t28::A21590 virtual ~A2() {}
1591
getA1t28::A21592 A1* getA1() {return this;}
getA2t28::A21593 A2* getA2() {return this;}
1594 };
1595
1596 struct A3
1597 : private A1,
1598 public A2
1599 {
1600 char _[93481];
~A3t28::A31601 virtual ~A3() {}
1602
getA12t28::A31603 A1* getA12() {return A2::getA1();}
getA2t28::A31604 A2* getA2() {return this;}
getA3t28::A31605 A3* getA3() {return this;}
1606 };
1607
test()1608 void test()
1609 {
1610 A1 a1;
1611 A2 a2;
1612 A3 a3;
1613 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1614 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1615 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1616 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1617
1618 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1619 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1620 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1621 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1622 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1623 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1624
1625 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1626 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1627 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1628 assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1629 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1630 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1631 }
1632
1633 } // t28
1634
1635 namespace t29
1636 {
1637
1638 struct A1
1639 {
1640 char _[43981];
~A1t29::A11641 virtual ~A1() {}
1642
getA1t29::A11643 A1* getA1() {return this;}
1644 };
1645
1646 struct A2
1647 : public A1
1648 {
1649 char _[34981];
~A2t29::A21650 virtual ~A2() {}
1651
getA1t29::A21652 A1* getA1() {return this;}
getA2t29::A21653 A2* getA2() {return this;}
1654 };
1655
1656 struct A3
1657 : public A1,
1658 private A2
1659 {
1660 char _[93481];
~A3t29::A31661 virtual ~A3() {}
1662
getA12t29::A31663 A1* getA12() {return A2::getA1();}
getA2t29::A31664 A2* getA2() {return this;}
getA3t29::A31665 A3* getA3() {return this;}
1666 };
1667
test()1668 void test()
1669 {
1670 A1 a1;
1671 A2 a2;
1672 A3 a3;
1673 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1674 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1675 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1676 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1677
1678 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1679 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1680 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1681 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1682 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1683
1684 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1685 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1686 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1687 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1688 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1689 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1690 }
1691
1692 } // t29
1693
1694 namespace t30
1695 {
1696
1697 struct A1
1698 {
1699 char _[43981];
~A1t30::A11700 virtual ~A1() {}
1701
getA1t30::A11702 A1* getA1() {return this;}
1703 };
1704
1705 struct A2
1706 : public A1
1707 {
1708 char _[34981];
~A2t30::A21709 virtual ~A2() {}
1710
getA1t30::A21711 A1* getA1() {return this;}
getA2t30::A21712 A2* getA2() {return this;}
1713 };
1714
1715 struct A3
1716 : private A1,
1717 private A2
1718 {
1719 char _[93481];
~A3t30::A31720 virtual ~A3() {}
1721
getA12t30::A31722 A1* getA12() {return A2::getA1();}
getA2t30::A31723 A2* getA2() {return this;}
getA3t30::A31724 A3* getA3() {return this;}
1725 };
1726
test()1727 void test()
1728 {
1729 A1 a1;
1730 A2 a2;
1731 A3 a3;
1732 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1733 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1734 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1735 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1736 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1737
1738 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1739 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1740 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1741 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1742 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1743
1744 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1745 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1746 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1747 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1748 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1749 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1750 }
1751
1752 } // t30
1753
1754 namespace t31
1755 {
1756
1757 struct A1
1758 {
1759 char _[43981];
~A1t31::A11760 virtual ~A1() {}
1761
getA1t31::A11762 A1* getA1() {return this;}
1763 };
1764
1765 struct A2
1766 : private A1
1767 {
1768 char _[34981];
~A2t31::A21769 virtual ~A2() {}
1770
getA1t31::A21771 A1* getA1() {return this;}
getA2t31::A21772 A2* getA2() {return this;}
1773 };
1774
1775 struct A3
1776 : public A1,
1777 private A2
1778 {
1779 char _[93481];
~A3t31::A31780 virtual ~A3() {}
1781
getA12t31::A31782 A1* getA12() {return A2::getA1();}
getA2t31::A31783 A2* getA2() {return this;}
getA3t31::A31784 A3* getA3() {return this;}
1785 };
1786
test()1787 void test()
1788 {
1789 A1 a1;
1790 A2 a2;
1791 A3 a3;
1792 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1793 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1794 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1795
1796 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1797 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1798 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1799 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1800 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1801
1802 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1803 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1804 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1805 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1806 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1807 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1808 }
1809
1810 } // t31
1811
1812 namespace t32
1813 {
1814
1815 struct A1
1816 {
1817 char _[43981];
~A1t32::A11818 virtual ~A1() {}
1819
getA1t32::A11820 A1* getA1() {return this;}
1821 };
1822
1823 struct A2
1824 : private A1
1825 {
1826 char _[34981];
~A2t32::A21827 virtual ~A2() {}
1828
getA1t32::A21829 A1* getA1() {return this;}
getA2t32::A21830 A2* getA2() {return this;}
1831 };
1832
1833 struct A3
1834 : private A1,
1835 public A2
1836 {
1837 char _[93481];
~A3t32::A31838 virtual ~A3() {}
1839
getA12t32::A31840 A1* getA12() {return A2::getA1();}
getA2t32::A31841 A2* getA2() {return this;}
getA3t32::A31842 A3* getA3() {return this;}
1843 };
1844
test()1845 void test()
1846 {
1847 A1 a1;
1848 A2 a2;
1849 A3 a3;
1850 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1851 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1852 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1853
1854 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1855 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1856 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1857 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1858 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1859
1860 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1861 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1862 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1863 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1864 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1865 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1866 }
1867
1868 } // t32
1869
1870 namespace t33
1871 {
1872
1873 struct A1
1874 {
1875 char _[43981];
~A1t33::A11876 virtual ~A1() {}
1877
getA1t33::A11878 A1* getA1() {return this;}
1879 };
1880
1881 struct A2
1882 : private A1
1883 {
1884 char _[34981];
~A2t33::A21885 virtual ~A2() {}
1886
getA1t33::A21887 A1* getA1() {return this;}
getA2t33::A21888 A2* getA2() {return this;}
1889 };
1890
1891 struct A3
1892 : private A1,
1893 private A2
1894 {
1895 char _[93481];
~A3t33::A31896 virtual ~A3() {}
1897
getA12t33::A31898 A1* getA12() {return A2::getA1();}
getA2t33::A31899 A2* getA2() {return this;}
getA3t33::A31900 A3* getA3() {return this;}
1901 };
1902
test()1903 void test()
1904 {
1905 A1 a1;
1906 A2 a2;
1907 A3 a3;
1908 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1909 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1910 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1911
1912 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1913 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1914 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1915 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1916 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1917
1918 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1919 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1920 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1921 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1922 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1923 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1924 }
1925
1926 } // t33
1927
1928 /*
1929
1930 A1
1931 | \
1932 A2 \
1933 \ |
1934 A3
1935
1936 */
1937
1938 namespace t34
1939 {
1940
1941 struct A1
1942 {
1943 char _[43981];
~A1t34::A11944 virtual ~A1() {}
1945
getA1t34::A11946 A1* getA1() {return this;}
1947 };
1948
1949 struct A2
1950 : public virtual A1
1951 {
1952 char _[34981];
~A2t34::A21953 virtual ~A2() {}
1954
getA1t34::A21955 A1* getA1() {return this;}
getA2t34::A21956 A2* getA2() {return this;}
1957 };
1958
1959 struct A3
1960 : public virtual A1,
1961 public A2
1962 {
1963 char _[93481];
~A3t34::A31964 virtual ~A3() {}
1965
getA1t34::A31966 A1* getA1() {return A1::getA1();}
getA2t34::A31967 A2* getA2() {return this;}
getA3t34::A31968 A3* getA3() {return this;}
1969 };
1970
test()1971 void test()
1972 {
1973 A1 a1;
1974 A2 a2;
1975 A3 a3;
1976 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1977 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1978 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1979 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1980 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1981 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1982
1983 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1984 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1985 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1986 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1987 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1988 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1989
1990 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1991 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1992 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1993 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1994 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1995 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1996 }
1997
1998 } // t34
1999
2000 namespace t35
2001 {
2002
2003 struct A1
2004 {
2005 char _[43981];
~A1t35::A12006 virtual ~A1() {}
2007
getA1t35::A12008 A1* getA1() {return this;}
2009 };
2010
2011 struct A2
2012 : private virtual A1
2013 {
2014 char _[34981];
~A2t35::A22015 virtual ~A2() {}
2016
getA1t35::A22017 A1* getA1() {return this;}
getA2t35::A22018 A2* getA2() {return this;}
2019 };
2020
2021 struct A3
2022 : public virtual A1,
2023 public A2
2024 {
2025 char _[93481];
~A3t35::A32026 virtual ~A3() {}
2027
getA1t35::A32028 A1* getA1() {return A1::getA1();}
getA2t35::A32029 A2* getA2() {return this;}
getA3t35::A32030 A3* getA3() {return this;}
2031 };
2032
test()2033 void test()
2034 {
2035 A1 a1;
2036 A2 a2;
2037 A3 a3;
2038 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2039 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2040 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2041 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2042
2043 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2044 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2045 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2046 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2047 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2048 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2049
2050 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2051 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2052 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2053 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2054 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2055 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2056 }
2057
2058 } // t35
2059
2060 namespace t36
2061 {
2062
2063 struct A1
2064 {
2065 char _[43981];
~A1t36::A12066 virtual ~A1() {}
2067
getA1t36::A12068 A1* getA1() {return this;}
2069 };
2070
2071 struct A2
2072 : public virtual A1
2073 {
2074 char _[34981];
~A2t36::A22075 virtual ~A2() {}
2076
getA1t36::A22077 A1* getA1() {return this;}
getA2t36::A22078 A2* getA2() {return this;}
2079 };
2080
2081 struct A3
2082 : private virtual A1,
2083 public A2
2084 {
2085 char _[93481];
~A3t36::A32086 virtual ~A3() {}
2087
getA1t36::A32088 A1* getA1() {return A1::getA1();}
getA2t36::A32089 A2* getA2() {return this;}
getA3t36::A32090 A3* getA3() {return this;}
2091 };
2092
test()2093 void test()
2094 {
2095 A1 a1;
2096 A2 a2;
2097 A3 a3;
2098 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2099 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2100 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2101 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2102 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2103 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2104
2105 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2106 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2107 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2108 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2109 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2110 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2111
2112 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2113 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2114 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2115 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2116 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2117 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2118 }
2119
2120 } // t36
2121
2122 namespace t37
2123 {
2124
2125 struct A1
2126 {
2127 char _[43981];
~A1t37::A12128 virtual ~A1() {}
2129
getA1t37::A12130 A1* getA1() {return this;}
2131 };
2132
2133 struct A2
2134 : public virtual A1
2135 {
2136 char _[34981];
~A2t37::A22137 virtual ~A2() {}
2138
getA1t37::A22139 A1* getA1() {return this;}
getA2t37::A22140 A2* getA2() {return this;}
2141 };
2142
2143 struct A3
2144 : public virtual A1,
2145 private A2
2146 {
2147 char _[93481];
~A3t37::A32148 virtual ~A3() {}
2149
getA1t37::A32150 A1* getA1() {return A1::getA1();}
getA2t37::A32151 A2* getA2() {return this;}
getA3t37::A32152 A3* getA3() {return this;}
2153 };
2154
test()2155 void test()
2156 {
2157 A1 a1;
2158 A2 a2;
2159 A3 a3;
2160 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2161 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2162 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2163 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2164 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2165 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2166
2167 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2168 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2169 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2170 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2171 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2172
2173 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2174 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2175 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2176 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2177 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2178 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2179 }
2180
2181 } // t37
2182
2183 namespace t38
2184 {
2185
2186 struct A1
2187 {
2188 char _[43981];
~A1t38::A12189 virtual ~A1() {}
2190
getA1t38::A12191 A1* getA1() {return this;}
2192 };
2193
2194 struct A2
2195 : public virtual A1
2196 {
2197 char _[34981];
~A2t38::A22198 virtual ~A2() {}
2199
getA1t38::A22200 A1* getA1() {return this;}
getA2t38::A22201 A2* getA2() {return this;}
2202 };
2203
2204 struct A3
2205 : private virtual A1,
2206 private A2
2207 {
2208 char _[93481];
~A3t38::A32209 virtual ~A3() {}
2210
getA1t38::A32211 A1* getA1() {return A1::getA1();}
getA2t38::A32212 A2* getA2() {return this;}
getA3t38::A32213 A3* getA3() {return this;}
2214 };
2215
test()2216 void test()
2217 {
2218 A1 a1;
2219 A2 a2;
2220 A3 a3;
2221 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2222 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2223 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2224 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2225 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2226
2227 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2228 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2229 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2230 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2231 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2232
2233 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2234 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2235 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2236 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2237 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2238 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2239 }
2240
2241 } // t38
2242
2243 namespace t39
2244 {
2245
2246 struct A1
2247 {
2248 char _[43981];
~A1t39::A12249 virtual ~A1() {}
2250
getA1t39::A12251 A1* getA1() {return this;}
2252 };
2253
2254 struct A2
2255 : private virtual A1
2256 {
2257 char _[34981];
~A2t39::A22258 virtual ~A2() {}
2259
getA1t39::A22260 A1* getA1() {return this;}
getA2t39::A22261 A2* getA2() {return this;}
2262 };
2263
2264 struct A3
2265 : public virtual A1,
2266 private A2
2267 {
2268 char _[93481];
~A3t39::A32269 virtual ~A3() {}
2270
getA1t39::A32271 A1* getA1() {return A1::getA1();}
getA2t39::A32272 A2* getA2() {return this;}
getA3t39::A32273 A3* getA3() {return this;}
2274 };
2275
test()2276 void test()
2277 {
2278 A1 a1;
2279 A2 a2;
2280 A3 a3;
2281 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2282 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2283 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2284 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2285
2286 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2287 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2288 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2289 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2290 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2291
2292 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2293 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2294 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2295 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2296 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2297 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2298 }
2299
2300 } // t39
2301
2302 namespace t40
2303 {
2304
2305 struct A1
2306 {
2307 char _[43981];
~A1t40::A12308 virtual ~A1() {}
2309
getA1t40::A12310 A1* getA1() {return this;}
2311 };
2312
2313 struct A2
2314 : private virtual A1
2315 {
2316 char _[34981];
~A2t40::A22317 virtual ~A2() {}
2318
getA1t40::A22319 A1* getA1() {return this;}
getA2t40::A22320 A2* getA2() {return this;}
2321 };
2322
2323 struct A3
2324 : private virtual A1,
2325 public A2
2326 {
2327 char _[93481];
~A3t40::A32328 virtual ~A3() {}
2329
getA1t40::A32330 A1* getA1() {return A1::getA1();}
getA2t40::A32331 A2* getA2() {return this;}
getA3t40::A32332 A3* getA3() {return this;}
2333 };
2334
test()2335 void test()
2336 {
2337 A1 a1;
2338 A2 a2;
2339 A3 a3;
2340 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2341 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2342 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2343
2344 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2345 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2346 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2347 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2348 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2349 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2350
2351 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2352 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2353 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2354 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2355 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2356 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2357 }
2358
2359 } // t40
2360
2361 namespace t41
2362 {
2363
2364 struct A1
2365 {
2366 char _[43981];
~A1t41::A12367 virtual ~A1() {}
2368
getA1t41::A12369 A1* getA1() {return this;}
2370 };
2371
2372 struct A2
2373 : private virtual A1
2374 {
2375 char _[34981];
~A2t41::A22376 virtual ~A2() {}
2377
getA1t41::A22378 A1* getA1() {return this;}
getA2t41::A22379 A2* getA2() {return this;}
2380 };
2381
2382 struct A3
2383 : private virtual A1,
2384 private A2
2385 {
2386 char _[93481];
~A3t41::A32387 virtual ~A3() {}
2388
getA1t41::A32389 A1* getA1() {return A1::getA1();}
getA2t41::A32390 A2* getA2() {return this;}
getA3t41::A32391 A3* getA3() {return this;}
2392 };
2393
test()2394 void test()
2395 {
2396 A1 a1;
2397 A2 a2;
2398 A3 a3;
2399 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2400 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2401 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2402
2403 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2404 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2405 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2406 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2407 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2408
2409 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2410 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2411 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2412 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2413 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2414 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2415 }
2416
2417 } // t41
2418
main(int,char **)2419 int main(int, char**)
2420 {
2421 timer t;
2422 t1::test();
2423 t2::test();
2424 t3::test();
2425 t4::test();
2426 t5::test();
2427 t6::test();
2428 t7::test();
2429 t8::test();
2430 t9::test();
2431 t10::test();
2432 t11::test();
2433 t12::test();
2434 t13::test();
2435 t14::test();
2436 t15::test();
2437 t16::test();
2438 t17::test();
2439 t18::test();
2440 t19::test();
2441 t20::test();
2442 t21::test();
2443 t22::test();
2444 t23::test();
2445 t24::test();
2446 t25::test();
2447 t26::test();
2448 t27::test();
2449 t28::test();
2450 t29::test();
2451 t30::test();
2452 t31::test();
2453 t32::test();
2454 t33::test();
2455 t34::test();
2456 t35::test();
2457 t36::test();
2458 t37::test();
2459 t38::test();
2460 t39::test();
2461 t40::test();
2462 t41::test();
2463
2464 return 0;
2465 }
2466