aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/initlist-lifetime2.C
blob: 77fc961c9667c09385bdda314b78c951bcc19ece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Test that we properly extend the lifetime of the initializer_list
// array even if the initializer_list is a subobject.
// { dg-do run { target c++11 } }

#include <initializer_list>

extern "C" void abort();
bool ok;

bool do_throw;

struct A {
  A(int) { if (do_throw) throw 42; }
  ~A() { if (!ok) abort(); }
};

typedef std::initializer_list<A> AL;
typedef std::initializer_list<AL> AL2;
typedef std::initializer_list<AL2> AL3;

struct B {
  AL al;
  const AL& alr;
};

struct A2
{
  const A& a1;
  const A& a2;
};

struct C {
  AL ar[2];
  B b;
  AL3 al3;
  A2 a2;
  A2 a2r[2];
  C():
    ar{{1,2},{3,4}},
    b{{5,6},{7,8}},
    al3{{{1},{2},{3}}},
    a2{1,2},
    a2r{{1,2},{3,4}}
  { ok = true; }
};

struct D {
  AL ar[2] = {{1,2},{3,4}};
  B b = {{5,6},{7,8}};
  AL3 al3 = {{{1},{2},{3}}};
  A2 a2 = {1,2};
  A2 a2r[2] = {{1,2},{3,4}};
  D() { ok = true; }
};

int main(int argc, const char** argv)
{
  do_throw = (argc > 1);	// always false, but optimizer can't tell
  ok = false;
  C c;
  ok = false;
  D d;
}