1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -verify %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc struct Base {
4*f4a2713aSLionel Sambuc static const int a = 1;
5*f4a2713aSLionel Sambuc };
6*f4a2713aSLionel Sambuc template<typename T> struct S : Base {
7*f4a2713aSLionel Sambuc enum E : int;
8*f4a2713aSLionel Sambuc constexpr int f() const;
9*f4a2713aSLionel Sambuc constexpr int g() const;
10*f4a2713aSLionel Sambuc void h();
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc template<> enum S<char>::E : int {}; // expected-note {{enum 'S<char>::E' was explicitly specialized here}}
13*f4a2713aSLionel Sambuc template<> enum S<short>::E : int { b = 2 };
14*f4a2713aSLionel Sambuc template<> enum S<int>::E : int { a = 4 };
15*f4a2713aSLionel Sambuc template<typename T> enum S<T>::E : int { b = 8 };
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambuc // The unqualified-id here names a member of the non-dependent base class Base
18*f4a2713aSLionel Sambuc // and not the injected enumerator name 'a' from the specialization.
f() const19*f4a2713aSLionel Sambuc template<typename T> constexpr int S<T>::f() const { return a; }
20*f4a2713aSLionel Sambuc static_assert(S<char>().f() == 1, "");
21*f4a2713aSLionel Sambuc static_assert(S<int>().f() == 1, "");
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc // The unqualified-id here names a member of the current instantiation, which
24*f4a2713aSLionel Sambuc // bizarrely might not exist in some instantiations.
g() const25*f4a2713aSLionel Sambuc template<typename T> constexpr int S<T>::g() const { return b; } // expected-error {{enumerator 'b' does not exist in instantiation of 'S<char>'}}
26*f4a2713aSLionel Sambuc static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}}
27*f4a2713aSLionel Sambuc static_assert(S<short>().g() == 2, "");
28*f4a2713aSLionel Sambuc static_assert(S<long>().g() == 8, "");
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc // 'b' is type-dependent, so these assertions should not fire before 'h' is
31*f4a2713aSLionel Sambuc // instantiated.
h()32*f4a2713aSLionel Sambuc template<typename T> void S<T>::h() {
33*f4a2713aSLionel Sambuc char c[S<T>::b];
34*f4a2713aSLionel Sambuc static_assert(b != 8, "");
35*f4a2713aSLionel Sambuc static_assert(sizeof(c) != 8, "");
36*f4a2713aSLionel Sambuc }
f()37*f4a2713aSLionel Sambuc void f() {
38*f4a2713aSLionel Sambuc S<short>().h(); // ok, b == 2
39*f4a2713aSLionel Sambuc }
40