2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / rtti3.C
blob760cc75927418dc160739004ead01cb2ae16e4da
1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance with 
4 // virtual functions
6 #include <typeinfo>
8 extern "C" {
9   int printf(const char *, ...);
10   void exit(int);
13 class X {
14  public:
15   int xi;
16   virtual int f() {return 0;};
19 class Y : public X {
20   short ys;
23 class Z : public Y {
24   int zi;
27 Z z;
28 Y y;
29 Y *yp = &z;
30 X *xp = &z;
31 Z *zp = &z;
33 class A {
34  public:
35   int Ai;
36   virtual int a() {return 0;};
39 class B {
40  public:
41   int Bi;
42   virtual int g() {return 0;};
45 class D : public A, public B {
46   int Di;
50 class E : public D, public B {
51   int Ei;
54 class E {
55   int Ei;
58 class F : public E, public D {
59   int Fi;
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;
70 void *vp = zp;
72 void error  (int i)
74   exit(i);
77 int main ()
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);
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);
94   dp = (D *)&f;
95   if (typeid(*aap) != typeid(*bbp)) error(37);
96   if (typeid(*dp) != typeid(*aap)) error(38);