aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/union3.C
blob: d95d30c6fe3ec23fd5b97c7f703287310e1275d1 (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
64
65
66
67
68
// Runtime test for C++11 unrestricted unions
// { dg-do run { target c++11 } }

int c, d;
struct A
{
  int i;
  A(): i(1) { ++c; }
  A(const A&): i(2) { ++c; }
  ~A() { ++d; }
};

union B
{
  A a;
  B() { }
  B(const B& b) { }
  ~B() { }
};

struct C
{
  union { A a; };
  C() { }
  C(const C&) { }
  ~C() { }
};

union D
{
  A a;
  D(): a() { }
  D(const D& d): a(d.a) { }
  ~D() { a.~A(); }
};

struct E
{
  union { A a; };
  E(): a() { }
  E(const E& e): a (e.a) { }
  ~E() { a.~A(); }
};

int main()
{
  {
    B b1;
    B b2(b1);

    C c1;
    C c2(c1);
  }

  if (c != 0 || d != 0)
    return c+d*10;

  {
    D d1;
    D d2(d1);

    E e1;
    E e2(e1);
  }

  if (c != 4 || d != 4)
    return c*100+d*1000;
}