1// RUN: %clang_cc1 -verify -std=c++11 %s 2 3// Unlike in C++98, C++11 allows unions to have static data members. 4 5union U1 { 6 static constexpr int k1 = 0; 7 static const int k2 = k1; 8 static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}} 9 static constexpr double k4 = k2; 10 static const double k5 = k4; // expected-error {{requires 'constexpr' specifier}} expected-note {{add 'constexpr'}} 11 int n[k1 + 3]; 12}; 13 14constexpr int U1::k1; 15constexpr int U1::k2; 16int U1::k3; 17 18const double U1::k4; 19const double U1::k5; 20 21template<typename T> 22union U2 { 23 static const int k1; 24 static double k2; 25 T t; 26}; 27template<typename T> constexpr int U2<T>::k1 = sizeof(U2<T>); 28template<typename T> double U2<T>::k2 = 5.3; 29 30static_assert(U2<int>::k1 == sizeof(int), ""); 31static_assert(U2<char>::k1 == sizeof(char), ""); 32 33union U3 { 34 static const int k; 35 U3() : k(0) {} // expected-error {{does not name a non-static data member}} 36}; 37 38struct S { 39 union { 40 static const int n; // expected-error {{static members cannot be declared in an anonymous union}} 41 int a; 42 int b; 43 }; 44}; 45static union { 46 static const int k; // expected-error {{static members cannot be declared in an anonymous union}} 47 int n; 48}; 49