blob: e9da38f558d3bf327fedaf014454bc187e5135fc [file] [log] [blame]
Richard Smith0724b7c2012-03-26 20:28:16 +00001// 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;
Richard Smith84046262013-04-21 01:08:50 +00008 constexpr int f() const;
9 constexpr int g() const; // expected-note {{declared here}}
Richard Smith0724b7c2012-03-26 20:28:16 +000010 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.
Richard Smith84046262013-04-21 01:08:50 +000019template<typename T> constexpr int S<T>::f() const { return a; }
Richard Smith0724b7c2012-03-26 20:28:16 +000020static_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.
Richard Smith84046262013-04-21 01:08:50 +000025template<typename T> constexpr int S<T>::g() const { return b; } // expected-error {{enumerator 'b' does not exist in instantiation of 'S<char>'}}
Richard Smith0724b7c2012-03-26 20:28:16 +000026static_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}