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