2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / vbase5.C
blob10c2f31315791bb6871c710406f9e88ed474b89b
1 // { dg-do run  }
2 // Copyright (C) 2000 Free Software Foundation, Inc.
3 // Contributed by Nathan Sidwell 19 Jan 2001 <nathan@codesourcery.com>
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.
9 extern "C" int printf (...);
11 int fail = 0;
13 /*{{{  struct Base*/
14 struct Base
16   unsigned m;
17   static Base *addr;
18   
19   Base ();
20   virtual ~Base ();
22 /*}}}*/
23 Base *Base::addr;
24 /*{{{  Base::Base ()*/
25 Base::Base ()
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;
34 /*}}}*/
35 /*{{{  Base::~Base ()*/
36 Base::~Base ()
38   printf ("Base dtor %x\n", this);
39   if (fail)
40     ;
41   else if (this != addr)
42     fail = 2;
43   else
44     addr = 0;
46 /*}}}*/
48 /*{{{  struct M10 : virtual Base*/
49 struct M10 : virtual Base
51   int m;
52   static M10 *addr;
53   
54   M10 ();
55   virtual ~M10 ();
57 /*}}}*/
58 M10 *M10::addr;
59 /*{{{  M10::M10 ()*/
60 M10::M10 ()
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;
69 /*}}}*/
70 /*{{{  M10::~M10 ()*/
71 M10::~M10 ()
73   printf ("M10 dtor %x\n", this);
74   if (fail)
75     ;
76   else if (this != addr)
77     fail = 4;
78   else
79     addr = 0;
81 /*}}}*/
83 /*{{{  struct M4 : virtual Base, virtual M10*/
84 struct M4 : virtual Base, virtual M10
86   int m;
87   static M4 *addr;
88   
89   M4 ();
90   virtual ~M4 ();
92 /*}}}*/
93 M4 *M4::addr;
94 /*{{{  M4::M4 ()*/
95 M4::M4 ()
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;
104 /*}}}*/
105 /*{{{  M4::~M4 ()*/
106 M4::~M4 ()
108   printf ("M4 dtor %x\n", this);
109   if (fail)
110     ;
111   else if (this != addr)
112     fail = 6;
113   else
114     addr = 0;
116 /*}}}*/
118 /*{{{  struct M5 : M4*/
119 struct M5 : M4
121   int m;
122   static M5 *addr;
123   
124   M5 ();
125   virtual ~M5 ();
127 /*}}}*/
128 M5 *M5::addr;
129 /*{{{  M5::M5 ()*/
130 M5::M5 ()
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;
139 /*}}}*/
140 /*{{{  M5::~M5 ()*/
141 M5::~M5 ()
143   printf ("M5 dtor %x\n", this);
144   if (fail)
145     ;
146   else if (this != addr)
147     fail = 8;
148   else
149     addr = 0;
151 /*}}}*/
153 /*{{{  struct M9 : M5, virtual M10*/
154 struct M9 : M5, virtual M10
156   int m;
157   static M9 *addr;
158   
159   M9 ();
160   virtual ~M9 ();
162 /*}}}*/
163 M9 *M9::addr;
164 /*{{{  M9::M9 ()*/
165 M9::M9 ()
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;
174 /*}}}*/
175 /*{{{  M9::~M9 ()*/
176 M9::~M9 ()
178   printf ("M9 dtor %x\n", this);
179   if (fail)
180     ;
181   else if (this != addr)
182     fail = 10;
183   else
184     addr = 0;
186 /*}}}*/
188 int main ()
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;