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#include "support/timer.hpp"
12
13// This test explicitly tests dynamic cast with types that have inaccessible
14// bases.
15#if defined(__clang__)
16#pragma clang diagnostic ignored "-Winaccessible-base"
17#endif
18
19/*
20
21A1   A2   A3
22
23*/
24
25namespace t1
26{
27
28struct A1
29{
30    char _[43981];
31    virtual ~A1() {}
32
33    A1* getA1() {return this;}
34};
35
36struct A2
37{
38    char _[34981];
39    virtual ~A2() {}
40
41    A2* getA2() {return this;}
42};
43
44struct A3
45{
46    char _[93481];
47    virtual ~A3() {}
48
49    A3* getA3() {return this;}
50};
51
52void test()
53{
54    A1 a1;
55    A2 a2;
56    A3 a3;
57    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
58    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
59    assert(dynamic_cast<A1*>(a3.getA3()) == 0);
60    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
61    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
62    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
63    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
64    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
65    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
66}
67
68}  // t1
69
70/*
71
72A1   A2
73|
74A3
75
76*/
77
78namespace t2
79{
80
81struct A1
82{
83    char _[43981];
84    virtual ~A1() {}
85
86    A1* getA1() {return this;}
87};
88
89struct A2
90{
91    char _[34981];
92    virtual ~A2() {}
93
94    A2* getA2() {return this;}
95};
96
97struct A3
98    : public A1
99{
100    char _[93481];
101    virtual ~A3() {}
102
103    A3* getA3() {return this;}
104};
105
106void test()
107{
108    A1 a1;
109    A2 a2;
110    A3 a3;
111    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
112    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
113    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
114    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
115
116    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
117    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
118    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
119    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
120
121    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
122    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
123    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
124    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
125}
126
127}  // t2
128
129namespace t3
130{
131
132struct A1
133{
134    char _[43981];
135    virtual ~A1() {}
136
137    A1* getA1() {return this;}
138};
139
140struct A2
141{
142    char _[34981];
143    virtual ~A2() {}
144
145    A2* getA2() {return this;}
146};
147
148struct A3
149    : public virtual A1
150{
151    char _[93481];
152    virtual ~A3() {}
153
154    A3* getA3() {return this;}
155};
156
157void test()
158{
159    A1 a1;
160    A2 a2;
161    A3 a3;
162    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
163    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
164    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
165    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
166
167    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
168    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
169    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
170    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
171
172    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
173    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
174    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
175    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
176}
177
178}  // t3
179
180namespace t4
181{
182
183struct A1
184{
185    char _[43981];
186    virtual ~A1() {}
187
188    A1* getA1() {return this;}
189};
190
191struct A2
192{
193    char _[34981];
194    virtual ~A2() {}
195
196    A2* getA2() {return this;}
197};
198
199struct A3
200    : private A1
201{
202    char _[93481];
203    virtual ~A3() {}
204
205    A1* getA1() {return this;}
206    A3* getA3() {return this;}
207};
208
209void test()
210{
211    A1 a1;
212    A2 a2;
213    A3 a3;
214    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
215    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
216    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
217
218    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
219    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
220    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
221    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
222
223    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
224    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
225    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
226    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
227}
228
229}  // t4
230
231namespace t5
232{
233
234struct A1
235{
236    char _[43981];
237    virtual ~A1() {}
238
239    A1* getA1() {return this;}
240};
241
242struct A2
243{
244    char _[34981];
245    virtual ~A2() {}
246
247    A2* getA2() {return this;}
248};
249
250struct A3
251    : private virtual A1
252{
253    char _[93481];
254    virtual ~A3() {}
255
256    A1* getA1() {return this;}
257    A3* getA3() {return this;}
258};
259
260void test()
261{
262    A1 a1;
263    A2 a2;
264    A3 a3;
265    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
266    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
267    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
268
269    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
270    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
271    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
272    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
273
274    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
275    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
276    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
277    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
278}
279
280}  // t5
281
282/*
283
284A1   A2
285 \  /
286  A3
287
288*/
289
290namespace t6
291{
292
293struct A1
294{
295    char _[43981];
296    virtual ~A1() {}
297
298    A1* getA1() {return this;}
299};
300
301struct A2
302{
303    char _[34981];
304    virtual ~A2() {}
305
306    A2* getA2() {return this;}
307};
308
309struct A3
310    : public A1,
311      public A2
312{
313    char _[93481];
314    virtual ~A3() {}
315
316    A1* getA1() {return this;}
317    A2* getA2() {return this;}
318    A3* getA3() {return this;}
319};
320
321void test()
322{
323    A1 a1;
324    A2 a2;
325    A3 a3;
326    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
327    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
328    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
329    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
330    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
331
332    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
333    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
334    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
335    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
336    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
337
338    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
339    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
340    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
341    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
342    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
343}
344
345}  // t6
346
347namespace t7
348{
349
350struct A1
351{
352    char _[43981];
353    virtual ~A1() {}
354
355    A1* getA1() {return this;}
356};
357
358struct A2
359{
360    char _[34981];
361    virtual ~A2() {}
362
363    A2* getA2() {return this;}
364};
365
366struct A3
367    : public virtual A1,
368      public A2
369{
370    char _[93481];
371    virtual ~A3() {}
372
373    A1* getA1() {return this;}
374    A2* getA2() {return this;}
375    A3* getA3() {return this;}
376};
377
378void test()
379{
380    A1 a1;
381    A2 a2;
382    A3 a3;
383    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
384    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
385    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
386    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
387    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
388
389    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
390    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
391    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
392    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
393    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
394
395    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
396    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
397    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
398    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
399    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
400}
401
402}  // t7
403
404namespace t8
405{
406
407struct A1
408{
409    char _[43981];
410    virtual ~A1() {}
411
412    A1* getA1() {return this;}
413};
414
415struct A2
416{
417    char _[34981];
418    virtual ~A2() {}
419
420    A2* getA2() {return this;}
421};
422
423struct A3
424    : private A1,
425      public A2
426{
427    char _[93481];
428    virtual ~A3() {}
429
430    A1* getA1() {return this;}
431    A2* getA2() {return this;}
432    A3* getA3() {return this;}
433};
434
435void test()
436{
437    A1 a1;
438    A2 a2;
439    A3 a3;
440    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
441    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
442    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
443    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
444
445    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
446    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
447    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
448    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
449    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
450
451    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
452    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
453    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
454    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
455    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
456}
457
458}  // t8
459
460namespace t9
461{
462
463struct A1
464{
465    char _[43981];
466    virtual ~A1() {}
467
468    A1* getA1() {return this;}
469};
470
471struct A2
472{
473    char _[34981];
474    virtual ~A2() {}
475
476    A2* getA2() {return this;}
477};
478
479struct A3
480    : private virtual A1,
481      public A2
482{
483    char _[93481];
484    virtual ~A3() {}
485
486    A1* getA1() {return this;}
487    A2* getA2() {return this;}
488    A3* getA3() {return this;}
489};
490
491void test()
492{
493    A1 a1;
494    A2 a2;
495    A3 a3;
496    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
497    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
498    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
499    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
500
501    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
502    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
503    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
504    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
505    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
506
507    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
508    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
509    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
510    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
511    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
512}
513
514}  // t9
515
516namespace t10
517{
518
519struct A1
520{
521    char _[43981];
522    virtual ~A1() {}
523
524    A1* getA1() {return this;}
525};
526
527struct A2
528{
529    char _[34981];
530    virtual ~A2() {}
531
532    A2* getA2() {return this;}
533};
534
535struct A3
536    : public virtual A1,
537      public virtual A2
538{
539    char _[93481];
540    virtual ~A3() {}
541
542    A1* getA1() {return this;}
543    A2* getA2() {return this;}
544    A3* getA3() {return this;}
545};
546
547void test()
548{
549    A1 a1;
550    A2 a2;
551    A3 a3;
552    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
553    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
554    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
555    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
556    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
557
558    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
559    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
560    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
561    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
562    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
563
564    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
565    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
566    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
567    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
568    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
569}
570
571}  // t10
572
573namespace t11
574{
575
576struct A1
577{
578    char _[43981];
579    virtual ~A1() {}
580
581    A1* getA1() {return this;}
582};
583
584struct A2
585{
586    char _[34981];
587    virtual ~A2() {}
588
589    A2* getA2() {return this;}
590};
591
592struct A3
593    : private A1,
594      public virtual A2
595{
596    char _[93481];
597    virtual ~A3() {}
598
599    A1* getA1() {return this;}
600    A2* getA2() {return this;}
601    A3* getA3() {return this;}
602};
603
604void test()
605{
606    A1 a1;
607    A2 a2;
608    A3 a3;
609    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
610    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
611    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
612    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
613
614    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
615    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
616    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
617    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
618    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
619
620    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
621    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
622    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
623    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
624    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
625}
626
627}  // t11
628
629namespace t12
630{
631
632struct A1
633{
634    char _[43981];
635    virtual ~A1() {}
636
637    A1* getA1() {return this;}
638};
639
640struct A2
641{
642    char _[34981];
643    virtual ~A2() {}
644
645    A2* getA2() {return this;}
646};
647
648struct A3
649    : private virtual A1,
650      public virtual A2
651{
652    char _[93481];
653    virtual ~A3() {}
654
655    A1* getA1() {return this;}
656    A2* getA2() {return this;}
657    A3* getA3() {return this;}
658};
659
660void test()
661{
662    A1 a1;
663    A2 a2;
664    A3 a3;
665    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
666    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
667    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
668    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
669
670    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
671    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
672    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
673    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
674    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
675
676    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
677    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
678    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
679    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
680    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
681}
682
683}  // t12
684
685namespace t13
686{
687
688struct A1
689{
690    char _[43981];
691    virtual ~A1() {}
692
693    A1* getA1() {return this;}
694};
695
696struct A2
697{
698    char _[34981];
699    virtual ~A2() {}
700
701    A2* getA2() {return this;}
702};
703
704struct A3
705    : private A1,
706      private A2
707{
708    char _[93481];
709    virtual ~A3() {}
710
711    A1* getA1() {return this;}
712    A2* getA2() {return this;}
713    A3* getA3() {return this;}
714};
715
716void test()
717{
718    A1 a1;
719    A2 a2;
720    A3 a3;
721    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
722    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
723    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
724    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
725
726    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
727    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
728    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
729    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
730
731    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
732    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
733    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
734    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
735    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
736}
737
738}  // t13
739
740namespace t14
741{
742
743struct A1
744{
745    char _[43981];
746    virtual ~A1() {}
747
748    A1* getA1() {return this;}
749};
750
751struct A2
752{
753    char _[34981];
754    virtual ~A2() {}
755
756    A2* getA2() {return this;}
757};
758
759struct A3
760    : private virtual A1,
761      private A2
762{
763    char _[93481];
764    virtual ~A3() {}
765
766    A1* getA1() {return this;}
767    A2* getA2() {return this;}
768    A3* getA3() {return this;}
769};
770
771void test()
772{
773    A1 a1;
774    A2 a2;
775    A3 a3;
776    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
777    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
778    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
779    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
780
781    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
782    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
783    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
784    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
785
786    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
787    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
788    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
789    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
790    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
791}
792
793}  // t14
794
795namespace t15
796{
797
798struct A1
799{
800    char _[43981];
801    virtual ~A1() {}
802
803    A1* getA1() {return this;}
804};
805
806struct A2
807{
808    char _[34981];
809    virtual ~A2() {}
810
811    A2* getA2() {return this;}
812};
813
814struct A3
815    : private virtual A1,
816      private virtual A2
817{
818    char _[93481];
819    virtual ~A3() {}
820
821    A1* getA1() {return this;}
822    A2* getA2() {return this;}
823    A3* getA3() {return this;}
824};
825
826void test()
827{
828    A1 a1;
829    A2 a2;
830    A3 a3;
831    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
832    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
833    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
834    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
835
836    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
837    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
838    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
839    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
840
841    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
842    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
843    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
844    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
845    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
846}
847
848}  // t15
849
850/*
851
852A1
853|
854A2
855|
856A3
857
858*/
859
860namespace t16
861{
862
863struct A1
864{
865    char _[43981];
866    virtual ~A1() {}
867
868    A1* getA1() {return this;}
869};
870
871struct A2
872    : public A1
873{
874    char _[34981];
875    virtual ~A2() {}
876
877    A1* getA1() {return this;}
878    A2* getA2() {return this;}
879};
880
881struct A3
882    : public A2
883{
884    char _[93481];
885    virtual ~A3() {}
886
887    A1* getA1() {return this;}
888    A2* getA2() {return this;}
889    A3* getA3() {return this;}
890};
891
892void test()
893{
894    A1 a1;
895    A2 a2;
896    A3 a3;
897    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
898    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
899    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
900    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
901    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
902    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
903
904    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
905    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
906    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
907    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
908    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
909    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
910
911    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
912    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
913    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
914    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
915    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
916    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
917}
918
919}  // t16
920
921namespace t17
922{
923
924struct A1
925{
926    char _[43981];
927    virtual ~A1() {}
928
929    A1* getA1() {return this;}
930};
931
932struct A2
933    : public virtual A1
934{
935    char _[34981];
936    virtual ~A2() {}
937
938    A1* getA1() {return this;}
939    A2* getA2() {return this;}
940};
941
942struct A3
943    : public A2
944{
945    char _[93481];
946    virtual ~A3() {}
947
948    A1* getA1() {return this;}
949    A2* getA2() {return this;}
950    A3* getA3() {return this;}
951};
952
953void test()
954{
955    A1 a1;
956    A2 a2;
957    A3 a3;
958    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
959    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
960    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
961    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
962    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
963    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
964
965    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
966    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
967    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
968    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
969    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
970    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
971
972    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
973    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
974    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
975    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
976    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
977    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
978}
979
980}  // t17
981
982namespace t18
983{
984
985struct A1
986{
987    char _[43981];
988    virtual ~A1() {}
989
990    A1* getA1() {return this;}
991};
992
993struct A2
994    : private A1
995{
996    char _[34981];
997    virtual ~A2() {}
998
999    A1* getA1() {return this;}
1000    A2* getA2() {return this;}
1001};
1002
1003struct A3
1004    : public A2
1005{
1006    char _[93481];
1007    virtual ~A3() {}
1008
1009    A2* getA2() {return this;}
1010    A3* getA3() {return this;}
1011};
1012
1013void test()
1014{
1015    A1 a1;
1016    A2 a2;
1017    A3 a3;
1018    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1019    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1020    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1021
1022    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1023    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1024    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1025    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1026    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1027    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1028
1029    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1030    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1031    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1032    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1033    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1034    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1035}
1036
1037}  // t18
1038
1039namespace t19
1040{
1041
1042struct A1
1043{
1044    char _[43981];
1045    virtual ~A1() {}
1046
1047    A1* getA1() {return this;}
1048};
1049
1050struct A2
1051    : protected virtual A1
1052{
1053    char _[34981];
1054    virtual ~A2() {}
1055
1056    A1* getA1() {return this;}
1057    A2* getA2() {return this;}
1058};
1059
1060struct A3
1061    : public A2
1062{
1063    char _[93481];
1064    virtual ~A3() {}
1065
1066    A2* getA2() {return this;}
1067    A3* getA3() {return this;}
1068};
1069
1070void test()
1071{
1072    A1 a1;
1073    A2 a2;
1074    A3 a3;
1075    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1076    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1077    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1078
1079    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1080    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1081    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1082    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1083    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1084    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1085
1086    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1087    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1088    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1089    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1090    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1091    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1092}
1093
1094}  // t19
1095
1096namespace t20
1097{
1098
1099struct A1
1100{
1101    char _[43981];
1102    virtual ~A1() {}
1103
1104    A1* getA1() {return this;}
1105};
1106
1107struct A2
1108    : public virtual A1
1109{
1110    char _[34981];
1111    virtual ~A2() {}
1112
1113    A1* getA1() {return this;}
1114    A2* getA2() {return this;}
1115};
1116
1117struct A3
1118    : public virtual A2
1119{
1120    char _[93481];
1121    virtual ~A3() {}
1122
1123    A1* getA1() {return this;}
1124    A2* getA2() {return this;}
1125    A3* getA3() {return this;}
1126};
1127
1128void test()
1129{
1130    A1 a1;
1131    A2 a2;
1132    A3 a3;
1133    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1134    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1135    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1136    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1137    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1138    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1139
1140    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1141    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1142    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1143    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1144    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1145    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1146
1147    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1148    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1149    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1150    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1151    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1152    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1153}
1154
1155}  // t20
1156
1157namespace t21
1158{
1159
1160struct A1
1161{
1162    char _[43981];
1163    virtual ~A1() {}
1164
1165    A1* getA1() {return this;}
1166};
1167
1168struct A2
1169    : private A1
1170{
1171    char _[34981];
1172    virtual ~A2() {}
1173
1174    A1* getA1() {return this;}
1175    A2* getA2() {return this;}
1176};
1177
1178struct A3
1179    : public virtual A2
1180{
1181    char _[93481];
1182    virtual ~A3() {}
1183
1184    A2* getA2() {return this;}
1185    A3* getA3() {return this;}
1186};
1187
1188void test()
1189{
1190    A1 a1;
1191    A2 a2;
1192    A3 a3;
1193    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1194    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1195    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1196
1197    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1198    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1199    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1200    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1201    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1202    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1203
1204    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1205    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1206    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1207    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1208    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1209    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1210}
1211
1212}  // t21
1213
1214namespace t22
1215{
1216
1217struct A1
1218{
1219    char _[43981];
1220    virtual ~A1() {}
1221
1222    A1* getA1() {return this;}
1223};
1224
1225struct A2
1226    : protected virtual A1
1227{
1228    char _[34981];
1229    virtual ~A2() {}
1230
1231    A1* getA1() {return this;}
1232    A2* getA2() {return this;}
1233};
1234
1235struct A3
1236    : public virtual A2
1237{
1238    char _[93481];
1239    virtual ~A3() {}
1240
1241    A2* getA2() {return this;}
1242    A3* getA3() {return this;}
1243};
1244
1245void test()
1246{
1247    A1 a1;
1248    A2 a2;
1249    A3 a3;
1250    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1251    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1252    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1253
1254    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1255    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1256    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1257    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1258    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1259    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1260
1261    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1262    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1263    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1264    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1265    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1266    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1267}
1268
1269}  // t22
1270
1271namespace t23
1272{
1273
1274struct A1
1275{
1276    char _[43981];
1277    virtual ~A1() {}
1278
1279    A1* getA1() {return this;}
1280};
1281
1282struct A2
1283    : private A1
1284{
1285    char _[34981];
1286    virtual ~A2() {}
1287
1288    A1* getA1() {return this;}
1289    A2* getA2() {return this;}
1290};
1291
1292struct A3
1293    : private A2
1294{
1295    char _[93481];
1296    virtual ~A3() {}
1297
1298    t23::A1* getA1() {return A2::getA1();}
1299    A2* getA2() {return this;}
1300    A3* getA3() {return this;}
1301};
1302
1303void test()
1304{
1305    A1 a1;
1306    A2 a2;
1307    A3 a3;
1308    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1309    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1310    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1311
1312    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1313    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1314    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1315    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1316    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1317
1318    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1319    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1320    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1321    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1322    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1323    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1324}
1325
1326}  // t23
1327
1328namespace t24
1329{
1330
1331struct A1
1332{
1333    char _[43981];
1334    virtual ~A1() {}
1335
1336    A1* getA1() {return this;}
1337};
1338
1339struct A2
1340    : protected virtual A1
1341{
1342    char _[34981];
1343    virtual ~A2() {}
1344
1345    A1* getA1() {return this;}
1346    A2* getA2() {return this;}
1347};
1348
1349struct A3
1350    : private A2
1351{
1352    char _[93481];
1353    virtual ~A3() {}
1354
1355    t24::A1* getA1() {return A2::getA1();}
1356    A2* getA2() {return this;}
1357    A3* getA3() {return this;}
1358};
1359
1360void test()
1361{
1362    A1 a1;
1363    A2 a2;
1364    A3 a3;
1365    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1366    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1367    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1368
1369    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1370    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1371    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1372    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1373    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1374
1375    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1376    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1377    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1378    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1379    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1380    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1381}
1382
1383}  // t24
1384
1385namespace t25
1386{
1387
1388struct A1
1389{
1390    char _[43981];
1391    virtual ~A1() {}
1392
1393    A1* getA1() {return this;}
1394};
1395
1396struct A2
1397    : protected virtual A1
1398{
1399    char _[34981];
1400    virtual ~A2() {}
1401
1402    A1* getA1() {return this;}
1403    A2* getA2() {return this;}
1404};
1405
1406struct A3
1407    : private virtual A2
1408{
1409    char _[93481];
1410    virtual ~A3() {}
1411
1412    t25::A1* getA1() {return A2::getA1();}
1413    A2* getA2() {return this;}
1414    A3* getA3() {return this;}
1415};
1416
1417void test()
1418{
1419    A1 a1;
1420    A2 a2;
1421    A3 a3;
1422    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1423    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1424    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1425
1426    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1427    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1428    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1429    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1430    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1431
1432    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1433    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1434    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1435    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1436    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1437    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1438}
1439
1440}  // t25
1441
1442/*
1443
1444A1 A1
1445|  |
1446A2 |
1447 \ |
1448  A3
1449
1450*/
1451
1452namespace t26
1453{
1454
1455struct A1
1456{
1457    char _[43981];
1458    virtual ~A1() {}
1459
1460    A1* getA1() {return this;}
1461};
1462
1463struct A2
1464    : public A1
1465{
1466    char _[34981];
1467    virtual ~A2() {}
1468
1469    A1* getA1() {return this;}
1470    A2* getA2() {return this;}
1471};
1472
1473struct A3
1474    : public A1,
1475      public A2
1476{
1477    char _[93481];
1478    virtual ~A3() {}
1479
1480    A1* getA12() {return A2::getA1();}
1481    A2* getA2() {return this;}
1482    A3* getA3() {return this;}
1483};
1484
1485void test()
1486{
1487    A1 a1;
1488    A2 a2;
1489    A3 a3;
1490    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1491    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1492    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1493    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1494    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1495
1496    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1497    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1498    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1499    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1500    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1501    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1502
1503    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1504    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1505    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1506    assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1507    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1508    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1509}
1510
1511}  // t26
1512
1513namespace t27
1514{
1515
1516struct A1
1517{
1518    char _[43981];
1519    virtual ~A1() {}
1520
1521    A1* getA1() {return this;}
1522};
1523
1524struct A2
1525    : private A1
1526{
1527    char _[34981];
1528    virtual ~A2() {}
1529
1530    A1* getA1() {return this;}
1531    A2* getA2() {return this;}
1532};
1533
1534struct A3
1535    : public A1,
1536      public A2
1537{
1538    char _[93481];
1539    virtual ~A3() {}
1540
1541    A1* getA12() {return A2::getA1();}
1542    A2* getA2() {return this;}
1543    A3* getA3() {return this;}
1544};
1545
1546void test()
1547{
1548    A1 a1;
1549    A2 a2;
1550    A3 a3;
1551    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1552    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1553    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1554
1555    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1556    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1557    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1558    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1559    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1560    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1561
1562    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1563    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1564    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1565    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1566    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1567    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1568}
1569
1570}  // t27
1571
1572namespace t28
1573{
1574
1575struct A1
1576{
1577    char _[43981];
1578    virtual ~A1() {}
1579
1580    A1* getA1() {return this;}
1581};
1582
1583struct A2
1584    : public A1
1585{
1586    char _[34981];
1587    virtual ~A2() {}
1588
1589    A1* getA1() {return this;}
1590    A2* getA2() {return this;}
1591};
1592
1593struct A3
1594    : private A1,
1595      public A2
1596{
1597    char _[93481];
1598    virtual ~A3() {}
1599
1600    A1* getA12() {return A2::getA1();}
1601    A2* getA2() {return this;}
1602    A3* getA3() {return this;}
1603};
1604
1605void test()
1606{
1607    A1 a1;
1608    A2 a2;
1609    A3 a3;
1610    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1611    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1612    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1613    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1614
1615    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1616    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1617    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1618    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1619    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1620    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1621
1622    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1623    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1624    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1625    assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1626    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1627    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1628}
1629
1630}  // t28
1631
1632namespace t29
1633{
1634
1635struct A1
1636{
1637    char _[43981];
1638    virtual ~A1() {}
1639
1640    A1* getA1() {return this;}
1641};
1642
1643struct A2
1644    : public A1
1645{
1646    char _[34981];
1647    virtual ~A2() {}
1648
1649    A1* getA1() {return this;}
1650    A2* getA2() {return this;}
1651};
1652
1653struct A3
1654    : public A1,
1655      private A2
1656{
1657    char _[93481];
1658    virtual ~A3() {}
1659
1660    A1* getA12() {return A2::getA1();}
1661    A2* getA2() {return this;}
1662    A3* getA3() {return this;}
1663};
1664
1665void test()
1666{
1667    A1 a1;
1668    A2 a2;
1669    A3 a3;
1670    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1671    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1672    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1673    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1674
1675    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1676    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1677    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1678    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1679    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1680
1681    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1682    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1683    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1684    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1685    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1686    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1687}
1688
1689}  // t29
1690
1691namespace t30
1692{
1693
1694struct A1
1695{
1696    char _[43981];
1697    virtual ~A1() {}
1698
1699    A1* getA1() {return this;}
1700};
1701
1702struct A2
1703    : public A1
1704{
1705    char _[34981];
1706    virtual ~A2() {}
1707
1708    A1* getA1() {return this;}
1709    A2* getA2() {return this;}
1710};
1711
1712struct A3
1713    : private A1,
1714      private A2
1715{
1716    char _[93481];
1717    virtual ~A3() {}
1718
1719    A1* getA12() {return A2::getA1();}
1720    A2* getA2() {return this;}
1721    A3* getA3() {return this;}
1722};
1723
1724void test()
1725{
1726    A1 a1;
1727    A2 a2;
1728    A3 a3;
1729    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1730    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1731    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1732    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1733    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1734
1735    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1736    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1737    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1738    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1739    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1740
1741    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1742    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1743    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1744    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1745    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1746    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1747}
1748
1749}  // t30
1750
1751namespace t31
1752{
1753
1754struct A1
1755{
1756    char _[43981];
1757    virtual ~A1() {}
1758
1759    A1* getA1() {return this;}
1760};
1761
1762struct A2
1763    : private A1
1764{
1765    char _[34981];
1766    virtual ~A2() {}
1767
1768    A1* getA1() {return this;}
1769    A2* getA2() {return this;}
1770};
1771
1772struct A3
1773    : public A1,
1774      private A2
1775{
1776    char _[93481];
1777    virtual ~A3() {}
1778
1779    A1* getA12() {return A2::getA1();}
1780    A2* getA2() {return this;}
1781    A3* getA3() {return this;}
1782};
1783
1784void test()
1785{
1786    A1 a1;
1787    A2 a2;
1788    A3 a3;
1789    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1790    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1791    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1792
1793    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1794    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1795    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1796    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1797    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1798
1799    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1800    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1801    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1802    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1803    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1804    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1805}
1806
1807}  // t31
1808
1809namespace t32
1810{
1811
1812struct A1
1813{
1814    char _[43981];
1815    virtual ~A1() {}
1816
1817    A1* getA1() {return this;}
1818};
1819
1820struct A2
1821    : private A1
1822{
1823    char _[34981];
1824    virtual ~A2() {}
1825
1826    A1* getA1() {return this;}
1827    A2* getA2() {return this;}
1828};
1829
1830struct A3
1831    : private A1,
1832      public A2
1833{
1834    char _[93481];
1835    virtual ~A3() {}
1836
1837    A1* getA12() {return A2::getA1();}
1838    A2* getA2() {return this;}
1839    A3* getA3() {return this;}
1840};
1841
1842void test()
1843{
1844    A1 a1;
1845    A2 a2;
1846    A3 a3;
1847    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1848    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1849    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1850
1851    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1852    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1853    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1854    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1855    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1856
1857    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1858    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1859    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1860    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1861    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1862    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1863}
1864
1865}  // t32
1866
1867namespace t33
1868{
1869
1870struct A1
1871{
1872    char _[43981];
1873    virtual ~A1() {}
1874
1875    A1* getA1() {return this;}
1876};
1877
1878struct A2
1879    : private A1
1880{
1881    char _[34981];
1882    virtual ~A2() {}
1883
1884    A1* getA1() {return this;}
1885    A2* getA2() {return this;}
1886};
1887
1888struct A3
1889    : private A1,
1890      private A2
1891{
1892    char _[93481];
1893    virtual ~A3() {}
1894
1895    A1* getA12() {return A2::getA1();}
1896    A2* getA2() {return this;}
1897    A3* getA3() {return this;}
1898};
1899
1900void test()
1901{
1902    A1 a1;
1903    A2 a2;
1904    A3 a3;
1905    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1906    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1907    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1908
1909    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1910    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1911    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1912    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1913    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1914
1915    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1916    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1917    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1918    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1919    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1920    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1921}
1922
1923}  // t33
1924
1925/*
1926
1927A1
1928| \
1929A2 \
1930 \ |
1931  A3
1932
1933*/
1934
1935namespace t34
1936{
1937
1938struct A1
1939{
1940    char _[43981];
1941    virtual ~A1() {}
1942
1943    A1* getA1() {return this;}
1944};
1945
1946struct A2
1947    : public virtual A1
1948{
1949    char _[34981];
1950    virtual ~A2() {}
1951
1952    A1* getA1() {return this;}
1953    A2* getA2() {return this;}
1954};
1955
1956struct A3
1957    : public virtual A1,
1958      public A2
1959{
1960    char _[93481];
1961    virtual ~A3() {}
1962
1963    A1* getA1() {return A1::getA1();}
1964    A2* getA2() {return this;}
1965    A3* getA3() {return this;}
1966};
1967
1968void test()
1969{
1970    A1 a1;
1971    A2 a2;
1972    A3 a3;
1973    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1974    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1975    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1976    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1977    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1978    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1979
1980    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1981    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1982    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1983    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1984    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1985    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1986
1987    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1988    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1989    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1990    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1991    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1992    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1993}
1994
1995}  // t34
1996
1997namespace t35
1998{
1999
2000struct A1
2001{
2002    char _[43981];
2003    virtual ~A1() {}
2004
2005    A1* getA1() {return this;}
2006};
2007
2008struct A2
2009    : private virtual A1
2010{
2011    char _[34981];
2012    virtual ~A2() {}
2013
2014    A1* getA1() {return this;}
2015    A2* getA2() {return this;}
2016};
2017
2018struct A3
2019    : public virtual A1,
2020      public A2
2021{
2022    char _[93481];
2023    virtual ~A3() {}
2024
2025    A1* getA1() {return A1::getA1();}
2026    A2* getA2() {return this;}
2027    A3* getA3() {return this;}
2028};
2029
2030void test()
2031{
2032    A1 a1;
2033    A2 a2;
2034    A3 a3;
2035    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2036    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2037    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2038    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2039
2040    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2041    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2042    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2043    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2044    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2045    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2046
2047    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2048    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2049    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2050    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2051    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2052    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2053}
2054
2055}  // t35
2056
2057namespace t36
2058{
2059
2060struct A1
2061{
2062    char _[43981];
2063    virtual ~A1() {}
2064
2065    A1* getA1() {return this;}
2066};
2067
2068struct A2
2069    : public virtual A1
2070{
2071    char _[34981];
2072    virtual ~A2() {}
2073
2074    A1* getA1() {return this;}
2075    A2* getA2() {return this;}
2076};
2077
2078struct A3
2079    : private virtual A1,
2080      public A2
2081{
2082    char _[93481];
2083    virtual ~A3() {}
2084
2085    A1* getA1() {return A1::getA1();}
2086    A2* getA2() {return this;}
2087    A3* getA3() {return this;}
2088};
2089
2090void test()
2091{
2092    A1 a1;
2093    A2 a2;
2094    A3 a3;
2095    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2096    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2097    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2098    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2099    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2100    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2101
2102    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2103    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2104    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2105    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2106    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2107    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2108
2109    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2110    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2111    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2112    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2113    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2114    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2115}
2116
2117}  // t36
2118
2119namespace t37
2120{
2121
2122struct A1
2123{
2124    char _[43981];
2125    virtual ~A1() {}
2126
2127    A1* getA1() {return this;}
2128};
2129
2130struct A2
2131    : public virtual A1
2132{
2133    char _[34981];
2134    virtual ~A2() {}
2135
2136    A1* getA1() {return this;}
2137    A2* getA2() {return this;}
2138};
2139
2140struct A3
2141    : public virtual A1,
2142      private A2
2143{
2144    char _[93481];
2145    virtual ~A3() {}
2146
2147    A1* getA1() {return A1::getA1();}
2148    A2* getA2() {return this;}
2149    A3* getA3() {return this;}
2150};
2151
2152void test()
2153{
2154    A1 a1;
2155    A2 a2;
2156    A3 a3;
2157    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2158    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2159    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2160    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2161    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2162    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2163
2164    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2165    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2166    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2167    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2168    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2169
2170    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2171    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2172    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2173    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2174    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2175    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2176}
2177
2178}  // t37
2179
2180namespace t38
2181{
2182
2183struct A1
2184{
2185    char _[43981];
2186    virtual ~A1() {}
2187
2188    A1* getA1() {return this;}
2189};
2190
2191struct A2
2192    : public virtual A1
2193{
2194    char _[34981];
2195    virtual ~A2() {}
2196
2197    A1* getA1() {return this;}
2198    A2* getA2() {return this;}
2199};
2200
2201struct A3
2202    : private virtual A1,
2203      private A2
2204{
2205    char _[93481];
2206    virtual ~A3() {}
2207
2208    A1* getA1() {return A1::getA1();}
2209    A2* getA2() {return this;}
2210    A3* getA3() {return this;}
2211};
2212
2213void test()
2214{
2215    A1 a1;
2216    A2 a2;
2217    A3 a3;
2218    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2219    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2220    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2221    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2222    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2223
2224    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2225    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2226    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2227    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2228    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2229
2230    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2231    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2232    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2233    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2234    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2235    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2236}
2237
2238}  // t38
2239
2240namespace t39
2241{
2242
2243struct A1
2244{
2245    char _[43981];
2246    virtual ~A1() {}
2247
2248    A1* getA1() {return this;}
2249};
2250
2251struct A2
2252    : private virtual A1
2253{
2254    char _[34981];
2255    virtual ~A2() {}
2256
2257    A1* getA1() {return this;}
2258    A2* getA2() {return this;}
2259};
2260
2261struct A3
2262    : public virtual A1,
2263      private A2
2264{
2265    char _[93481];
2266    virtual ~A3() {}
2267
2268    A1* getA1() {return A1::getA1();}
2269    A2* getA2() {return this;}
2270    A3* getA3() {return this;}
2271};
2272
2273void test()
2274{
2275    A1 a1;
2276    A2 a2;
2277    A3 a3;
2278    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2279    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2280    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2281    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2282
2283    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2284    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2285    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2286    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2287    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2288
2289    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2290    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2291    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2292    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2293    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2294    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2295}
2296
2297}  // t39
2298
2299namespace t40
2300{
2301
2302struct A1
2303{
2304    char _[43981];
2305    virtual ~A1() {}
2306
2307    A1* getA1() {return this;}
2308};
2309
2310struct A2
2311    : private virtual A1
2312{
2313    char _[34981];
2314    virtual ~A2() {}
2315
2316    A1* getA1() {return this;}
2317    A2* getA2() {return this;}
2318};
2319
2320struct A3
2321    : private virtual A1,
2322      public A2
2323{
2324    char _[93481];
2325    virtual ~A3() {}
2326
2327    A1* getA1() {return A1::getA1();}
2328    A2* getA2() {return this;}
2329    A3* getA3() {return this;}
2330};
2331
2332void test()
2333{
2334    A1 a1;
2335    A2 a2;
2336    A3 a3;
2337    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2338    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2339    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2340
2341    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2342    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2343    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2344    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2345    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2346    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2347
2348    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2349    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2350    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2351    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2352    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2353    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2354}
2355
2356}  // t40
2357
2358namespace t41
2359{
2360
2361struct A1
2362{
2363    char _[43981];
2364    virtual ~A1() {}
2365
2366    A1* getA1() {return this;}
2367};
2368
2369struct A2
2370    : private virtual A1
2371{
2372    char _[34981];
2373    virtual ~A2() {}
2374
2375    A1* getA1() {return this;}
2376    A2* getA2() {return this;}
2377};
2378
2379struct A3
2380    : private virtual A1,
2381      private A2
2382{
2383    char _[93481];
2384    virtual ~A3() {}
2385
2386    A1* getA1() {return A1::getA1();}
2387    A2* getA2() {return this;}
2388    A3* getA3() {return this;}
2389};
2390
2391void test()
2392{
2393    A1 a1;
2394    A2 a2;
2395    A3 a3;
2396    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2397    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2398    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2399
2400    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2401    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2402    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2403    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2404    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2405
2406    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2407    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2408    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2409    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2410    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2411    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2412}
2413
2414}  // t41
2415
2416int main()
2417{
2418    timer t;
2419    t1::test();
2420    t2::test();
2421    t3::test();
2422    t4::test();
2423    t5::test();
2424    t6::test();
2425    t7::test();
2426    t8::test();
2427    t9::test();
2428    t10::test();
2429    t11::test();
2430    t12::test();
2431    t13::test();
2432    t14::test();
2433    t15::test();
2434    t16::test();
2435    t17::test();
2436    t18::test();
2437    t19::test();
2438    t20::test();
2439    t21::test();
2440    t22::test();
2441    t23::test();
2442    t24::test();
2443    t25::test();
2444    t26::test();
2445    t27::test();
2446    t28::test();
2447    t29::test();
2448    t30::test();
2449    t31::test();
2450    t32::test();
2451    t33::test();
2452    t34::test();
2453    t35::test();
2454    t36::test();
2455    t37::test();
2456    t38::test();
2457    t39::test();
2458    t40::test();
2459    t41::test();
2460}
2461