1 //===------------------------- dynamic_cast5.cpp --------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include <cassert>
11
12 namespace t1
13 {
14
15 struct A1
16 {
17 char _[43981];
~A1t1::A118 virtual ~A1() {}
19
getA1t1::A120 A1* getA1() {return this;}
21 };
22
23 struct A2
24 {
25 char _[34981];
~A2t1::A226 virtual ~A2() {}
27
getA2t1::A228 A2* getA2() {return this;}
29 };
30
31 struct A3
32 : public virtual A1,
33 private A2
34 {
35 char _[93481];
~A3t1::A336 virtual ~A3() {}
37
getA1t1::A338 A1* getA1() {return A1::getA1();}
getA2t1::A339 A2* getA2() {return A2::getA2();}
getA3t1::A340 A3* getA3() {return this;}
41 };
42
43 struct A4
44 : public A3,
45 public A2
46 {
47 char _[13489];
~A4t1::A448 virtual ~A4() {}
49
getA1t1::A450 t1::A1* getA1() {return A3::getA1();}
getA2t1::A451 A2* getA2() {return A3::getA2();}
getA3t1::A452 A3* getA3() {return A3::getA3();}
getA4t1::A453 A4* getA4() {return this;}
54 };
55
56 struct A5
57 : public A4,
58 public A3
59 {
60 char _[13489];
~A5t1::A561 virtual ~A5() {}
62
getA1t1::A563 t1::A1* getA1() {return A4::getA1();}
getA2t1::A564 A2* getA2() {return A4::getA2();}
getA3t1::A565 A3* getA3() {return A4::getA3();}
getA4t1::A566 A4* getA4() {return A4::getA4();}
getA5t1::A567 A5* getA5() {return this;}
68 };
69
test()70 void test()
71 {
72 A1 a1;
73 A2 a2;
74 A3 a3;
75 A4 a4;
76 A5 a5;
77
78 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
79 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
80 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
81 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
82 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
83 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
84 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
85 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
86 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
87 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
88 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
89 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
90 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
91 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
92
93 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
94 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
95 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
96 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
97 // assert(dynamic_cast<A2*>(a3.getA3()) == 0); // cast to private base
98 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
99 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
100 // assert(dynamic_cast<A2*>(a4.getA3()) == 0); // cast to private base
101 // assert(dynamic_cast<A2*>(a4.getA4()) == 0); // cast to ambiguous base
102 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
103 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
104 // assert(dynamic_cast<A2*>(a5.getA3()) == 0); // cast to private base
105 // assert(dynamic_cast<A2*>(a5.getA4()) == 0); // cast to ambiguous base
106 // assert(dynamic_cast<A2*>(a5.getA5()) == 0); // cast to ambiguous base
107
108 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
109 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
110 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
111 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
112 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
113 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
114 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
115 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
116 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
117 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
118 assert(dynamic_cast<A3*>(a5.getA2()) == 0);
119 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
120 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
121 // assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
122
123 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
124 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
125 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
126 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
127 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
128 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
129 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
130 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
131 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
132 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
133 assert(dynamic_cast<A4*>(a5.getA2()) == 0);
134 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
135 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
136 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
137
138 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
139 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
140 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
141 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
142 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
143 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
144 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
145 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
146 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
147 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
148 assert(dynamic_cast<A5*>(a5.getA2()) == 0);
149 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
150 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
151 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
152 }
153
154 } // t1
155
156 namespace t2
157 {
158
159 struct A1
160 {
161 char _[43981];
~A1t2::A1162 virtual ~A1() {}
163
getA1t2::A1164 A1* getA1() {return this;}
165 };
166
167 struct A2
168 {
169 char _[34981];
~A2t2::A2170 virtual ~A2() {}
171
getA2t2::A2172 A2* getA2() {return this;}
173 };
174
175 struct A3
176 : public virtual A1,
177 public A2
178 {
179 char _[93481];
~A3t2::A3180 virtual ~A3() {}
181
getA1t2::A3182 A1* getA1() {return A1::getA1();}
getA2t2::A3183 A2* getA2() {return A2::getA2();}
getA3t2::A3184 A3* getA3() {return this;}
185 };
186
187 struct A4
188 : public A3,
189 public A2
190 {
191 char _[13489];
~A4t2::A4192 virtual ~A4() {}
193
getA1t2::A4194 t2::A1* getA1() {return A3::getA1();}
getA2t2::A4195 A2* getA2() {return A3::getA2();}
getA3t2::A4196 A3* getA3() {return A3::getA3();}
getA4t2::A4197 A4* getA4() {return this;}
198 };
199
200 struct A5
201 : public A4,
202 public A3
203 {
204 char _[13489];
~A5t2::A5205 virtual ~A5() {}
206
getA1t2::A5207 t2::A1* getA1() {return A4::getA1();}
getA2t2::A5208 A2* getA2() {return A4::getA2();}
getA3t2::A5209 A3* getA3() {return A4::getA3();}
getA4t2::A5210 A4* getA4() {return A4::getA4();}
getA5t2::A5211 A5* getA5() {return this;}
212 };
213
test()214 void test()
215 {
216 A1 a1;
217 A2 a2;
218 A3 a3;
219 A4 a4;
220 A5 a5;
221
222 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
223 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
224 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
225 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
226 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
227 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
228 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
229 assert(dynamic_cast<A1*>(a4.getA3()) == a4.getA1());
230 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
231 assert(dynamic_cast<A1*>(a5.getA1()) == a5.getA1());
232 assert(dynamic_cast<A1*>(a5.getA2()) == a5.getA1());
233 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA1());
234 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA1());
235 assert(dynamic_cast<A1*>(a5.getA5()) == a5.getA1());
236
237 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
238 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
239 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
240 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
241 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
242 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
243 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
244 assert(dynamic_cast<A2*>(a4.getA3()) == a4.getA2());
245 // assert(dynamic_cast<A2*>(a4.getA4()) == 0); // cast to ambiguous base
246 assert(dynamic_cast<A2*>(a5.getA1()) == 0);
247 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
248 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
249 // assert(dynamic_cast<A2*>(a5.getA4()) == 0); // cast to ambiguous base
250 // assert(dynamic_cast<A2*>(a5.getA5()) == 0); // cast to ambiguous base
251
252 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
253 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
254 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
255 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
256 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
257 assert(dynamic_cast<A3*>(a4.getA1()) == a4.getA3());
258 assert(dynamic_cast<A3*>(a4.getA2()) == a4.getA3());
259 assert(dynamic_cast<A3*>(a4.getA3()) == a4.getA3());
260 assert(dynamic_cast<A3*>(a4.getA4()) == a4.getA3());
261 assert(dynamic_cast<A3*>(a5.getA1()) == 0);
262 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
263 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
264 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
265 // assert(dynamic_cast<A3*>(a5.getA5()) == 0); // cast to ambiguous base
266
267 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
268 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
269 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
270 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
271 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
272 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
273 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
274 assert(dynamic_cast<A4*>(a4.getA3()) == a4.getA4());
275 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
276 assert(dynamic_cast<A4*>(a5.getA1()) == a5.getA4());
277 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
278 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
279 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
280 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
281
282 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
283 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
284 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
285 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
286 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
287 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
288 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
289 assert(dynamic_cast<A5*>(a4.getA3()) == 0);
290 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
291 assert(dynamic_cast<A5*>(a5.getA1()) == a5.getA5());
292 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
293 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
294 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
295 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
296 }
297
298 } // t2
299
300 namespace t3
301 {
302
303 struct A1
304 {
305 char _[43981];
~A1t3::A1306 virtual ~A1() {}
307
getA1t3::A1308 A1* getA1() {return this;}
309 };
310
311 struct A2
312 {
313 char _[34981];
~A2t3::A2314 virtual ~A2() {}
315
getA2t3::A2316 A2* getA2() {return this;}
317 };
318
319 struct A3
320 : public A1,
321 public virtual A2
322 {
323 char _[93481];
~A3t3::A3324 virtual ~A3() {}
325
getA1t3::A3326 A1* getA1() {return A1::getA1();}
getA2t3::A3327 A2* getA2() {return A2::getA2();}
getA3t3::A3328 A3* getA3() {return this;}
329 };
330
331 struct A4
332 : public A1,
333 public virtual A2
334 {
335 char _[13489];
~A4t3::A4336 virtual ~A4() {}
337
getA1t3::A4338 A1* getA1() {return A1::getA1();}
getA2t3::A4339 A2* getA2() {return A2::getA2();}
getA4t3::A4340 A4* getA4() {return this;}
341 };
342
343 struct A5
344 : public A3,
345 public A4
346 {
347 char _[41389];
~A5t3::A5348 virtual ~A5() {}
349
getA14t3::A5350 A1* getA14() {return A4::getA1();}
getA13t3::A5351 A1* getA13() {return A3::getA1();}
getA2t3::A5352 A2* getA2() {return A4::getA2();}
getA3t3::A5353 A3* getA3() {return A3::getA3();}
getA4t3::A5354 A4* getA4() {return A4::getA4();}
getA5t3::A5355 A5* getA5() {return this;}
356 };
357
test()358 void test()
359 {
360 A1 a1;
361 A2 a2;
362 A3 a3;
363 A4 a4;
364 A5 a5;
365
366 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
367 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
368 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
369 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
370 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
371 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
372 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
373 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
374 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
375 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
376 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
377 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
378 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
379
380 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
381 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
382 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
383 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
384 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
385 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
386 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
387 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
388 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
389 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
390 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
391 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
392 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
393 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
394
395 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
396 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
397 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
398 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
399 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
400 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
401 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
402 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
403 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
404 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
405 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
406 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
407 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
408 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
409
410 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
411 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
412 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
413 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
414 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
415 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
416 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
417 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
418 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
419 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
420 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
421 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
422 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
423 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
424
425 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
426 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
427 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
428 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
429 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
430 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
431 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
432 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
433 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
434 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
435 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
436 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
437 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
438 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
439 }
440
441 } // t3
442
443 namespace t4
444 {
445
446 struct A1
447 {
448 char _[43981];
~A1t4::A1449 virtual ~A1() {}
450
getA1t4::A1451 A1* getA1() {return this;}
452 };
453
454 struct A2
455 {
456 char _[34981];
~A2t4::A2457 virtual ~A2() {}
458
getA2t4::A2459 A2* getA2() {return this;}
460 };
461
462 struct A3
463 : protected A1,
464 public virtual A2
465 {
466 char _[93481];
~A3t4::A3467 virtual ~A3() {}
468
getA1t4::A3469 A1* getA1() {return A1::getA1();}
getA2t4::A3470 A2* getA2() {return A2::getA2();}
getA3t4::A3471 A3* getA3() {return this;}
472 };
473
474 struct A4
475 : public A1,
476 public virtual A2
477 {
478 char _[13489];
~A4t4::A4479 virtual ~A4() {}
480
getA1t4::A4481 A1* getA1() {return A1::getA1();}
getA2t4::A4482 A2* getA2() {return A2::getA2();}
getA4t4::A4483 A4* getA4() {return this;}
484 };
485
486 struct A5
487 : public A3,
488 public A4
489 {
490 char _[41389];
~A5t4::A5491 virtual ~A5() {}
492
getA14t4::A5493 A1* getA14() {return A4::getA1();}
getA13t4::A5494 A1* getA13() {return A3::getA1();}
getA2t4::A5495 A2* getA2() {return A4::getA2();}
getA3t4::A5496 A3* getA3() {return A3::getA3();}
getA4t4::A5497 A4* getA4() {return A4::getA4();}
getA5t4::A5498 A5* getA5() {return this;}
499 };
500
test()501 void test()
502 {
503 A1 a1;
504 A2 a2;
505 A3 a3;
506 A4 a4;
507 A5 a5;
508
509 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
510 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
511 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
512 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
513 // assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1()); // cast to protected base
514 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
515 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
516 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
517 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
518 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
519 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
520 // assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13()); // cast to protected base
521 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
522
523 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
524 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
525 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
526 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
527 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
528 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
529 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
530 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
531 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
532 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
533 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
534 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
535 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
536 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
537
538 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
539 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
540 assert(dynamic_cast<A3*>(a3.getA1()) == 0);
541 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
542 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
543 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
544 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
545 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
546 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
547 assert(dynamic_cast<A3*>(a5.getA13()) == 0);
548 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
549 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
550 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
551 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
552
553 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
554 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
555 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
556 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
557 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
558 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
559 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
560 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
561 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
562 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
563 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
564 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
565 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
566 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
567
568 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
569 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
570 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
571 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
572 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
573 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
574 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
575 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
576 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
577 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
578 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
579 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
580 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
581 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
582 }
583
584 } // t4
585
586 namespace t5
587 {
588
589 struct A1
590 {
591 char _[43981];
~A1t5::A1592 virtual ~A1() {}
593
getA1t5::A1594 A1* getA1() {return this;}
595 };
596
597 struct A2
598 {
599 char _[34981];
~A2t5::A2600 virtual ~A2() {}
601
getA2t5::A2602 A2* getA2() {return this;}
603 };
604
605 struct A3
606 : public A1,
607 protected virtual A2
608 {
609 char _[93481];
~A3t5::A3610 virtual ~A3() {}
611
getA1t5::A3612 A1* getA1() {return A1::getA1();}
getA2t5::A3613 A2* getA2() {return A2::getA2();}
getA3t5::A3614 A3* getA3() {return this;}
615 };
616
617 struct A4
618 : public A1,
619 public virtual A2
620 {
621 char _[13489];
~A4t5::A4622 virtual ~A4() {}
623
getA1t5::A4624 A1* getA1() {return A1::getA1();}
getA2t5::A4625 A2* getA2() {return A2::getA2();}
getA4t5::A4626 A4* getA4() {return this;}
627 };
628
629 struct A5
630 : public A3,
631 public A4
632 {
633 char _[41389];
~A5t5::A5634 virtual ~A5() {}
635
getA14t5::A5636 A1* getA14() {return A4::getA1();}
getA13t5::A5637 A1* getA13() {return A3::getA1();}
getA2t5::A5638 A2* getA2() {return A4::getA2();}
getA3t5::A5639 A3* getA3() {return A3::getA3();}
getA4t5::A5640 A4* getA4() {return A4::getA4();}
getA5t5::A5641 A5* getA5() {return this;}
642 };
643
test()644 void test()
645 {
646 A1 a1;
647 A2 a2;
648 A3 a3;
649 A4 a4;
650 A5 a5;
651
652 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
653 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
654 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
655 assert(dynamic_cast<A1*>(a3.getA2()) == 0);
656 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
657 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
658 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
659 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
660 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
661 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
662 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
663 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
664 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
665
666 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
667 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
668 assert(dynamic_cast<A2*>(a3.getA1()) == 0);
669 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
670 // assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2()); // cast to protected base
671 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
672 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
673 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
674 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
675 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
676 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
677 // assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2()); // cast to protected base
678 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
679 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
680
681 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
682 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
683 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
684 assert(dynamic_cast<A3*>(a3.getA2()) == 0);
685 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
686 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
687 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
688 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
689 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
690 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
691 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
692 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
693 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
694 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
695
696 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
697 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
698 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
699 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
700 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
701 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
702 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
703 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
704 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
705 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
706 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
707 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
708 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
709 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
710
711 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
712 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
713 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
714 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
715 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
716 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
717 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
718 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
719 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
720 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
721 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
722 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
723 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
724 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
725 }
726
727 } // t5
728
729 namespace t6
730 {
731
732 struct A1
733 {
734 char _[43981];
~A1t6::A1735 virtual ~A1() {}
736
getA1t6::A1737 A1* getA1() {return this;}
738 };
739
740 struct A2
741 {
742 char _[34981];
~A2t6::A2743 virtual ~A2() {}
744
getA2t6::A2745 A2* getA2() {return this;}
746 };
747
748 struct A3
749 : public A1,
750 public virtual A2
751 {
752 char _[93481];
~A3t6::A3753 virtual ~A3() {}
754
getA1t6::A3755 A1* getA1() {return A1::getA1();}
getA2t6::A3756 A2* getA2() {return A2::getA2();}
getA3t6::A3757 A3* getA3() {return this;}
758 };
759
760 struct A4
761 : protected A1,
762 public virtual A2
763 {
764 char _[13489];
~A4t6::A4765 virtual ~A4() {}
766
getA1t6::A4767 A1* getA1() {return A1::getA1();}
getA2t6::A4768 A2* getA2() {return A2::getA2();}
getA4t6::A4769 A4* getA4() {return this;}
770 };
771
772 struct A5
773 : public A3,
774 public A4
775 {
776 char _[41389];
~A5t6::A5777 virtual ~A5() {}
778
getA14t6::A5779 A1* getA14() {return A4::getA1();}
getA13t6::A5780 A1* getA13() {return A3::getA1();}
getA2t6::A5781 A2* getA2() {return A4::getA2();}
getA3t6::A5782 A3* getA3() {return A3::getA3();}
getA4t6::A5783 A4* getA4() {return A4::getA4();}
getA5t6::A5784 A5* getA5() {return this;}
785 };
786
test()787 void test()
788 {
789 A1 a1;
790 A2 a2;
791 A3 a3;
792 A4 a4;
793 A5 a5;
794
795 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
796 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
797 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
798 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
799 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
800 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
801 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
802 // assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1()); // cast to protected base
803 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
804 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
805 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
806 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
807 // assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14()); // cast to protected base
808
809 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
810 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
811 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
812 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
813 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
814 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
815 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
816 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
817 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
818 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
819 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
820 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
821 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
822 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
823
824 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
825 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
826 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
827 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
828 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
829 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
830 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
831 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
832 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
833 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
834 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
835 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
836 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
837 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
838
839 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
840 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
841 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
842 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
843 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
844 assert(dynamic_cast<A4*>(a4.getA1()) == 0);
845 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
846 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
847 assert(dynamic_cast<A4*>(a5.getA14()) == 0);
848 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
849 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
850 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
851 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
852 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
853
854 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
855 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
856 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
857 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
858 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
859 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
860 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
861 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
862 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
863 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
864 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
865 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
866 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
867 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
868 }
869
870 } // t6
871
872 namespace t7
873 {
874
875 struct A1
876 {
877 char _[43981];
~A1t7::A1878 virtual ~A1() {}
879
getA1t7::A1880 A1* getA1() {return this;}
881 };
882
883 struct A2
884 {
885 char _[34981];
~A2t7::A2886 virtual ~A2() {}
887
getA2t7::A2888 A2* getA2() {return this;}
889 };
890
891 struct A3
892 : public A1,
893 public virtual A2
894 {
895 char _[93481];
~A3t7::A3896 virtual ~A3() {}
897
getA1t7::A3898 A1* getA1() {return A1::getA1();}
getA2t7::A3899 A2* getA2() {return A2::getA2();}
getA3t7::A3900 A3* getA3() {return this;}
901 };
902
903 struct A4
904 : public A1,
905 protected virtual A2
906 {
907 char _[13489];
~A4t7::A4908 virtual ~A4() {}
909
getA1t7::A4910 A1* getA1() {return A1::getA1();}
getA2t7::A4911 A2* getA2() {return A2::getA2();}
getA4t7::A4912 A4* getA4() {return this;}
913 };
914
915 struct A5
916 : public A3,
917 public A4
918 {
919 char _[41389];
~A5t7::A5920 virtual ~A5() {}
921
getA14t7::A5922 A1* getA14() {return A4::getA1();}
getA13t7::A5923 A1* getA13() {return A3::getA1();}
getA2t7::A5924 A2* getA2() {return A4::getA2();}
getA3t7::A5925 A3* getA3() {return A3::getA3();}
getA4t7::A5926 A4* getA4() {return A4::getA4();}
getA5t7::A5927 A5* getA5() {return this;}
928 };
929
test()930 void test()
931 {
932 A1 a1;
933 A2 a2;
934 A3 a3;
935 A4 a4;
936 A5 a5;
937
938 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
939 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
940 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
941 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
942 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
943 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
944 assert(dynamic_cast<A1*>(a4.getA2()) == 0);
945 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
946 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
947 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
948 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
949 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
950 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
951
952 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
953 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
954 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
955 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
956 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
957 assert(dynamic_cast<A2*>(a4.getA1()) == 0);
958 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
959 // assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2()); // cast to protected base
960 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
961 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
962 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
963 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
964 // assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2()); // cast to protected base
965 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
966
967 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
968 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
969 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
970 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
971 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
972 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
973 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
974 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
975 assert(dynamic_cast<A3*>(a5.getA14()) == a5.getA3());
976 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
977 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
978 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
979 assert(dynamic_cast<A3*>(a5.getA4()) == a5.getA3());
980 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
981
982 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
983 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
984 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
985 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
986 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
987 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
988 assert(dynamic_cast<A4*>(a4.getA2()) == 0);
989 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
990 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
991 assert(dynamic_cast<A4*>(a5.getA13()) == a5.getA4());
992 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
993 assert(dynamic_cast<A4*>(a5.getA3()) == a5.getA4());
994 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
995 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
996
997 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
998 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
999 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1000 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1001 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1002 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1003 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1004 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1005 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1006 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1007 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1008 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1009 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1010 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1011 }
1012
1013 } // t7
1014
1015 namespace t8
1016 {
1017
1018 struct A1
1019 {
1020 char _[43981];
~A1t8::A11021 virtual ~A1() {}
1022
getA1t8::A11023 A1* getA1() {return this;}
1024 };
1025
1026 struct A2
1027 {
1028 char _[34981];
~A2t8::A21029 virtual ~A2() {}
1030
getA2t8::A21031 A2* getA2() {return this;}
1032 };
1033
1034 struct A3
1035 : public A1,
1036 public virtual A2
1037 {
1038 char _[93481];
~A3t8::A31039 virtual ~A3() {}
1040
getA1t8::A31041 A1* getA1() {return A1::getA1();}
getA2t8::A31042 A2* getA2() {return A2::getA2();}
getA3t8::A31043 A3* getA3() {return this;}
1044 };
1045
1046 struct A4
1047 : public A1,
1048 public virtual A2
1049 {
1050 char _[13489];
~A4t8::A41051 virtual ~A4() {}
1052
getA1t8::A41053 A1* getA1() {return A1::getA1();}
getA2t8::A41054 A2* getA2() {return A2::getA2();}
getA4t8::A41055 A4* getA4() {return this;}
1056 };
1057
1058 struct A5
1059 : protected A3,
1060 public A4
1061 {
1062 char _[41389];
~A5t8::A51063 virtual ~A5() {}
1064
getA14t8::A51065 A1* getA14() {return A4::getA1();}
getA13t8::A51066 A1* getA13() {return A3::getA1();}
getA2t8::A51067 A2* getA2() {return A4::getA2();}
getA3t8::A51068 A3* getA3() {return A3::getA3();}
getA4t8::A51069 A4* getA4() {return A4::getA4();}
getA5t8::A51070 A5* getA5() {return this;}
1071 };
1072
test()1073 void test()
1074 {
1075 A1 a1;
1076 A2 a2;
1077 A3 a3;
1078 A4 a4;
1079 A5 a5;
1080
1081 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1082 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1083 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1084 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1085 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1086 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1087 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1088 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1089 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1090 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1091 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1092 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1093 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1094
1095 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1096 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1097 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1098 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1099 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1100 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1101 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1102 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1103 assert(dynamic_cast<A2*>(a5.getA14()) == a5.getA2());
1104 assert(dynamic_cast<A2*>(a5.getA13()) == 0);
1105 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1106 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1107 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1108 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1109
1110 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1111 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1112 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1113 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1114 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1115 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1116 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1117 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1118 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1119 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1120 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1121 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1122 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1123 // assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3()); // cast to protected base
1124
1125 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1126 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1127 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1128 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1129 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1130 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1131 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1132 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1133 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1134 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1135 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1136 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1137 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1138 assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4());
1139
1140 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1141 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1142 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1143 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1144 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1145 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1146 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1147 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1148 assert(dynamic_cast<A5*>(a5.getA14()) == a5.getA5());
1149 assert(dynamic_cast<A5*>(a5.getA13()) == 0);
1150 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1151 assert(dynamic_cast<A5*>(a5.getA3()) == 0);
1152 assert(dynamic_cast<A5*>(a5.getA4()) == a5.getA5());
1153 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1154 }
1155
1156 } // t8
1157
1158 namespace t9
1159 {
1160
1161 struct A1
1162 {
1163 char _[43981];
~A1t9::A11164 virtual ~A1() {}
1165
getA1t9::A11166 A1* getA1() {return this;}
1167 };
1168
1169 struct A2
1170 {
1171 char _[34981];
~A2t9::A21172 virtual ~A2() {}
1173
getA2t9::A21174 A2* getA2() {return this;}
1175 };
1176
1177 struct A3
1178 : public A1,
1179 public virtual A2
1180 {
1181 char _[93481];
~A3t9::A31182 virtual ~A3() {}
1183
getA1t9::A31184 A1* getA1() {return A1::getA1();}
getA2t9::A31185 A2* getA2() {return A2::getA2();}
getA3t9::A31186 A3* getA3() {return this;}
1187 };
1188
1189 struct A4
1190 : public A1,
1191 public virtual A2
1192 {
1193 char _[13489];
~A4t9::A41194 virtual ~A4() {}
1195
getA1t9::A41196 A1* getA1() {return A1::getA1();}
getA2t9::A41197 A2* getA2() {return A2::getA2();}
getA4t9::A41198 A4* getA4() {return this;}
1199 };
1200
1201 struct A5
1202 : public A3,
1203 protected A4
1204 {
1205 char _[41389];
~A5t9::A51206 virtual ~A5() {}
1207
getA14t9::A51208 A1* getA14() {return A4::getA1();}
getA13t9::A51209 A1* getA13() {return A3::getA1();}
getA2t9::A51210 A2* getA2() {return A4::getA2();}
getA3t9::A51211 A3* getA3() {return A3::getA3();}
getA4t9::A51212 A4* getA4() {return A4::getA4();}
getA5t9::A51213 A5* getA5() {return this;}
1214 };
1215
test()1216 void test()
1217 {
1218 A1 a1;
1219 A2 a2;
1220 A3 a3;
1221 A4 a4;
1222 A5 a5;
1223
1224 assert(dynamic_cast<A1*>(a1.getA1()) == a1.getA1());
1225 assert(dynamic_cast<A1*>(a2.getA2()) == 0);
1226 assert(dynamic_cast<A1*>(a3.getA1()) == a3.getA1());
1227 assert(dynamic_cast<A1*>(a3.getA2()) == a3.getA1());
1228 assert(dynamic_cast<A1*>(a3.getA3()) == a3.getA1());
1229 assert(dynamic_cast<A1*>(a4.getA1()) == a4.getA1());
1230 assert(dynamic_cast<A1*>(a4.getA2()) == a4.getA1());
1231 assert(dynamic_cast<A1*>(a4.getA4()) == a4.getA1());
1232 assert(dynamic_cast<A1*>(a5.getA14()) == a5.getA14());
1233 assert(dynamic_cast<A1*>(a5.getA13()) == a5.getA13());
1234 assert(dynamic_cast<A1*>(a5.getA2()) == 0);
1235 assert(dynamic_cast<A1*>(a5.getA3()) == a5.getA13());
1236 assert(dynamic_cast<A1*>(a5.getA4()) == a5.getA14());
1237
1238 assert(dynamic_cast<A2*>(a1.getA1()) == 0);
1239 assert(dynamic_cast<A2*>(a2.getA2()) == a2.getA2());
1240 assert(dynamic_cast<A2*>(a3.getA1()) == a3.getA2());
1241 assert(dynamic_cast<A2*>(a3.getA2()) == a3.getA2());
1242 assert(dynamic_cast<A2*>(a3.getA3()) == a3.getA2());
1243 assert(dynamic_cast<A2*>(a4.getA1()) == a4.getA2());
1244 assert(dynamic_cast<A2*>(a4.getA2()) == a4.getA2());
1245 assert(dynamic_cast<A2*>(a4.getA4()) == a4.getA2());
1246 assert(dynamic_cast<A2*>(a5.getA14()) == 0);
1247 assert(dynamic_cast<A2*>(a5.getA13()) == a5.getA2());
1248 assert(dynamic_cast<A2*>(a5.getA2()) == a5.getA2());
1249 assert(dynamic_cast<A2*>(a5.getA3()) == a5.getA2());
1250 assert(dynamic_cast<A2*>(a5.getA4()) == a5.getA2());
1251 assert(dynamic_cast<A2*>(a5.getA5()) == a5.getA2());
1252
1253 assert(dynamic_cast<A3*>(a1.getA1()) == 0);
1254 assert(dynamic_cast<A3*>(a2.getA2()) == 0);
1255 assert(dynamic_cast<A3*>(a3.getA1()) == a3.getA3());
1256 assert(dynamic_cast<A3*>(a3.getA2()) == a3.getA3());
1257 assert(dynamic_cast<A3*>(a3.getA3()) == a3.getA3());
1258 assert(dynamic_cast<A3*>(a4.getA1()) == 0);
1259 assert(dynamic_cast<A3*>(a4.getA2()) == 0);
1260 assert(dynamic_cast<A3*>(a4.getA4()) == 0);
1261 assert(dynamic_cast<A3*>(a5.getA14()) == 0);
1262 assert(dynamic_cast<A3*>(a5.getA13()) == a5.getA3());
1263 assert(dynamic_cast<A3*>(a5.getA2()) == a5.getA3());
1264 assert(dynamic_cast<A3*>(a5.getA3()) == a5.getA3());
1265 assert(dynamic_cast<A3*>(a5.getA4()) == 0);
1266 assert(dynamic_cast<A3*>(a5.getA5()) == a5.getA3());
1267
1268 assert(dynamic_cast<A4*>(a1.getA1()) == 0);
1269 assert(dynamic_cast<A4*>(a2.getA2()) == 0);
1270 assert(dynamic_cast<A4*>(a3.getA1()) == 0);
1271 assert(dynamic_cast<A4*>(a3.getA2()) == 0);
1272 assert(dynamic_cast<A4*>(a3.getA3()) == 0);
1273 assert(dynamic_cast<A4*>(a4.getA1()) == a4.getA4());
1274 assert(dynamic_cast<A4*>(a4.getA2()) == a4.getA4());
1275 assert(dynamic_cast<A4*>(a4.getA4()) == a4.getA4());
1276 assert(dynamic_cast<A4*>(a5.getA14()) == a5.getA4());
1277 assert(dynamic_cast<A4*>(a5.getA13()) == 0);
1278 assert(dynamic_cast<A4*>(a5.getA2()) == a5.getA4());
1279 assert(dynamic_cast<A4*>(a5.getA3()) == 0);
1280 assert(dynamic_cast<A4*>(a5.getA4()) == a5.getA4());
1281 // assert(dynamic_cast<A4*>(a5.getA5()) == a5.getA4()); // cast to protected base
1282
1283 assert(dynamic_cast<A5*>(a1.getA1()) == 0);
1284 assert(dynamic_cast<A5*>(a2.getA2()) == 0);
1285 assert(dynamic_cast<A5*>(a3.getA1()) == 0);
1286 assert(dynamic_cast<A5*>(a3.getA2()) == 0);
1287 assert(dynamic_cast<A5*>(a3.getA3()) == 0);
1288 assert(dynamic_cast<A5*>(a4.getA1()) == 0);
1289 assert(dynamic_cast<A5*>(a4.getA2()) == 0);
1290 assert(dynamic_cast<A5*>(a4.getA4()) == 0);
1291 assert(dynamic_cast<A5*>(a5.getA14()) == 0);
1292 assert(dynamic_cast<A5*>(a5.getA13()) == a5.getA5());
1293 assert(dynamic_cast<A5*>(a5.getA2()) == a5.getA5());
1294 assert(dynamic_cast<A5*>(a5.getA3()) == a5.getA5());
1295 assert(dynamic_cast<A5*>(a5.getA4()) == 0);
1296 assert(dynamic_cast<A5*>(a5.getA5()) == a5.getA5());
1297 }
1298
1299 } // t9
1300
1301 #include <time.h>
1302 #include <stdio.h>
1303
now_us()1304 double now_us() {
1305 struct timespec ts;
1306 clock_gettime(CLOCK_MONOTONIC, &ts);
1307 return ts.tv_sec * 1e3 + ts.tv_nsec * 1e-6;
1308 }
1309
main()1310 int main()
1311 {
1312 double t0 = now_us();
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();
1322 double t1 = now_us();
1323 printf("%.1g microseconds\n", t1 - t0);
1324 return 0;
1325 }
1326