diff options
Diffstat (limited to 'test/SemaTemplate')
48 files changed, 594 insertions, 80 deletions
diff --git a/test/SemaTemplate/anonymous-union.cpp b/test/SemaTemplate/anonymous-union.cpp index 59d1f25..97ecd6e 100644 --- a/test/SemaTemplate/anonymous-union.cpp +++ b/test/SemaTemplate/anonymous-union.cpp @@ -17,3 +17,24 @@ struct T1 : public T0, public T { struct A : public T0 { }; void f1(T1<A> *S) { S->f0(); } // expected-note{{instantiation of member function}} + +namespace rdar8635664 { + template<typename T> + struct X { + struct inner; + + struct inner { + union { + int x; + float y; + }; + + typedef T type; + }; + }; + + void test() { + X<int>::inner i; + i.x = 0; + } +} diff --git a/test/SemaTemplate/attributes.cpp b/test/SemaTemplate/attributes.cpp index f4c1887..e208bd2 100644 --- a/test/SemaTemplate/attributes.cpp +++ b/test/SemaTemplate/attributes.cpp @@ -7,7 +7,7 @@ namespace attribute_aligned { }; template <bool X> struct check { - int check_failed[X ? 1 : -1]; // expected-error {{array size is negative}} + int check_failed[X ? 1 : -1]; // expected-error {{array with a negative size}} }; template <int N> struct check_alignment { diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index 1be1bc0..e772212 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -56,3 +56,21 @@ namespace M { } template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}} + +namespace PR8001 { + template<typename T1> + struct Foo { + template<typename T2> class Bar; + typedef Bar<T1> Baz; + + template<typename T2> + struct Bar { + Bar() {} + }; + }; + + void pr8001() { + Foo<int>::Baz x; + Foo<int>::Bar<int> y(x); + } +} diff --git a/test/SemaTemplate/class-template-id.cpp b/test/SemaTemplate/class-template-id.cpp index 50e0b00..3b02778 100644 --- a/test/SemaTemplate/class-template-id.cpp +++ b/test/SemaTemplate/class-template-id.cpp @@ -9,7 +9,7 @@ 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 'A<int> const *'}} + return ptr2; // expected-error{{cannot initialize return object of type '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> *'}} } diff --git a/test/SemaTemplate/class-template-spec.cpp b/test/SemaTemplate/class-template-spec.cpp index c65802e..07a5e29 100644 --- a/test/SemaTemplate/class-template-spec.cpp +++ b/test/SemaTemplate/class-template-spec.cpp @@ -86,7 +86,7 @@ namespace N { template<> struct N::B<int> { }; // okay -template<> struct N::B<float> { }; // expected-error{{originally}} +template<> struct N::B<float> { }; // expected-warning{{originally}} namespace M { template<> struct ::N::B<short> { }; // expected-error{{class template specialization of 'B' not in a namespace enclosing 'N'}} diff --git a/test/SemaTemplate/constructor-template.cpp b/test/SemaTemplate/constructor-template.cpp index b6ca72e..cf3fdfb 100644 --- a/test/SemaTemplate/constructor-template.cpp +++ b/test/SemaTemplate/constructor-template.cpp @@ -71,16 +71,16 @@ struct X3 { template<> X3::X3(X3); // expected-error{{must pass its first argument by reference}} struct X4 { - X4(); // expected-note{{candidate constructor}} + X4(); ~X4(); - X4(X4&); // expected-note {{candidate constructor}} + X4(X4&); template<typename T> X4(const T&, int = 17); }; X4 test_X4(bool Cond, X4 x4) { X4 a(x4, 17); // okay, constructor template X4 b(x4); // okay, copy constructor - return X4(); // expected-error{{no matching constructor}} + return X4(); } // Instantiation of a non-dependent use of a constructor @@ -109,3 +109,20 @@ void test_X5_X6() { X5<X6> tf; X5<X6> tf2(tf); } + +namespace PR8182 { + struct foo { + foo(); + template<class T> foo(T&); + + private: + foo(const foo&); + }; + + void test_foo() { + foo f1; + foo f2(f1); + foo f3 = f1; + } + +} diff --git a/test/SemaTemplate/current-instantiation.cpp b/test/SemaTemplate/current-instantiation.cpp index 8caac93..fe7213f 100644 --- a/test/SemaTemplate/current-instantiation.cpp +++ b/test/SemaTemplate/current-instantiation.cpp @@ -199,3 +199,19 @@ namespace Expressions { typename Enable_If<Is_Same<U, Class<T> >::value, void>::type Class<T>::foo() {} } + +namespace PR9255 { + template<typename T> + class X0 { + public: + class Inner1; + + class Inner2 { + public: + void f() + { + Inner1::f.g(); + } + }; + }; +} diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index 9400a0a..15c061c 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' which would make 'T const' equal 'char'}} + template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: can't deduce a type for 'T' which would make 'const T' equal 'char'}} char *char_maker(); void test() { make(char_maker); // expected-error {{no matching function for call to 'make'}} @@ -134,3 +134,19 @@ namespace test2 { f(0, p); } } + +// rdar://problem/8537391 +namespace test3 { + struct Foo { + template <void F(char)> static inline void foo(); + }; + + class Bar { + template<typename T> static inline void wobble(T ch); + + public: + static void madness() { + Foo::foo<wobble<char> >(); + } + }; +} diff --git a/test/SemaTemplate/default-expr-arguments-2.cpp b/test/SemaTemplate/default-expr-arguments-2.cpp index 88cc43d..378999d 100644 --- a/test/SemaTemplate/default-expr-arguments-2.cpp +++ b/test/SemaTemplate/default-expr-arguments-2.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s // This is a wacky test to ensure that we're actually instantiating -// the default rguments of the constructor when the function type is +// the default arguments of the constructor when the function type is // otherwise non-dependent. namespace PR6733 { template <class T> diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 7c3525a..5d301be 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -151,7 +151,7 @@ namespace pr5301 { namespace PR5810 { template<typename T> struct allocator { - allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array size is negative}} + allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array with a negative size}} }; template<typename T> @@ -206,3 +206,89 @@ namespace InstForInit { Holder<int> h(i); } }; + +namespace PR5810b { + template<typename T> + T broken() { + T t; + double**** not_it = t; + } + + void f(int = broken<int>()); + void g() { f(17); } +} + +namespace PR5810c { + template<typename T> + struct X { + X() { + T t; + double *****p = t; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}} + } + X(const X&) { } + }; + + struct Y : X<int> { // expected-note{{instantiation of}} + }; + + void f(Y y = Y()); + + void g() { f(); } +} + +namespace PR8127 { + template< typename T > class PointerClass { + public: + PointerClass( T * object_p ) : p_( object_p ) { + p_->acquire(); + } + private: + T * p_; + }; + + class ExternallyImplementedClass; + + class MyClass { + void foo( PointerClass<ExternallyImplementedClass> = 0 ); + }; +} + +namespace rdar8427926 { + template<typename T> + struct Boom { + ~Boom() { + T t; + double *******ptr = t; // expected-error 2{{cannot initialize}} + } + }; + + Boom<float> *bfp; + + struct X { + void f(Boom<int> = Boom<int>()) { } // expected-note{{requested here}} + void g(int x = (delete bfp, 0)); // expected-note{{requested here}} + }; + + void test(X *x) { + x->f(); + x->g(); + } +} + +namespace PR8401 { + template<typename T> + struct A { + A() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + }; + + template<typename T> + struct B { + B(const A<T>& a = A<T>()); // expected-note{{in instantiation of}} + }; + + void f(B<int> b = B<int>()); + + void g() { + f(); + } +} diff --git a/test/SemaTemplate/dependent-base-classes.cpp b/test/SemaTemplate/dependent-base-classes.cpp index e64d623..895eacc 100644 --- a/test/SemaTemplate/dependent-base-classes.cpp +++ b/test/SemaTemplate/dependent-base-classes.cpp @@ -105,7 +105,9 @@ namespace PR6081 { void f0(const X & k) { this->template f1<int>()(k); // expected-error{{'f1' following the 'template' keyword does not refer to a template}} \ - // FIXME: expected-error{{unqualified-id}} + // FIXME: expected-error{{unqualified-id}} \ + // expected-error{{function-style cast or type construction}} \ + // expected-error{{expected expression}} } }; } diff --git a/test/SemaTemplate/dependent-expr.cpp b/test/SemaTemplate/dependent-expr.cpp index e25afce..a1ddd24 100644 --- a/test/SemaTemplate/dependent-expr.cpp +++ b/test/SemaTemplate/dependent-expr.cpp @@ -45,3 +45,29 @@ namespace PR7724 { template<typename OT> int myMethod() { return 2 && sizeof(OT); } } + +namespace test4 { + template <typename T> T *addressof(T &v) { + return reinterpret_cast<T*>( + &const_cast<char&>(reinterpret_cast<const volatile char &>(v))); + } +} + +namespace test5 { + template <typename T> class chained_map { + int k; + void lookup() const { + int &v = (int &)k; + } + }; +} + +namespace PR8795 { + template <class _CharT> int test(_CharT t) + { + int data [] = { + sizeof(_CharT) > sizeof(char) + }; + return data[0]; + } +} diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp index 7796106..5776ddc 100644 --- a/test/SemaTemplate/dependent-names.cpp +++ b/test/SemaTemplate/dependent-names.cpp @@ -102,3 +102,30 @@ namespace test1 { template struct Derived<int>; // expected-note {{requested here}} } + +namespace PR8966 { + template <class T> + class MyClassCore + { + }; + + template <class T> + class MyClass : public MyClassCore<T> + { + public: + enum { + N + }; + + // static member declaration + static const char* array [N]; + + void f() { + MyClass<T>::InBase = 17; + } + }; + + // static member definition + template <class T> + const char* MyClass<T>::array [MyClass<T>::N] = { "A", "B", "C" }; +} diff --git a/test/SemaTemplate/elaborated-type-specifier.cpp b/test/SemaTemplate/elaborated-type-specifier.cpp index b34660a..514c5f2 100644 --- a/test/SemaTemplate/elaborated-type-specifier.cpp +++ b/test/SemaTemplate/elaborated-type-specifier.cpp @@ -34,3 +34,7 @@ namespace PR6649 { class T::bar { int x; }; // expected-error{{nested name specifier for a declaration cannot depend on a template parameter}} }; } + +namespace rdar8568507 { + template <class T> struct A *makeA(T t); +} diff --git a/test/SemaTemplate/enum-forward.cpp b/test/SemaTemplate/enum-forward.cpp new file mode 100644 index 0000000..3a4f05c --- /dev/null +++ b/test/SemaTemplate/enum-forward.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -fms-extensions %s + +template<typename T> +struct X { + enum E *e; +}; + +X<int> xi; diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index 3a1446e..ffec3c2 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -84,6 +84,10 @@ namespace explicit_instantiation_after_implicit_instantiation { template struct X0<1>; } +template<typename> struct X3 { }; +inline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}} +static template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}} + namespace PR7622 { // expected-note{{to match this}} template<typename,typename=int> struct basic_streambuf; diff --git a/test/SemaTemplate/explicit-specialization-member.cpp b/test/SemaTemplate/explicit-specialization-member.cpp index 417cdc1..7fe6bf3 100644 --- a/test/SemaTemplate/explicit-specialization-member.cpp +++ b/test/SemaTemplate/explicit-specialization-member.cpp @@ -13,11 +13,9 @@ template<> void X0<char>::f1(type); namespace PR6161 { template<typename _CharT> class numpunct : public locale::facet // expected-error{{use of undeclared identifier 'locale'}} \ - // expected-error{{expected class name}} \ - // expected-note{{attempt to specialize declaration here}} + // expected-error{{expected class name}} { static locale::id id; // expected-error{{use of undeclared identifier}} }; - numpunct<char>::~numpunct(); // expected-error{{template specialization requires 'template<>'}} \ - // expected-error{{specialization of member 'PR6161::numpunct<char>::~numpunct' does not specialize an instantiated member}} + numpunct<char>::~numpunct(); // expected-error{{expected the class name after '~' to name a destructor}} } diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 1d62804..703daea 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -93,7 +93,7 @@ namespace test4 { }; template<typename T> void f(const A<T>&) { - int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}} + int a[sizeof(T) ? -1 : -1]; // expected-error {{array with a negative size}} } void f() { @@ -207,3 +207,12 @@ namespace PR7013b { } } + +namespace PR8649 { + template<typename T, typename U, unsigned N> + struct X { + template<unsigned M> friend class X<T, U, M>; // expected-error{{partial specialization cannot be declared as a friend}} + }; + + X<int, float, 7> x; +} diff --git a/test/SemaTemplate/fun-template-def.cpp b/test/SemaTemplate/fun-template-def.cpp index 309921c..0427781 100644 --- a/test/SemaTemplate/fun-template-def.cpp +++ b/test/SemaTemplate/fun-template-def.cpp @@ -42,7 +42,7 @@ T f1(T t1, U u1, int i1) dummy d1 = sizeof(t1); // expected-error {{no viable conversion}} dummy d2 = offsetof(T, foo); // expected-error {{no viable conversion}} dummy d3 = __alignof(u1); // expected-error {{no viable conversion}} - i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'std::type_info const'}} + i1 = typeid(t1); // expected-error {{assigning to 'int' from incompatible type 'const std::type_info'}} return u1; } diff --git a/test/SemaTemplate/function-template-specialization.cpp b/test/SemaTemplate/function-template-specialization.cpp index 9afc99f..a0d41b2 100644 --- a/test/SemaTemplate/function-template-specialization.cpp +++ b/test/SemaTemplate/function-template-specialization.cpp @@ -41,3 +41,8 @@ namespace PR5833 { } template <> bool PR5833::f0<float>(float &t1) {} +// PR8295 +namespace PR8295 { + template <typename T> void f(T t) {} + template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}} +} diff --git a/test/SemaTemplate/inject-templated-friend-post.cpp b/test/SemaTemplate/inject-templated-friend-post.cpp index 98ac38e..39c445c 100644 --- a/test/SemaTemplate/inject-templated-friend-post.cpp +++ b/test/SemaTemplate/inject-templated-friend-post.cpp @@ -2,8 +2,8 @@ // RUN: %clang %s -S -emit-llvm -o - -DPROTOTYPE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" // RUN: %clang %s -S -emit-llvm -o - -DINSTANTIATE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" // RUN: %clang %s -S -emit-llvm -o - -DPROTOTYPE -DINSTANTIATE | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" -// RUN: %clang -cc1 %s -DREDEFINE -verify -// RUN: %clang -cc1 %s -DPROTOTYPE -DREDEFINE -verify +// RUN: %clang_cc1 %s -DREDEFINE -verify +// RUN: %clang_cc1 %s -DPROTOTYPE -DREDEFINE -verify // PR8007: friend function not instantiated, reordered version. // Corresponds to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392 diff --git a/test/SemaTemplate/inject-templated-friend.cpp b/test/SemaTemplate/inject-templated-friend.cpp index fbe86d9..7be613b 100644 --- a/test/SemaTemplate/inject-templated-friend.cpp +++ b/test/SemaTemplate/inject-templated-friend.cpp @@ -1,5 +1,5 @@ // RUN: %clang %s -S -emit-llvm -o - | grep -e "define linkonce_odr.*_ZlsR11std_ostreamRK8StreamerI3FooE" -// RUN: %clang -cc1 %s -DREDEFINE -verify +// RUN: %clang_cc1 %s -DREDEFINE -verify // PR8007: friend function not instantiated. struct std_ostream diff --git a/test/SemaTemplate/instantiate-anonymous-union.cpp b/test/SemaTemplate/instantiate-anonymous-union.cpp index f2862db..68b233a 100644 --- a/test/SemaTemplate/instantiate-anonymous-union.cpp +++ b/test/SemaTemplate/instantiate-anonymous-union.cpp @@ -66,3 +66,24 @@ namespace PR7402 { X x(42.0); } + +namespace PR9188 { + struct X0 { + union { + int member; + }; + }; + + static union { + int global; + }; + + struct X1 : X0 { + template<typename T> + int f() { + return this->X0::member + PR9188::global; + } + }; + + template int X1::f<int>(); +} diff --git a/test/SemaTemplate/instantiate-cast.cpp b/test/SemaTemplate/instantiate-cast.cpp index 9669b20..abf1b3c 100644 --- a/test/SemaTemplate/instantiate-cast.cpp +++ b/test/SemaTemplate/instantiate-cast.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -struct A { int x; }; +struct A { int x; }; // expected-note 2 {{candidate constructor}} class Base { public: @@ -23,7 +23,7 @@ struct Constructible { template<typename T, typename U> struct CStyleCast0 { void f(T t) { - (void)((U)t); // expected-error{{C-style cast from 'A' to 'int' is not allowed}} + (void)((U)t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}} } }; @@ -36,7 +36,7 @@ template struct CStyleCast0<A, int>; // expected-note{{instantiation}} template<typename T, typename U> struct StaticCast0 { void f(T t) { - (void)static_cast<U>(t); // expected-error{{static_cast from 'int' to 'A' is not allowed}} + (void)static_cast<U>(t); // expected-error{{no matching conversion for static_cast from 'int' to 'A'}} } }; @@ -89,7 +89,7 @@ template struct ConstCast0<int const *, float *>; // expected-note{{instantiatio template<typename T, typename U> struct FunctionalCast1 { void f(T t) { - (void)U(t); // expected-error{{functional-style cast from 'A' to 'int' is not allowed}} + (void)U(t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}} } }; diff --git a/test/SemaTemplate/instantiate-complete.cpp b/test/SemaTemplate/instantiate-complete.cpp index c13930d..4b27da7 100644 --- a/test/SemaTemplate/instantiate-complete.cpp +++ b/test/SemaTemplate/instantiate-complete.cpp @@ -11,8 +11,7 @@ struct X { // expected-error{{data member instantiated with function type 'int (int)'}} \ // expected-error{{data member instantiated with function type 'char (char)'}} \ // expected-error{{data member instantiated with function type 'short (short)'}} \ - // expected-error{{data member instantiated with function type 'float (float)'}} \ - // expected-error{{data member instantiated with function type 'long (long)'}} + // expected-error{{data member instantiated with function type 'float (float)'}} }; X<int> f() { return 0; } @@ -44,7 +43,6 @@ void test_memptr(X<long> *p1, long X<long>::*pm1, X<long(long)> *p2, long (X<long(long)>::*pm2)(long)) { (void)(p1->*pm1); - (void)((p2->*pm2)(0)); // expected-note{{in instantiation of template class 'X<long (long)>' requested here}} } // Reference binding to a base @@ -128,3 +126,23 @@ namespace pr7199 { template class B<int>; // expected-note {{in instantiation}} } + +namespace PR8425 { + template <typename T> + class BaseT {}; + + template <typename T> + class DerivedT : public BaseT<T> {}; + + template <typename T> + class FromT { + public: + operator DerivedT<T>() const { return DerivedT<T>(); } + }; + + void test() { + FromT<int> ft; + BaseT<int> bt(ft); + } +} + diff --git a/test/SemaTemplate/instantiate-default-assignment-operator.cpp b/test/SemaTemplate/instantiate-default-assignment-operator.cpp index 8b97f59..31cdef5 100644 --- a/test/SemaTemplate/instantiate-default-assignment-operator.cpp +++ b/test/SemaTemplate/instantiate-default-assignment-operator.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s template<typename> struct PassRefPtr { }; template<typename T> struct RefPtr { - RefPtr& operator=(const RefPtr&) { int a[sizeof(T) ? -1 : -1];} // expected-error 2 {{array size is negative}} + RefPtr& operator=(const RefPtr&) { int a[sizeof(T) ? -1 : -1];} // expected-error 2 {{array with a negative size}} RefPtr& operator=(const PassRefPtr<T>&); }; diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index adae1da..74eb5e5 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s // --------------------------------------------------------------------- // C++ Functional Casts @@ -46,8 +46,8 @@ template struct Temporaries0<5, 7>; // Ensure that both the constructor and the destructor are instantiated by // checking for parse errors from each. template<int N> struct BadX { - BadX() { int a[-N]; } // expected-error {{array size is negative}} - ~BadX() { int a[-N]; } // expected-error {{array size is negative}} + BadX() { int a[-N]; } // expected-error {{array with a negative size}} + ~BadX() { int a[-N]; } // expected-error {{array with a negative size}} }; template<int N> @@ -319,7 +319,7 @@ template struct NonDepMemberCall0<float&>; // expected-note{{instantiation}} template<typename T> struct QualifiedDeclRef0 { T f() { - return is_pod<X>::value; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'bool const'}} + return is_pod<X>::value; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'const bool'}} } }; diff --git a/test/SemaTemplate/instantiate-field.cpp b/test/SemaTemplate/instantiate-field.cpp index d825cd7..a148ee4 100644 --- a/test/SemaTemplate/instantiate-field.cpp +++ b/test/SemaTemplate/instantiate-field.cpp @@ -90,3 +90,15 @@ namespace PR7355 { A<int> ai; // expected-note{{in instantiation of}} } + +namespace PR8712 { + template <int dim> + class B { + public: + B(const unsigned char i); + unsigned char value : (dim > 0 ? dim : 1); + }; + + template <int dim> + inline B<dim>::B(const unsigned char i) : value(i) {} +} diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index 651c02c..dbd1e69 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s template<typename T, typename U> struct X0 { void f(T x, U y) { diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index d57ba8a..20b62c1 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -50,3 +50,18 @@ namespace local_class_with_virtual_functions { struct S { }; void test() { f<S>(); } } + +namespace PR8801 { + template<typename T> + void foo() { + class X; + typedef int (X::*pmf_type)(); + class X : public T { }; + + pmf_type pmf = &T::foo; + } + + struct Y { int foo(); }; + + template void foo<Y>(); +} diff --git a/test/SemaTemplate/instantiate-member-expr.cpp b/test/SemaTemplate/instantiate-member-expr.cpp index 188705c..a31569a 100644 --- a/test/SemaTemplate/instantiate-member-expr.cpp +++ b/test/SemaTemplate/instantiate-member-expr.cpp @@ -6,10 +6,10 @@ struct S { template<typename T> struct vector { - void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array size is negative}} + void push_back(const T&) { int a[sizeof(T) ? -1: -1]; } // expected-error {{array with a negative size}} }; -class GRExprEngine { +class ExprEngine { public: typedef vector<S<void *> >CheckersOrdered; CheckersOrdered Checkers; @@ -22,8 +22,8 @@ public: class RetainReleaseChecker { }; -void f(GRExprEngine& Eng) { - Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'GRExprEngine::registerCheck<RetainReleaseChecker>' requested here}} +void f(ExprEngine& Eng) { + Eng.registerCheck(new RetainReleaseChecker); // expected-note {{in instantiation of function template specialization 'ExprEngine::registerCheck<RetainReleaseChecker>' requested here}} } // PR 5838 @@ -49,3 +49,20 @@ namespace test1 { }; template struct O::B<int>; // expected-note {{in instantiation}} } + +// PR7248 +namespace test2 { + template <class T> struct A { + void foo() { + T::bar(); // expected-error {{type 'int' cannot}} + } + }; + + template <class T> class B { + void foo(A<T> a) { + a.test2::template A<T>::foo(); // expected-note {{in instantiation}} + } + }; + + template class B<int>; +} diff --git a/test/SemaTemplate/instantiate-member-pointers.cpp b/test/SemaTemplate/instantiate-member-pointers.cpp index dca0f62..0db90e3 100644 --- a/test/SemaTemplate/instantiate-member-pointers.cpp +++ b/test/SemaTemplate/instantiate-member-pointers.cpp @@ -61,7 +61,7 @@ namespace ValueDepMemberPointer { typedef instantiate_function<&S::instantiate> x; // expected-note{{instantiation}} }; template <typename T> void S<T>::instantiate() { - int a[(int)sizeof(T)-42]; // expected-error{{array size is negative}} + int a[(int)sizeof(T)-42]; // expected-error{{array with a negative size}} } S<int> s; } diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp index 8f4063b..e2f7275 100644 --- a/test/SemaTemplate/instantiate-member-template.cpp +++ b/test/SemaTemplate/instantiate-member-template.cpp @@ -203,3 +203,15 @@ namespace PR7669 { X<int>::Y<int>::Z<0,int>(); } } + +namespace PR8489 { + template <typename CT> + class C { + template<typename FT> + void F() {} // expected-note{{FT}} + }; + void f() { + C<int> c; + c.F(); // expected-error{{no matching member function}} + } +} diff --git a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp index cbadcde..027c1e8 100644 --- a/test/SemaTemplate/instantiate-non-type-template-parameter.cpp +++ b/test/SemaTemplate/instantiate-non-type-template-parameter.cpp @@ -34,3 +34,22 @@ namespace PR6986 { ckey_m m; } } + +namespace rdar8980215 { + enum E { E1, E2, E3 }; + + template<typename T, E e = E2> + struct X0 { + X0() {} + template<typename U> X0(const X0<U, e> &); + }; + + template<typename T> + struct X1 : X0<T> { + X1() {} + template<typename U> X1(const X1<U> &x) : X0<T>(x) { } + }; + + X1<int> x1i; + X1<float> x1f(x1i); +} diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp index e90ac52..0c06075 100644 --- a/test/SemaTemplate/instantiate-static-var.cpp +++ b/test/SemaTemplate/instantiate-static-var.cpp @@ -2,7 +2,7 @@ template<typename T, T Divisor> class X { public: - static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} + static const T value = 10 / Divisor; // expected-error{{in-class initializer is not a constant expression}} }; int array1[X<int, 2>::value == 5? 1 : -1]; @@ -11,7 +11,7 @@ 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-error{{'value' can only be initialized if it is a static const integral data member}} + static const T value = 0; // expected-warning{{in-class initializer for static data member of type 'const float' is a C++0x extension}} }; Y<float> fy; // expected-note{{in instantiation of template class 'Y<float>' requested here}} diff --git a/test/SemaTemplate/instantiate-template-template-parm.cpp b/test/SemaTemplate/instantiate-template-template-parm.cpp index f48a0c7..a70c7e8 100644 --- a/test/SemaTemplate/instantiate-template-template-parm.cpp +++ b/test/SemaTemplate/instantiate-template-template-parm.cpp @@ -44,3 +44,54 @@ template<long V> struct X3l { }; // expected-note{{different type 'long'}} X2<int, X3i> x2okay; X2<long, X3l> x2bad; // expected-note{{instantiation}} + +template <typename T, template <T, T> class TT, class R = TT<1, 2> > +struct Comp { + typedef R r1; + template <T x, T y> struct gt { + static const bool result = x > y; + }; + typedef gt<2, 1> r2; +}; + +template <int x, int y> struct lt { + static const bool result = x < y; +}; + +Comp<int, lt> c0; + +namespace PR8629 { + template<template<int> class TT> struct X0 + { + static void apply(); + }; + template<int> struct Type { }; + + template<class T> struct X1 + { + template<class U> struct Inner; + + template<class U> void g() + { + typedef Inner<U> Init; + X0<Init::template VeryInner>::apply(); + } + template<int N> void f () + { + g<Type<N> >(); + } + }; + template<class T> template<class U> struct X1<T>::Inner + { + template<int> struct VeryInner { + }; + }; + struct X1Container + { + X1Container() + { + simplex_.f<0>(); + } + X1<double> simplex_; + }; +} diff --git a/test/SemaTemplate/instantiate-try-catch.cpp b/test/SemaTemplate/instantiate-try-catch.cpp index aa809e4..f1ffd063 100644 --- a/test/SemaTemplate/instantiate-try-catch.cpp +++ b/test/SemaTemplate/instantiate-try-catch.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++0x -verify %s +// RUN: %clang_cc1 -fexceptions -fsyntax-only -std=c++0x -verify %s template<typename T> struct TryCatch0 { void f() { diff --git a/test/SemaTemplate/instantiate-using-decl.cpp b/test/SemaTemplate/instantiate-using-decl.cpp index 2579044..1bfcb7a 100644 --- a/test/SemaTemplate/instantiate-using-decl.cpp +++ b/test/SemaTemplate/instantiate-using-decl.cpp @@ -61,3 +61,22 @@ namespace test2 { template void bar(char *); } + +namespace test3 { + template <typename T> struct t { + struct s1 { + T f1() const; + }; + struct s2 : s1 { + using s1::f1; + T f1() const; + }; + }; + + void f2() + { + t<int>::s2 a; + t<int>::s2 const & b = a; + b.f1(); + } +} diff --git a/test/SemaTemplate/instantiation-default-1.cpp b/test/SemaTemplate/instantiation-default-1.cpp index 6f5a660..99154a5 100644 --- a/test/SemaTemplate/instantiation-default-1.cpp +++ b/test/SemaTemplate/instantiation-default-1.cpp @@ -36,7 +36,7 @@ typedef int& int_ref_t; Def2<int_ref_t> *d2; // expected-note{{in instantiation of default argument for 'Def2<int &>' required here}} -template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<int const>'}} +template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<const int>'}} template<typename T, typename T2 = T&> struct Def3; diff --git a/test/SemaTemplate/member-access-ambig.cpp b/test/SemaTemplate/member-access-ambig.cpp new file mode 100644 index 0000000..bf19043 --- /dev/null +++ b/test/SemaTemplate/member-access-ambig.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR8439 +class A +{ +}; + +class B +{ +public: + A & m; +}; + +class Base +{ +public: + B &f(); +}; + +class Derived1 : public Base { }; + +class Derived2 : public Base { }; + +class X : public B, public Derived2, public Derived1 +{ +public: + virtual void g(); +}; + +void X::g() +{ + m.f<int>(); // expected-error{{no member named 'f' in 'A'}} \ + // expected-error{{expected '(' for function-style cast}} \ + // expected-error{{expected expression}} +} diff --git a/test/SemaTemplate/member-access-expr.cpp b/test/SemaTemplate/member-access-expr.cpp index 16b9515..f1aa30e 100644 --- a/test/SemaTemplate/member-access-expr.cpp +++ b/test/SemaTemplate/member-access-expr.cpp @@ -132,3 +132,18 @@ namespace test5 { } }; } + +// PR8739 +namespace test6 { + struct A {}; + struct B {}; + template <class T> class Base; + template <class T> class Derived : public Base<T> { + A *field; + void get(B **ptr) { + // It's okay if at some point we figure out how to diagnose this + // at instantiation time. + *ptr = field; + } + }; +} diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index 6f51591..5be5a13 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wconversion -verify %s template<int N> struct A; // expected-note 5{{template parameter is declared here}} A<0> *a0; @@ -58,7 +58,7 @@ template<X const &AnX> struct A4; // expected-note 2{{template parameter is decl X an_X; A4<an_X> *a15_1; // okay A4<*X_volatile_ptr> *a15_2; // expected-error{{non-type template argument does not refer to any declaration}} -A4<y> *15_3; // expected-error{{non-type template parameter of reference type 'X const &' cannot bind to template argument of type 'struct Y'}} \ +A4<y> *15_3; // expected-error{{non-type template parameter of reference type 'const X &' cannot bind to template argument of type 'struct Y'}} \ // FIXME: expected-error{{expected unqualified-id}} template<int (&fr)(int)> struct A5; // expected-note{{template parameter is declared here}} @@ -87,7 +87,7 @@ template<int Z::*pm> struct A7c; A7<&Z::int_member> *a18_1; A7c<&Z::int_member> *a18_2; A7<&Z::float_member> *a18_3; // expected-error{{non-type template argument of type 'float Z::*' cannot be converted to a value of type 'int Z::*'}} -A7c<(&Z::int_member)> *a18_3; // expected-error{{non-type template argument cannot be surrounded by parentheses}} +A7c<(&Z::int_member)> *a18_4; // expected-warning{{address non-type template argument cannot be surrounded by parentheses}} template<unsigned char C> struct Overflow; // expected-note{{template parameter is declared here}} @@ -169,7 +169,8 @@ namespace pr6249 { } namespace PR6723 { - template<unsigned char C> void f(int (&a)[C]); // expected-note 2{{candidate template ignored}} + template<unsigned char C> void f(int (&a)[C]); // expected-note {{candidate template ignored}} \ + // expected-note{{candidate function [with C = '\x00'] not viable: no known conversion from 'int [512]' to 'int (&)[0]' for 1st argument}} void g() { int arr512[512]; f(arr512); // expected-error{{no matching function for call}} @@ -243,3 +244,22 @@ namespace test8 { B<&c03> b03; } } + +namespace PR8372 { + template <int I> void foo() { } // expected-note{{template parameter is declared here}} + void bar() { foo <0x80000000> (); } // expected-warning{{non-type template argument value '2147483648' truncated to '-2147483648' for template parameter of type 'int'}} +} + +namespace PR9227 { + template <bool B> struct enable_if_bool { }; + template <> struct enable_if_bool<true> { typedef int type; }; + void test_bool() { enable_if_bool<false>::type i; } // expected-error{{enable_if_bool<false>}} + + template <char C> struct enable_if_char { }; + template <> struct enable_if_char<'a'> { typedef int type; }; + void test_char_0() { enable_if_char<0>::type i; } // expected-error{{enable_if_char<'\x00'>}} + void test_char_b() { enable_if_char<'b'>::type i; } // expected-error{{enable_if_char<'b'>}} + void test_char_possibly_negative() { enable_if_char<'\x02'>::type i; } // expected-error{{enable_if_char<'\x02'>}} + void test_char_single_quote() { enable_if_char<'\''>::type i; } // expected-error{{enable_if_char<'\''>}} + void test_char_backslash() { enable_if_char<'\\'>::type i; } // expected-error{{enable_if_char<'\\'>}} +} diff --git a/test/SemaTemplate/temp_class_spec_neg.cpp b/test/SemaTemplate/temp_class_spec_neg.cpp index c8e8a57..6b129a5 100644 --- a/test/SemaTemplate/temp_class_spec_neg.cpp +++ b/test/SemaTemplate/temp_class_spec_neg.cpp @@ -9,7 +9,7 @@ namespace N { } template<typename T> -struct N::M::A<T*> { }; // expected-error{{originally}} +struct N::M::A<T*> { }; // expected-warning{{originally}} // C++ [temp.class.spec]p9 // bullet 1 diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 5a313bf..38045e0 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -117,3 +117,40 @@ namespace PR6463 { return x; } } + +namespace PR7419 { + template <typename T> struct S { + typedef typename T::Y T2; + typedef typename T2::Z T3; + typedef typename T3::W T4; + T4 *f(); + + typedef typename T::template Y<int> TT2; + typedef typename TT2::template Z<float> TT3; + typedef typename TT3::template W<double> TT4; + TT4 g(); + }; + + template <typename T> typename T::Y::Z::W *S<T>::f() { } + template <typename T> typename T::template Y<int>::template Z<float>::template W<double> S<T>::g() { } +} + +namespace rdar8740998 { + template<typename T> + struct X : public T { + using T::iterator; // expected-note{{add 'typename' to treat this using declaration as a type}} \ + // expected-error{{dependent using declaration resolved to type without 'typename'}} + + void f() { + typename X<T>::iterator i; // expected-error{{typename specifier refers to a dependent using declaration for a value 'iterator' in 'X<T>'}} + } + }; + + struct HasIterator { + typedef int *iterator; // expected-note{{target of using declaration}} + }; + + void test_X(X<HasIterator> xi) { // expected-note{{in instantiation of template class}} + xi.f(); + } +} diff --git a/test/SemaTemplate/variadic-class-template-1.cpp b/test/SemaTemplate/variadic-class-template-1.cpp deleted file mode 100644 index 6da64fb..0000000 --- a/test/SemaTemplate/variadic-class-template-1.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x - -template<typename ... Args = int> struct S1 { }; // expected-error{{template parameter pack cannot have a default argument}} -template<typename ... Args, typename T> struct S2 { }; // expected-error{{template parameter pack must be the last template parameter}} diff --git a/test/SemaTemplate/variadic-class-template-2.cpp b/test/SemaTemplate/variadic-class-template-2.cpp deleted file mode 100644 index 5099771..0000000 --- a/test/SemaTemplate/variadic-class-template-2.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x - -// Type parameters packs -template <typename ...> struct TS1 {}; // expected-note{{template parameter is declared here}} -template struct TS1<>; -template struct TS1<int>; -template struct TS1<int, int>; -template struct TS1<int, 10>; // expected-error{{template argument for template type parameter must be a type}} - -template <typename, typename ...> struct TS2 {}; // expected-note{{template is declared here}} -template struct TS2<>; // expected-error{{too few template arguments for class template 'TS2'}} -template struct TS2<int>; -template struct TS2<int, int>; - -template <typename = int, typename ...> struct TS3 {}; // expected-note{{template parameter is declared here}} -template struct TS3<>; // expected-note{{previous explicit instantiation is here}} -template struct TS3<int>; // expected-error{{duplicate explicit instantiation of 'TS3}} -template struct TS3<int, int>; -template struct TS3<10>; // expected-error{{template argument for template type parameter must be a type}} diff --git a/test/SemaTemplate/variadic-parse.cpp b/test/SemaTemplate/variadic-parse.cpp deleted file mode 100644 index d8b77b3..0000000 --- a/test/SemaTemplate/variadic-parse.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x - -// Parsing type parameter packs. -template <typename ... Args> struct T1 {}; -template <typename ... > struct T2 {}; - diff --git a/test/SemaTemplate/variadic-unsupported.cpp b/test/SemaTemplate/variadic-unsupported.cpp deleted file mode 100644 index 9f2b080..0000000 --- a/test/SemaTemplate/variadic-unsupported.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s - -// Type parameter packs. -template <typename ... > struct T1 {}; // expected-error{{variadic templates are only allowed in C++0x}} - |