1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance with
4 // virtual functions
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;
f()16   virtual int f() {return 0;};
17 };
18 
19 class Y : public X {
20   short ys;
21 };
22 
23 class Z : public Y {
24   int zi;
25 };
26 
27 Z z;
28 Y y;
29 Y *yp = &z;
30 X *xp = &z;
31 Z *zp = &z;
32 
33 class A {
34  public:
35   int Ai;
a()36   virtual int a() {return 0;};
37 };
38 
39 class B {
40  public:
41   int Bi;
g()42   virtual int g() {return 0;};
43 };
44 
45 class D : public A, public B {
46   int Di;
47 };
48 
49 /*
50 class E : public D, public B {
51   int Ei;
52 };
53 */
54 class E {
55   int Ei;
56 };
57 
58 class F : public E, public D {
59   int Fi;
60 };
61 
62 D d;
63 A *ap = &d;
64 B *bp = &d;
65 D *dp = &d;
66 F f;
67 A *aap = &f;
68 B *bbp = &f;
69 
70 void *vp = zp;
71 
error(int i)72 void error  (int i)
73 {
74   exit(i);
75 }
76 
main()77 int main ()
78 {
79   if (typeid(z) != typeid(Z)) error(1);
80   if (typeid(*yp) != typeid(Z)) error(2);
81   if (typeid(*yp) != typeid(*zp)) error(3);
82   if (typeid(xp) == typeid(yp)) error(4);
83 
84   xp = (X *)&y;
85   if (typeid(*xp) == typeid(*yp)) error(5);
86   if (typeid(*xp) != typeid(Y)) error(6);
87 
88   if (typeid(*ap) != typeid(*bp)) error (31);
89   if (typeid(*ap) != typeid(D)) error(32);
90   vp = dp;
91   vp = dynamic_cast<void*> ((B *)vp);
92   if (dp != (D *)vp) error(35);
93 
94   dp = (D *)&f;
95   if (typeid(*aap) != typeid(*bbp)) error(37);
96   if (typeid(*dp) != typeid(*aap)) error(38);
97 }
98