// RUN: %clang_cc1 -verify -std=c++11 %s

// Unlike in C++98, C++11 allows unions to have static data members.

union U1 {
  static constexpr int k1 = 0;
  static const int k2 = k1;
  static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}}
  static constexpr double k4 = k2;
  static const double k5 = k4; // expected-warning {{GNU extension}} expected-note {{use 'constexpr'}}
  int n[k1 + 3];
};

constexpr int U1::k1;
constexpr int U1::k2;
int U1::k3;

const double U1::k4;
const double U1::k5;

template<typename T>
union U2 {
  static const int k1;
  static double k2;
  T t;
};
template<typename T> constexpr int U2<T>::k1 = sizeof(U2<T>);
template<typename T> double U2<T>::k2 = 5.3;

static_assert(U2<int>::k1 == sizeof(int), "");
static_assert(U2<char>::k1 == sizeof(char), "");

union U3 {
  static const int k;
  U3() : k(0) {} // expected-error {{does not name a non-static data member}}
};

// RUN: %clang_cc1 -verify -std=c++11 %s

// Unlike in C++98, C++11 allows unions to have static data members.

union U1 {
  static constexpr int k1 = 0;
  static const int k2 = k1;
  static int k3 = k2; // expected-error {{non-const static data member must be initialized out of line}}
  static constexpr double k4 = k2;
  static const double k5 = k4; // expected-warning {{GNU extension}} expected-note {{use 'constexpr'}}
  int n[k1 + 3];
};

constexpr int U1::k1;
constexpr int U1::k2;
int U1::k3;

const double U1::k4;
const double U1::k5;

template<typename T>
union U2 {
  static const int k1;
  static double k2;
  T t;
};
template<typename T> constexpr int U2<T>::k1 = sizeof(U2<T>);
template<typename T> double U2<T>::k2 = 5.3;

static_assert(U2<int>::k1 == sizeof(int), "");
static_assert(U2<char>::k1 == sizeof(char), "");

union U3 {
  static const int k;
  U3() : k(0) {} // expected-error {{does not name a non-static data member}}
};

struct S {
  union {
    static const int n; // expected-error {{static members cannot be declared in an anonymous union}}
    int a;
    int b;
  };
};
static union {
  static const int k; // expected-error {{static members cannot be declared in an anonymous union}}
  int n;
};

Make sure we still reject static data members in anonymous unions in C++11.
Make sure we still reject static data members in anonymous unions in C++11.


git-svn-id: ffe668792ed300d6c2daa1f6eba2e0aa28d7ec6c@150724 91177308-0d34-0410-b5e6-96231b3b80d8
