p8-0x.cpp revision 762bb9d0ad20320b9f97a841dce57ba5e8e48b07
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2
3int n;
4struct S {
5  int &a; // expected-note 2{{here}}
6  int &b = n;
7
8  union {
9    const int k = 42;
10  };
11
12  S() {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}}
13  S(int) : a(n) {} // ok
14  S(char) : b(n) {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}}
15  S(double) : a(n), b(n) {} // ok
16} s(0);
17
18union U {
19  int a = 0;
20  char b = 'x';
21
22  // FIXME: these should all be rejected
23  U() {} // desired-error {{at most one member of a union may be initialized}}
24  U(int) : a(1) {} // desired-error {{at most one member of a union may be initialized}}
25  U(char) : b('y') {} // desired-error {{at most one member of a union may be initialized}}
26  U(double) : a(1), b('y') {} // desired-error {{at most one member of a union may be initialized}}
27};
28
29// PR10954: variant members do not acquire an implicit initializer.
30namespace VariantMembers {
31  struct NoDefaultCtor {
32    NoDefaultCtor(int);
33  };
34  union V {
35    NoDefaultCtor ndc;
36    int n;
37
38    V() {}
39    V(int n) : n(n) {}
40    V(int n, bool) : ndc(n) {}
41  };
42  struct K {
43    union {
44      NoDefaultCtor ndc;
45      int n;
46    };
47    K() {}
48    K(int n) : n(n) {}
49    K(int n, bool) : ndc(n) {}
50  };
51  struct Nested {
52    Nested() {}
53    union {
54      struct {
55        NoDefaultCtor ndc;
56      };
57    };
58  };
59}
60