gcc/testsuite/g++.dg/cpp0x/initlist6.C
raw| 1 | // Test for initlist lifetime |
| 2 | // { dg-do run { target c++11 } } |
| 3 | |
| 4 | #include <initializer_list> |
| 5 | |
| 6 | int c; |
| 7 | |
| 8 | struct A |
| 9 | { |
| 10 | A(int,int) { ++c; } |
| 11 | ~A() { --c; } |
| 12 | }; |
| 13 | |
| 14 | void f (std::initializer_list<A> l) { } |
| 15 | |
| 16 | int main() |
| 17 | { |
| 18 | f({ {1,2}, {3,4} }); |
| 19 | if (c != 0) |
| 20 | return 1; |
| 21 | |
| 22 | { |
| 23 | std::initializer_list<A> l { {1,2}, {3,4} }; |
| 24 | if (c != 2) |
| 25 | return 2; |
| 26 | } |
| 27 | if (c != 0) |
| 28 | return 3; |
| 29 | } |