1 // { dg-do run  }
2 // Copyright (C) 2001 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 9 Jun 2001 <nathan@codesourcery.com>
4 
5 // Bug 3089. We ICE'd in construction vtables.
6 
7 int failed;
8 
fail(int val)9 void fail (int val)
10 {
11   if (!failed)
12     failed = val;
13 }
14 
15 struct A
16 {
17   virtual ~A();
18   A ();
19   virtual void check (void *whole, void *base);
20 };
21 
A()22 A::A ()
23 {
24   check (this, this);
25 }
~A()26 A::~A ()
27 {
28   check (this, this);
29 }
30 
check(void * whole,void * base)31 void A::check (void *whole, void *base)
32 {
33   if (dynamic_cast <void *> (this) != whole)
34     fail (1);
35   else if (this != base)
36     fail (2);
37 }
38 
39 struct B
40 {
41   virtual ~B ();
42   B ();
43   virtual void check (void *whole, void *base);
44 };
45 
B()46 B::B ()
47 {
48   check (this, this);
49 }
~B()50 B::~B ()
51 {
52   check (this, this);
53 }
check(void * whole,void * base)54 void B::check (void *whole, void *base)
55 {
56   if (dynamic_cast <void *> (this) != whole)
57     fail (3);
58   else if (this != base)
59     fail (4);
60 }
61 
62 struct C : virtual public B, virtual public A
63 {
64   virtual ~C ();
65   C ();
66   virtual void check (void *whole, void *base);
67 };
C()68 C::C ()
69 {
70   check (this, this);
71 }
~C()72 C::~C ()
73 {
74   check (this, this);
75 }
check(void * whole,void * base)76 void C::check (void *whole, void *base)
77 {
78   if (dynamic_cast <void *> (this) != whole)
79     fail (5);
80   else if (this != base)
81     fail (6);
82   A::check (whole, static_cast <A *> (this));
83   B::check (whole, static_cast <B *> (this));
84 }
85 
86 struct D : virtual public A
87 {
88   virtual ~D ();
89   D ();
90   virtual void check (void *whole, void *base);
91 };
D()92 D::D ()
93 {
94   check (this, this);
95 }
~D()96 D::~D ()
97 {
98   check (this, this);
99 }
check(void * whole,void * base)100 void D::check (void *whole, void *base)
101 {
102   if (dynamic_cast <void *> (this) != whole)
103     fail (5);
104   else if (this != base)
105     fail (6);
106   A::check (whole, static_cast <A *> (this));
107 }
108 
109 struct E : virtual public C, virtual public D
110 {
111   virtual ~E ();
112   E ();
113   virtual void check (void *whole, void *base);
114 };
E()115 E::E ()
116 {
117   check (this, this);
118 }
~E()119 E::~E ()
120 {
121   check (this, this);
122 }
check(void * whole,void * base)123 void E::check (void *whole, void *base)
124 {
125   if (dynamic_cast <void *> (this) != whole)
126     fail (5);
127   else if (this != base)
128     fail (6);
129   C::check (whole, static_cast <C *> (this));
130   D::check (whole, static_cast <D *> (this));
131 }
132 
133 struct F : virtual public E
134 {
135   virtual ~F ();
136   F ();
137   virtual void check (void *whole, void *base);
138 };
F()139 F::F ()
140 {
141   check (this, this);
142 }
~F()143 F::~F ()
144 {
145   check (this, this);
146 }
check(void * whole,void * base)147 void F::check (void *whole, void *base)
148 {
149   if (dynamic_cast <void *> (this) != whole)
150     fail (5);
151   else if (this != base)
152     fail (6);
153   E::check (whole, static_cast <F *> (this));
154 }
155 
main()156 int main ()
157 {
158   A a;
159   B b;
160   C c;
161   D d;
162   E e;
163   F f;
164 
165   return failed;
166 }
167