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