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