60 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s2 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) {} // ok14 S(char) : b(n) {} // expected-error {{constructor for 'S' must explicitly initialize the reference member 'a'}}15 S(double) : a(n), b(n) {} // ok16} s(0);17 18union U {19 int a = 0; // expected-note {{previous initialization}}20 char b = 'x'; // expected-error {{initializing multiple members of union}}21 22 U() {}23 U(int) : a(1) {}24 U(char) : b('y') {}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.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