1 //===------------------------- dynamic_cast3.cpp --------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include <cassert>
11
12 /*
13
14 A1 A2 A3
15
16 */
17
18 namespace t1
19 {
20
21 struct A1
22 {
23 char _[43981];
~A1t1::A124 virtual ~A1() {}
25
getA1t1::A126 A1* getA1() {return this;}
27 };
28
29 struct A2
30 {
31 char _[34981];
~A2t1::A232 virtual ~A2() {}
33
getA2t1::A234 A2* getA2() {return this;}
35 };
36
37 struct A3
38 {
39 char _[93481];
~A3t1::A340 virtual ~A3() {}
41
getA3t1::A342 A3* getA3() {return this;}
43 };
44
test()45 void test()
46 {
47 A1 a1;
48 A2 a2;
49 A3 a3;
50 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
51 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
52 assert(dynamic_cast<A1*>(a3.getA3()) == 0);
53 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
54 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
55 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
56 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
57 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
58 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
59 }
60
61 } // t1
62
63 /*
64
65 A1 A2
66 |
67 A3
68
69 */
70
71 namespace t2
72 {
73
74 struct A1
75 {
76 char _[43981];
~A1t2::A177 virtual ~A1() {}
78
getA1t2::A179 A1* getA1() {return this;}
80 };
81
82 struct A2
83 {
84 char _[34981];
~A2t2::A285 virtual ~A2() {}
86
getA2t2::A287 A2* getA2() {return this;}
88 };
89
90 struct A3
91 : public A1
92 {
93 char _[93481];
~A3t2::A394 virtual ~A3() {}
95
getA3t2::A396 A3* getA3() {return this;}
97 };
98
test()99 void test()
100 {
101 A1 a1;
102 A2 a2;
103 A3 a3;
104 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
105 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
106 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
107 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
108
109 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
110 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
111 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
112 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
113
114 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
115 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
116 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
117 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
118 }
119
120 } // t2
121
122 namespace t3
123 {
124
125 struct A1
126 {
127 char _[43981];
~A1t3::A1128 virtual ~A1() {}
129
getA1t3::A1130 A1* getA1() {return this;}
131 };
132
133 struct A2
134 {
135 char _[34981];
~A2t3::A2136 virtual ~A2() {}
137
getA2t3::A2138 A2* getA2() {return this;}
139 };
140
141 struct A3
142 : public virtual A1
143 {
144 char _[93481];
~A3t3::A3145 virtual ~A3() {}
146
getA3t3::A3147 A3* getA3() {return this;}
148 };
149
test()150 void test()
151 {
152 A1 a1;
153 A2 a2;
154 A3 a3;
155 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
156 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
157 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
158 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
159
160 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
161 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
162 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
163 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
164
165 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
166 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
167 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
168 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
169 }
170
171 } // t3
172
173 namespace t4
174 {
175
176 struct A1
177 {
178 char _[43981];
~A1t4::A1179 virtual ~A1() {}
180
getA1t4::A1181 A1* getA1() {return this;}
182 };
183
184 struct A2
185 {
186 char _[34981];
~A2t4::A2187 virtual ~A2() {}
188
getA2t4::A2189 A2* getA2() {return this;}
190 };
191
192 struct A3
193 : private A1
194 {
195 char _[93481];
~A3t4::A3196 virtual ~A3() {}
197
getA1t4::A3198 A1* getA1() {return this;}
getA3t4::A3199 A3* getA3() {return this;}
200 };
201
test()202 void test()
203 {
204 A1 a1;
205 A2 a2;
206 A3 a3;
207 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
208 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
209 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
210
211 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
212 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
213 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
214 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
215
216 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
217 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
218 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
219 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
220 }
221
222 } // t4
223
224 namespace t5
225 {
226
227 struct A1
228 {
229 char _[43981];
~A1t5::A1230 virtual ~A1() {}
231
getA1t5::A1232 A1* getA1() {return this;}
233 };
234
235 struct A2
236 {
237 char _[34981];
~A2t5::A2238 virtual ~A2() {}
239
getA2t5::A2240 A2* getA2() {return this;}
241 };
242
243 struct A3
244 : private virtual A1
245 {
246 char _[93481];
~A3t5::A3247 virtual ~A3() {}
248
getA1t5::A3249 A1* getA1() {return this;}
getA3t5::A3250 A3* getA3() {return this;}
251 };
252
test()253 void test()
254 {
255 A1 a1;
256 A2 a2;
257 A3 a3;
258 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
259 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
260 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
261
262 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
263 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
264 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
265 assert(dynamic_cast<A2*>(a3.getA3()) == 0);
266
267 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
268 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
269 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
270 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
271 }
272
273 } // t5
274
275 /*
276
277 A1 A2
278 \ /
279 A3
280
281 */
282
283 namespace t6
284 {
285
286 struct A1
287 {
288 char _[43981];
~A1t6::A1289 virtual ~A1() {}
290
getA1t6::A1291 A1* getA1() {return this;}
292 };
293
294 struct A2
295 {
296 char _[34981];
~A2t6::A2297 virtual ~A2() {}
298
getA2t6::A2299 A2* getA2() {return this;}
300 };
301
302 struct A3
303 : public A1,
304 public A2
305 {
306 char _[93481];
~A3t6::A3307 virtual ~A3() {}
308
getA1t6::A3309 A1* getA1() {return this;}
getA2t6::A3310 A2* getA2() {return this;}
getA3t6::A3311 A3* getA3() {return this;}
312 };
313
test()314 void test()
315 {
316 A1 a1;
317 A2 a2;
318 A3 a3;
319 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
320 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
321 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
322 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
323 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
324
325 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
326 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
327 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
328 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
329 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
330
331 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
332 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
333 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
334 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
335 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
336 }
337
338 } // t6
339
340 namespace t7
341 {
342
343 struct A1
344 {
345 char _[43981];
~A1t7::A1346 virtual ~A1() {}
347
getA1t7::A1348 A1* getA1() {return this;}
349 };
350
351 struct A2
352 {
353 char _[34981];
~A2t7::A2354 virtual ~A2() {}
355
getA2t7::A2356 A2* getA2() {return this;}
357 };
358
359 struct A3
360 : public virtual A1,
361 public A2
362 {
363 char _[93481];
~A3t7::A3364 virtual ~A3() {}
365
getA1t7::A3366 A1* getA1() {return this;}
getA2t7::A3367 A2* getA2() {return this;}
getA3t7::A3368 A3* getA3() {return this;}
369 };
370
test()371 void test()
372 {
373 A1 a1;
374 A2 a2;
375 A3 a3;
376 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
377 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
378 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
379 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
380 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
381
382 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
383 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
384 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
385 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
386 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
387
388 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
389 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
390 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
391 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
392 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
393 }
394
395 } // t7
396
397 namespace t8
398 {
399
400 struct A1
401 {
402 char _[43981];
~A1t8::A1403 virtual ~A1() {}
404
getA1t8::A1405 A1* getA1() {return this;}
406 };
407
408 struct A2
409 {
410 char _[34981];
~A2t8::A2411 virtual ~A2() {}
412
getA2t8::A2413 A2* getA2() {return this;}
414 };
415
416 struct A3
417 : private A1,
418 public A2
419 {
420 char _[93481];
~A3t8::A3421 virtual ~A3() {}
422
getA1t8::A3423 A1* getA1() {return this;}
getA2t8::A3424 A2* getA2() {return this;}
getA3t8::A3425 A3* getA3() {return this;}
426 };
427
test()428 void test()
429 {
430 A1 a1;
431 A2 a2;
432 A3 a3;
433 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
434 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
435 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
436 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
437
438 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
439 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
440 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
441 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
442 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
443
444 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
445 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
446 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
447 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
448 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
449 }
450
451 } // t8
452
453 namespace t9
454 {
455
456 struct A1
457 {
458 char _[43981];
~A1t9::A1459 virtual ~A1() {}
460
getA1t9::A1461 A1* getA1() {return this;}
462 };
463
464 struct A2
465 {
466 char _[34981];
~A2t9::A2467 virtual ~A2() {}
468
getA2t9::A2469 A2* getA2() {return this;}
470 };
471
472 struct A3
473 : private virtual A1,
474 public A2
475 {
476 char _[93481];
~A3t9::A3477 virtual ~A3() {}
478
getA1t9::A3479 A1* getA1() {return this;}
getA2t9::A3480 A2* getA2() {return this;}
getA3t9::A3481 A3* getA3() {return this;}
482 };
483
test()484 void test()
485 {
486 A1 a1;
487 A2 a2;
488 A3 a3;
489 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
490 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
491 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
492 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
493
494 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
495 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
496 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
497 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
498 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
499
500 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
501 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
502 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
503 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
504 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
505 }
506
507 } // t9
508
509 namespace t10
510 {
511
512 struct A1
513 {
514 char _[43981];
~A1t10::A1515 virtual ~A1() {}
516
getA1t10::A1517 A1* getA1() {return this;}
518 };
519
520 struct A2
521 {
522 char _[34981];
~A2t10::A2523 virtual ~A2() {}
524
getA2t10::A2525 A2* getA2() {return this;}
526 };
527
528 struct A3
529 : public virtual A1,
530 public virtual A2
531 {
532 char _[93481];
~A3t10::A3533 virtual ~A3() {}
534
getA1t10::A3535 A1* getA1() {return this;}
getA2t10::A3536 A2* getA2() {return this;}
getA3t10::A3537 A3* getA3() {return this;}
538 };
539
test()540 void test()
541 {
542 A1 a1;
543 A2 a2;
544 A3 a3;
545 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
546 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
547 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
548 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
549 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
550
551 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
552 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
553 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
554 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
555 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
556
557 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
558 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
559 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
560 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
561 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
562 }
563
564 } // t10
565
566 namespace t11
567 {
568
569 struct A1
570 {
571 char _[43981];
~A1t11::A1572 virtual ~A1() {}
573
getA1t11::A1574 A1* getA1() {return this;}
575 };
576
577 struct A2
578 {
579 char _[34981];
~A2t11::A2580 virtual ~A2() {}
581
getA2t11::A2582 A2* getA2() {return this;}
583 };
584
585 struct A3
586 : private A1,
587 public virtual A2
588 {
589 char _[93481];
~A3t11::A3590 virtual ~A3() {}
591
getA1t11::A3592 A1* getA1() {return this;}
getA2t11::A3593 A2* getA2() {return this;}
getA3t11::A3594 A3* getA3() {return this;}
595 };
596
test()597 void test()
598 {
599 A1 a1;
600 A2 a2;
601 A3 a3;
602 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
603 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
604 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
605 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
606
607 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
608 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
609 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
610 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
611 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
612
613 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
614 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
615 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
616 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
617 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
618 }
619
620 } // t11
621
622 namespace t12
623 {
624
625 struct A1
626 {
627 char _[43981];
~A1t12::A1628 virtual ~A1() {}
629
getA1t12::A1630 A1* getA1() {return this;}
631 };
632
633 struct A2
634 {
635 char _[34981];
~A2t12::A2636 virtual ~A2() {}
637
getA2t12::A2638 A2* getA2() {return this;}
639 };
640
641 struct A3
642 : private virtual A1,
643 public virtual A2
644 {
645 char _[93481];
~A3t12::A3646 virtual ~A3() {}
647
getA1t12::A3648 A1* getA1() {return this;}
getA2t12::A3649 A2* getA2() {return this;}
getA3t12::A3650 A3* getA3() {return this;}
651 };
652
test()653 void test()
654 {
655 A1 a1;
656 A2 a2;
657 A3 a3;
658 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
659 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
660 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
661 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
662
663 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
664 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
665 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
666 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
667 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
668
669 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
670 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
671 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
672 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
673 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
674 }
675
676 } // t12
677
678 namespace t13
679 {
680
681 struct A1
682 {
683 char _[43981];
~A1t13::A1684 virtual ~A1() {}
685
getA1t13::A1686 A1* getA1() {return this;}
687 };
688
689 struct A2
690 {
691 char _[34981];
~A2t13::A2692 virtual ~A2() {}
693
getA2t13::A2694 A2* getA2() {return this;}
695 };
696
697 struct A3
698 : private A1,
699 private A2
700 {
701 char _[93481];
~A3t13::A3702 virtual ~A3() {}
703
getA1t13::A3704 A1* getA1() {return this;}
getA2t13::A3705 A2* getA2() {return this;}
getA3t13::A3706 A3* getA3() {return this;}
707 };
708
test()709 void test()
710 {
711 A1 a1;
712 A2 a2;
713 A3 a3;
714 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
715 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
716 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
717 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
718
719 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
720 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
721 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
722 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
723
724 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
725 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
726 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
727 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
728 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
729 }
730
731 } // t13
732
733 namespace t14
734 {
735
736 struct A1
737 {
738 char _[43981];
~A1t14::A1739 virtual ~A1() {}
740
getA1t14::A1741 A1* getA1() {return this;}
742 };
743
744 struct A2
745 {
746 char _[34981];
~A2t14::A2747 virtual ~A2() {}
748
getA2t14::A2749 A2* getA2() {return this;}
750 };
751
752 struct A3
753 : private virtual A1,
754 private A2
755 {
756 char _[93481];
~A3t14::A3757 virtual ~A3() {}
758
getA1t14::A3759 A1* getA1() {return this;}
getA2t14::A3760 A2* getA2() {return this;}
getA3t14::A3761 A3* getA3() {return this;}
762 };
763
test()764 void test()
765 {
766 A1 a1;
767 A2 a2;
768 A3 a3;
769 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
770 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
771 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
772 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
773
774 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
775 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
776 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
777 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
778
779 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
780 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
781 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
782 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
783 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
784 }
785
786 } // t14
787
788 namespace t15
789 {
790
791 struct A1
792 {
793 char _[43981];
~A1t15::A1794 virtual ~A1() {}
795
getA1t15::A1796 A1* getA1() {return this;}
797 };
798
799 struct A2
800 {
801 char _[34981];
~A2t15::A2802 virtual ~A2() {}
803
getA2t15::A2804 A2* getA2() {return this;}
805 };
806
807 struct A3
808 : private virtual A1,
809 private virtual A2
810 {
811 char _[93481];
~A3t15::A3812 virtual ~A3() {}
813
getA1t15::A3814 A1* getA1() {return this;}
getA2t15::A3815 A2* getA2() {return this;}
getA3t15::A3816 A3* getA3() {return this;}
817 };
818
test()819 void test()
820 {
821 A1 a1;
822 A2 a2;
823 A3 a3;
824 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
825 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
826 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
827 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
828
829 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
830 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
831 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
832 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
833
834 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
835 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
836 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
837 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
838 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
839 }
840
841 } // t15
842
843 /*
844
845 A1
846 |
847 A2
848 |
849 A3
850
851 */
852
853 namespace t16
854 {
855
856 struct A1
857 {
858 char _[43981];
~A1t16::A1859 virtual ~A1() {}
860
getA1t16::A1861 A1* getA1() {return this;}
862 };
863
864 struct A2
865 : public A1
866 {
867 char _[34981];
~A2t16::A2868 virtual ~A2() {}
869
getA1t16::A2870 A1* getA1() {return this;}
getA2t16::A2871 A2* getA2() {return this;}
872 };
873
874 struct A3
875 : public A2
876 {
877 char _[93481];
~A3t16::A3878 virtual ~A3() {}
879
getA1t16::A3880 A1* getA1() {return this;}
getA2t16::A3881 A2* getA2() {return this;}
getA3t16::A3882 A3* getA3() {return this;}
883 };
884
test()885 void test()
886 {
887 A1 a1;
888 A2 a2;
889 A3 a3;
890 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
891 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
892 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
893 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
894 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
895 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
896
897 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
898 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
899 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
900 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
901 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
902 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
903
904 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
905 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
906 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
907 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
908 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
909 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
910 }
911
912 } // t16
913
914 namespace t17
915 {
916
917 struct A1
918 {
919 char _[43981];
~A1t17::A1920 virtual ~A1() {}
921
getA1t17::A1922 A1* getA1() {return this;}
923 };
924
925 struct A2
926 : public virtual A1
927 {
928 char _[34981];
~A2t17::A2929 virtual ~A2() {}
930
getA1t17::A2931 A1* getA1() {return this;}
getA2t17::A2932 A2* getA2() {return this;}
933 };
934
935 struct A3
936 : public A2
937 {
938 char _[93481];
~A3t17::A3939 virtual ~A3() {}
940
getA1t17::A3941 A1* getA1() {return this;}
getA2t17::A3942 A2* getA2() {return this;}
getA3t17::A3943 A3* getA3() {return this;}
944 };
945
test()946 void test()
947 {
948 A1 a1;
949 A2 a2;
950 A3 a3;
951 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
952 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
953 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
954 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
955 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
956 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
957
958 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
959 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
960 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
961 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
962 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
963 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
964
965 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
966 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
967 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
968 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
969 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
970 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
971 }
972
973 } // t17
974
975 namespace t18
976 {
977
978 struct A1
979 {
980 char _[43981];
~A1t18::A1981 virtual ~A1() {}
982
getA1t18::A1983 A1* getA1() {return this;}
984 };
985
986 struct A2
987 : private A1
988 {
989 char _[34981];
~A2t18::A2990 virtual ~A2() {}
991
getA1t18::A2992 A1* getA1() {return this;}
getA2t18::A2993 A2* getA2() {return this;}
994 };
995
996 struct A3
997 : public A2
998 {
999 char _[93481];
~A3t18::A31000 virtual ~A3() {}
1001
getA2t18::A31002 A2* getA2() {return this;}
getA3t18::A31003 A3* getA3() {return this;}
1004 };
1005
test()1006 void test()
1007 {
1008 A1 a1;
1009 A2 a2;
1010 A3 a3;
1011 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1012 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1013 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1014
1015 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1016 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1017 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1018 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1019 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1020 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1021
1022 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1023 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1024 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1025 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1026 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1027 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1028 }
1029
1030 } // t18
1031
1032 namespace t19
1033 {
1034
1035 struct A1
1036 {
1037 char _[43981];
~A1t19::A11038 virtual ~A1() {}
1039
getA1t19::A11040 A1* getA1() {return this;}
1041 };
1042
1043 struct A2
1044 : protected virtual A1
1045 {
1046 char _[34981];
~A2t19::A21047 virtual ~A2() {}
1048
getA1t19::A21049 A1* getA1() {return this;}
getA2t19::A21050 A2* getA2() {return this;}
1051 };
1052
1053 struct A3
1054 : public A2
1055 {
1056 char _[93481];
~A3t19::A31057 virtual ~A3() {}
1058
getA2t19::A31059 A2* getA2() {return this;}
getA3t19::A31060 A3* getA3() {return this;}
1061 };
1062
test()1063 void test()
1064 {
1065 A1 a1;
1066 A2 a2;
1067 A3 a3;
1068 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1069 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1070 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1071
1072 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1073 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1074 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1075 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1076 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1077 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1078
1079 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1080 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1081 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1082 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1083 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1084 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1085 }
1086
1087 } // t19
1088
1089 namespace t20
1090 {
1091
1092 struct A1
1093 {
1094 char _[43981];
~A1t20::A11095 virtual ~A1() {}
1096
getA1t20::A11097 A1* getA1() {return this;}
1098 };
1099
1100 struct A2
1101 : public virtual A1
1102 {
1103 char _[34981];
~A2t20::A21104 virtual ~A2() {}
1105
getA1t20::A21106 A1* getA1() {return this;}
getA2t20::A21107 A2* getA2() {return this;}
1108 };
1109
1110 struct A3
1111 : public virtual A2
1112 {
1113 char _[93481];
~A3t20::A31114 virtual ~A3() {}
1115
getA1t20::A31116 A1* getA1() {return this;}
getA2t20::A31117 A2* getA2() {return this;}
getA3t20::A31118 A3* getA3() {return this;}
1119 };
1120
test()1121 void test()
1122 {
1123 A1 a1;
1124 A2 a2;
1125 A3 a3;
1126 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1127 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1128 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1129 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1130 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1131 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1132
1133 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1134 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1135 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1136 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1137 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1138 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1139
1140 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1141 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1142 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1143 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1144 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1145 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1146 }
1147
1148 } // t20
1149
1150 namespace t21
1151 {
1152
1153 struct A1
1154 {
1155 char _[43981];
~A1t21::A11156 virtual ~A1() {}
1157
getA1t21::A11158 A1* getA1() {return this;}
1159 };
1160
1161 struct A2
1162 : private A1
1163 {
1164 char _[34981];
~A2t21::A21165 virtual ~A2() {}
1166
getA1t21::A21167 A1* getA1() {return this;}
getA2t21::A21168 A2* getA2() {return this;}
1169 };
1170
1171 struct A3
1172 : public virtual A2
1173 {
1174 char _[93481];
~A3t21::A31175 virtual ~A3() {}
1176
getA2t21::A31177 A2* getA2() {return this;}
getA3t21::A31178 A3* getA3() {return this;}
1179 };
1180
test()1181 void test()
1182 {
1183 A1 a1;
1184 A2 a2;
1185 A3 a3;
1186 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1187 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1188 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1189
1190 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1191 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1192 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1193 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1194 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1195 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1196
1197 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1198 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1199 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1200 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1201 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1202 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1203 }
1204
1205 } // t21
1206
1207 namespace t22
1208 {
1209
1210 struct A1
1211 {
1212 char _[43981];
~A1t22::A11213 virtual ~A1() {}
1214
getA1t22::A11215 A1* getA1() {return this;}
1216 };
1217
1218 struct A2
1219 : protected virtual A1
1220 {
1221 char _[34981];
~A2t22::A21222 virtual ~A2() {}
1223
getA1t22::A21224 A1* getA1() {return this;}
getA2t22::A21225 A2* getA2() {return this;}
1226 };
1227
1228 struct A3
1229 : public virtual A2
1230 {
1231 char _[93481];
~A3t22::A31232 virtual ~A3() {}
1233
getA2t22::A31234 A2* getA2() {return this;}
getA3t22::A31235 A3* getA3() {return this;}
1236 };
1237
test()1238 void test()
1239 {
1240 A1 a1;
1241 A2 a2;
1242 A3 a3;
1243 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1244 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1245 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1246
1247 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1248 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1249 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1250 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1251 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1252 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1253
1254 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1255 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1256 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1257 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1258 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1259 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1260 }
1261
1262 } // t22
1263
1264 namespace t23
1265 {
1266
1267 struct A1
1268 {
1269 char _[43981];
~A1t23::A11270 virtual ~A1() {}
1271
getA1t23::A11272 A1* getA1() {return this;}
1273 };
1274
1275 struct A2
1276 : private A1
1277 {
1278 char _[34981];
~A2t23::A21279 virtual ~A2() {}
1280
getA1t23::A21281 A1* getA1() {return this;}
getA2t23::A21282 A2* getA2() {return this;}
1283 };
1284
1285 struct A3
1286 : private A2
1287 {
1288 char _[93481];
~A3t23::A31289 virtual ~A3() {}
1290
getA1t23::A31291 t23::A1* getA1() {return A2::getA1();}
getA2t23::A31292 A2* getA2() {return this;}
getA3t23::A31293 A3* getA3() {return this;}
1294 };
1295
test()1296 void test()
1297 {
1298 A1 a1;
1299 A2 a2;
1300 A3 a3;
1301 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1302 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1303 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1304
1305 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1306 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1307 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1308 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1309 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1310
1311 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1312 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1313 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1314 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1315 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1316 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1317 }
1318
1319 } // t23
1320
1321 namespace t24
1322 {
1323
1324 struct A1
1325 {
1326 char _[43981];
~A1t24::A11327 virtual ~A1() {}
1328
getA1t24::A11329 A1* getA1() {return this;}
1330 };
1331
1332 struct A2
1333 : protected virtual A1
1334 {
1335 char _[34981];
~A2t24::A21336 virtual ~A2() {}
1337
getA1t24::A21338 A1* getA1() {return this;}
getA2t24::A21339 A2* getA2() {return this;}
1340 };
1341
1342 struct A3
1343 : private A2
1344 {
1345 char _[93481];
~A3t24::A31346 virtual ~A3() {}
1347
getA1t24::A31348 t24::A1* getA1() {return A2::getA1();}
getA2t24::A31349 A2* getA2() {return this;}
getA3t24::A31350 A3* getA3() {return this;}
1351 };
1352
test()1353 void test()
1354 {
1355 A1 a1;
1356 A2 a2;
1357 A3 a3;
1358 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1359 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1360 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1361
1362 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1363 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1364 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1365 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1366 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1367
1368 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1369 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1370 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1371 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1372 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1373 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1374 }
1375
1376 } // t24
1377
1378 namespace t25
1379 {
1380
1381 struct A1
1382 {
1383 char _[43981];
~A1t25::A11384 virtual ~A1() {}
1385
getA1t25::A11386 A1* getA1() {return this;}
1387 };
1388
1389 struct A2
1390 : protected virtual A1
1391 {
1392 char _[34981];
~A2t25::A21393 virtual ~A2() {}
1394
getA1t25::A21395 A1* getA1() {return this;}
getA2t25::A21396 A2* getA2() {return this;}
1397 };
1398
1399 struct A3
1400 : private virtual A2
1401 {
1402 char _[93481];
~A3t25::A31403 virtual ~A3() {}
1404
getA1t25::A31405 t25::A1* getA1() {return A2::getA1();}
getA2t25::A31406 A2* getA2() {return this;}
getA3t25::A31407 A3* getA3() {return this;}
1408 };
1409
test()1410 void test()
1411 {
1412 A1 a1;
1413 A2 a2;
1414 A3 a3;
1415 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1416 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1417 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1418
1419 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1420 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1421 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1422 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1423 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1424
1425 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1426 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1427 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1428 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1429 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1430 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1431 }
1432
1433 } // t25
1434
1435 /*
1436
1437 A1 A1
1438 | |
1439 A2 |
1440 \ |
1441 A3
1442
1443 */
1444
1445 namespace t26
1446 {
1447
1448 struct A1
1449 {
1450 char _[43981];
~A1t26::A11451 virtual ~A1() {}
1452
getA1t26::A11453 A1* getA1() {return this;}
1454 };
1455
1456 struct A2
1457 : public A1
1458 {
1459 char _[34981];
~A2t26::A21460 virtual ~A2() {}
1461
getA1t26::A21462 A1* getA1() {return this;}
getA2t26::A21463 A2* getA2() {return this;}
1464 };
1465
1466 struct A3
1467 : public A1,
1468 public A2
1469 {
1470 char _[93481];
~A3t26::A31471 virtual ~A3() {}
1472
getA12t26::A31473 A1* getA12() {return A2::getA1();}
getA2t26::A31474 A2* getA2() {return this;}
getA3t26::A31475 A3* getA3() {return this;}
1476 };
1477
test()1478 void test()
1479 {
1480 A1 a1;
1481 A2 a2;
1482 A3 a3;
1483 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1484 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1485 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1486 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1487 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1488
1489 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1490 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1491 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1492 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1493 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1494 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1495
1496 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1497 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1498 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1499 assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1500 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1501 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1502 }
1503
1504 } // t26
1505
1506 namespace t27
1507 {
1508
1509 struct A1
1510 {
1511 char _[43981];
~A1t27::A11512 virtual ~A1() {}
1513
getA1t27::A11514 A1* getA1() {return this;}
1515 };
1516
1517 struct A2
1518 : private A1
1519 {
1520 char _[34981];
~A2t27::A21521 virtual ~A2() {}
1522
getA1t27::A21523 A1* getA1() {return this;}
getA2t27::A21524 A2* getA2() {return this;}
1525 };
1526
1527 struct A3
1528 : public A1,
1529 public A2
1530 {
1531 char _[93481];
~A3t27::A31532 virtual ~A3() {}
1533
getA12t27::A31534 A1* getA12() {return A2::getA1();}
getA2t27::A31535 A2* getA2() {return this;}
getA3t27::A31536 A3* getA3() {return this;}
1537 };
1538
test()1539 void test()
1540 {
1541 A1 a1;
1542 A2 a2;
1543 A3 a3;
1544 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1545 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1546 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1547
1548 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1549 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1550 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1551 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1552 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1553 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1554
1555 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1556 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1557 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1558 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1559 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1560 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1561 }
1562
1563 } // t27
1564
1565 namespace t28
1566 {
1567
1568 struct A1
1569 {
1570 char _[43981];
~A1t28::A11571 virtual ~A1() {}
1572
getA1t28::A11573 A1* getA1() {return this;}
1574 };
1575
1576 struct A2
1577 : public A1
1578 {
1579 char _[34981];
~A2t28::A21580 virtual ~A2() {}
1581
getA1t28::A21582 A1* getA1() {return this;}
getA2t28::A21583 A2* getA2() {return this;}
1584 };
1585
1586 struct A3
1587 : private A1,
1588 public A2
1589 {
1590 char _[93481];
~A3t28::A31591 virtual ~A3() {}
1592
getA12t28::A31593 A1* getA12() {return A2::getA1();}
getA2t28::A31594 A2* getA2() {return this;}
getA3t28::A31595 A3* getA3() {return this;}
1596 };
1597
test()1598 void test()
1599 {
1600 A1 a1;
1601 A2 a2;
1602 A3 a3;
1603 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1604 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1605 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1606 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1607
1608 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1609 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1610 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1611 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1612 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1613 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1614
1615 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1616 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1617 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1618 assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1619 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1620 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1621 }
1622
1623 } // t28
1624
1625 namespace t29
1626 {
1627
1628 struct A1
1629 {
1630 char _[43981];
~A1t29::A11631 virtual ~A1() {}
1632
getA1t29::A11633 A1* getA1() {return this;}
1634 };
1635
1636 struct A2
1637 : public A1
1638 {
1639 char _[34981];
~A2t29::A21640 virtual ~A2() {}
1641
getA1t29::A21642 A1* getA1() {return this;}
getA2t29::A21643 A2* getA2() {return this;}
1644 };
1645
1646 struct A3
1647 : public A1,
1648 private A2
1649 {
1650 char _[93481];
~A3t29::A31651 virtual ~A3() {}
1652
getA12t29::A31653 A1* getA12() {return A2::getA1();}
getA2t29::A31654 A2* getA2() {return this;}
getA3t29::A31655 A3* getA3() {return this;}
1656 };
1657
test()1658 void test()
1659 {
1660 A1 a1;
1661 A2 a2;
1662 A3 a3;
1663 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1664 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1665 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1666 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1667
1668 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1669 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1670 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1671 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1672 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1673
1674 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1675 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1676 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1677 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1678 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1679 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1680 }
1681
1682 } // t29
1683
1684 namespace t30
1685 {
1686
1687 struct A1
1688 {
1689 char _[43981];
~A1t30::A11690 virtual ~A1() {}
1691
getA1t30::A11692 A1* getA1() {return this;}
1693 };
1694
1695 struct A2
1696 : public A1
1697 {
1698 char _[34981];
~A2t30::A21699 virtual ~A2() {}
1700
getA1t30::A21701 A1* getA1() {return this;}
getA2t30::A21702 A2* getA2() {return this;}
1703 };
1704
1705 struct A3
1706 : private A1,
1707 private A2
1708 {
1709 char _[93481];
~A3t30::A31710 virtual ~A3() {}
1711
getA12t30::A31712 A1* getA12() {return A2::getA1();}
getA2t30::A31713 A2* getA2() {return this;}
getA3t30::A31714 A3* getA3() {return this;}
1715 };
1716
test()1717 void test()
1718 {
1719 A1 a1;
1720 A2 a2;
1721 A3 a3;
1722 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1723 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1724 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1725 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1726 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1727
1728 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1729 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1730 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1731 assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1732 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1733
1734 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1735 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1736 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1737 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1738 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1739 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1740 }
1741
1742 } // t30
1743
1744 namespace t31
1745 {
1746
1747 struct A1
1748 {
1749 char _[43981];
~A1t31::A11750 virtual ~A1() {}
1751
getA1t31::A11752 A1* getA1() {return this;}
1753 };
1754
1755 struct A2
1756 : private A1
1757 {
1758 char _[34981];
~A2t31::A21759 virtual ~A2() {}
1760
getA1t31::A21761 A1* getA1() {return this;}
getA2t31::A21762 A2* getA2() {return this;}
1763 };
1764
1765 struct A3
1766 : public A1,
1767 private A2
1768 {
1769 char _[93481];
~A3t31::A31770 virtual ~A3() {}
1771
getA12t31::A31772 A1* getA12() {return A2::getA1();}
getA2t31::A31773 A2* getA2() {return this;}
getA3t31::A31774 A3* getA3() {return this;}
1775 };
1776
test()1777 void test()
1778 {
1779 A1 a1;
1780 A2 a2;
1781 A3 a3;
1782 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1783 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1784 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1785
1786 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1787 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1788 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1789 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1790 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1791
1792 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1793 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1794 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1795 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1796 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1797 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1798 }
1799
1800 } // t31
1801
1802 namespace t32
1803 {
1804
1805 struct A1
1806 {
1807 char _[43981];
~A1t32::A11808 virtual ~A1() {}
1809
getA1t32::A11810 A1* getA1() {return this;}
1811 };
1812
1813 struct A2
1814 : private A1
1815 {
1816 char _[34981];
~A2t32::A21817 virtual ~A2() {}
1818
getA1t32::A21819 A1* getA1() {return this;}
getA2t32::A21820 A2* getA2() {return this;}
1821 };
1822
1823 struct A3
1824 : private A1,
1825 public A2
1826 {
1827 char _[93481];
~A3t32::A31828 virtual ~A3() {}
1829
getA12t32::A31830 A1* getA12() {return A2::getA1();}
getA2t32::A31831 A2* getA2() {return this;}
getA3t32::A31832 A3* getA3() {return this;}
1833 };
1834
test()1835 void test()
1836 {
1837 A1 a1;
1838 A2 a2;
1839 A3 a3;
1840 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1841 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1842 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1843
1844 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1845 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1846 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1847 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1848 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1849
1850 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1851 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1852 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1853 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1854 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1855 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1856 }
1857
1858 } // t32
1859
1860 namespace t33
1861 {
1862
1863 struct A1
1864 {
1865 char _[43981];
~A1t33::A11866 virtual ~A1() {}
1867
getA1t33::A11868 A1* getA1() {return this;}
1869 };
1870
1871 struct A2
1872 : private A1
1873 {
1874 char _[34981];
~A2t33::A21875 virtual ~A2() {}
1876
getA1t33::A21877 A1* getA1() {return this;}
getA2t33::A21878 A2* getA2() {return this;}
1879 };
1880
1881 struct A3
1882 : private A1,
1883 private A2
1884 {
1885 char _[93481];
~A3t33::A31886 virtual ~A3() {}
1887
getA12t33::A31888 A1* getA12() {return A2::getA1();}
getA2t33::A31889 A2* getA2() {return this;}
getA3t33::A31890 A3* getA3() {return this;}
1891 };
1892
test()1893 void test()
1894 {
1895 A1 a1;
1896 A2 a2;
1897 A3 a3;
1898 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1899 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1900 assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1901
1902 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1903 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1904 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1905 assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1906 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1907
1908 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1909 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1910 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1911 assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1912 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1913 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1914 }
1915
1916 } // t33
1917
1918 /*
1919
1920 A1
1921 | \
1922 A2 \
1923 \ |
1924 A3
1925
1926 */
1927
1928 namespace t34
1929 {
1930
1931 struct A1
1932 {
1933 char _[43981];
~A1t34::A11934 virtual ~A1() {}
1935
getA1t34::A11936 A1* getA1() {return this;}
1937 };
1938
1939 struct A2
1940 : public virtual A1
1941 {
1942 char _[34981];
~A2t34::A21943 virtual ~A2() {}
1944
getA1t34::A21945 A1* getA1() {return this;}
getA2t34::A21946 A2* getA2() {return this;}
1947 };
1948
1949 struct A3
1950 : public virtual A1,
1951 public A2
1952 {
1953 char _[93481];
~A3t34::A31954 virtual ~A3() {}
1955
getA1t34::A31956 A1* getA1() {return A1::getA1();}
getA2t34::A31957 A2* getA2() {return this;}
getA3t34::A31958 A3* getA3() {return this;}
1959 };
1960
test()1961 void test()
1962 {
1963 A1 a1;
1964 A2 a2;
1965 A3 a3;
1966 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1967 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1968 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1969 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1970 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1971 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1972
1973 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1974 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1975 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1976 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1977 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1978 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1979
1980 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1981 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1982 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1983 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1984 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1985 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1986 }
1987
1988 } // t34
1989
1990 namespace t35
1991 {
1992
1993 struct A1
1994 {
1995 char _[43981];
~A1t35::A11996 virtual ~A1() {}
1997
getA1t35::A11998 A1* getA1() {return this;}
1999 };
2000
2001 struct A2
2002 : private virtual A1
2003 {
2004 char _[34981];
~A2t35::A22005 virtual ~A2() {}
2006
getA1t35::A22007 A1* getA1() {return this;}
getA2t35::A22008 A2* getA2() {return this;}
2009 };
2010
2011 struct A3
2012 : public virtual A1,
2013 public A2
2014 {
2015 char _[93481];
~A3t35::A32016 virtual ~A3() {}
2017
getA1t35::A32018 A1* getA1() {return A1::getA1();}
getA2t35::A32019 A2* getA2() {return this;}
getA3t35::A32020 A3* getA3() {return this;}
2021 };
2022
test()2023 void test()
2024 {
2025 A1 a1;
2026 A2 a2;
2027 A3 a3;
2028 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2029 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2030 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2031 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2032
2033 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2034 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2035 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2036 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2037 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2038 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2039
2040 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2041 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2042 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2043 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2044 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2045 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2046 }
2047
2048 } // t35
2049
2050 namespace t36
2051 {
2052
2053 struct A1
2054 {
2055 char _[43981];
~A1t36::A12056 virtual ~A1() {}
2057
getA1t36::A12058 A1* getA1() {return this;}
2059 };
2060
2061 struct A2
2062 : public virtual A1
2063 {
2064 char _[34981];
~A2t36::A22065 virtual ~A2() {}
2066
getA1t36::A22067 A1* getA1() {return this;}
getA2t36::A22068 A2* getA2() {return this;}
2069 };
2070
2071 struct A3
2072 : private virtual A1,
2073 public A2
2074 {
2075 char _[93481];
~A3t36::A32076 virtual ~A3() {}
2077
getA1t36::A32078 A1* getA1() {return A1::getA1();}
getA2t36::A32079 A2* getA2() {return this;}
getA3t36::A32080 A3* getA3() {return this;}
2081 };
2082
test()2083 void test()
2084 {
2085 A1 a1;
2086 A2 a2;
2087 A3 a3;
2088 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2089 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2090 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2091 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2092 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2093 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2094
2095 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2096 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2097 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2098 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2099 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2100 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2101
2102 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2103 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2104 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2105 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2106 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2107 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2108 }
2109
2110 } // t36
2111
2112 namespace t37
2113 {
2114
2115 struct A1
2116 {
2117 char _[43981];
~A1t37::A12118 virtual ~A1() {}
2119
getA1t37::A12120 A1* getA1() {return this;}
2121 };
2122
2123 struct A2
2124 : public virtual A1
2125 {
2126 char _[34981];
~A2t37::A22127 virtual ~A2() {}
2128
getA1t37::A22129 A1* getA1() {return this;}
getA2t37::A22130 A2* getA2() {return this;}
2131 };
2132
2133 struct A3
2134 : public virtual A1,
2135 private A2
2136 {
2137 char _[93481];
~A3t37::A32138 virtual ~A3() {}
2139
getA1t37::A32140 A1* getA1() {return A1::getA1();}
getA2t37::A32141 A2* getA2() {return this;}
getA3t37::A32142 A3* getA3() {return this;}
2143 };
2144
test()2145 void test()
2146 {
2147 A1 a1;
2148 A2 a2;
2149 A3 a3;
2150 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2151 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2152 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2153 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2154 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2155 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2156
2157 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2158 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2159 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2160 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2161 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2162
2163 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2164 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2165 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2166 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2167 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2168 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2169 }
2170
2171 } // t37
2172
2173 namespace t38
2174 {
2175
2176 struct A1
2177 {
2178 char _[43981];
~A1t38::A12179 virtual ~A1() {}
2180
getA1t38::A12181 A1* getA1() {return this;}
2182 };
2183
2184 struct A2
2185 : public virtual A1
2186 {
2187 char _[34981];
~A2t38::A22188 virtual ~A2() {}
2189
getA1t38::A22190 A1* getA1() {return this;}
getA2t38::A22191 A2* getA2() {return this;}
2192 };
2193
2194 struct A3
2195 : private virtual A1,
2196 private A2
2197 {
2198 char _[93481];
~A3t38::A32199 virtual ~A3() {}
2200
getA1t38::A32201 A1* getA1() {return A1::getA1();}
getA2t38::A32202 A2* getA2() {return this;}
getA3t38::A32203 A3* getA3() {return this;}
2204 };
2205
test()2206 void test()
2207 {
2208 A1 a1;
2209 A2 a2;
2210 A3 a3;
2211 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2212 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2213 assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2214 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2215 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2216
2217 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2218 assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2219 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2220 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2221 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2222
2223 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2224 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2225 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2226 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2227 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2228 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2229 }
2230
2231 } // t38
2232
2233 namespace t39
2234 {
2235
2236 struct A1
2237 {
2238 char _[43981];
~A1t39::A12239 virtual ~A1() {}
2240
getA1t39::A12241 A1* getA1() {return this;}
2242 };
2243
2244 struct A2
2245 : private virtual A1
2246 {
2247 char _[34981];
~A2t39::A22248 virtual ~A2() {}
2249
getA1t39::A22250 A1* getA1() {return this;}
getA2t39::A22251 A2* getA2() {return this;}
2252 };
2253
2254 struct A3
2255 : public virtual A1,
2256 private A2
2257 {
2258 char _[93481];
~A3t39::A32259 virtual ~A3() {}
2260
getA1t39::A32261 A1* getA1() {return A1::getA1();}
getA2t39::A32262 A2* getA2() {return this;}
getA3t39::A32263 A3* getA3() {return this;}
2264 };
2265
test()2266 void test()
2267 {
2268 A1 a1;
2269 A2 a2;
2270 A3 a3;
2271 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2272 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2273 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2274 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2275
2276 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2277 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2278 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2279 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2280 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2281
2282 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2283 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2284 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2285 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2286 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2287 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2288 }
2289
2290 } // t39
2291
2292 namespace t40
2293 {
2294
2295 struct A1
2296 {
2297 char _[43981];
~A1t40::A12298 virtual ~A1() {}
2299
getA1t40::A12300 A1* getA1() {return this;}
2301 };
2302
2303 struct A2
2304 : private virtual A1
2305 {
2306 char _[34981];
~A2t40::A22307 virtual ~A2() {}
2308
getA1t40::A22309 A1* getA1() {return this;}
getA2t40::A22310 A2* getA2() {return this;}
2311 };
2312
2313 struct A3
2314 : private virtual A1,
2315 public A2
2316 {
2317 char _[93481];
~A3t40::A32318 virtual ~A3() {}
2319
getA1t40::A32320 A1* getA1() {return A1::getA1();}
getA2t40::A32321 A2* getA2() {return this;}
getA3t40::A32322 A3* getA3() {return this;}
2323 };
2324
test()2325 void test()
2326 {
2327 A1 a1;
2328 A2 a2;
2329 A3 a3;
2330 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2331 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2332 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2333
2334 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2335 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2336 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2337 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2338 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2339 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2340
2341 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2342 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2343 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2344 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2345 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2346 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2347 }
2348
2349 } // t40
2350
2351 namespace t41
2352 {
2353
2354 struct A1
2355 {
2356 char _[43981];
~A1t41::A12357 virtual ~A1() {}
2358
getA1t41::A12359 A1* getA1() {return this;}
2360 };
2361
2362 struct A2
2363 : private virtual A1
2364 {
2365 char _[34981];
~A2t41::A22366 virtual ~A2() {}
2367
getA1t41::A22368 A1* getA1() {return this;}
getA2t41::A22369 A2* getA2() {return this;}
2370 };
2371
2372 struct A3
2373 : private virtual A1,
2374 private A2
2375 {
2376 char _[93481];
~A3t41::A32377 virtual ~A3() {}
2378
getA1t41::A32379 A1* getA1() {return A1::getA1();}
getA2t41::A32380 A2* getA2() {return this;}
getA3t41::A32381 A3* getA3() {return this;}
2382 };
2383
test()2384 void test()
2385 {
2386 A1 a1;
2387 A2 a2;
2388 A3 a3;
2389 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2390 assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2391 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2392
2393 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2394 assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2395 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2396 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2397 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2398
2399 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2400 assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2401 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2402 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2403 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2404 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2405 }
2406
2407 } // t41
2408
2409 #include <chrono>
2410 #include <iostream>
2411
main()2412 int main()
2413 {
2414 typedef std::chrono::high_resolution_clock Clock;
2415 typedef Clock::time_point time_point;
2416 typedef std::chrono::duration<double, std::micro> NS;
2417 time_point t0 = Clock::now();
2418 t1::test();
2419 t2::test();
2420 t3::test();
2421 t4::test();
2422 t5::test();
2423 t6::test();
2424 t7::test();
2425 t8::test();
2426 t9::test();
2427 t10::test();
2428 t11::test();
2429 t12::test();
2430 t13::test();
2431 t14::test();
2432 t15::test();
2433 t16::test();
2434 t17::test();
2435 t18::test();
2436 t19::test();
2437 t20::test();
2438 t21::test();
2439 t22::test();
2440 t23::test();
2441 t24::test();
2442 t25::test();
2443 t26::test();
2444 t27::test();
2445 t28::test();
2446 t29::test();
2447 t30::test();
2448 t31::test();
2449 t32::test();
2450 t33::test();
2451 t34::test();
2452 t35::test();
2453 t36::test();
2454 t37::test();
2455 t38::test();
2456 t39::test();
2457 t40::test();
2458 t41::test();
2459 time_point t1 = Clock::now();
2460 std::cout << NS(t1-t0).count() << " microseconds\n";
2461 }
2462