// RUN: %clang_cc1 -verify -fsyntax-only %s -Wno-c++11-extensions -Wno-c++1y-extensions -DPRECXX11 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-c++1y-extensions %s // RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s #define CONST const class A { template CONST T wrong; // expected-error {{member 'wrong' declared as a template}} template CONST T wrong_init = 5; // expected-error {{member 'wrong_init' declared as a template}} template static CONST T right = T(100); template static CONST T right = 5; template CONST int right; // expected-error {{member 'right' declared as a template}} template CONST float right = 5; // expected-error {{member 'right' declared as a template}} template<> static CONST int right = 7; // expected-error {{explicit specialization of 'right' in class scope}} template<> static CONST float right; // expected-error {{explicit specialization of 'right' in class scope}} template static CONST int right; // expected-error {{template specialization requires 'template<>'}} \ // expected-error {{explicit specialization of 'right' in class scope}} }; namespace out_of_line { class B0 { template static CONST T right = T(100); template static CONST T right = T(5); }; template<> CONST int B0::right = 7; template CONST int B0::right; template<> CONST int B0::right; template CONST int B0::right; class B1 { template static CONST T right; template static CONST T right; }; template CONST T B1::right = T(100); template CONST T B1::right = T(5); class B2 { template static CONST T right = T(100); // expected-note {{previous definition is here}} template static CONST T right = T(5); // expected-note {{previous definition is here}} }; template CONST T B2::right = T(100); // expected-error {{redefinition of 'right'}} template CONST T B2::right = T(5); // expected-error {{redefinition of 'right'}} class B3 { template static CONST T right = T(100); template static CONST T right = T(5); }; template CONST T B3::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} template CONST T B3::right; // expected-error {{forward declaration of variable template partial specialization cannot have a nested name specifier}} class B4 { template static CONST T right; template static CONST T right; template static CONST T right_def = T(100); template static CONST T right_def; // expected-note {{explicit instantiation refers here}} }; template CONST T B4::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} template CONST T B4::right; // expected-error {{forward declaration of variable template partial specialization cannot have a nested name specifier}} \ // expected-note {{explicit instantiation refers here}} template CONST int B4::right; // expected-error {{explicit instantiation of undefined static data member template 'right' of class}} template CONST int B4::right_def; // expected-error {{explicit instantiation of undefined static data member template 'right_def' of class}} } namespace non_const_init { class A { template static T wrong_inst = T(10); // expected-error {{non-const static data member must be initialized out of line}} template static T wrong_inst_fixed; }; template int A::wrong_inst; // expected-note {{in instantiation of static data member 'non_const_init::A::wrong_inst' requested here}} template T A::wrong_inst_fixed = T(10); template int A::wrong_inst_fixed; class B { template static T wrong_inst; template static T wrong_inst = T(100); // expected-error {{non-const static data member must be initialized out of line}} template static T wrong_inst_fixed; template static T wrong_inst_fixed; }; template int B::wrong_inst; // expected-note {{in instantiation of static data member 'non_const_init::B::wrong_inst' requested here}} template T B::wrong_inst_fixed = T(100); template int B::wrong_inst_fixed; class C { template static CONST T right_inst = T(10); template static CONST T right_inst = T(100); }; template CONST int C::right_inst; template CONST int C::right_inst; namespace pointers { struct C0 { template static U Data; template static CONST U Data = U(); // Okay }; template CONST int C0::Data; struct C1a { template static U Data; template static U* Data; // Okay, with out-of-line definition }; template T* C1a::Data = new T(); template int* C1a::Data; struct C1b { template static U Data; template static CONST U* Data; // Okay, with out-of-line definition }; template CONST T* C1b::Data = (T*)(0); template CONST int* C1b::Data; struct C2a { template static U Data; template static U* Data = new U(); // expected-error {{non-const static data member must be initialized out of line}} }; template int* C2a::Data; // expected-note {{in instantiation of static data member 'non_const_init::pointers::C2a::Data' requested here}} struct C2b { // FIXME: ?!? Should this be an error? pointer-types are automatically non-const? template static U Data; template static CONST U* Data = (U*)(0); // expected-error {{non-const static data member must be initialized out of line}} }; template CONST int* C2b::Data; // expected-note {{in instantiation of static data member 'non_const_init::pointers::C2b::Data' requested here}} } } #ifndef PRECXX11 namespace constexpred { class A { template constexpr T wrong; // expected-error {{member 'wrong' declared as a template}} \ // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} template constexpr T wrong_init = 5; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} template static constexpr T right = T(100); template static constexpr T right = 5; template constexpr int right; // expected-error {{member 'right' declared as a template}} \ // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} template constexpr float right = 5; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} template<> static constexpr int right = 7; // expected-error {{explicit specialization of 'right' in class scope}} template<> static constexpr float right; // expected-error {{explicit specialization of 'right' in class scope}} template static constexpr int right; // expected-error {{template specialization requires 'template<>'}} \ // expected-error {{explicit specialization of 'right' in class scope}} }; } #endif struct matrix_constants { // TODO: (?) }; namespace in_class_template { template class D0 { template static U Data; template static CONST U Data = U(); }; template CONST int D0::Data; template class D1 { template static U Data; template static U* Data; }; template template U* D1::Data = (U*)(0); template int* D1::Data; template class D2 { template static U Data; template static U* Data; }; template<> template U* D2::Data = (U*)(0) + 1; template int* D1::Data; template struct D3 { template static CONST U Data = U(100); }; template CONST int D3::Data; #ifndef PRECXX11 static_assert(D3::Data == 100, ""); #endif namespace bug_files { // FIXME: A bug has been filed addressing an issue similar to these. // No error diagnosis should be produced, because an // explicit specialization of a member templates of class // template specialization should not inherit the partial // specializations from the class template specialization. template class D0 { template static U Data; template static CONST U Data = U(10); // expected-note {{previous definition is here}} }; template<> template U D0::Data = U(100); // expected-error{{redefinition of 'Data'}} template class D1 { template static U Data; template static U* Data; // expected-note {{previous definition is here}} }; template template U* D1::Data = (U*)(0); template<> template U* D1::Data = (U*)(0) + 1; // expected-error{{redefinition of 'Data'}} } namespace other_bugs { // FIXME: This fails to properly initilize the variable 'k'. template struct S { template static int V; template static int V0; }; template struct S; template template int S::V0 = 123; template template int S::V = 123; int k = S::V; } } namespace in_nested_classes { // TODO: }