2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / rttid4.C
blob91c42629099ed2e18a8bc41dc81a0d8485a6a4f4
1 // { dg-do run  }
2 // { dg-options "-w" }
3 // test of rtti of single inheritance and multiple inheritance with 
4 // virtual inheritance
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() {};
20 class Y : public virtual X {
21   short ys;
24 class Z : public virtual 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() {};
40 class B {
41 public:
42   int Bi;
43   virtual int g() {};
46 class D : public virtual A, private B {
47   int Di;
50 class E : public virtual D, public B {
51   int Ei;
54 class F : public E, public virtual D {
55   int Fi;
58 D d;
59 A *ap = &d;
60 B *bp = (B *)&d;
61 F f;
62 F *fp = &f;
63 A *aap = &f;
64 D *dp = &f;
65 E *ep = &f;
66 B *bbp = (B *)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 ()
85   vp = (void *)0;
87   vp = dynamic_cast<Y *> (&z);
88   if (vp == 0) error(11);
90   vp = dynamic_cast<Z *> (yp);
91   if (vp == 0) error(11);
93   vp = dynamic_cast<X *> (yp);
94   if (vp == 0) error(12);
96   vp = dynamic_cast<D *> (dp);
97   if (vp != (void *)dp) error(21);
99   // Ill-formed: dynamic_cast to private or ambiguous base
100   //   vp = dynamic_cast<B *> (dp);
101   //   if (vp == (void *)dp) error(21);
103   //   vp = dynamic_cast<B *> (fp);
104   //   if (vp == (void *)bbp) error(22);
106   vp = dynamic_cast<void *> (aap);
107   if (vp != (void *)fp) error(23);
109   vp = dynamic_cast<B *> (aap);
110   if (vp == (void *)bbp) error(24);