blob: d353bda27ce5122bbfa6231b64545cad0fde9404 [file] [log] [blame]
Richard Smithb9c64d82012-02-16 20:41:22 +00001// 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-warning {{GNU extension}} expected-note {{use '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};