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