[X86] avx512-pmovxrm.ll - replace X32 checks with X86. NFC.
[llvm-project.git] / libcxxabi / test / dynamic_cast5.pass.cpp
blobbb2cb886ce951ed757fe3e99f8d427936f1308a1
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 //===----------------------------------------------------------------------===//
9 #include <cassert>
10 #include "support/timer.h"
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
20 namespace t1
23 struct A1
25 char _[43981];
26 virtual ~A1() {}
28 A1* getA1() {return this;}
31 struct A2
33 char _[34981];
34 virtual ~A2() {}
36 A2* getA2() {return this;}
39 struct A3
40 : public virtual A1,
41 private A2
43 char _[93481];
44 virtual ~A3() {}
46 A1* getA1() {return A1::getA1();}
47 A2* getA2() {return A2::getA2();}
48 A3* getA3() {return this;}
51 struct A4
52 : public A3,
53 public A2
55 char _[13489];
56 virtual ~A4() {}
58 t1::A1* getA1() {return A3::getA1();}
59 A2* getA2() {return A3::getA2();}
60 A3* getA3() {return A3::getA3();}
61 A4* getA4() {return this;}
64 struct A5
65 : public A4,
66 public A3
68 char _[13489];
69 virtual ~A5() {}
71 t1::A1* getA1() {return A4::getA1();}
72 A2* getA2() {return A4::getA2();}
73 A3* getA3() {return A4::getA3();}
74 A4* getA4() {return A4::getA4();}
75 A5* getA5() {return this;}
78 void test()
80 A1 a1;
81 A2 a2;
82 A3 a3;
83 A4 a4;
84 A5 a5;
86 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
87 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
88 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
89 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
90 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
91 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
92 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
93 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
94 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
95 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
96 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
97 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
98 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
99 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
101 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
102 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
103 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
104 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
105 // assert(dynamic_cast<A2*>(a3.getA3()) == 0); // cast to private base
106 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
107 assert(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
110 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
111 assert(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
116 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
117 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
118 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
119 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
120 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
121 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
122 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
123 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
124 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
125 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
126 assert(dynamic_cast<A3*>(a5.getA2()) == 0);
127 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
128 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
129 // assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
131 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
132 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
133 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
134 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
135 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
136 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
137 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
138 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
139 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
140 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
141 assert(dynamic_cast<A4*>(a5.getA2()) == 0);
142 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
143 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
144 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
146 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
147 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
148 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
149 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
150 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
151 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
152 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
153 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
154 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
155 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
156 assert(dynamic_cast<A5*>(a5.getA2()) == 0);
157 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
158 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
159 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
162 } // t1
164 namespace t2
167 struct A1
169 char _[43981];
170 virtual ~A1() {}
172 A1* getA1() {return this;}
175 struct A2
177 char _[34981];
178 virtual ~A2() {}
180 A2* getA2() {return this;}
183 struct A3
184 : public virtual A1,
185 public A2
187 char _[93481];
188 virtual ~A3() {}
190 A1* getA1() {return A1::getA1();}
191 A2* getA2() {return A2::getA2();}
192 A3* getA3() {return this;}
195 struct A4
196 : public A3,
197 public A2
199 char _[13489];
200 virtual ~A4() {}
202 t2::A1* getA1() {return A3::getA1();}
203 A2* getA2() {return A3::getA2();}
204 A3* getA3() {return A3::getA3();}
205 A4* getA4() {return this;}
208 struct A5
209 : public A4,
210 public A3
212 char _[13489];
213 virtual ~A5() {}
215 t2::A1* getA1() {return A4::getA1();}
216 A2* getA2() {return A4::getA2();}
217 A3* getA3() {return A4::getA3();}
218 A4* getA4() {return A4::getA4();}
219 A5* getA5() {return this;}
222 void test()
224 A1 a1;
225 A2 a2;
226 A3 a3;
227 A4 a4;
228 A5 a5;
230 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
231 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
232 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
233 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
234 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
235 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
236 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
237 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
238 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
239 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
240 assert(dynamic_cast<A1*>(a5.getA2()) == a5.getA1());
241 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
242 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
243 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
245 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
246 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
247 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
248 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
249 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
250 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
251 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
252 assert(dynamic_cast<A2*>(a4.getA3()) == a4.getA2());
253 // assert(dynamic_cast<A2*>(a4.getA4()) == 0); // cast to ambiguous base
254 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
255 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
256 assert(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
260 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
261 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
262 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
263 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
264 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
265 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
266 assert(dynamic_cast<A3*>(a4.getA2()) == a4.getA3());
267 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
268 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
269 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
270 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
271 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
272 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
273 // assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
275 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
276 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
277 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
278 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
279 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
280 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
281 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
282 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
283 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
284 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
285 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
286 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
287 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
288 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
290 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
291 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
292 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
293 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
294 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
295 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
296 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
297 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
298 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
299 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
300 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
301 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
302 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
303 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
306 } // t2
308 namespace t3
311 struct A1
313 char _[43981];
314 virtual ~A1() {}
316 A1* getA1() {return this;}
319 struct A2
321 char _[34981];
322 virtual ~A2() {}
324 A2* getA2() {return this;}
327 struct A3
328 : public A1,
329 public virtual A2
331 char _[93481];
332 virtual ~A3() {}
334 A1* getA1() {return A1::getA1();}
335 A2* getA2() {return A2::getA2();}
336 A3* getA3() {return this;}
339 struct A4
340 : public A1,
341 public virtual A2
343 char _[13489];
344 virtual ~A4() {}
346 A1* getA1() {return A1::getA1();}
347 A2* getA2() {return A2::getA2();}
348 A4* getA4() {return this;}
351 struct A5
352 : public A3,
353 public A4
355 char _[41389];
356 virtual ~A5() {}
358 A1* getA14() {return A4::getA1();}
359 A1* getA13() {return A3::getA1();}
360 A2* getA2() {return A4::getA2();}
361 A3* getA3() {return A3::getA3();}
362 A4* getA4() {return A4::getA4();}
363 A5* getA5() {return this;}
366 void test()
368 A1 a1;
369 A2 a2;
370 A3 a3;
371 A4 a4;
372 A5 a5;
374 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
375 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
376 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
377 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
378 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
379 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
380 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
381 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
382 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
383 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
384 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
385 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
386 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
388 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
389 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
390 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
391 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
392 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
393 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
394 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
395 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
396 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
397 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
398 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
399 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
400 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
401 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
403 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
404 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
405 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
406 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
407 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
408 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
409 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
410 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
411 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
412 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
413 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
414 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
415 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
416 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
418 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
419 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
420 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
421 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
422 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
423 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
424 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
425 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
426 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
427 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
428 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
429 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
430 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
431 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
433 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
434 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
435 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
436 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
437 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
438 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
439 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
440 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
441 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
442 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
443 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
444 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
445 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
446 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
449 } // t3
451 namespace t4
454 struct A1
456 char _[43981];
457 virtual ~A1() {}
459 A1* getA1() {return this;}
462 struct A2
464 char _[34981];
465 virtual ~A2() {}
467 A2* getA2() {return this;}
470 struct A3
471 : protected A1,
472 public virtual A2
474 char _[93481];
475 virtual ~A3() {}
477 A1* getA1() {return A1::getA1();}
478 A2* getA2() {return A2::getA2();}
479 A3* getA3() {return this;}
482 struct A4
483 : public A1,
484 public virtual A2
486 char _[13489];
487 virtual ~A4() {}
489 A1* getA1() {return A1::getA1();}
490 A2* getA2() {return A2::getA2();}
491 A4* getA4() {return this;}
494 struct A5
495 : public A3,
496 public A4
498 char _[41389];
499 virtual ~A5() {}
501 A1* getA14() {return A4::getA1();}
502 A1* getA13() {return A3::getA1();}
503 A2* getA2() {return A4::getA2();}
504 A3* getA3() {return A3::getA3();}
505 A4* getA4() {return A4::getA4();}
506 A5* getA5() {return this;}
509 void test()
511 A1 a1;
512 A2 a2;
513 A3 a3;
514 A4 a4;
515 A5 a5;
517 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
518 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
519 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
520 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
521 // assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1()); // cast to protected base
522 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
523 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
524 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
525 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
526 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
527 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
528 // assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13()); // cast to protected base
529 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
531 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
532 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
533 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
534 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
535 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
536 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
537 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
538 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
539 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
540 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
541 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
542 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
543 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
544 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
546 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
547 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
548 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
549 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
550 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
551 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
552 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
553 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
554 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
555 assert(dynamic_cast<A3*>(a5.getA13()) == 0);
556 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
557 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
558 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
559 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
561 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
562 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
563 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
564 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
565 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
566 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
567 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
568 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
569 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
570 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
571 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
572 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
573 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
574 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
576 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
577 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
578 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
579 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
580 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
581 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
582 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
583 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
584 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
585 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
586 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
587 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
588 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
589 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
592 } // t4
594 namespace t5
597 struct A1
599 char _[43981];
600 virtual ~A1() {}
602 A1* getA1() {return this;}
605 struct A2
607 char _[34981];
608 virtual ~A2() {}
610 A2* getA2() {return this;}
613 struct A3
614 : public A1,
615 protected virtual A2
617 char _[93481];
618 virtual ~A3() {}
620 A1* getA1() {return A1::getA1();}
621 A2* getA2() {return A2::getA2();}
622 A3* getA3() {return this;}
625 struct A4
626 : public A1,
627 public virtual A2
629 char _[13489];
630 virtual ~A4() {}
632 A1* getA1() {return A1::getA1();}
633 A2* getA2() {return A2::getA2();}
634 A4* getA4() {return this;}
637 struct A5
638 : public A3,
639 public A4
641 char _[41389];
642 virtual ~A5() {}
644 A1* getA14() {return A4::getA1();}
645 A1* getA13() {return A3::getA1();}
646 A2* getA2() {return A4::getA2();}
647 A3* getA3() {return A3::getA3();}
648 A4* getA4() {return A4::getA4();}
649 A5* getA5() {return this;}
652 void test()
654 A1 a1;
655 A2 a2;
656 A3 a3;
657 A4 a4;
658 A5 a5;
660 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
661 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
662 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
663 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
664 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
665 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
666 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
667 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
668 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
669 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
670 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
671 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
672 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
674 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
675 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
676 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
677 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
678 // assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2()); // cast to protected base
679 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
680 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
681 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
682 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
683 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
684 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
685 // assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2()); // cast to protected base
686 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
687 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
689 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
690 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
691 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
692 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
693 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
694 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
695 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
696 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
697 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
698 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
699 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
700 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
701 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
702 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
704 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
705 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
706 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
707 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
708 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
709 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
710 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
711 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
712 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
713 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
714 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
715 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
716 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
717 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
719 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
720 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
721 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
722 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
723 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
724 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
725 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
726 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
727 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
728 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
729 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
730 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
731 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
732 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
735 } // t5
737 namespace t6
740 struct A1
742 char _[43981];
743 virtual ~A1() {}
745 A1* getA1() {return this;}
748 struct A2
750 char _[34981];
751 virtual ~A2() {}
753 A2* getA2() {return this;}
756 struct A3
757 : public A1,
758 public virtual A2
760 char _[93481];
761 virtual ~A3() {}
763 A1* getA1() {return A1::getA1();}
764 A2* getA2() {return A2::getA2();}
765 A3* getA3() {return this;}
768 struct A4
769 : protected A1,
770 public virtual A2
772 char _[13489];
773 virtual ~A4() {}
775 A1* getA1() {return A1::getA1();}
776 A2* getA2() {return A2::getA2();}
777 A4* getA4() {return this;}
780 struct A5
781 : public A3,
782 public A4
784 char _[41389];
785 virtual ~A5() {}
787 A1* getA14() {return A4::getA1();}
788 A1* getA13() {return A3::getA1();}
789 A2* getA2() {return A4::getA2();}
790 A3* getA3() {return A3::getA3();}
791 A4* getA4() {return A4::getA4();}
792 A5* getA5() {return this;}
795 void test()
797 A1 a1;
798 A2 a2;
799 A3 a3;
800 A4 a4;
801 A5 a5;
803 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
804 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
805 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
806 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
807 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
808 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
809 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
810 // assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1()); // cast to protected base
811 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
812 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
813 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
814 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
815 // assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14()); // cast to protected base
817 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
818 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
819 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
820 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
821 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
822 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
823 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
824 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
825 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
826 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
827 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
828 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
829 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
830 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
832 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
833 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
834 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
835 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
836 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
837 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
838 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
839 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
840 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
841 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
842 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
843 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
844 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
845 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
847 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
848 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
849 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
850 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
851 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
852 assert(dynamic_cast<A4*>(a4.getA1()) == 0);
853 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
854 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
855 assert(dynamic_cast<A4*>(a5.getA14()) == 0);
856 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
857 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
858 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
859 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
860 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
862 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
863 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
864 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
865 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
866 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
867 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
868 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
869 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
870 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
871 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
872 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
873 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
874 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
875 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
878 } // t6
880 namespace t7
883 struct A1
885 char _[43981];
886 virtual ~A1() {}
888 A1* getA1() {return this;}
891 struct A2
893 char _[34981];
894 virtual ~A2() {}
896 A2* getA2() {return this;}
899 struct A3
900 : public A1,
901 public virtual A2
903 char _[93481];
904 virtual ~A3() {}
906 A1* getA1() {return A1::getA1();}
907 A2* getA2() {return A2::getA2();}
908 A3* getA3() {return this;}
911 struct A4
912 : public A1,
913 protected virtual A2
915 char _[13489];
916 virtual ~A4() {}
918 A1* getA1() {return A1::getA1();}
919 A2* getA2() {return A2::getA2();}
920 A4* getA4() {return this;}
923 struct A5
924 : public A3,
925 public A4
927 char _[41389];
928 virtual ~A5() {}
930 A1* getA14() {return A4::getA1();}
931 A1* getA13() {return A3::getA1();}
932 A2* getA2() {return A4::getA2();}
933 A3* getA3() {return A3::getA3();}
934 A4* getA4() {return A4::getA4();}
935 A5* getA5() {return this;}
938 void test()
940 A1 a1;
941 A2 a2;
942 A3 a3;
943 A4 a4;
944 A5 a5;
946 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
947 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
948 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
949 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
950 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
951 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
952 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
953 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
954 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
955 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
956 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
957 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
958 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
960 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
961 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
962 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
963 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
964 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
965 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
966 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
967 // assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2()); // cast to protected base
968 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
969 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
970 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
971 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
972 // assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2()); // cast to protected base
973 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
975 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
976 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
977 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
978 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
979 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
980 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
981 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
982 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
983 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
984 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
985 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
986 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
987 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
988 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
990 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
991 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
992 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
993 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
994 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
995 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
996 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
997 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
998 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
999 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
1000 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1001 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
1002 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1003 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
1005 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1006 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1007 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1008 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1009 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1010 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1011 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1012 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1013 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1014 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1015 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1016 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1017 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1018 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1021 } // t7
1023 namespace t8
1026 struct A1
1028 char _[43981];
1029 virtual ~A1() {}
1031 A1* getA1() {return this;}
1034 struct A2
1036 char _[34981];
1037 virtual ~A2() {}
1039 A2* getA2() {return this;}
1042 struct A3
1043 : public A1,
1044 public virtual A2
1046 char _[93481];
1047 virtual ~A3() {}
1049 A1* getA1() {return A1::getA1();}
1050 A2* getA2() {return A2::getA2();}
1051 A3* getA3() {return this;}
1054 struct A4
1055 : public A1,
1056 public virtual A2
1058 char _[13489];
1059 virtual ~A4() {}
1061 A1* getA1() {return A1::getA1();}
1062 A2* getA2() {return A2::getA2();}
1063 A4* getA4() {return this;}
1066 struct A5
1067 : protected A3,
1068 public A4
1070 char _[41389];
1071 virtual ~A5() {}
1073 A1* getA14() {return A4::getA1();}
1074 A1* getA13() {return A3::getA1();}
1075 A2* getA2() {return A4::getA2();}
1076 A3* getA3() {return A3::getA3();}
1077 A4* getA4() {return A4::getA4();}
1078 A5* getA5() {return this;}
1081 void test()
1083 A1 a1;
1084 A2 a2;
1085 A3 a3;
1086 A4 a4;
1087 A5 a5;
1089 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1090 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1091 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1092 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1093 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1094 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1095 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1096 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1097 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1098 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1099 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1100 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1101 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1103 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1104 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1105 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1106 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1107 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1108 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1109 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1110 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1111 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
1112 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
1113 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1114 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1115 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1116 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1118 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1119 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1120 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1121 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1122 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1123 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1124 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1125 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1126 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1127 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1128 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1129 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1130 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1131 // assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3()); // cast to protected base
1133 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1134 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1135 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1136 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1137 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1138 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1139 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1140 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1141 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1142 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1143 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1144 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1145 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1146 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
1148 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1149 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1150 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1151 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1152 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1153 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1154 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1155 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1156 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1157 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
1158 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1159 assert(dynamic_cast<A5*>(a5.getA3()) == 0);
1160 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1161 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1164 } // t8
1166 namespace t9
1169 struct A1
1171 char _[43981];
1172 virtual ~A1() {}
1174 A1* getA1() {return this;}
1177 struct A2
1179 char _[34981];
1180 virtual ~A2() {}
1182 A2* getA2() {return this;}
1185 struct A3
1186 : public A1,
1187 public virtual A2
1189 char _[93481];
1190 virtual ~A3() {}
1192 A1* getA1() {return A1::getA1();}
1193 A2* getA2() {return A2::getA2();}
1194 A3* getA3() {return this;}
1197 struct A4
1198 : public A1,
1199 public virtual A2
1201 char _[13489];
1202 virtual ~A4() {}
1204 A1* getA1() {return A1::getA1();}
1205 A2* getA2() {return A2::getA2();}
1206 A4* getA4() {return this;}
1209 struct A5
1210 : public A3,
1211 protected A4
1213 char _[41389];
1214 virtual ~A5() {}
1216 A1* getA14() {return A4::getA1();}
1217 A1* getA13() {return A3::getA1();}
1218 A2* getA2() {return A4::getA2();}
1219 A3* getA3() {return A3::getA3();}
1220 A4* getA4() {return A4::getA4();}
1221 A5* getA5() {return this;}
1224 void test()
1226 A1 a1;
1227 A2 a2;
1228 A3 a3;
1229 A4 a4;
1230 A5 a5;
1232 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1233 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1234 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1235 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1236 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1237 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1238 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1239 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1240 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1241 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1242 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1243 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1244 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1246 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1247 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1248 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1249 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1250 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1251 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1252 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1253 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1254 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
1255 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
1256 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1257 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1258 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1259 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1261 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1262 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1263 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1264 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1265 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1266 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1267 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1268 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1269 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1270 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1271 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1272 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1273 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1274 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
1276 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1277 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1278 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1279 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1280 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1281 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1282 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1283 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1284 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1285 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1286 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1287 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1288 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1289 // assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4()); // cast to protected base
1291 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1292 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1293 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1294 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1295 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1296 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1297 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1298 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1299 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
1300 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1301 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1302 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1303 assert(dynamic_cast<A5*>(a5.getA4()) == 0);
1304 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1307 } // t9
1310 int main(int, char**)
1312 timer t;
1313 t1::test();
1314 t2::test();
1315 t3::test();
1316 t4::test();
1317 t5::test();
1318 t6::test();
1319 t7::test();
1320 t8::test();
1321 t9::test();
1323 return 0;