2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / rttid3.C
blob0e3b97443dce1a3e7e9536879d5b07010219d273
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
7 #include <typeinfo>
9 extern "C" {
10   int printf(const char *, ...);
11   void exit(int);
14 class X {
15  public:
16   int xi;
17   virtual int f() {return 0;};
20 class Y : public X {
21   short ys;
24 class Z : public Y {
25   int zi;
28 Z z;
29 Y y;
30 Y *yp = &z;
31 X *xp = &z;
32 Z *zp = &z;
34 class A {
35  public:
36   int Ai;
37   virtual int a() {return 0;};
40 class B {
41  public:
42   int Bi;
43   virtual int g() {return 0;};
46 class D : public A, public B {
47   int Di;
51 class E : public D, public B {
52   int Ei;
55 class E {
56   int Ei;
59 class F : public E, public D {
60   int Fi;
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;
72 void *vp = zp;
75 void error (int i)
77   printf("FAIL\n");
78   exit(i);
82 void error  (int i)
84   exit(i);
87 int main ()
89   vp = (void *)0;
91   vp = dynamic_cast<Y *> (&z);
92   if (vp == 0) error(11);
94   vp = dynamic_cast<Z *> (yp);
95   if (vp == 0) error(11);
97   vp = dynamic_cast<X *> (yp);
98   if (vp == 0) error(12);
100   vp = dynamic_cast<D *> (dp);
101   if (vp != (void *)dp) error(21);
103   vp = dynamic_cast<B *> (dp);
104   if (vp == (void *)dp) error(21);
106   vp = dynamic_cast<B *> (fp);
107   if (vp != (void *)bbp) error(22);
109   vp = dynamic_cast<void *> (aap);
110   if (vp != (void *)fp) error(23);
112   vp = dynamic_cast<B *> (aap);
113   if (vp != (void *)bbp) error(24);