diff options
Diffstat (limited to 'clang/test/CXX/temp')
4 files changed, 94 insertions, 22 deletions
diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp index 4fbc45a7d7d..21399b62046 100644 --- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp @@ -1,4 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + // This test creates cases where implicit instantiations of various entities // would cause a diagnostic, but provides expliict specializations for those @@ -16,7 +19,10 @@ struct NonDefaultConstructible { // -- function template namespace N0 { - template<typename T> void f0(T) { // expected-note{{here}} + template<typename T> void f0(T) { +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif T t; } @@ -36,7 +42,11 @@ namespace N1 { template<> void N0::f0(long) { } // expected-error{{does not enclose namespace}} } -template<> void N0::f0(double); // expected-warning{{C++11 extension}} +template<> void N0::f0(double); +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of function template specialization of 'f0' outside namespace 'N0' is a C++11 extension}} +#endif + template<> void N0::f0(double) { } struct X1 { @@ -49,21 +59,39 @@ struct X1 { namespace N0 { template<typename T> -struct X0 { // expected-note 2{{here}} - static T member; // expected-note{{here}} +struct X0 { // expected-note {{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L +// expected-note@-2 {{explicitly specialized declaration is here}} +#endif + static T member; +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif - void f1(T t) { // expected-note{{explicitly specialized declaration is here}} + void f1(T t) { +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif t = 17; } - struct Inner : public T { }; // expected-note 3{{here}} + struct Inner : public T { }; // expected-note 2{{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif template<typename U> - struct InnerTemplate : public T { }; // expected-note 2{{explicitly specialized}} \ - // expected-error{{base specifier}} + struct InnerTemplate : public T { }; // expected-note {{explicitly specialized declaration is here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif + // expected-error@-4 {{base specifier must name a class}} template<typename U> - void ft1(T t, U u); // expected-note{{explicitly specialized}} + void ft1(T t, U u); +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif }; } @@ -76,7 +104,10 @@ void N0::X0<T>::ft1(T t, U u) { template<typename T> T N0::X0<T>::member; -template<> struct N0::X0<void> { }; // expected-warning{{C++11 extension}} +template<> struct N0::X0<void> { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'X0' outside namespace 'N0' is a C++11 extension}} +#endif N0::X0<void> test_X0; namespace N1 { @@ -92,7 +123,10 @@ template<> struct N0::X0<volatile void> { }; // -- member function of a class template -template<> void N0::X0<void*>::f1(void *) { } // expected-warning{{member function specialization}} +template<> void N0::X0<void*>::f1(void *) { } +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of member function specialization of 'f1' outside namespace 'N0' is a C++11 extension}} +#endif void test_spec(N0::X0<void*> xvp, void *vp) { xvp.f1(vp); @@ -125,7 +159,10 @@ NonDefaultConstructible &get_static_member() { return N0::X0<NonDefaultConstructible>::member; } -template<> int N0::X0<int>::member; // expected-warning{{C++11 extension}} +template<> int N0::X0<int>::member; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of static data member specialization of 'member' outside namespace 'N0' is a C++11 extension}} +#endif template<> float N0::X0<float>::member = 3.14f; @@ -153,7 +190,10 @@ namespace N0 { } template<> -struct N0::X0<long>::Inner { }; // expected-warning{{C++11 extension}} +struct N0::X0<long>::Inner { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of member class specialization of 'Inner' outside namespace 'N0' is a C++11 extension}} +#endif template<> struct N0::X0<float>::Inner { }; @@ -192,7 +232,10 @@ template<> template<> struct N0::X0<int>::InnerTemplate<long> { }; // okay template<> template<> -struct N0::X0<int>::InnerTemplate<float> { }; // expected-warning{{class template specialization}} +struct N0::X0<int>::InnerTemplate<float> { }; +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'InnerTemplate' outside namespace 'N0' is a C++11 extension}} +#endif namespace N1 { template<> template<> @@ -224,7 +267,10 @@ template<> template<> void N0::X0<void*>::ft1(void *, unsigned) { } // okay template<> template<> -void N0::X0<void*>::ft1(void *, float) { } // expected-warning{{function template specialization}} +void N0::X0<void*>::ft1(void *, float) { } +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of function template specialization of 'ft1' outside namespace 'N0' is a C++11 extension}} +#endif namespace N1 { template<> template<> diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp index c8b7def5a44..d82691c7c86 100644 --- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp @@ -1,14 +1,20 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace N { - template<class T> class X; // expected-note {{'N::X' declared here}} \ - // expected-note {{explicitly specialized declaration is here}} + template<class T> class X; // expected-note {{'N::X' declared here}} +#if __cplusplus <= 199711L + // expected-note@-2 {{explicitly specialized declaration is here}} +#endif } // TODO: Don't add a namespace qualifier to the template if it would trigger // the warning about the specialization being outside of the namespace. -template<> class X<int> { /* ... */ }; // expected-error {{no template named 'X'; did you mean 'N::X'?}} \ - // expected-warning {{first declaration of class template specialization of 'X' outside namespace 'N' is a C++11 extension}} +template<> class X<int> { /* ... */ }; // expected-error {{no template named 'X'; did you mean 'N::X'?}} +#if __cplusplus <= 199711L +// expected-warning@-2 {{first declaration of class template specialization of 'X' outside namespace 'N' is a C++11 extension}} +#endif namespace N { diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp index 1dfcf0ce2d2..027022176f8 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p2.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++98 -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -std=c++11 %s // Example from the standard template<class T> class Array { void mf() { } }; @@ -39,5 +41,16 @@ namespace N { } using namespace N; -template struct X1<int>; // expected-warning{{must occur in}} -template void f1(int); // expected-warning{{must occur in}} +template struct X1<int>; +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::X1' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::X1' must occur in namespace 'N'}} +#endif + +template void f1(int); +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::f1' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::f1' must occur in namespace 'N'}} +#endif diff --git a/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp b/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp index 8422c519a76..ca1f9a391ed 100644 --- a/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.explicit/p5.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wc++11-compat %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s namespace N { template<class T> class Y { // expected-note{{explicit instantiation refers here}} @@ -11,7 +13,12 @@ template class Z<int>; // expected-error{{explicit instantiation of non-template // FIXME: This example from the standard is wrong; note posted to CWG reflector // on 10/27/2009 using N::Y; -template class Y<int>; // expected-warning{{must occur in}} +template class Y<int>; +#if __cplusplus <= 199711L +// expected-warning@-2 {{explicit instantiation of 'N::Y' must occur in namespace 'N'}} +#else +// expected-error@-4 {{explicit instantiation of 'N::Y' must occur in namespace 'N'}} +#endif template class N::Y<char*>; template void N::Y<double>::mf(); |