OSDN Git Service

2012-12-15 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / initlist-lifetime1.C
1 // Test that we properly extend the lifetime of the initializer_list
2 // array even if the initializer_list is a subobject.
3 // { dg-options -std=c++0x }
4 // { dg-do run }
5
6 #include <initializer_list>
7
8 extern "C" void abort();
9 bool ok;
10
11 bool do_throw;
12
13 struct A {
14   A(int) { if (do_throw) throw 42; }
15   ~A() { if (!ok) abort(); }
16 };
17
18 typedef std::initializer_list<A> AL;
19 typedef std::initializer_list<AL> AL2;
20 typedef std::initializer_list<AL2> AL3;
21
22 struct B {
23   AL al;
24   const AL& alr;
25 };
26
27 int main(int argc, const char** argv)
28 {
29   do_throw = (argc > 1);        // always false, but optimizer can't tell
30   AL ar[] = {{1,2},{3,4}};
31   B b = {{5,6},{7,8}};
32   AL3 al3 = {{{1},{2},{3}}};
33   ok = true;
34 }