libstdc++: [_Hashtable] Fix some implementation inconsistencies
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / initlist-lifetime2.C
blob732736691e384884b06d24a27b0022fe9621def9
1 // Test that we properly extend the lifetime of the initializer_list
2 // array even if the initializer_list is a subobject.
3 // { dg-do run { target c++11 } }
5 #include <initializer_list>
7 extern "C" void abort();
8 bool ok;
10 bool do_throw;
12 struct A {
13   A(int) { if (do_throw) throw 42; }
14   ~A() { if (!ok) abort(); }
17 typedef std::initializer_list<A> AL;
18 typedef std::initializer_list<AL> AL2;
19 typedef std::initializer_list<AL2> AL3;
21 struct B {
22   AL al;
23   const AL& alr;
26 struct A2
28   const A& a1;
29   const A& a2;
32 struct C {
33   AL ar[2];
34   B b;
35   AL3 al3;
36   A2 a2;
37   A2 a2r[2];
38   C():
39     ar{{1,2},{3,4}},
40     b{{5,6},{7,8}},
41     al3{{{1},{2},{3}}},
42     a2{1,2},
43     a2r{{1,2},{3,4}}
44   { ok = true; }
47 struct D {
48   AL ar[2] = {{1,2},{3,4}};
49   B b = {{5,6},{7,8}};
50   AL3 al3 = {{{1},{2},{3}}};
51   A2 a2 = {1,2};
52   A2 a2r[2] = {{1,2},{3,4}};
53   D() { ok = true; }
56 volatile bool always_false = false;
58 int main(int argc, const char** argv)
60   do_throw = always_false;      // always false, but optimizer can't tell
61   ok = false;
62   C c;
63   ok = false;
64   D d;