OSDN Git Service

PR c++/45114 - Support C++11 alias-declaration
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / cpp0x / initlist-lifetime2.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 struct A2
28 {
29   const A& a1;
30   const A& a2;
31 };
32
33 struct C {
34   AL ar[2];
35   B b;
36   AL3 al3;
37   A2 a2;
38   A2 a2r[2];
39   C():
40     ar{{1,2},{3,4}},
41     b{{5,6},{7,8}},
42     al3{{{1},{2},{3}}},
43     a2{1,2},
44     a2r{{1,2},{3,4}}
45   { ok = true; }
46 };
47
48 struct D {
49   AL ar[2] = {{1,2},{3,4}};
50   B b = {{5,6},{7,8}};
51   AL3 al3 = {{{1},{2},{3}}};
52   A2 a2 = {1,2};
53   A2 a2r[2] = {{1,2},{3,4}};
54   D() { ok = true; }
55 };
56
57 int main(int argc, const char** argv)
58 {
59   do_throw = (argc > 1);        // always false, but optimizer can't tell
60   ok = false;
61   C c;
62   ok = false;
63   D d;
64 }