OSDN Git Service

fdb1f9e090d84d3b15061ddd2dd358baed876c1c
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / rtti3.C
1 // test of rtti of single inheritance and multiple inheritance with 
2 // virtual functions
3 // Special g++ Options: -frtti
4
5 #include <typeinfo>
6
7 extern "C" {
8   int printf(const char *, ...);
9   void exit(int);
10 }
11
12 class X {
13  public:
14   int xi;
15   virtual int f() {};
16 };
17
18 class Y : public X {
19   short ys;
20 };
21
22 class Z : public Y {
23   int zi;
24 };
25
26 Z z;
27 Y y;
28 Y *yp = &z;
29 X *xp = &z;
30 Z *zp = &z;
31
32 class A {
33  public:
34   int Ai;
35   virtual int a() {};
36 };
37
38 class B {
39  public:
40   int Bi;
41   virtual int g() {};
42 };
43
44 class D : public A, public B {
45   int Di;
46 };
47
48 /*
49 class E : public D, public B {
50   int Ei;
51 };
52 */
53 class E {
54   int Ei;
55 };
56
57 class F : public E, public D {
58   int Fi;
59 };
60
61 D d;
62 A *ap = &d;
63 B *bp = &d;
64 D *dp = &d;
65 F f;
66 A *aap = &f;
67 B *bbp = &f;
68
69 void *vp = zp;
70
71 void error  (int i)
72 {
73   exit(i);
74 }
75
76 int main ()
77 {
78   if (typeid(z) != typeid(Z)) error(1);
79   if (typeid(*yp) != typeid(Z)) error(2);
80   if (typeid(*yp) != typeid(*zp)) error(3);
81   if (typeid(xp) == typeid(yp)) error(4);
82
83   xp = (X *)&y;
84   if (typeid(*xp) == typeid(*yp)) error(5);
85   if (typeid(*xp) != typeid(Y)) error(6);
86   
87   if (typeid(*ap) != typeid(*bp)) error (31);
88   if (typeid(*ap) != typeid(D)) error(32);
89   vp = dp;
90   vp = dynamic_cast<void*> ((B *)vp);
91   if (dp != (D *)vp) error(35);
92
93   dp = (D *)&f;
94   if (typeid(*aap) != typeid(*bbp)) error(37);
95   if (typeid(*dp) != typeid(*aap)) error(38);
96 }