2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / rttid2.C
blob06746506fce57edc8778653357c954a99182f407
1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance classes
4 // dynamic casting
6 #include <typeinfo>
8 extern "C" {
9   int printf(const char *, ...);
10   void exit(int);
13 class X {
14  public:
15   int xi;
18 class Y : public X {
19   short ys;
22 class Z : public Y {
23   int zi;
26 Z z;
27 Y y;
28 Y *yp = &z;
29 X *xp = &z;
30 Z *zp = &z;
32 class A {
33  public:
34   int Ai;
37 class B {
38  public:
39   int Bi;
42 class D : public A, public B {
43   int Di;
47 class E : public D, public B {
48   int Ei;
51 class E {
52   int Ei;
55 class F : public E, public D {
56   int Fi;
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;
68 void *vp = zp;
71 void error (int i)
73   printf("FAIL\n");
74   exit(i);
78 void error  (int i)
80   exit(i);
83 int main ()
86   vp = (void *)0;
88   vp = dynamic_cast<Y *> (&z);
89   if (vp == 0) error(11);
91   vp = dynamic_cast<X *> (yp);
92   if (vp == 0) error(12);
94   vp = dynamic_cast<D *> (dp);
95   if (vp != (void *)dp) error(21);
97   vp = dynamic_cast<B *> (fp);
98   if (vp != (void *)bbp) error(22);