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