1 // { dg-do run }
2 // Copyright (C) 2000 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 19 Jan 2001 <nathan@codesourcery.com>
4
5 // Bug 1701. building a vbase path was not using the shortest number of
6 // vbases. Normally that's just a pessimization, unfortunately during
7 // constructoring it leads to uninitialized reads.
8
9 extern "C" int printf (...);
10
11 int fail = 0;
12
13 /*{{{ struct Base*/
14 struct Base
15 {
16 unsigned m;
17 static Base *addr;
18
19 Base ();
20 virtual ~Base ();
21 };
22 /*}}}*/
23 Base *Base::addr;
24 /*{{{ Base::Base ()*/
Base()25 Base::Base ()
26 {
27 printf ("Base (%u) ctor %x\n", sizeof (Base), this);
28 if (fail) ;
29 else if (addr)
30 fail = 1;
31 else
32 addr = this;
33 }
34 /*}}}*/
35 /*{{{ Base::~Base ()*/
~Base()36 Base::~Base ()
37 {
38 printf ("Base dtor %x\n", this);
39 if (fail)
40 ;
41 else if (this != addr)
42 fail = 2;
43 else
44 addr = 0;
45 }
46 /*}}}*/
47
48 /*{{{ struct M10 : virtual Base*/
49 struct M10 : virtual Base
50 {
51 int m;
52 static M10 *addr;
53
54 M10 ();
55 virtual ~M10 ();
56 };
57 /*}}}*/
58 M10 *M10::addr;
59 /*{{{ M10::M10 ()*/
M10()60 M10::M10 ()
61 {
62 printf ("M10 (%u) ctor %x\n", sizeof (M10), this);
63 if (fail) ;
64 else if (addr)
65 fail = 3;
66 else
67 addr = this;
68 }
69 /*}}}*/
70 /*{{{ M10::~M10 ()*/
~M10()71 M10::~M10 ()
72 {
73 printf ("M10 dtor %x\n", this);
74 if (fail)
75 ;
76 else if (this != addr)
77 fail = 4;
78 else
79 addr = 0;
80 }
81 /*}}}*/
82
83 /*{{{ struct M4 : virtual Base, virtual M10*/
84 struct M4 : virtual Base, virtual M10
85 {
86 int m;
87 static M4 *addr;
88
89 M4 ();
90 virtual ~M4 ();
91 };
92 /*}}}*/
93 M4 *M4::addr;
94 /*{{{ M4::M4 ()*/
M4()95 M4::M4 ()
96 {
97 printf ("M4 (%u) ctor %x\n", sizeof (M4), this);
98 if (fail) ;
99 else if (addr)
100 fail = 5;
101 else
102 addr = this;
103 }
104 /*}}}*/
105 /*{{{ M4::~M4 ()*/
~M4()106 M4::~M4 ()
107 {
108 printf ("M4 dtor %x\n", this);
109 if (fail)
110 ;
111 else if (this != addr)
112 fail = 6;
113 else
114 addr = 0;
115 }
116 /*}}}*/
117
118 /*{{{ struct M5 : M4*/
119 struct M5 : M4
120 {
121 int m;
122 static M5 *addr;
123
124 M5 ();
125 virtual ~M5 ();
126 };
127 /*}}}*/
128 M5 *M5::addr;
129 /*{{{ M5::M5 ()*/
M5()130 M5::M5 ()
131 {
132 printf ("M5 (%u) ctor %x\n", sizeof (M5), this);
133 if (fail) ;
134 else if (addr)
135 fail = 7;
136 else
137 addr = this;
138 }
139 /*}}}*/
140 /*{{{ M5::~M5 ()*/
~M5()141 M5::~M5 ()
142 {
143 printf ("M5 dtor %x\n", this);
144 if (fail)
145 ;
146 else if (this != addr)
147 fail = 8;
148 else
149 addr = 0;
150 }
151 /*}}}*/
152
153 /*{{{ struct M9 : M5, virtual M10*/
154 struct M9 : M5, virtual M10
155 {
156 int m;
157 static M9 *addr;
158
159 M9 ();
160 virtual ~M9 ();
161 };
162 /*}}}*/
163 M9 *M9::addr;
164 /*{{{ M9::M9 ()*/
M9()165 M9::M9 ()
166 {
167 printf ("M9 (%u), ctor %x\n", sizeof (M9), this);
168 if (fail) ;
169 else if (addr)
170 fail = 9;
171 else
172 addr = this;
173 }
174 /*}}}*/
175 /*{{{ M9::~M9 ()*/
~M9()176 M9::~M9 ()
177 {
178 printf ("M9 dtor %x\n", this);
179 if (fail)
180 ;
181 else if (this != addr)
182 fail = 10;
183 else
184 addr = 0;
185 }
186 /*}}}*/
187
main()188 int main ()
189 {
190 M9 *m9;
191 Base *r;
192
193 m9 = new M9 ();
194 r = m9;
195 if (fail)
196 return fail;
197 void *top = dynamic_cast <void *> (r);
198 if (top != m9)
199 return 20;
200 r->~Base ();
201
202 return fail;
203 }
204