diff options
Diffstat (limited to 'test/SemaTemplate')
29 files changed, 397 insertions, 50 deletions
diff --git a/test/SemaTemplate/alias-templates.cpp b/test/SemaTemplate/alias-templates.cpp index e7be184db3d6..1849ff64026b 100644 --- a/test/SemaTemplate/alias-templates.cpp +++ b/test/SemaTemplate/alias-templates.cpp @@ -201,3 +201,23 @@ namespace PR16904 { template <typename T, typename U, typename V> using derived2 = ::PR16904::base<T, U>::template derived<V>; // expected-error {{expected a type}} expected-error {{expected ';'}} } + +namespace PR14858 { + template<typename ...T> using X = int[sizeof...(T)]; + + template<typename ...U> struct Y { + using Z = X<U...>; + }; + using A = Y<int, int, int, int>::Z; + using A = int[4]; + + // FIXME: These should be treated as being redeclarations. + template<typename ...T> void f(X<T...> &) {} + template<typename ...T> void f(int(&)[sizeof...(T)]) {} + + template<typename ...T> void g(X<typename T::type...> &) {} + template<typename ...T> void g(int(&)[sizeof...(T)]) {} // ok, different + + template<typename ...T, typename ...U> void h(X<T...> &) {} + template<typename ...T, typename ...U> void h(X<U...> &) {} // ok, different +} diff --git a/test/SemaTemplate/class-template-ctor-initializer.cpp b/test/SemaTemplate/class-template-ctor-initializer.cpp index 6043327b7bab..6dae20774585 100644 --- a/test/SemaTemplate/class-template-ctor-initializer.cpp +++ b/test/SemaTemplate/class-template-ctor-initializer.cpp @@ -1,4 +1,6 @@ // 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 template<class X> struct A {}; @@ -55,7 +57,11 @@ namespace PR7259 { } namespace NonDependentError { - struct Base { Base(int); }; // expected-note 2{{candidate}} + struct Base { Base(int); }; // expected-note {{candidate constructor not viable}} +// expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-3 {{candidate constructor (the implicit move constructor) not viable}} +#endif template<typename T> struct Derived1 : Base { diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index 4f861dea7058..63482d84df0c 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -152,3 +152,10 @@ void DontCrashOnThis() { T &pT = T(); pT; } + +namespace abstract_dependent_class { + template<typename T> struct A { + virtual A<T> *clone() = 0; // expected-note {{pure virtual}} + }; + template<typename T> A<T> *A<T>::clone() { return new A<T>; } // expected-error {{abstract class type 'A<T>'}} +} diff --git a/test/SemaTemplate/class-template-id.cpp b/test/SemaTemplate/class-template-id.cpp index 5bbc70c9552c..50cb3ef59ea4 100644 --- a/test/SemaTemplate/class-template-id.cpp +++ b/test/SemaTemplate/class-template-id.cpp @@ -9,9 +9,9 @@ A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) { if (ptr) return ptr; // okay else if (ptr2) - return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'const A<int> *'}} + return ptr2; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'const A<int> *'}} else { - return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' with an lvalue of type 'A<int, double> *'}} + return ptr3; // expected-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'A<int, double> *'}} } } diff --git a/test/SemaTemplate/constructor-template.cpp b/test/SemaTemplate/constructor-template.cpp index c5306a6e32f4..ee8475b3cdb8 100644 --- a/test/SemaTemplate/constructor-template.cpp +++ b/test/SemaTemplate/constructor-template.cpp @@ -1,5 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -struct X0 { // expected-note{{candidate}} +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +struct X0 { // expected-note {{candidate constructor (the implicit copy constructor) not viable}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}} +#endif X0(int); // expected-note{{candidate}} template<typename T> X0(T); // expected-note {{candidate}} template<typename T, typename U> X0(T*, U*); // expected-note {{candidate}} diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index e33d1576da58..bf0812277d57 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -107,7 +107,7 @@ namespace PR7463 { } namespace test0 { - template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'char'}} + template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: cannot deduce a type for 'T' that would make 'const T' equal 'char'}} char *char_maker(); void test() { make(char_maker); // expected-error {{no matching function for call to 'make'}} diff --git a/test/SemaTemplate/default-arguments.cpp b/test/SemaTemplate/default-arguments.cpp index 439a30392118..740a5a9d07b3 100644 --- a/test/SemaTemplate/default-arguments.cpp +++ b/test/SemaTemplate/default-arguments.cpp @@ -1,4 +1,6 @@ // 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 template<typename T, int N = 2> struct X; // expected-note{{template is declared here}} X<int, 1> *x1; @@ -142,7 +144,10 @@ namespace PR9643 { namespace PR16288 { template<typename X> struct S { - template<typename T = int, typename U> // expected-warning {{C++11}} + template<typename T = int, typename U> +#if __cplusplus <= 199711L // C++03 or earlier modes + // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}} +#endif void f(); }; template<typename X> @@ -152,10 +157,25 @@ namespace PR16288 { namespace DR1635 { template <class T> struct X { - template <class U = typename T::type> static void f(int) {} // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} \ - // expected-warning {{C++11}} + template <class U = typename T::type> static void f(int) {} // expected-error {{type 'int' cannot be used prior to '::' because it has no members}} +#if __cplusplus <= 199711L // C++03 or earlier modes + // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}} +#endif static void f(...) {} }; int g() { X<int>::f(0); } // expected-note {{in instantiation of template class 'DR1635::X<int>' requested here}} } + +namespace NondefDecls { + template<typename T> void f1() { + int g1(int defarg = T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} + } + template void f1<int>(); // expected-note{{in instantiation of function template specialization 'NondefDecls::f1<int>' requested here}} +} + +template <typename T> +struct C { + C(T t = ); // expected-error {{expected expression}} +}; +C<int> obj; diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 14b072a1a5ee..438f5b1aa95f 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.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 + template<typename T> class C { C(int a0 = 0); }; @@ -6,6 +9,9 @@ template<> C<char>::C(int a0); struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}} +#endif template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} \ // expected-note{{passing argument to parameter 'b' here}} @@ -67,7 +73,10 @@ void test_x0(X0<int> xi) { xi.f(17); } -struct NotDefaultConstructible { // expected-note 2{{candidate}} +struct NotDefaultConstructible { // expected-note 2 {{candidate constructor (the implicit copy constructor) not viable}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}} +#endif NotDefaultConstructible(int); // expected-note 2{{candidate}} }; diff --git a/test/SemaTemplate/derived.cpp b/test/SemaTemplate/derived.cpp index cbd004cf6195..bad72b5d6766 100644 --- a/test/SemaTemplate/derived.cpp +++ b/test/SemaTemplate/derived.cpp @@ -4,8 +4,8 @@ template<typename T> class vector2 {}; template<typename T> class vector : vector2<T> {}; -template<typename T> void Foo2(vector2<const T*> V) {} // expected-note{{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'int'}} -template<typename T> void Foo(vector<const T*> V) {} // expected-note {{candidate template ignored: can't deduce a type for 'T' that would make 'const T' equal 'int'}} +template<typename T> void Foo2(vector2<const T*> V) {} // expected-note{{candidate template ignored: cannot deduce a type for 'T' that would make 'const T' equal 'int'}} +template<typename T> void Foo(vector<const T*> V) {} // expected-note {{candidate template ignored: cannot deduce a type for 'T' that would make 'const T' equal 'int'}} void test() { Foo2(vector2<int*>()); // expected-error{{no matching function for call to 'Foo2'}} diff --git a/test/SemaTemplate/fun-template-def.cpp b/test/SemaTemplate/fun-template-def.cpp index 2d515b4b155a..037747d35c0d 100644 --- a/test/SemaTemplate/fun-template-def.cpp +++ b/test/SemaTemplate/fun-template-def.cpp @@ -1,4 +1,6 @@ // 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 // Tests that dependent expressions are always allowed, whereas non-dependent // are checked as usual. @@ -9,6 +11,9 @@ namespace std { class type_info {}; } struct dummy {}; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} +#if __cplusplus >= 201103L // C++11 or later +// expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}} +#endif template<typename T> int f0(T x) { diff --git a/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp index f62ef61758a4..6e8323d1ee2c 100644 --- a/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp +++ b/test/SemaTemplate/instantiate-exception-spec-cxx11.cpp @@ -178,3 +178,11 @@ namespace Variadic { } } + +namespace NondefDecls { + template<typename T> void f1() { + int g1(int) noexcept(T::error); // expected-error{{type 'int' cannot be used prior to '::' because it has no members}} + } + template void f1<int>(); // expected-note{{in instantiation of function template specialization 'NondefDecls::f1<int>' requested here}} +} + diff --git a/test/SemaTemplate/instantiate-expr-3.cpp b/test/SemaTemplate/instantiate-expr-3.cpp index ca88b00300dc..90c322cbf373 100644 --- a/test/SemaTemplate/instantiate-expr-3.cpp +++ b/test/SemaTemplate/instantiate-expr-3.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s // --------------------------------------------------------------------- // Imaginary literals @@ -108,12 +108,41 @@ template<typename VaList, typename ArgType> struct VaArg1 { void f(int n, ...) { VaList va; - __builtin_va_start(va, n); // expected-error{{int}} + __builtin_va_start(va, n); // expected-error{{int}} expected-error{{char *}} for (int i = 0; i != n; ++i) (void)__builtin_va_arg(va, ArgType); // expected-error{{int}} - __builtin_va_end(va); // expected-error{{int}} + __builtin_va_end(va); // expected-error{{int}} expected-error{{char *}} } }; template struct VaArg1<__builtin_va_list, int>; +template struct VaArg1<__builtin_ms_va_list, int>; // expected-note{{instantiation}} template struct VaArg1<int, int>; // expected-note{{instantiation}} + +template<typename ArgType> +struct VaArg2 { + void __attribute__((ms_abi)) f(int n, ...) { + __builtin_ms_va_list va; + __builtin_ms_va_start(va, n); + for (int i = 0; i != n; ++i) + (void)__builtin_va_arg(va, ArgType); + __builtin_ms_va_end(va); + } +}; + +template struct VaArg2<int>; + +template<typename VaList, typename ArgType> +struct VaArg3 { + void __attribute__((ms_abi)) f(int n, ...) { + VaList va; + __builtin_ms_va_start(va, n); // expected-error{{int}} expected-error{{__va_list_tag}} + for (int i = 0; i != n; ++i) + (void)__builtin_va_arg(va, ArgType); // expected-error{{int}} + __builtin_ms_va_end(va); // expected-error{{int}} expected-error{{__va_list_tag}} + } +}; + +template struct VaArg3<__builtin_ms_va_list, int>; +template struct VaArg3<__builtin_va_list, int>; // expected-note{{instantiation}} +template struct VaArg3<int, int>; // expected-note{{instantiation}} diff --git a/test/SemaTemplate/instantiate-expr-6.cpp b/test/SemaTemplate/instantiate-expr-6.cpp new file mode 100644 index 000000000000..e6f7fe3f6607 --- /dev/null +++ b/test/SemaTemplate/instantiate-expr-6.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++11 -emit-llvm-only %s + +struct X { + template<typename T> static typename T::type g(T t); + template<typename T> auto f(T t) -> decltype(g(t)); + void f(...); +}; + +void test() { + X().f(0); + X().f(0); +} diff --git a/test/SemaTemplate/instantiate-function-2.cpp b/test/SemaTemplate/instantiate-function-2.cpp index f5089c962397..ffdb4c914457 100644 --- a/test/SemaTemplate/instantiate-function-2.cpp +++ b/test/SemaTemplate/instantiate-function-2.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 + template <typename T> struct S { S() { } S(T t); @@ -46,7 +49,10 @@ namespace PR9654 { namespace AliasTagDef { template<typename T> T f() { - using S = struct { // expected-warning {{C++11}} + using S = struct { +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif T g() { return T(); } diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index c0ea6a0bc870..a61af7a5af38 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -448,3 +448,30 @@ namespace PR21332 { } template void f7<int>(); } + +// rdar://23721638: Ensure that we correctly perform implicit +// conversions when instantiating the default arguments of local functions. +namespace rdar23721638 { + struct A { + A(const char *) = delete; // expected-note 2 {{explicitly marked deleted here}} + }; + + template <typename T> void foo() { + struct Inner { // expected-note {{in instantiation}} + void operator()(T a = "") {} // expected-error {{conversion function from 'const char [1]' to 'rdar23721638::A' invokes a deleted function}} + // expected-note@-1 {{passing argument to parameter 'a' here}} + // expected-note@-2 {{candidate function not viable}} + }; + Inner()(); // expected-error {{no matching function}} + } + template void foo<A>(); // expected-note 2 {{in instantiation}} + + template <typename T> void bar() { + auto lambda = [](T a = "") {}; // expected-error {{conversion function from 'const char [1]' to 'rdar23721638::A' invokes a deleted function}} + // expected-note@-1 {{passing argument to parameter 'a' here}} + // expected-note@-2 {{candidate function not viable}} + // expected-note@-3 {{conversion candidate of type}} + lambda(); // expected-error {{no matching function}} + } + template void bar<A>(); // expected-note {{in instantiation}} +} diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp index a7b3433b3544..648ee4153fdc 100644 --- a/test/SemaTemplate/instantiate-static-var.cpp +++ b/test/SemaTemplate/instantiate-static-var.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 + template<typename T, T Divisor> class X { public: @@ -11,7 +14,13 @@ X<int, 0> xi0; // expected-note{{in instantiation of template class 'X<int, 0>' template<typename T> class Y { - static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a GNU extension}} + static const T value = 0; +#if __cplusplus <= 199711L +// expected-warning@-2 {{in-class initializer for static data member of type 'const float' is a GNU extension}} +#else +// expected-error@-4 {{in-class initializer for static data member of type 'const float' requires 'constexpr' specifier}} +// expected-note@-5 {{add 'constexpr'}} +#endif }; Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}} diff --git a/test/SemaTemplate/instantiate-using-decl.cpp b/test/SemaTemplate/instantiate-using-decl.cpp index a6a4ea0e0f6d..0bbb3ca9c88c 100644 --- a/test/SemaTemplate/instantiate-using-decl.cpp +++ b/test/SemaTemplate/instantiate-using-decl.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s namespace test0 { namespace N { } @@ -104,3 +105,65 @@ namespace PR16936 { x.f(); } } + +namespace pr21923 { +template <typename> struct Base { + int field; + void method(); +}; +template <typename Scalar> struct Derived : Base<Scalar> { + using Base<Scalar>::field; + using Base<Scalar>::method; + static void m_fn1() { + // expected-error@+1 {{invalid use of member 'field' in static member function}} + (void)field; + // expected-error@+1 {{invalid use of member 'field' in static member function}} + (void)&field; + // expected-error@+1 {{call to non-static member function without an object argument}} + (void)method; + // expected-error@+1 {{call to non-static member function without an object argument}} + (void)&method; + // expected-error@+1 {{call to non-static member function without an object argument}} + method(); + (void)&Base<Scalar>::field; + (void)&Base<Scalar>::method; + } +#if __cplusplus >= 201103L + // These usages are OK in C++11 due to the unevaluated context. + enum { TheSize = sizeof(field) }; + typedef decltype(field) U; +#else + // expected-error@+1 {{invalid use of non-static data member 'field'}} + enum { TheSize = sizeof(field) }; +#endif +}; + +#if __cplusplus < 201103L +// C++98 has an extra note for TheSize. +// expected-note@+2 {{requested here}} +#endif +template class Derived<int>; // expected-note {{requested here}} + +// This is interesting because we form an UnresolvedLookupExpr in the static +// function template and an UnresolvedMemberExpr in the instance function +// template. As a result, we get slightly different behavior. +struct UnresolvedTemplateNames { + template <typename> void maybe_static(); +#if __cplusplus < 201103L + // expected-warning@+2 {{default template arguments for a function template are a C++11 extension}} +#endif + template <typename T, typename T::type = 0> static void maybe_static(); + + template <typename T> + void instance_method() { (void)maybe_static<T>(); } + template <typename T> + static void static_method() { + // expected-error@+1 {{call to non-static member function without an object argument}} + (void)maybe_static<T>(); + } +}; +void force_instantiation(UnresolvedTemplateNames x) { + x.instance_method<int>(); + UnresolvedTemplateNames::static_method<int>(); // expected-note {{requested here}} +} +} // pr21923 diff --git a/test/SemaTemplate/instantiate-var-template.cpp b/test/SemaTemplate/instantiate-var-template.cpp index bd7c43334f7d..b7b83e4afdd5 100644 --- a/test/SemaTemplate/instantiate-var-template.cpp +++ b/test/SemaTemplate/instantiate-var-template.cpp @@ -34,3 +34,9 @@ namespace InstantiationDependent { static_assert(a<sizeof(sizeof(f(T())))> == 0, ""); // expected-error {{static_assert failed}} } } + +namespace PR24483 { + template<typename> struct A; + template<typename... T> A<T...> models; + template<> struct B models<>; // expected-error {{incomplete type 'struct B'}} expected-note {{forward declaration}} +} diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 9fa59e626ee7..4f3df277d912 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -4,8 +4,8 @@ template <class T> class A { public: - void f(T a) { }// expected-note {{must qualify identifier to find this declaration in dependent base class}} - void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}} + void f(T a) { }// expected-note 2{{must qualify identifier to find this declaration in dependent base class}} + void g();// expected-note 2{{must qualify identifier to find this declaration in dependent base class}} }; template <class T> @@ -13,13 +13,13 @@ class B : public A<T> { public: void z(T a) { - f(a); // expected-warning {{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} - g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} + f(a); // expected-warning 2{{use of identifier 'f' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} + g(); // expected-warning 2{{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} } }; template class B<int>; // expected-note {{requested here}} -template class B<char>; +template class B<char>; // expected-note {{requested here}} void test() { @@ -308,7 +308,7 @@ template <typename T> struct B { struct NameFromBase { T m; }; }; // expected-no template <typename T> struct C : A<T>, B<T> { NameFromBase m; // expected-error {{member 'NameFromBase' found in multiple base classes of different types}} expected-warning {{use of identifier 'NameFromBase' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} }; -static_assert(sizeof(C<int>) == 4, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C<int>' requested here}} +static_assert(sizeof(C<int>) != 0, ""); // expected-note {{in instantiation of template class 'two_types_in_base::C<int>' requested here}} } namespace type_and_decl_in_base { diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp index 635687d4f6b7..78d09d13deea 100644 --- a/test/SemaTemplate/nested-name-spec-template.cpp +++ b/test/SemaTemplate/nested-name-spec-template.cpp @@ -1,4 +1,6 @@ // 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 { namespace M { @@ -21,8 +23,15 @@ namespace N { } M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } - M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}} - M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}} + M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } +#if __cplusplus <= 199711L + // expected-warning@-2 {{'template' keyword outside of a template}} +#endif + + M::template Promote<int> pi; +#if __cplusplus <= 199711L + // expected-warning@-2 {{'template' keyword outside of a template}} +#endif } N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } diff --git a/test/SemaTemplate/overload-candidates.cpp b/test/SemaTemplate/overload-candidates.cpp index 544d897e2449..c0abb5b17488 100644 --- a/test/SemaTemplate/overload-candidates.cpp +++ b/test/SemaTemplate/overload-candidates.cpp @@ -1,4 +1,6 @@ // 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 template<typename T> const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}} @@ -94,8 +96,11 @@ namespace PR15673 { struct a_trait : std::false_type {}; template<typename T, - typename Requires = typename std::enable_if<a_trait<T>::value>::type> // expected-warning {{C++11 extension}} - // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} + typename Requires = typename std::enable_if<a_trait<T>::value>::type> +#if __cplusplus <= 199711L + // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}} +#endif + // expected-note@-4 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} void foo() {} void bar() { foo<int>(); } // expected-error {{no matching function for call to 'foo'}} @@ -108,7 +113,10 @@ namespace PR15673 { struct a_pony : std::enable_if<some_trait<T>::value> {}; template<typename T, - typename Requires = typename a_pony<T>::type> // expected-warning {{C++11 extension}} + typename Requires = typename a_pony<T>::type> +#if __cplusplus <= 199711L + // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}} +#endif // FIXME: The source location here is poor. void baz() { } // expected-note {{candidate template ignored: substitution failure [with T = int]: no type named 'type' in 'PR15673::a_pony<int>'}} void quux() { baz<int>(); } // expected-error {{no matching function for call to 'baz'}} @@ -116,11 +124,17 @@ namespace PR15673 { // FIXME: This note doesn't make it clear which candidate we rejected. template <typename T> - using unicorns = typename std::enable_if<some_trait<T>::value>::type; // expected-warning {{C++11 extension}} - // expected-note@-1 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} + using unicorns = typename std::enable_if<some_trait<T>::value>::type; +#if __cplusplus <= 199711L + // expected-warning@-2 {{alias declarations are a C++11 extension}} +#endif + // expected-note@-4 {{candidate template ignored: disabled by 'enable_if' [with T = int]}} template<typename T, - typename Requires = unicorns<T> > // expected-warning {{C++11 extension}} + typename Requires = unicorns<T> > +#if __cplusplus <= 199711L + // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}} +#endif void wibble() {} void wobble() { wibble<int>(); } // expected-error {{no matching function for call to 'wibble'}} } diff --git a/test/SemaTemplate/partial-spec-instantiate.cpp b/test/SemaTemplate/partial-spec-instantiate.cpp index a93af5026d37..d5ecd8c1e3bf 100644 --- a/test/SemaTemplate/partial-spec-instantiate.cpp +++ b/test/SemaTemplate/partial-spec-instantiate.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// 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 // PR4607 template <class T> struct X {}; @@ -47,4 +49,9 @@ namespace rdar9169404 { }; X<bool, -1>::type value; +#if __cplusplus >= 201103L + // expected-error@-2 {{non-type template argument evaluates to -1, which cannot be narrowed to type 'bool'}} +#else + // expected-no-diagnostics +#endif } diff --git a/test/SemaTemplate/qualified-names-diag.cpp b/test/SemaTemplate/qualified-names-diag.cpp index b2df47bfff4c..06b94926c75f 100644 --- a/test/SemaTemplate/qualified-names-diag.cpp +++ b/test/SemaTemplate/qualified-names-diag.cpp @@ -1,7 +1,12 @@ // 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 std { - template<typename T> class vector { }; // expected-note{{candidate}} + template<typename T> class vector { }; // expected-note{{candidate function (the implicit copy assignment operator) not viable}} +#if __cplusplus >= 201103L // C++11 or later + // expected-note@-2 {{candidate function (the implicit move assignment operator) not viable}} +#endif } typedef int INT; diff --git a/test/SemaTemplate/recovery-crash.cpp b/test/SemaTemplate/recovery-crash.cpp index 78f6db40d5c8..02f80495bb94 100644 --- a/test/SemaTemplate/recovery-crash.cpp +++ b/test/SemaTemplate/recovery-crash.cpp @@ -35,3 +35,25 @@ namespace PR16225 { g<S>(0); // expected-note {{in instantiation of function template specialization}} } } + +namespace test1 { + template <typename> class ArraySlice {}; + class Foo; + class NonTemplateClass { + void MemberFunction(ArraySlice<Foo>, int); + template <class T> void MemberFuncTemplate(ArraySlice<T>, int); + }; + void NonTemplateClass::MemberFunction(ArraySlice<Foo> resource_data, + int now) { + // expected-note@+1 {{in instantiation of function template specialization 'test1::NonTemplateClass::MemberFuncTemplate<test1::Foo>'}} + MemberFuncTemplate(resource_data, now); + } + template <class T> + void NonTemplateClass::MemberFuncTemplate(ArraySlice<T> resource_data, int) { + // expected-error@+1 {{use of undeclared identifier 'UndeclaredMethod'}} + UndeclaredMethod(resource_data); + } + // expected-error@+2 {{out-of-line definition of 'UndeclaredMethod' does not match any declaration}} + // expected-note@+1 {{must qualify identifier to find this declaration in dependent base class}} + void NonTemplateClass::UndeclaredMethod() {} +} diff --git a/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp b/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp index 5000927d8941..548f7f8f34fb 100644 --- a/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp +++ b/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp @@ -148,3 +148,10 @@ namespace DeclMatch { template<typename T, T> int f() { return X<T>::n; } int k = f<int, 0>(); // ok, friend } + +namespace PR24921 { + enum E { e }; + template<E> void f(); + template<int> void f(int); + template<> void f<e>() {} +} diff --git a/test/SemaTemplate/temp_arg_template.cpp b/test/SemaTemplate/temp_arg_template.cpp index dec5dd37d484..4a0ed05d8799 100644 --- a/test/SemaTemplate/temp_arg_template.cpp +++ b/test/SemaTemplate/temp_arg_template.cpp @@ -1,4 +1,6 @@ // 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 template<template<typename T> class X> struct A; // expected-note 2{{previous template template parameter is here}} @@ -31,7 +33,10 @@ template<typename T> void f(int); A<f> *a9; // expected-error{{must be a class template}} // Evil digraph '<:' is parsed as '[', expect error. -A<::N::Z> *a10; // expected-error{{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} +A<::N::Z> *a10; +#if __cplusplus <= 199711L +// expected-error@-2 {{found '<::' after a template name which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}} +#endif // Do not do a digraph correction here. A<: :N::Z> *a11; // expected-error{{expected expression}} \ @@ -56,16 +61,28 @@ namespace N { } // PR12179 -template <typename Primitive, template <Primitive...> class F> // expected-warning {{variadic templates are a C++11 extension}} +template <typename Primitive, template <Primitive...> class F> +#if __cplusplus <= 199711L +// expected-warning@-2 {{variadic templates are a C++11 extension}} +#endif + struct unbox_args { typedef typename Primitive::template call<F> x; }; -template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}} +template <template <typename> class... Templates> +#if __cplusplus <= 199711L +// expected-warning@-2 {{variadic templates are a C++11 extension}} +#endif + struct template_tuple {}; template <typename T> struct identity {}; -template <template <typename> class... Templates> // expected-warning {{variadic templates are a C++11 extension}} +template <template <typename> class... Templates> +#if __cplusplus <= 199711L +// expected-warning@-2 {{variadic templates are a C++11 extension}} +#endif + template_tuple<Templates...> f7() {} void foo() { diff --git a/test/SemaTemplate/temp_class_spec_neg.cpp b/test/SemaTemplate/temp_class_spec_neg.cpp index be5fbb154ea8..1c77038ab8a9 100644 --- a/test/SemaTemplate/temp_class_spec_neg.cpp +++ b/test/SemaTemplate/temp_class_spec_neg.cpp @@ -1,15 +1,23 @@ // 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 template<typename T> struct vector; // C++ [temp.class.spec]p6: namespace N { namespace M { - template<typename T> struct A; // expected-note{{here}} + template<typename T> struct A; +#if __cplusplus <= 199711L // C++03 or earlier modes + // expected-note@-2{{explicitly specialized declaration is here}} +#endif } } template<typename T> -struct N::M::A<T*> { }; // expected-warning{{C++11 extension}} +struct N::M::A<T*> { }; +#if __cplusplus <= 199711L +// expected-warning@-2{{first declaration of class template partial specialization of 'A' outside namespace 'M' is a C++11 extension}} +#endif // C++ [temp.class.spec]p9 // bullet 1 diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 44cf966e33b5..2856c99b6ddf 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -1,4 +1,6 @@ // 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 template<typename T, typename U> struct is_same { static const bool value = false; @@ -27,8 +29,11 @@ struct make_pair { int a0[is_same<metafun_apply2<make_pair, int, float>::type, pair<int, float> >::value? 1 : -1]; int a1[is_same< - typename make_pair::template apply<int, float>, // expected-warning{{'template' keyword outside of a template}} \ - // expected-warning{{'typename' occurs outside of a template}} + typename make_pair::template apply<int, float>, +#if __cplusplus <= 199711L // C++03 and earlier modes + // expected-warning@-2 {{'template' keyword outside of a template}} + // expected-warning@-3 {{'typename' occurs outside of a template}} +#endif make_pair::apply<int, float> >::value? 1 : -1]; diff --git a/test/SemaTemplate/typename-specifier.cpp b/test/SemaTemplate/typename-specifier.cpp index 602e9030636d..b36a103b65ae 100644 --- a/test/SemaTemplate/typename-specifier.cpp +++ b/test/SemaTemplate/typename-specifier.cpp @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused -fms-compatibility -DMSVC +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -Wno-unused +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s -Wno-unused -fms-compatibility -DMSVC +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -Wno-unused +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -Wno-unused -fms-compatibility -DMSVC namespace N { struct A { typedef int type; @@ -16,22 +20,38 @@ namespace N { int i; -typename N::A::type *ip1 = &i; // expected-warning{{'typename' occurs outside of a template}} -typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} \ -// expected-warning{{'typename' occurs outside of a template}} -typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} \ -// expected-warning{{'typename' occurs outside of a template}} +typename N::A::type *ip1 = &i; +#if __cplusplus <= 199711L // C++03 or earlier modes +// expected-warning@-2 {{'typename' occurs outside of a template}} +#endif +typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} +#if __cplusplus <= 199711L +// expected-warning@-2 {{'typename' occurs outside of a template}} +#endif +typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} +#if __cplusplus <= 199711L +// expected-warning@-2 {{'typename' occurs outside of a template}} +#endif void test(double d) { - typename N::A::type f(typename N::A::type(a)); // expected-warning{{disambiguated as a function declaration}} \ - // expected-note{{add a pair of parentheses}} expected-warning 2{{'typename' occurs outside of a template}} + typename N::A::type f(typename N::A::type(a)); // expected-warning{{disambiguated as a function declaration}} + // expected-note@-1 {{add a pair of parentheses}} +#if __cplusplus <= 199711L + // expected-warning@-3 2{{'typename' occurs outside of a template}} +#endif int five = f(5); using namespace N; - for (typename A::type i = 0; i < 10; ++i) // expected-warning{{'typename' occurs outside of a template}} + for (typename A::type i = 0; i < 10; ++i) +#if __cplusplus <= 199711L +// expected-warning@-2 {{'typename' occurs outside of a template}} +#endif five += 1; - const typename N::A::type f2(d); // expected-warning{{'typename' occurs outside of a template}} + const typename N::A::type f2(d); +#if __cplusplus <= 199711L +// expected-warning@-2 {{'typename' occurs outside of a template}} +#endif } namespace N { |
