gcc/testsuite/g++.old-deja/g++.jason/temporary3.C
raw| 1 | // { dg-do run } |
| 2 | // Bug: the temporary returned from f is elided, causing a to be constructed |
| 3 | // twice but only destroyed once. |
| 4 | |
| 5 | extern "C" int printf (const char *, ...); |
| 6 | |
| 7 | int c,d; |
| 8 | |
| 9 | struct A { |
| 10 | A (int) { c++; } |
| 11 | ~A () { d++; } |
| 12 | A (const A&) { c++; } |
| 13 | int i; |
| 14 | }; |
| 15 | |
| 16 | A f () |
| 17 | { return 1; } |
| 18 | |
| 19 | int main () |
| 20 | { |
| 21 | { |
| 22 | A a (1); |
| 23 | a = f (); |
| 24 | } |
| 25 | printf ("%d %d\n", c, d); |
| 26 | return c != d; |
| 27 | } |