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