Richard Smith | 0724b7c | 2012-03-26 20:28:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -verify %s |
| 2 | |
| 3 | struct Base { |
| 4 | static const int a = 1; |
| 5 | }; |
| 6 | template<typename T> struct S : Base { |
| 7 | enum E : int; |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 8 | constexpr int f() const; |
| 9 | constexpr int g() const; // expected-note {{declared here}} |
Richard Smith | 0724b7c | 2012-03-26 20:28:16 +0000 | [diff] [blame] | 10 | void h(); |
| 11 | }; |
| 12 | template<> enum S<char>::E : int {}; // expected-note {{enum 'S<char>::E' was explicitly specialized here}} |
| 13 | template<> enum S<short>::E : int { b = 2 }; |
| 14 | template<> enum S<int>::E : int { a = 4 }; |
| 15 | template<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. |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 19 | template<typename T> constexpr int S<T>::f() const { return a; } |
Richard Smith | 0724b7c | 2012-03-26 20:28:16 +0000 | [diff] [blame] | 20 | static_assert(S<char>().f() == 1, ""); |
| 21 | static_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. |
Richard Smith | 8404626 | 2013-04-21 01:08:50 +0000 | [diff] [blame] | 25 | template<typename T> constexpr int S<T>::g() const { return b; } // expected-error {{enumerator 'b' does not exist in instantiation of 'S<char>'}} |
Richard Smith | 0724b7c | 2012-03-26 20:28:16 +0000 | [diff] [blame] | 26 | static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}} expected-note {{undefined}} |
| 27 | static_assert(S<short>().g() == 2, ""); |
| 28 | static_assert(S<long>().g() == 8, ""); |
| 29 | |
| 30 | // 'b' is type-dependent, so these assertions should not fire before 'h' is |
| 31 | // instantiated. |
| 32 | template<typename T> void S<T>::h() { |
| 33 | char c[S<T>::b]; |
| 34 | static_assert(b != 8, ""); |
| 35 | static_assert(sizeof(c) != 8, ""); |
| 36 | } |
| 37 | void f() { |
| 38 | S<short>().h(); // ok, b == 2 |
| 39 | } |