1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 
3 int n;
4 struct S {
5   int &a; // expected-note 2{{here}}
6   int &b = n;
7 
8   union {
9     const int k = 42;
10   };
11 
SS12   S() {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}}
SS13   S(int) : a(n) {} // ok
SS14   S(char) : b(n) {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}}
SS15   S(double) : a(n), b(n) {} // ok
16 } s(0);
17 
18 union U {
19   int a = 0; // expected-note {{previous initialization}}
20   char b = 'x'; // expected-error {{initializing multiple members of union}}
21 
U()22   U() {}
U(int)23   U(int) : a(1) {}
U(char)24   U(char) : b('y') {}
U(double)25   U(double) : a(1), // expected-note{{previous initialization is here}}
26               b('y') {} // expected-error{{initializing multiple members of union}}
27 };
28 
29 // PR10954: variant members do not acquire an implicit initializer.
30 namespace VariantMembers {
31   struct NoDefaultCtor {
32     NoDefaultCtor(int);
33   };
34   union V {
35     NoDefaultCtor ndc;
36     int n;
37 
V()38     V() {}
V(int n)39     V(int n) : n(n) {}
V(int n,bool)40     V(int n, bool) : ndc(n) {}
41   };
42   struct K {
43     union {
44       NoDefaultCtor ndc;
45       int n;
46     };
KVariantMembers::K47     K() {}
KVariantMembers::K48     K(int n) : n(n) {}
KVariantMembers::K49     K(int n, bool) : ndc(n) {}
50   };
51   struct Nested {
NestedVariantMembers::Nested52     Nested() {}
53     union {
54       struct {
55         NoDefaultCtor ndc;
56       };
57     };
58   };
59 }
60