diff options
author | Larisse Voufo <lvoufo@google.com> | 2013-08-22 00:59:14 +0000 |
---|---|---|
committer | Larisse Voufo <lvoufo@google.com> | 2013-08-22 00:59:14 +0000 |
commit | 72caf2bb6bae001319d1b0d924821442d13bf541 (patch) | |
tree | df17618b6cb9891264c691f27e5467d281172479 /clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | |
parent | 6c46216daff59623f20a2a389ebd1eea39cdf376 (diff) | |
download | bcm5719-llvm-72caf2bb6bae001319d1b0d924821442d13bf541.tar.gz bcm5719-llvm-72caf2bb6bae001319d1b0d924821442d13bf541.zip |
Refactor for clarity and simplicity.
llvm-svn: 188974
Diffstat (limited to 'clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp')
-rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | 112 |
1 files changed, 57 insertions, 55 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'}} |