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; // desired-note 5 {{previous initialization is here}} 20 char b = 'x'; 21 22 // FIXME: these should all be rejected U()23 U() {} // desired-error {{initializing multiple members of union}} U(int)24 U(int) : a(1) {} // desired-error {{initializing multiple members of union}} U(char)25 U(char) : b('y') {} // desired-error {{initializing multiple members of union}} 26 // this expected note should be removed & the note should appear on the 27 // declaration of 'a' when this set of cases is handled correctly. U(double)28 U(double) : a(1), // expected-note{{previous initialization is here}} desired-error {{initializing multiple members of union}} 29 b('y') {} // expected-error{{initializing multiple members of union}} 30 }; 31 32 // PR10954: variant members do not acquire an implicit initializer. 33 namespace VariantMembers { 34 struct NoDefaultCtor { 35 NoDefaultCtor(int); 36 }; 37 union V { 38 NoDefaultCtor ndc; 39 int n; 40 V()41 V() {} V(int n)42 V(int n) : n(n) {} V(int n,bool)43 V(int n, bool) : ndc(n) {} 44 }; 45 struct K { 46 union { 47 NoDefaultCtor ndc; 48 int n; 49 }; KVariantMembers::K50 K() {} KVariantMembers::K51 K(int n) : n(n) {} KVariantMembers::K52 K(int n, bool) : ndc(n) {} 53 }; 54 struct Nested { NestedVariantMembers::Nested55 Nested() {} 56 union { 57 struct { 58 NoDefaultCtor ndc; 59 }; 60 }; 61 }; 62 } 63