| 1 |
// PR c++/12253 |
| 2 |
// We should not destroy the temporary A passed to the |
| 3 |
// constructor for b[0] before going on to construct b[1]. |
| 4 |
|
| 5 |
// { dg-do run } |
| 6 |
|
| 7 |
extern "C" int printf (const char *, ...); |
| 8 |
|
| 9 |
int c; |
| 10 |
int r; |
| 11 |
|
| 12 |
struct A |
| 13 |
{ |
| 14 |
A() { printf ("A()\n"); ++c; } |
| 15 |
A(const A&) { printf ("A(const A&)\n"); ++c; } |
| 16 |
~A() { printf ("~A()\n"); --c; } |
| 17 |
}; |
| 18 |
|
| 19 |
struct B |
| 20 |
{ |
| 21 |
B(int i, const A& = A()) { |
| 22 |
printf ("B()\n"); |
| 23 |
if (c != i) r = 1; |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
int main() |
| 28 |
{ |
| 29 |
B b[] = { 1, 2 }; |
| 30 |
return r; |
| 31 |
} |