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