OSDN Git Service

* typeck2.c (abstract_virtual_errors): Reword diagnostics, make them
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / rtti2.C
1 // { dg-do run  }
2 // { dg-options "-frtti" }
3 // test of rtti of single inheritance and multiple inheritance classes
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 };
16
17 class Y : public X {
18   short ys;
19 };
20
21 class Z : public Y {
22   int zi;
23 };
24
25 Z z;
26 Y y;
27 Y *yp = &z;
28 X *xp = &z;
29 Z *zp = &z;
30
31 class A {
32  public:
33   int Ai;
34 };
35
36 class B {
37  public:
38   int Bi;
39 };
40
41 class D : public A, public B {
42   int Di;
43 };
44
45 /*
46 class E : public D, public B {
47   int Ei;
48 };
49 */
50 class E {
51   int Ei;
52 };
53
54 class F : public E, public D {
55   int Fi;
56 };
57
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;
65
66 void *vp = zp;
67
68 void error  (int i)
69 {
70   exit(i);
71 }
72
73 int main ()
74 {
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);
79
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);
86
87   if (typeid(*aap) == typeid(*bbp)) error(33);
88   if (typeid(*dp) == typeid(*aap)) error(34);
89 }