llvm-project

Форк
0
/
dynamic_cast3.pass.cpp 
2463 строки · 51.4 Кб
1
//===----------------------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8

9
#include <cassert>
10
#include "support/timer.h"
11

12
// This test explicitly tests dynamic cast with types that have inaccessible
13
// bases.
14
#if defined(__clang__)
15
#   pragma clang diagnostic ignored "-Winaccessible-base"
16
#elif defined(__GNUC__)
17
#   pragma GCC diagnostic ignored "-Winaccessible-base"
18
#endif
19

20
/*
21

22
A1   A2   A3
23

24
*/
25

26
namespace t1
27
{
28

29
struct A1
30
{
31
    char _[43981];
32
    virtual ~A1() {}
33

34
    A1* getA1() {return this;}
35
};
36

37
struct A2
38
{
39
    char _[34981];
40
    virtual ~A2() {}
41

42
    A2* getA2() {return this;}
43
};
44

45
struct A3
46
{
47
    char _[93481];
48
    virtual ~A3() {}
49

50
    A3* getA3() {return this;}
51
};
52

53
void test()
54
{
55
    A1 a1;
56
    A2 a2;
57
    A3 a3;
58
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
59
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
60
    assert(dynamic_cast<A1*>(a3.getA3()) == 0);
61
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
62
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
63
    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
64
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
65
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
66
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
67
}
68

69
}  // t1
70

71
/*
72

73
A1   A2
74
|
75
A3
76

77
*/
78

79
namespace t2
80
{
81

82
struct A1
83
{
84
    char _[43981];
85
    virtual ~A1() {}
86

87
    A1* getA1() {return this;}
88
};
89

90
struct A2
91
{
92
    char _[34981];
93
    virtual ~A2() {}
94

95
    A2* getA2() {return this;}
96
};
97

98
struct A3
99
    : public A1
100
{
101
    char _[93481];
102
    virtual ~A3() {}
103

104
    A3* getA3() {return this;}
105
};
106

107
void test()
108
{
109
    A1 a1;
110
    A2 a2;
111
    A3 a3;
112
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
113
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
114
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
115
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
116

117
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
118
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
119
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
120
    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
121

122
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
123
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
124
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
125
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
126
}
127

128
}  // t2
129

130
namespace t3
131
{
132

133
struct A1
134
{
135
    char _[43981];
136
    virtual ~A1() {}
137

138
    A1* getA1() {return this;}
139
};
140

141
struct A2
142
{
143
    char _[34981];
144
    virtual ~A2() {}
145

146
    A2* getA2() {return this;}
147
};
148

149
struct A3
150
    : public virtual A1
151
{
152
    char _[93481];
153
    virtual ~A3() {}
154

155
    A3* getA3() {return this;}
156
};
157

158
void test()
159
{
160
    A1 a1;
161
    A2 a2;
162
    A3 a3;
163
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
164
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
165
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
166
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
167

168
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
169
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
170
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
171
    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
172

173
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
174
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
175
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
176
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
177
}
178

179
}  // t3
180

181
namespace t4
182
{
183

184
struct A1
185
{
186
    char _[43981];
187
    virtual ~A1() {}
188

189
    A1* getA1() {return this;}
190
};
191

192
struct A2
193
{
194
    char _[34981];
195
    virtual ~A2() {}
196

197
    A2* getA2() {return this;}
198
};
199

200
struct A3
201
    : private A1
202
{
203
    char _[93481];
204
    virtual ~A3() {}
205

206
    A1* getA1() {return this;}
207
    A3* getA3() {return this;}
208
};
209

210
void test()
211
{
212
    A1 a1;
213
    A2 a2;
214
    A3 a3;
215
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
216
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
217
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
218

219
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
220
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
221
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
222
    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
223

224
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
225
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
226
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
227
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
228
}
229

230
}  // t4
231

232
namespace t5
233
{
234

235
struct A1
236
{
237
    char _[43981];
238
    virtual ~A1() {}
239

240
    A1* getA1() {return this;}
241
};
242

243
struct A2
244
{
245
    char _[34981];
246
    virtual ~A2() {}
247

248
    A2* getA2() {return this;}
249
};
250

251
struct A3
252
    : private virtual A1
253
{
254
    char _[93481];
255
    virtual ~A3() {}
256

257
    A1* getA1() {return this;}
258
    A3* getA3() {return this;}
259
};
260

261
void test()
262
{
263
    A1 a1;
264
    A2 a2;
265
    A3 a3;
266
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
267
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
268
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
269

270
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
271
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
272
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
273
    assert(dynamic_cast<A2*>(a3.getA3()) == 0);
274

275
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
276
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
277
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
278
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
279
}
280

281
}  // t5
282

283
/*
284

285
A1   A2
286
 \  /
287
  A3
288

289
*/
290

291
namespace t6
292
{
293

294
struct A1
295
{
296
    char _[43981];
297
    virtual ~A1() {}
298

299
    A1* getA1() {return this;}
300
};
301

302
struct A2
303
{
304
    char _[34981];
305
    virtual ~A2() {}
306

307
    A2* getA2() {return this;}
308
};
309

310
struct A3
311
    : public A1,
312
      public A2
313
{
314
    char _[93481];
315
    virtual ~A3() {}
316

317
    A1* getA1() {return this;}
318
    A2* getA2() {return this;}
319
    A3* getA3() {return this;}
320
};
321

322
void test()
323
{
324
    A1 a1;
325
    A2 a2;
326
    A3 a3;
327
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
328
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
329
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
330
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
331
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
332

333
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
334
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
335
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
336
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
337
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
338

339
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
340
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
341
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
342
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
343
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
344
}
345

346
}  // t6
347

348
namespace t7
349
{
350

351
struct A1
352
{
353
    char _[43981];
354
    virtual ~A1() {}
355

356
    A1* getA1() {return this;}
357
};
358

359
struct A2
360
{
361
    char _[34981];
362
    virtual ~A2() {}
363

364
    A2* getA2() {return this;}
365
};
366

367
struct A3
368
    : public virtual A1,
369
      public A2
370
{
371
    char _[93481];
372
    virtual ~A3() {}
373

374
    A1* getA1() {return this;}
375
    A2* getA2() {return this;}
376
    A3* getA3() {return this;}
377
};
378

379
void test()
380
{
381
    A1 a1;
382
    A2 a2;
383
    A3 a3;
384
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
385
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
386
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
387
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
388
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
389

390
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
391
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
392
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
393
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
394
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
395

396
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
397
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
398
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
399
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
400
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
401
}
402

403
}  // t7
404

405
namespace t8
406
{
407

408
struct A1
409
{
410
    char _[43981];
411
    virtual ~A1() {}
412

413
    A1* getA1() {return this;}
414
};
415

416
struct A2
417
{
418
    char _[34981];
419
    virtual ~A2() {}
420

421
    A2* getA2() {return this;}
422
};
423

424
struct A3
425
    : private A1,
426
      public A2
427
{
428
    char _[93481];
429
    virtual ~A3() {}
430

431
    A1* getA1() {return this;}
432
    A2* getA2() {return this;}
433
    A3* getA3() {return this;}
434
};
435

436
void test()
437
{
438
    A1 a1;
439
    A2 a2;
440
    A3 a3;
441
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
442
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
443
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
444
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
445

446
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
447
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
448
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
449
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
450
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
451

452
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
453
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
454
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
455
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
456
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
457
}
458

459
}  // t8
460

461
namespace t9
462
{
463

464
struct A1
465
{
466
    char _[43981];
467
    virtual ~A1() {}
468

469
    A1* getA1() {return this;}
470
};
471

472
struct A2
473
{
474
    char _[34981];
475
    virtual ~A2() {}
476

477
    A2* getA2() {return this;}
478
};
479

480
struct A3
481
    : private virtual A1,
482
      public A2
483
{
484
    char _[93481];
485
    virtual ~A3() {}
486

487
    A1* getA1() {return this;}
488
    A2* getA2() {return this;}
489
    A3* getA3() {return this;}
490
};
491

492
void test()
493
{
494
    A1 a1;
495
    A2 a2;
496
    A3 a3;
497
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
498
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
499
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
500
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
501

502
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
503
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
504
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
505
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
506
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
507

508
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
509
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
510
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
511
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
512
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
513
}
514

515
}  // t9
516

517
namespace t10
518
{
519

520
struct A1
521
{
522
    char _[43981];
523
    virtual ~A1() {}
524

525
    A1* getA1() {return this;}
526
};
527

528
struct A2
529
{
530
    char _[34981];
531
    virtual ~A2() {}
532

533
    A2* getA2() {return this;}
534
};
535

536
struct A3
537
    : public virtual A1,
538
      public virtual A2
539
{
540
    char _[93481];
541
    virtual ~A3() {}
542

543
    A1* getA1() {return this;}
544
    A2* getA2() {return this;}
545
    A3* getA3() {return this;}
546
};
547

548
void test()
549
{
550
    A1 a1;
551
    A2 a2;
552
    A3 a3;
553
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
554
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
555
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
556
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
557
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
558

559
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
560
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
561
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
562
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
563
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
564

565
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
566
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
567
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
568
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
569
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
570
}
571

572
}  // t10
573

574
namespace t11
575
{
576

577
struct A1
578
{
579
    char _[43981];
580
    virtual ~A1() {}
581

582
    A1* getA1() {return this;}
583
};
584

585
struct A2
586
{
587
    char _[34981];
588
    virtual ~A2() {}
589

590
    A2* getA2() {return this;}
591
};
592

593
struct A3
594
    : private A1,
595
      public virtual A2
596
{
597
    char _[93481];
598
    virtual ~A3() {}
599

600
    A1* getA1() {return this;}
601
    A2* getA2() {return this;}
602
    A3* getA3() {return this;}
603
};
604

605
void test()
606
{
607
    A1 a1;
608
    A2 a2;
609
    A3 a3;
610
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
611
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
612
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
613
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
614

615
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
616
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
617
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
618
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
619
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
620

621
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
622
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
623
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
624
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
625
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
626
}
627

628
}  // t11
629

630
namespace t12
631
{
632

633
struct A1
634
{
635
    char _[43981];
636
    virtual ~A1() {}
637

638
    A1* getA1() {return this;}
639
};
640

641
struct A2
642
{
643
    char _[34981];
644
    virtual ~A2() {}
645

646
    A2* getA2() {return this;}
647
};
648

649
struct A3
650
    : private virtual A1,
651
      public virtual A2
652
{
653
    char _[93481];
654
    virtual ~A3() {}
655

656
    A1* getA1() {return this;}
657
    A2* getA2() {return this;}
658
    A3* getA3() {return this;}
659
};
660

661
void test()
662
{
663
    A1 a1;
664
    A2 a2;
665
    A3 a3;
666
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
667
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
668
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
669
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
670

671
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
672
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
673
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
674
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
675
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
676

677
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
678
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
679
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
680
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
681
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
682
}
683

684
}  // t12
685

686
namespace t13
687
{
688

689
struct A1
690
{
691
    char _[43981];
692
    virtual ~A1() {}
693

694
    A1* getA1() {return this;}
695
};
696

697
struct A2
698
{
699
    char _[34981];
700
    virtual ~A2() {}
701

702
    A2* getA2() {return this;}
703
};
704

705
struct A3
706
    : private A1,
707
      private A2
708
{
709
    char _[93481];
710
    virtual ~A3() {}
711

712
    A1* getA1() {return this;}
713
    A2* getA2() {return this;}
714
    A3* getA3() {return this;}
715
};
716

717
void test()
718
{
719
    A1 a1;
720
    A2 a2;
721
    A3 a3;
722
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
723
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
724
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
725
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
726

727
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
728
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
729
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
730
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
731

732
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
733
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
734
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
735
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
736
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
737
}
738

739
}  // t13
740

741
namespace t14
742
{
743

744
struct A1
745
{
746
    char _[43981];
747
    virtual ~A1() {}
748

749
    A1* getA1() {return this;}
750
};
751

752
struct A2
753
{
754
    char _[34981];
755
    virtual ~A2() {}
756

757
    A2* getA2() {return this;}
758
};
759

760
struct A3
761
    : private virtual A1,
762
      private A2
763
{
764
    char _[93481];
765
    virtual ~A3() {}
766

767
    A1* getA1() {return this;}
768
    A2* getA2() {return this;}
769
    A3* getA3() {return this;}
770
};
771

772
void test()
773
{
774
    A1 a1;
775
    A2 a2;
776
    A3 a3;
777
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
778
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
779
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
780
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
781

782
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
783
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
784
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
785
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
786

787
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
788
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
789
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
790
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
791
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
792
}
793

794
}  // t14
795

796
namespace t15
797
{
798

799
struct A1
800
{
801
    char _[43981];
802
    virtual ~A1() {}
803

804
    A1* getA1() {return this;}
805
};
806

807
struct A2
808
{
809
    char _[34981];
810
    virtual ~A2() {}
811

812
    A2* getA2() {return this;}
813
};
814

815
struct A3
816
    : private virtual A1,
817
      private virtual A2
818
{
819
    char _[93481];
820
    virtual ~A3() {}
821

822
    A1* getA1() {return this;}
823
    A2* getA2() {return this;}
824
    A3* getA3() {return this;}
825
};
826

827
void test()
828
{
829
    A1 a1;
830
    A2 a2;
831
    A3 a3;
832
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
833
    assert(dynamic_cast<A1*>(a2.getA2()) == 0);
834
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
835
    assert(dynamic_cast<A1*>(a3.getA2()) == 0);
836

837
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
838
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
839
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
840
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
841

842
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
843
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
844
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
845
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
846
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
847
}
848

849
}  // t15
850

851
/*
852

853
A1
854
|
855
A2
856
|
857
A3
858

859
*/
860

861
namespace t16
862
{
863

864
struct A1
865
{
866
    char _[43981];
867
    virtual ~A1() {}
868

869
    A1* getA1() {return this;}
870
};
871

872
struct A2
873
    : public A1
874
{
875
    char _[34981];
876
    virtual ~A2() {}
877

878
    A1* getA1() {return this;}
879
    A2* getA2() {return this;}
880
};
881

882
struct A3
883
    : public A2
884
{
885
    char _[93481];
886
    virtual ~A3() {}
887

888
    A1* getA1() {return this;}
889
    A2* getA2() {return this;}
890
    A3* getA3() {return this;}
891
};
892

893
void test()
894
{
895
    A1 a1;
896
    A2 a2;
897
    A3 a3;
898
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
899
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
900
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
901
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
902
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
903
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
904

905
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
906
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
907
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
908
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
909
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
910
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
911

912
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
913
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
914
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
915
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
916
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
917
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
918
}
919

920
}  // t16
921

922
namespace t17
923
{
924

925
struct A1
926
{
927
    char _[43981];
928
    virtual ~A1() {}
929

930
    A1* getA1() {return this;}
931
};
932

933
struct A2
934
    : public virtual A1
935
{
936
    char _[34981];
937
    virtual ~A2() {}
938

939
    A1* getA1() {return this;}
940
    A2* getA2() {return this;}
941
};
942

943
struct A3
944
    : public A2
945
{
946
    char _[93481];
947
    virtual ~A3() {}
948

949
    A1* getA1() {return this;}
950
    A2* getA2() {return this;}
951
    A3* getA3() {return this;}
952
};
953

954
void test()
955
{
956
    A1 a1;
957
    A2 a2;
958
    A3 a3;
959
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
960
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
961
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
962
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
963
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
964
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
965

966
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
967
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
968
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
969
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
970
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
971
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
972

973
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
974
    assert(dynamic_cast<A3*>(a2.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
}
980

981
}  // t17
982

983
namespace t18
984
{
985

986
struct A1
987
{
988
    char _[43981];
989
    virtual ~A1() {}
990

991
    A1* getA1() {return this;}
992
};
993

994
struct A2
995
    : private A1
996
{
997
    char _[34981];
998
    virtual ~A2() {}
999

1000
    A1* getA1() {return this;}
1001
    A2* getA2() {return this;}
1002
};
1003

1004
struct A3
1005
    : public A2
1006
{
1007
    char _[93481];
1008
    virtual ~A3() {}
1009

1010
    A2* getA2() {return this;}
1011
    A3* getA3() {return this;}
1012
};
1013

1014
void test()
1015
{
1016
    A1 a1;
1017
    A2 a2;
1018
    A3 a3;
1019
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1020
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1021
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1022

1023
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1024
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1025
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1026
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1027
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1028
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1029

1030
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1031
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1032
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1033
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1034
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1035
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1036
}
1037

1038
}  // t18
1039

1040
namespace t19
1041
{
1042

1043
struct A1
1044
{
1045
    char _[43981];
1046
    virtual ~A1() {}
1047

1048
    A1* getA1() {return this;}
1049
};
1050

1051
struct A2
1052
    : protected virtual A1
1053
{
1054
    char _[34981];
1055
    virtual ~A2() {}
1056

1057
    A1* getA1() {return this;}
1058
    A2* getA2() {return this;}
1059
};
1060

1061
struct A3
1062
    : public A2
1063
{
1064
    char _[93481];
1065
    virtual ~A3() {}
1066

1067
    A2* getA2() {return this;}
1068
    A3* getA3() {return this;}
1069
};
1070

1071
void test()
1072
{
1073
    A1 a1;
1074
    A2 a2;
1075
    A3 a3;
1076
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1077
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1078
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1079

1080
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1081
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1082
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1083
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1084
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1085
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1086

1087
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1088
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1089
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1090
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1091
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1092
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1093
}
1094

1095
}  // t19
1096

1097
namespace t20
1098
{
1099

1100
struct A1
1101
{
1102
    char _[43981];
1103
    virtual ~A1() {}
1104

1105
    A1* getA1() {return this;}
1106
};
1107

1108
struct A2
1109
    : public virtual A1
1110
{
1111
    char _[34981];
1112
    virtual ~A2() {}
1113

1114
    A1* getA1() {return this;}
1115
    A2* getA2() {return this;}
1116
};
1117

1118
struct A3
1119
    : public virtual A2
1120
{
1121
    char _[93481];
1122
    virtual ~A3() {}
1123

1124
    A1* getA1() {return this;}
1125
    A2* getA2() {return this;}
1126
    A3* getA3() {return this;}
1127
};
1128

1129
void test()
1130
{
1131
    A1 a1;
1132
    A2 a2;
1133
    A3 a3;
1134
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1135
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1136
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1137
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1138
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1139
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1140

1141
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1142
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1143
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1144
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1145
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1146
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1147

1148
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1149
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1150
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1151
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1152
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1153
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1154
}
1155

1156
}  // t20
1157

1158
namespace t21
1159
{
1160

1161
struct A1
1162
{
1163
    char _[43981];
1164
    virtual ~A1() {}
1165

1166
    A1* getA1() {return this;}
1167
};
1168

1169
struct A2
1170
    : private A1
1171
{
1172
    char _[34981];
1173
    virtual ~A2() {}
1174

1175
    A1* getA1() {return this;}
1176
    A2* getA2() {return this;}
1177
};
1178

1179
struct A3
1180
    : public virtual A2
1181
{
1182
    char _[93481];
1183
    virtual ~A3() {}
1184

1185
    A2* getA2() {return this;}
1186
    A3* getA3() {return this;}
1187
};
1188

1189
void test()
1190
{
1191
    A1 a1;
1192
    A2 a2;
1193
    A3 a3;
1194
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1195
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1196
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1197

1198
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1199
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1200
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1201
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1202
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1203
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1204

1205
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1206
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1207
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1208
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1209
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1210
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1211
}
1212

1213
}  // t21
1214

1215
namespace t22
1216
{
1217

1218
struct A1
1219
{
1220
    char _[43981];
1221
    virtual ~A1() {}
1222

1223
    A1* getA1() {return this;}
1224
};
1225

1226
struct A2
1227
    : protected virtual A1
1228
{
1229
    char _[34981];
1230
    virtual ~A2() {}
1231

1232
    A1* getA1() {return this;}
1233
    A2* getA2() {return this;}
1234
};
1235

1236
struct A3
1237
    : public virtual A2
1238
{
1239
    char _[93481];
1240
    virtual ~A3() {}
1241

1242
    A2* getA2() {return this;}
1243
    A3* getA3() {return this;}
1244
};
1245

1246
void test()
1247
{
1248
    A1 a1;
1249
    A2 a2;
1250
    A3 a3;
1251
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1252
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1253
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1254

1255
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1256
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1257
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1258
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1259
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1260
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1261

1262
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1263
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1264
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1265
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1266
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1267
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1268
}
1269

1270
}  // t22
1271

1272
namespace t23
1273
{
1274

1275
struct A1
1276
{
1277
    char _[43981];
1278
    virtual ~A1() {}
1279

1280
    A1* getA1() {return this;}
1281
};
1282

1283
struct A2
1284
    : private A1
1285
{
1286
    char _[34981];
1287
    virtual ~A2() {}
1288

1289
    A1* getA1() {return this;}
1290
    A2* getA2() {return this;}
1291
};
1292

1293
struct A3
1294
    : private A2
1295
{
1296
    char _[93481];
1297
    virtual ~A3() {}
1298

1299
    t23::A1* getA1() {return A2::getA1();}
1300
    A2* getA2() {return this;}
1301
    A3* getA3() {return this;}
1302
};
1303

1304
void test()
1305
{
1306
    A1 a1;
1307
    A2 a2;
1308
    A3 a3;
1309
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1310
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1311
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1312

1313
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1314
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1315
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1316
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1317
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1318

1319
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1320
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1321
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1322
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1323
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1324
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1325
}
1326

1327
}  // t23
1328

1329
namespace t24
1330
{
1331

1332
struct A1
1333
{
1334
    char _[43981];
1335
    virtual ~A1() {}
1336

1337
    A1* getA1() {return this;}
1338
};
1339

1340
struct A2
1341
    : protected virtual A1
1342
{
1343
    char _[34981];
1344
    virtual ~A2() {}
1345

1346
    A1* getA1() {return this;}
1347
    A2* getA2() {return this;}
1348
};
1349

1350
struct A3
1351
    : private A2
1352
{
1353
    char _[93481];
1354
    virtual ~A3() {}
1355

1356
    t24::A1* getA1() {return A2::getA1();}
1357
    A2* getA2() {return this;}
1358
    A3* getA3() {return this;}
1359
};
1360

1361
void test()
1362
{
1363
    A1 a1;
1364
    A2 a2;
1365
    A3 a3;
1366
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1367
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1368
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1369

1370
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1371
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1372
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1373
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1374
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1375

1376
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1377
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1378
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1379
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1380
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1381
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1382
}
1383

1384
}  // t24
1385

1386
namespace t25
1387
{
1388

1389
struct A1
1390
{
1391
    char _[43981];
1392
    virtual ~A1() {}
1393

1394
    A1* getA1() {return this;}
1395
};
1396

1397
struct A2
1398
    : protected virtual A1
1399
{
1400
    char _[34981];
1401
    virtual ~A2() {}
1402

1403
    A1* getA1() {return this;}
1404
    A2* getA2() {return this;}
1405
};
1406

1407
struct A3
1408
    : private virtual A2
1409
{
1410
    char _[93481];
1411
    virtual ~A3() {}
1412

1413
    t25::A1* getA1() {return A2::getA1();}
1414
    A2* getA2() {return this;}
1415
    A3* getA3() {return this;}
1416
};
1417

1418
void test()
1419
{
1420
    A1 a1;
1421
    A2 a2;
1422
    A3 a3;
1423
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1424
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1425
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1426

1427
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1428
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1429
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1430
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
1431
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1432

1433
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1434
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1435
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1436
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
1437
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1438
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1439
}
1440

1441
}  // t25
1442

1443
/*
1444

1445
A1 A1
1446
|  |
1447
A2 |
1448
 \ |
1449
  A3
1450

1451
*/
1452

1453
namespace t26
1454
{
1455

1456
struct A1
1457
{
1458
    char _[43981];
1459
    virtual ~A1() {}
1460

1461
    A1* getA1() {return this;}
1462
};
1463

1464
struct A2
1465
    : public A1
1466
{
1467
    char _[34981];
1468
    virtual ~A2() {}
1469

1470
    A1* getA1() {return this;}
1471
    A2* getA2() {return this;}
1472
};
1473

1474
struct A3
1475
    : public A1,
1476
      public A2
1477
{
1478
    char _[93481];
1479
    virtual ~A3() {}
1480

1481
    A1* getA12() {return A2::getA1();}
1482
    A2* getA2() {return this;}
1483
    A3* getA3() {return this;}
1484
};
1485

1486
void test()
1487
{
1488
    A1 a1;
1489
    A2 a2;
1490
    A3 a3;
1491
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1492
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1493
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1494
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1495
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1496

1497
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1498
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1499
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1500
    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1501
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1502
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1503

1504
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1505
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1506
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1507
    assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1508
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1509
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1510
}
1511

1512
}  // t26
1513

1514
namespace t27
1515
{
1516

1517
struct A1
1518
{
1519
    char _[43981];
1520
    virtual ~A1() {}
1521

1522
    A1* getA1() {return this;}
1523
};
1524

1525
struct A2
1526
    : private A1
1527
{
1528
    char _[34981];
1529
    virtual ~A2() {}
1530

1531
    A1* getA1() {return this;}
1532
    A2* getA2() {return this;}
1533
};
1534

1535
struct A3
1536
    : public A1,
1537
      public A2
1538
{
1539
    char _[93481];
1540
    virtual ~A3() {}
1541

1542
    A1* getA12() {return A2::getA1();}
1543
    A2* getA2() {return this;}
1544
    A3* getA3() {return this;}
1545
};
1546

1547
void test()
1548
{
1549
    A1 a1;
1550
    A2 a2;
1551
    A3 a3;
1552
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1553
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1554
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1555

1556
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1557
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1558
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1559
    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1560
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1561
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1562

1563
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1564
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1565
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1566
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1567
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1568
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1569
}
1570

1571
}  // t27
1572

1573
namespace t28
1574
{
1575

1576
struct A1
1577
{
1578
    char _[43981];
1579
    virtual ~A1() {}
1580

1581
    A1* getA1() {return this;}
1582
};
1583

1584
struct A2
1585
    : public A1
1586
{
1587
    char _[34981];
1588
    virtual ~A2() {}
1589

1590
    A1* getA1() {return this;}
1591
    A2* getA2() {return this;}
1592
};
1593

1594
struct A3
1595
    : private A1,
1596
      public A2
1597
{
1598
    char _[93481];
1599
    virtual ~A3() {}
1600

1601
    A1* getA12() {return A2::getA1();}
1602
    A2* getA2() {return this;}
1603
    A3* getA3() {return this;}
1604
};
1605

1606
void test()
1607
{
1608
    A1 a1;
1609
    A2 a2;
1610
    A3 a3;
1611
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1612
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1613
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1614
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1615

1616
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1617
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1618
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1619
    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1620
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1621
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1622

1623
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1624
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1625
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1626
    assert(dynamic_cast<A3*>(a3.getA12()) == a3.getA3());
1627
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1628
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1629
}
1630

1631
}  // t28
1632

1633
namespace t29
1634
{
1635

1636
struct A1
1637
{
1638
    char _[43981];
1639
    virtual ~A1() {}
1640

1641
    A1* getA1() {return this;}
1642
};
1643

1644
struct A2
1645
    : public A1
1646
{
1647
    char _[34981];
1648
    virtual ~A2() {}
1649

1650
    A1* getA1() {return this;}
1651
    A2* getA2() {return this;}
1652
};
1653

1654
struct A3
1655
    : public A1,
1656
      private A2
1657
{
1658
    char _[93481];
1659
    virtual ~A3() {}
1660

1661
    A1* getA12() {return A2::getA1();}
1662
    A2* getA2() {return this;}
1663
    A3* getA3() {return this;}
1664
};
1665

1666
void test()
1667
{
1668
    A1 a1;
1669
    A2 a2;
1670
    A3 a3;
1671
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1672
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1673
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1674
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1675

1676
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1677
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1678
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1679
    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1680
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1681

1682
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1683
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1684
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1685
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1686
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1687
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1688
}
1689

1690
}  // t29
1691

1692
namespace t30
1693
{
1694

1695
struct A1
1696
{
1697
    char _[43981];
1698
    virtual ~A1() {}
1699

1700
    A1* getA1() {return this;}
1701
};
1702

1703
struct A2
1704
    : public A1
1705
{
1706
    char _[34981];
1707
    virtual ~A2() {}
1708

1709
    A1* getA1() {return this;}
1710
    A2* getA2() {return this;}
1711
};
1712

1713
struct A3
1714
    : private A1,
1715
      private A2
1716
{
1717
    char _[93481];
1718
    virtual ~A3() {}
1719

1720
    A1* getA12() {return A2::getA1();}
1721
    A2* getA2() {return this;}
1722
    A3* getA3() {return this;}
1723
};
1724

1725
void test()
1726
{
1727
    A1 a1;
1728
    A2 a2;
1729
    A3 a3;
1730
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1731
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1732
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1733
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1734
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA12());
1735

1736
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1737
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1738
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1739
    assert(dynamic_cast<A2*>(a3.getA12()) == a3.getA2());
1740
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1741

1742
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1743
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1744
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1745
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1746
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1747
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1748
}
1749

1750
}  // t30
1751

1752
namespace t31
1753
{
1754

1755
struct A1
1756
{
1757
    char _[43981];
1758
    virtual ~A1() {}
1759

1760
    A1* getA1() {return this;}
1761
};
1762

1763
struct A2
1764
    : private A1
1765
{
1766
    char _[34981];
1767
    virtual ~A2() {}
1768

1769
    A1* getA1() {return this;}
1770
    A2* getA2() {return this;}
1771
};
1772

1773
struct A3
1774
    : public A1,
1775
      private A2
1776
{
1777
    char _[93481];
1778
    virtual ~A3() {}
1779

1780
    A1* getA12() {return A2::getA1();}
1781
    A2* getA2() {return this;}
1782
    A3* getA3() {return this;}
1783
};
1784

1785
void test()
1786
{
1787
    A1 a1;
1788
    A2 a2;
1789
    A3 a3;
1790
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1791
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1792
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1793

1794
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1795
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1796
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1797
    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1798
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1799

1800
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1801
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1802
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1803
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1804
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1805
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1806
}
1807

1808
}  // t31
1809

1810
namespace t32
1811
{
1812

1813
struct A1
1814
{
1815
    char _[43981];
1816
    virtual ~A1() {}
1817

1818
    A1* getA1() {return this;}
1819
};
1820

1821
struct A2
1822
    : private A1
1823
{
1824
    char _[34981];
1825
    virtual ~A2() {}
1826

1827
    A1* getA1() {return this;}
1828
    A2* getA2() {return this;}
1829
};
1830

1831
struct A3
1832
    : private A1,
1833
      public A2
1834
{
1835
    char _[93481];
1836
    virtual ~A3() {}
1837

1838
    A1* getA12() {return A2::getA1();}
1839
    A2* getA2() {return this;}
1840
    A3* getA3() {return this;}
1841
};
1842

1843
void test()
1844
{
1845
    A1 a1;
1846
    A2 a2;
1847
    A3 a3;
1848
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1849
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1850
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1851

1852
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1853
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1854
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1855
    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1856
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1857

1858
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1859
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1860
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1861
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1862
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1863
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1864
}
1865

1866
}  // t32
1867

1868
namespace t33
1869
{
1870

1871
struct A1
1872
{
1873
    char _[43981];
1874
    virtual ~A1() {}
1875

1876
    A1* getA1() {return this;}
1877
};
1878

1879
struct A2
1880
    : private A1
1881
{
1882
    char _[34981];
1883
    virtual ~A2() {}
1884

1885
    A1* getA1() {return this;}
1886
    A2* getA2() {return this;}
1887
};
1888

1889
struct A3
1890
    : private A1,
1891
      private A2
1892
{
1893
    char _[93481];
1894
    virtual ~A3() {}
1895

1896
    A1* getA12() {return A2::getA1();}
1897
    A2* getA2() {return this;}
1898
    A3* getA3() {return this;}
1899
};
1900

1901
void test()
1902
{
1903
    A1 a1;
1904
    A2 a2;
1905
    A3 a3;
1906
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1907
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1908
    assert(dynamic_cast<A1*>(a3.getA12()) == a3.getA12());
1909

1910
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1911
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
1912
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1913
    assert(dynamic_cast<A2*>(a3.getA12()) == 0);
1914
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1915

1916
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1917
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1918
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1919
    assert(dynamic_cast<A3*>(a3.getA12()) == 0);
1920
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
1921
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1922
}
1923

1924
}  // t33
1925

1926
/*
1927

1928
A1
1929
| \
1930
A2 \
1931
 \ |
1932
  A3
1933

1934
*/
1935

1936
namespace t34
1937
{
1938

1939
struct A1
1940
{
1941
    char _[43981];
1942
    virtual ~A1() {}
1943

1944
    A1* getA1() {return this;}
1945
};
1946

1947
struct A2
1948
    : public virtual A1
1949
{
1950
    char _[34981];
1951
    virtual ~A2() {}
1952

1953
    A1* getA1() {return this;}
1954
    A2* getA2() {return this;}
1955
};
1956

1957
struct A3
1958
    : public virtual A1,
1959
      public A2
1960
{
1961
    char _[93481];
1962
    virtual ~A3() {}
1963

1964
    A1* getA1() {return A1::getA1();}
1965
    A2* getA2() {return this;}
1966
    A3* getA3() {return this;}
1967
};
1968

1969
void test()
1970
{
1971
    A1 a1;
1972
    A2 a2;
1973
    A3 a3;
1974
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1975
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
1976
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
1977
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1978
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1979
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1980

1981
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1982
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
1983
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1984
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1985
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1986
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1987

1988
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1989
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
1990
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1991
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1992
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1993
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1994
}
1995

1996
}  // t34
1997

1998
namespace t35
1999
{
2000

2001
struct A1
2002
{
2003
    char _[43981];
2004
    virtual ~A1() {}
2005

2006
    A1* getA1() {return this;}
2007
};
2008

2009
struct A2
2010
    : private virtual A1
2011
{
2012
    char _[34981];
2013
    virtual ~A2() {}
2014

2015
    A1* getA1() {return this;}
2016
    A2* getA2() {return this;}
2017
};
2018

2019
struct A3
2020
    : public virtual A1,
2021
      public A2
2022
{
2023
    char _[93481];
2024
    virtual ~A3() {}
2025

2026
    A1* getA1() {return A1::getA1();}
2027
    A2* getA2() {return this;}
2028
    A3* getA3() {return this;}
2029
};
2030

2031
void test()
2032
{
2033
    A1 a1;
2034
    A2 a2;
2035
    A3 a3;
2036
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2037
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2038
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2039
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2040

2041
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2042
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2043
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2044
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2045
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2046
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2047

2048
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2049
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2050
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2051
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2052
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2053
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2054
}
2055

2056
}  // t35
2057

2058
namespace t36
2059
{
2060

2061
struct A1
2062
{
2063
    char _[43981];
2064
    virtual ~A1() {}
2065

2066
    A1* getA1() {return this;}
2067
};
2068

2069
struct A2
2070
    : public virtual A1
2071
{
2072
    char _[34981];
2073
    virtual ~A2() {}
2074

2075
    A1* getA1() {return this;}
2076
    A2* getA2() {return this;}
2077
};
2078

2079
struct A3
2080
    : private virtual A1,
2081
      public A2
2082
{
2083
    char _[93481];
2084
    virtual ~A3() {}
2085

2086
    A1* getA1() {return A1::getA1();}
2087
    A2* getA2() {return this;}
2088
    A3* getA3() {return this;}
2089
};
2090

2091
void test()
2092
{
2093
    A1 a1;
2094
    A2 a2;
2095
    A3 a3;
2096
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2097
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2098
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2099
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2100
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2101
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2102

2103
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2104
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2105
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2106
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2107
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2108
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2109

2110
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2111
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2112
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2113
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2114
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2115
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2116
}
2117

2118
}  // t36
2119

2120
namespace t37
2121
{
2122

2123
struct A1
2124
{
2125
    char _[43981];
2126
    virtual ~A1() {}
2127

2128
    A1* getA1() {return this;}
2129
};
2130

2131
struct A2
2132
    : public virtual A1
2133
{
2134
    char _[34981];
2135
    virtual ~A2() {}
2136

2137
    A1* getA1() {return this;}
2138
    A2* getA2() {return this;}
2139
};
2140

2141
struct A3
2142
    : public virtual A1,
2143
      private A2
2144
{
2145
    char _[93481];
2146
    virtual ~A3() {}
2147

2148
    A1* getA1() {return A1::getA1();}
2149
    A2* getA2() {return this;}
2150
    A3* getA3() {return this;}
2151
};
2152

2153
void test()
2154
{
2155
    A1 a1;
2156
    A2 a2;
2157
    A3 a3;
2158
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2159
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2160
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2161
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2162
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2163
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2164

2165
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2166
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2167
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2168
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2169
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2170

2171
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2172
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2173
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2174
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2175
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2176
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2177
}
2178

2179
}  // t37
2180

2181
namespace t38
2182
{
2183

2184
struct A1
2185
{
2186
    char _[43981];
2187
    virtual ~A1() {}
2188

2189
    A1* getA1() {return this;}
2190
};
2191

2192
struct A2
2193
    : public virtual A1
2194
{
2195
    char _[34981];
2196
    virtual ~A2() {}
2197

2198
    A1* getA1() {return this;}
2199
    A2* getA2() {return this;}
2200
};
2201

2202
struct A3
2203
    : private virtual A1,
2204
      private A2
2205
{
2206
    char _[93481];
2207
    virtual ~A3() {}
2208

2209
    A1* getA1() {return A1::getA1();}
2210
    A2* getA2() {return this;}
2211
    A3* getA3() {return this;}
2212
};
2213

2214
void test()
2215
{
2216
    A1 a1;
2217
    A2 a2;
2218
    A3 a3;
2219
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2220
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2221
    assert(dynamic_cast<A1*>(a2.getA2()) == a2.getA1());
2222
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2223
    assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
2224

2225
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2226
    assert(dynamic_cast<A2*>(a2.getA1()) == a2.getA2());
2227
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2228
    assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
2229
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2230

2231
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2232
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2233
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2234
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2235
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2236
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2237
}
2238

2239
}  // t38
2240

2241
namespace t39
2242
{
2243

2244
struct A1
2245
{
2246
    char _[43981];
2247
    virtual ~A1() {}
2248

2249
    A1* getA1() {return this;}
2250
};
2251

2252
struct A2
2253
    : private virtual A1
2254
{
2255
    char _[34981];
2256
    virtual ~A2() {}
2257

2258
    A1* getA1() {return this;}
2259
    A2* getA2() {return this;}
2260
};
2261

2262
struct A3
2263
    : public virtual A1,
2264
      private A2
2265
{
2266
    char _[93481];
2267
    virtual ~A3() {}
2268

2269
    A1* getA1() {return A1::getA1();}
2270
    A2* getA2() {return this;}
2271
    A3* getA3() {return this;}
2272
};
2273

2274
void test()
2275
{
2276
    A1 a1;
2277
    A2 a2;
2278
    A3 a3;
2279
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2280
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2281
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2282
    assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
2283

2284
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2285
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2286
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2287
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2288
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2289

2290
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2291
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2292
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2293
    assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
2294
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2295
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2296
}
2297

2298
}  // t39
2299

2300
namespace t40
2301
{
2302

2303
struct A1
2304
{
2305
    char _[43981];
2306
    virtual ~A1() {}
2307

2308
    A1* getA1() {return this;}
2309
};
2310

2311
struct A2
2312
    : private virtual A1
2313
{
2314
    char _[34981];
2315
    virtual ~A2() {}
2316

2317
    A1* getA1() {return this;}
2318
    A2* getA2() {return this;}
2319
};
2320

2321
struct A3
2322
    : private virtual A1,
2323
      public A2
2324
{
2325
    char _[93481];
2326
    virtual ~A3() {}
2327

2328
    A1* getA1() {return A1::getA1();}
2329
    A2* getA2() {return this;}
2330
    A3* getA3() {return this;}
2331
};
2332

2333
void test()
2334
{
2335
    A1 a1;
2336
    A2 a2;
2337
    A3 a3;
2338
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2339
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2340
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2341

2342
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2343
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2344
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2345
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2346
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2347
    assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
2348

2349
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2350
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2351
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2352
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2353
    assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
2354
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2355
}
2356

2357
}  // t40
2358

2359
namespace t41
2360
{
2361

2362
struct A1
2363
{
2364
    char _[43981];
2365
    virtual ~A1() {}
2366

2367
    A1* getA1() {return this;}
2368
};
2369

2370
struct A2
2371
    : private virtual A1
2372
{
2373
    char _[34981];
2374
    virtual ~A2() {}
2375

2376
    A1* getA1() {return this;}
2377
    A2* getA2() {return this;}
2378
};
2379

2380
struct A3
2381
    : private virtual A1,
2382
      private A2
2383
{
2384
    char _[93481];
2385
    virtual ~A3() {}
2386

2387
    A1* getA1() {return A1::getA1();}
2388
    A2* getA2() {return this;}
2389
    A3* getA3() {return this;}
2390
};
2391

2392
void test()
2393
{
2394
    A1 a1;
2395
    A2 a2;
2396
    A3 a3;
2397
    assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
2398
    assert(dynamic_cast<A1*>(a2.getA1()) == a2.getA1());
2399
    assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
2400

2401
    assert(dynamic_cast<A2*>(a1.getA1()) == 0);
2402
    assert(dynamic_cast<A2*>(a2.getA1()) == 0);
2403
    assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
2404
    assert(dynamic_cast<A2*>(a3.getA1()) == 0);
2405
    assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
2406

2407
    assert(dynamic_cast<A3*>(a1.getA1()) == 0);
2408
    assert(dynamic_cast<A3*>(a2.getA1()) == 0);
2409
    assert(dynamic_cast<A3*>(a2.getA2()) == 0);
2410
    assert(dynamic_cast<A3*>(a3.getA1()) == 0);
2411
    assert(dynamic_cast<A3*>(a3.getA2()) == 0);
2412
    assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
2413
}
2414

2415
}  // t41
2416

2417
int main(int, char**)
2418
{
2419
    timer t;
2420
    t1::test();
2421
    t2::test();
2422
    t3::test();
2423
    t4::test();
2424
    t5::test();
2425
    t6::test();
2426
    t7::test();
2427
    t8::test();
2428
    t9::test();
2429
    t10::test();
2430
    t11::test();
2431
    t12::test();
2432
    t13::test();
2433
    t14::test();
2434
    t15::test();
2435
    t16::test();
2436
    t17::test();
2437
    t18::test();
2438
    t19::test();
2439
    t20::test();
2440
    t21::test();
2441
    t22::test();
2442
    t23::test();
2443
    t24::test();
2444
    t25::test();
2445
    t26::test();
2446
    t27::test();
2447
    t28::test();
2448
    t29::test();
2449
    t30::test();
2450
    t31::test();
2451
    t32::test();
2452
    t33::test();
2453
    t34::test();
2454
    t35::test();
2455
    t36::test();
2456
    t37::test();
2457
    t38::test();
2458
    t39::test();
2459
    t40::test();
2460
    t41::test();
2461

2462
    return 0;
2463
}
2464

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.