summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/vbase5.C
blob: 3d22ff50dff4ac6068fd959f5dde3f014c1018db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// { dg-do run  }
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 19 Jan 2001 <nathan@codesourcery.com>

// Bug 1701. building a vbase path was not using the shortest number of
// vbases. Normally that's just a pessimization, unfortunately during
// constructoring it leads to uninitialized reads.

extern "C" int printf (const char*,...);

int fail = 0;

/*{{{  struct Base*/
struct Base
{
  unsigned m;
  static Base *addr;
  
  Base ();
  virtual ~Base ();
};
/*}}}*/
Base *Base::addr;
/*{{{  Base::Base ()*/
Base::Base ()
{
  printf ("Base (%u) ctor %x\n", sizeof (Base), this);
  if (fail) ;
  else if (addr)
    fail = 1;
  else
    addr = this;
}
/*}}}*/
/*{{{  Base::~Base ()*/
Base::~Base ()
{
  printf ("Base dtor %x\n", this);
  if (fail)
    ;
  else if (this != addr)
    fail = 2;
  else
    addr = 0;
}
/*}}}*/

/*{{{  struct M10 : virtual Base*/
struct M10 : virtual Base
{
  int m;
  static M10 *addr;
  
  M10 ();
  virtual ~M10 ();
};
/*}}}*/
M10 *M10::addr;
/*{{{  M10::M10 ()*/
M10::M10 ()
{
  printf ("M10 (%u) ctor %x\n", sizeof (M10), this);
  if (fail) ;
  else if (addr)
    fail = 3;
  else
    addr = this;
}
/*}}}*/
/*{{{  M10::~M10 ()*/
M10::~M10 ()
{
  printf ("M10 dtor %x\n", this);
  if (fail)
    ;
  else if (this != addr)
    fail = 4;
  else
    addr = 0;
}
/*}}}*/

/*{{{  struct M4 : virtual Base, virtual M10*/
struct M4 : virtual Base, virtual M10
{
  int m;
  static M4 *addr;
  
  M4 ();
  virtual ~M4 ();
};
/*}}}*/
M4 *M4::addr;
/*{{{  M4::M4 ()*/
M4::M4 ()
{
  printf ("M4 (%u) ctor %x\n", sizeof (M4), this);
  if (fail) ;
  else if (addr)
    fail = 5;
  else
    addr = this;
}
/*}}}*/
/*{{{  M4::~M4 ()*/
M4::~M4 ()
{
  printf ("M4 dtor %x\n", this);
  if (fail)
    ;
  else if (this != addr)
    fail = 6;
  else
    addr = 0;
}
/*}}}*/

/*{{{  struct M5 : M4*/
struct M5 : M4
{
  int m;
  static M5 *addr;
  
  M5 ();
  virtual ~M5 ();
};
/*}}}*/
M5 *M5::addr;
/*{{{  M5::M5 ()*/
M5::M5 ()
{
  printf ("M5 (%u) ctor %x\n", sizeof (M5), this);
  if (fail) ;
  else if (addr)
    fail = 7;
  else
    addr = this;
}
/*}}}*/
/*{{{  M5::~M5 ()*/
M5::~M5 ()
{
  printf ("M5 dtor %x\n", this);
  if (fail)
    ;
  else if (this != addr)
    fail = 8;
  else
    addr = 0;
}
/*}}}*/

/*{{{  struct M9 : M5, virtual M10*/
struct M9 : M5, virtual M10
{
  int m;
  static M9 *addr;
  
  M9 ();
  virtual ~M9 ();
};
/*}}}*/
M9 *M9::addr;
/*{{{  M9::M9 ()*/
M9::M9 ()
{
  printf ("M9 (%u), ctor %x\n", sizeof (M9), this);
  if (fail) ;
  else if (addr)
    fail = 9;
  else
    addr = this;
}
/*}}}*/
/*{{{  M9::~M9 ()*/
M9::~M9 ()
{
  printf ("M9 dtor %x\n", this);
  if (fail)
    ;
  else if (this != addr)
    fail = 10;
  else
    addr = 0;
}
/*}}}*/

int main ()
{
  M9 *m9;
  Base *r;
  
  m9 = new M9 ();
  r = m9;
  if (fail)
    return fail;
  void *top = dynamic_cast <void *> (r);
  if (top != m9)
    return 20;
  r->~Base ();
  
  return fail;
}