diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | 112 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp | 44 |
2 files changed, 79 insertions, 77 deletions
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index 077394f2130..c7053549235 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -2,61 +2,63 @@ // 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<typename T> const T wrong; // expected-error {{member 'wrong' declared as a template}} - template<typename T> const T wrong_init = 5; // expected-error {{member 'wrong_init' declared as a template}} - template<typename T, typename T0> static const T right = T(100); - template<typename T> static const T right<T,int> = 5; - template<typename T> const int right<int,T>; // expected-error {{member 'right' declared as a template}} - template<typename T> const float right<float,T> = 5; // expected-error {{member 'right' declared as a template}} - template<> static const int right<int,int> = 7; // expected-error {{explicit specialization of 'right' in class scope}} - template<> static const float right<float,int>; // expected-error {{explicit specialization of 'right' in class scope}} - template static const int right<int,int>; // expected-error {{template specialization requires 'template<>'}} \ + template<typename T> CONST T wrong; // expected-error {{member 'wrong' declared as a template}} + template<typename T> CONST T wrong_init = 5; // expected-error {{member 'wrong_init' declared as a template}} + template<typename T, typename T0> static CONST T right = T(100); + template<typename T> static CONST T right<T,int> = 5; + template<typename T> CONST int right<int,T>; // expected-error {{member 'right' declared as a template}} + template<typename T> CONST float right<float,T> = 5; // expected-error {{member 'right' declared as a template}} + template<> static CONST int right<int,int> = 7; // expected-error {{explicit specialization of 'right' in class scope}} + template<> static CONST float right<float,int>; // expected-error {{explicit specialization of 'right' in class scope}} + template static CONST int right<int,int>; // expected-error {{template specialization requires 'template<>'}} \ // expected-error {{explicit specialization of 'right' in class scope}} }; namespace out_of_line { class B0 { - template<typename T, typename T0> static const T right = T(100); - template<typename T> static const T right<T,int> = T(5); + template<typename T, typename T0> static CONST T right = T(100); + template<typename T> static CONST T right<T,int> = T(5); }; - template<> const int B0::right<int,int> = 7; - template const int B0::right<int,int>; - template<> const int B0::right<int,float>; - template const int B0::right<int,float>; + template<> CONST int B0::right<int,int> = 7; + template CONST int B0::right<int,int>; + template<> CONST int B0::right<int,float>; + template CONST int B0::right<int,float>; class B1 { - template<typename T, typename T0> static const T right; - template<typename T> static const T right<T,int>; + template<typename T, typename T0> static CONST T right; + template<typename T> static CONST T right<T,int>; }; - template<typename T, typename T0> const T B1::right = T(100); - template<typename T> const T B1::right<T,int> = T(5); + template<typename T, typename T0> CONST T B1::right = T(100); + template<typename T> CONST T B1::right<T,int> = T(5); class B2 { - template<typename T, typename T0> static const T right = T(100); // expected-note {{previous definition is here}} - template<typename T> static const T right<T,int> = T(5); // expected-note {{previous definition is here}} + template<typename T, typename T0> static CONST T right = T(100); // expected-note {{previous definition is here}} + template<typename T> static CONST T right<T,int> = T(5); // expected-note {{previous definition is here}} }; - template<typename T, typename T0> const T B2::right = T(100); // expected-error {{redefinition of 'right'}} - template<typename T> const T B2::right<T,int> = T(5); // expected-error {{redefinition of 'right'}} + template<typename T, typename T0> CONST T B2::right = T(100); // expected-error {{redefinition of 'right'}} + template<typename T> CONST T B2::right<T,int> = T(5); // expected-error {{redefinition of 'right'}} class B3 { - template<typename T, typename T0> static const T right = T(100); - template<typename T> static const T right<T,int> = T(5); + template<typename T, typename T0> static CONST T right = T(100); + template<typename T> static CONST T right<T,int> = T(5); }; - template<typename T, typename T0> const T B3::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} - template<typename T> const T B3::right<T,int>; // expected-error {{forward declaration of variable template partial specialization cannot have a nested name specifier}} + template<typename T, typename T0> CONST T B3::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} + template<typename T> CONST T B3::right<T,int>; // expected-error {{forward declaration of variable template partial specialization cannot have a nested name specifier}} class B4 { - template<typename T, typename T0> static const T right; - template<typename T> static const T right<T,int>; - template<typename T, typename T0> static const T right_def = T(100); - template<typename T> static const T right_def<T,int>; // expected-note {{explicit instantiation refers here}} + template<typename T, typename T0> static CONST T right; + template<typename T> static CONST T right<T,int>; + template<typename T, typename T0> static CONST T right_def = T(100); + template<typename T> static CONST T right_def<T,int>; // expected-note {{explicit instantiation refers here}} }; - template<typename T, typename T0> const T B4::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} - template<typename T> const T B4::right<T,int>; // expected-error {{forward declaration of variable template partial specialization cannot have a nested name specifier}} \ + template<typename T, typename T0> CONST T B4::right; // expected-error {{forward declaration of variable template cannot have a nested name specifier}} + template<typename T> CONST T B4::right<T,int>; // 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<int,int>; // expected-error {{explicit instantiation of undefined static data member template 'right' of class}} - template const int B4::right_def<int,int>; // expected-error {{explicit instantiation of undefined static data member template 'right_def' of class}} + template CONST int B4::right<int,int>; // expected-error {{explicit instantiation of undefined static data member template 'right' of class}} + template CONST int B4::right_def<int,int>; // expected-error {{explicit instantiation of undefined static data member template 'right_def' of class}} } namespace non_const_init { @@ -80,19 +82,19 @@ namespace non_const_init { template int B::wrong_inst_fixed<int>; class C { - template<typename T> static const T right_inst = T(10); - template<typename T> static const T right_inst<T*> = T(100); + template<typename T> static CONST T right_inst = T(10); + template<typename T> static CONST T right_inst<T*> = T(100); }; - template const int C::right_inst<int>; - template const int C::right_inst<int*>; + template CONST int C::right_inst<int>; + template CONST int C::right_inst<int*>; namespace pointers { struct C0 { template<typename U> static U Data; - template<typename U> static const U Data<U*> = U(); // Okay + template<typename U> static CONST U Data<U*> = U(); // Okay }; - template const int C0::Data<int*>; + template CONST int C0::Data<int*>; struct C1a { template<typename U> static U Data; @@ -103,10 +105,10 @@ namespace non_const_init { struct C1b { template<typename U> static U Data; - template<typename U> static const U* Data<U>; // Okay, with out-of-line definition + template<typename U> static CONST U* Data<U>; // Okay, with out-of-line definition }; - template<typename T> const T* C1b::Data<T> = (T*)(0); - template const int* C1b::Data<int>; + template<typename T> CONST T* C1b::Data<T> = (T*)(0); + template CONST int* C1b::Data<int>; struct C2a { template<typename U> static U Data; @@ -116,9 +118,9 @@ namespace non_const_init { struct C2b { // FIXME: ?!? Should this be an error? pointer-types are automatically non-const? template<typename U> static U Data; - template<typename U> static const U* Data<U> = (U*)(0); // expected-error {{non-const static data member must be initialized out of line}} + template<typename U> static CONST U* Data<U> = (U*)(0); // expected-error {{non-const static data member must be initialized out of line}} }; - template const int* C2b::Data<int>; // expected-note {{in instantiation of static data member 'non_const_init::pointers::C2b::Data<int>' requested here}} + template CONST int* C2b::Data<int>; // expected-note {{in instantiation of static data member 'non_const_init::pointers::C2b::Data<int>' requested here}} } } @@ -131,9 +133,9 @@ namespace in_class_template { template<typename T> class D0 { template<typename U> static U Data; - template<typename U> static const U Data<U*> = U(); + template<typename U> static CONST U Data<U*> = U(); }; - template const int D0<float>::Data<int*>; + template CONST int D0<float>::Data<int*>; template<typename T> class D1 { @@ -152,27 +154,27 @@ namespace in_class_template { template<> template<typename U> U* D2<float>::Data<U*> = (U*)(0) + 1; template int* D1<float>::Data<int*>; - + template<typename T> struct D3 { - template<typename U> static const U Data = U(100); + template<typename U> static CONST U Data = U(100); }; - template const int D3<float>::Data<int>; + template CONST int D3<float>::Data<int>; #ifndef PRECXX11 static_assert(D3<float>::Data<int> == 100, ""); #endif namespace bug_files { - // FIXME: A bug has been filed addressing an issue similar to these. + // 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 + // explicit specialization of a member templates of class + // template specialization should not inherit the partial // specializations from the class template specialization. template<typename T> class D0 { template<typename U> static U Data; - template<typename U> static const U Data<U*> = U(10); // expected-note {{previous definition is here}} + template<typename U> static CONST U Data<U*> = U(10); // expected-note {{previous definition is here}} }; template<> template<typename U> U D0<float>::Data<U*> = U(100); // expected-error{{redefinition of 'Data'}} diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp index 61fccac038b..49be0bdcbe2 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -verify -fsyntax-only -Wno-c++11-extensions -Wno-c++1y-extensions %s -// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -Wno-c++1y-extensions %s -DCXX11 -// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s -DCXX11 +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-c++11-extensions -Wno-c++1y-extensions %s -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 -#ifdef CXX11 - #define CONST constexpr -#else +#ifdef PRECXX11 #define CONST const +#else + #define CONST constexpr #endif template<typename T> @@ -15,7 +15,7 @@ template<typename T> CONST T cpi = T(3.1415926535897932385); // expected-note {{template is declared here}} template<typename T> extern CONST T vc; -#ifdef CXX11 +#ifndef PRECXX11 // expected-error@-2 {{constexpr variable declaration must be a definition}} #endif @@ -46,7 +46,7 @@ namespace use_in_top_level_funcs { double use_circular_area(double r) { CONST float t = const_circular_area(2.0) - 12; -#ifdef CXX11 +#ifndef PRECXX11 static_assert(const_circular_area(2) == 12, ""); CONST int test = (t > 0) && (t < 1); static_assert(test, ""); @@ -104,7 +104,7 @@ namespace odr_tmpl { // expected-note {{previous definition is here}} template<typename T> extern int v; // expected-error {{redefinition of 'v' with a different type: 'int' vs 'T'}} -#ifdef CXX11 +#ifndef PRECXX11 template<typename T> extern auto v; // expected-error {{declaration of variable 'v' with type 'auto' requires an initializer}} #endif @@ -112,7 +112,7 @@ namespace odr_tmpl { extern int var; // expected-error {{redefinition of 'var' as different kind of symbol}} } -#ifdef CXX11 +#ifndef PRECXX11 namespace pvt_auto { template<typename T> auto v0; // expected-error {{declaration of variable 'v0' with type 'auto' requires an initializer}} template<typename T> auto v1 = T(); // expected-note {{previous definition is here}} @@ -159,7 +159,7 @@ namespace explicit_instantiation { template CONST int pi1<int>; // expected-note {{previous explicit instantiation is here}} template CONST int pi1<int>; // expected-error {{duplicate explicit instantiation of 'pi1<int>'}} -#ifdef CXX11 +#ifndef PRECXX11 namespace auto_var { template<typename T> auto var0 = T(); template auto var0<int>; // expected-error {{'auto' variable template instantiation is not allowed}} @@ -188,7 +188,7 @@ namespace explicit_specialization { template<> CONST int pi2<int,int> = 4; -#ifdef CXX11 +#ifndef PRECXX11 void foo() { static_assert(pi2<int,int> == 4, ""); static_assert(pi2<float,int> == 2, ""); @@ -242,13 +242,13 @@ namespace explicit_specialization { T pi0 = T(3.1415926535897932385); template<> int pi0<int> = 10; // expected-note 3{{previous definition is here}} -#ifdef CXX11 +#ifndef PRECXX11 // expected-note@-2 {{previous definition is here}} #endif template<> int pi0<int> = 10; // expected-error {{redefinition of 'pi0<int>'}} template<> CONST int pi0<int> = 10; // expected-error {{redefinition of 'pi0' with a different type: 'const int' vs 'int'}} template<> float pi0<int> = 10; // expected-error {{redefinition of 'pi0' with a different type: 'float' vs 'int'}} -#ifdef CXX11 +#ifndef PRECXX11 template<> auto pi0<int> = 10; // expected-error {{redefinition of 'pi0<int>'}} #endif @@ -289,7 +289,7 @@ namespace explicit_specialization { template<typename T> CONST int pi2<T,int> = 2; } -#ifdef CXX11 +#ifndef PRECXX11 namespace auto_var { template<typename T, typename> auto var0 = T(); template<typename T> auto var0<T,int> = T(); @@ -314,7 +314,7 @@ namespace explicit_specialization { // TODO: template<typename T> T var = T(); template<typename T> T* var<T> = new T(); -#ifdef CXX11 +#ifndef PRECXX11 template<typename T> auto var<T*> = T(); // expected-note {{previous definition is here}} template<typename T> T var<T*> = T(); // expected-error {{redefinition of 'var' with a different type: 'T' vs 'auto'}} #endif @@ -323,7 +323,7 @@ namespace explicit_specialization { namespace narrowing { template<typename T> T v = {1234}; // expected-warning {{implicit conversion from 'int' to 'char' changes value from 1234 to}} -#ifdef CXX11 +#ifndef PRECXX11 // expected-error@-2 {{constant expression evaluates to 1234 which cannot be narrowed to type 'char'}}\ // expected-note@-2 {{override this message by inserting an explicit cast}} #endif @@ -338,7 +338,7 @@ namespace attributes { // TODO: } -#ifdef CXX11 +#ifndef PRECXX11 namespace arrays { template<typename T> T* arr = new T[10]{T(10), T(23)}; @@ -390,13 +390,13 @@ namespace nested { namespace n1 { template<typename T> T pi1a = T(3.1415926535897932385); -#ifdef CXX11 +#ifndef PRECXX11 // expected-note@-2 {{explicit instantiation refers here}} #endif template<typename T> T pi1b = T(3.1415926535897932385); // expected-note {{explicitly specialized declaration is here}} -#ifdef CXX11 +#ifndef PRECXX11 // expected-note@-2 {{explicit instantiation refers here}} #endif } @@ -406,7 +406,7 @@ namespace nested { int i1 = pi1a<int>; template float pi1a<float>; -#ifdef CXX11 +#ifndef PRECXX11 // expected-error@-2 {{explicit instantiation of 'pi1a<float>' not in a namespace enclosing 'n1'}} #endif float f1 = pi1a<float>; @@ -419,7 +419,7 @@ namespace nested { int i1 = n1::pi1b<int>; template float n1::pi1b<float>; -#ifdef CXX11 +#ifndef PRECXX11 // expected-error@-2 {{explicit instantiation of 'pi1b<float>' not in a namespace enclosing 'n1'}} #endif float f1 = n1::pi1b<float>; |