1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance classes
4 // dynamic casting
5 
6 #include <typeinfo>
7 
8 extern "C" {
9   int printf(const char *, ...);
10   void exit(int);
11 }
12 
13 class X {
14  public:
15   int xi;
16 };
17 
18 class Y : public X {
19   short ys;
20 };
21 
22 class Z : public Y {
23   int zi;
24 };
25 
26 Z z;
27 Y y;
28 Y *yp = &z;
29 X *xp = &z;
30 Z *zp = &z;
31 
32 class A {
33  public:
34   int Ai;
35 };
36 
37 class B {
38  public:
39   int Bi;
40 };
41 
42 class D : public A, public B {
43   int Di;
44 };
45 
46 /*
47 class E : public D, public B {
48   int Ei;
49 };
50 */
51 class E {
52   int Ei;
53 };
54 
55 class F : public E, public D {
56   int Fi;
57 };
58 
59 D d;
60 A *ap = &d;
61 B *bp = &d;
62 F f;
63 F *fp = &f;
64 A *aap = &f;
65 D *dp = &f;
66 B *bbp = dp;
67 
68 void *vp = zp;
69 
70 /*
71 void error (int i)
72 {
73   printf("FAIL\n");
74   exit(i);
75 }
76 */
77 
error(int i)78 void error  (int i)
79 {
80   exit(i);
81 }
82 
main()83 int main ()
84 {
85 
86   vp = (void *)0;
87 
88   vp = dynamic_cast<Y *> (&z);
89   if (vp == 0) error(11);
90 
91   vp = dynamic_cast<X *> (yp);
92   if (vp == 0) error(12);
93 
94   vp = dynamic_cast<D *> (dp);
95   if (vp != (void *)dp) error(21);
96 
97   vp = dynamic_cast<B *> (fp);
98   if (vp != (void *)bbp) error(22);
99 
100 }
101 
102