| 1 |
// { dg-do run } |
| 2 |
// Origin: Mark Mitchell <[email protected]> |
| 3 |
// This test case checks that the return value optimization works for |
| 4 |
// empty classes. |
| 5 |
|
| 6 |
// PR c++/5995 |
| 7 |
|
| 8 |
extern "C" void abort(); |
| 9 |
extern "C" int printf (const char *, ...); |
| 10 |
|
| 11 |
int i; |
| 12 |
|
| 13 |
struct A; |
| 14 |
|
| 15 |
struct A* as[10]; |
| 16 |
|
| 17 |
struct A { |
| 18 |
A () { as[i++] = this; } |
| 19 |
A (const A&) { as[i++] = this; } |
| 20 |
~A() { if (i == 0 || as[--i] != this) abort(); } |
| 21 |
}; |
| 22 |
|
| 23 |
A f() { return A(); } |
| 24 |
|
| 25 |
int main () |
| 26 |
{ |
| 27 |
A a (f ()); |
| 28 |
} |