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