gcc/testsuite/g++.dg/opt/nrv9.C
raw| 1 | // PR c++/19317 |
| 2 | // { dg-do run } |
| 3 | // If we do both NRV and caller-side return slot opt for ga = f() |
| 4 | // constructing la sets ga.i to 0 too soon. |
| 5 | |
| 6 | extern "C" void abort(); |
| 7 | |
| 8 | struct A |
| 9 | { |
| 10 | int i; |
| 11 | int pad[32]; // force return in memory |
| 12 | A(): i(0) {} |
| 13 | A(int ia): i(ia) {} |
| 14 | }; |
| 15 | |
| 16 | A ga(42); |
| 17 | |
| 18 | A f() |
| 19 | { |
| 20 | A la; |
| 21 | if (ga.i != 42) |
| 22 | abort(); |
| 23 | return la; |
| 24 | } |
| 25 | |
| 26 | int main() |
| 27 | { |
| 28 | ga = f (); |
| 29 | } |