2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / rtti2.C
blob4cc1319c93cd53d8e9c9ae3eecf1505ed48bab49
1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance classes
5 #include <typeinfo>
7 extern "C" {
8   int printf(const char *, ...);
9   void exit(int);
12 class X {
13  public:
14   int xi;
17 class Y : public X {
18   short ys;
21 class Z : public Y {
22   int zi;
25 Z z;
26 Y y;
27 Y *yp = &z;
28 X *xp = &z;
29 Z *zp = &z;
31 class A {
32  public:
33   int Ai;
36 class B {
37  public:
38   int Bi;
41 class D : public A, public B {
42   int Di;
46 class E : public D, public B {
47   int Ei;
50 class E {
51   int Ei;
54 class F : public E, public D {
55   int Fi;
58 D d;
59 A *ap = &d;
60 B *bp = &d;
61 F f;
62 A *aap = &f;
63 D *dp = &f;
64 B *bbp = dp;
66 void *vp = zp;
68 void error  (int i)
70   exit(i);
73 int main ()
75   if (typeid(z) != typeid(Z)) error(1);
76   if (typeid(*yp) == typeid(Z)) error(2);
77   if (typeid(*yp) == typeid(*zp)) error(3);
78   if (typeid(xp) == typeid(yp)) error(4);
80   xp = (X *)&y;
81   if (typeid(*xp) == typeid(*yp)) error(5);
82   if (typeid(*xp) == typeid(Y)) error(6);
83   
84   if (typeid(*ap) == typeid(*bp)) error (31);
85   if (typeid(*ap) == typeid(D)) error(32);
87   if (typeid(*aap) == typeid(*bbp)) error(33);
88   if (typeid(*dp) == typeid(*aap)) error(34);