diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-04-02 08:55:10 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-04-02 08:55:10 +0000 |
commit | 11d2b2d2bb706fca0656f2760839721bb7f6cb6f (patch) | |
tree | d374cdca417e76f1bf101f139dba2db1d10ee8f7 /test/SemaTemplate | |
parent | c0c7bca4e5b8d12699dc93a0da49e9e4bb79671b (diff) |
Notes
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r-- | test/SemaTemplate/dependent-base-classes.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/friend-template.cpp | 8 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-declref.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-elab-type-specifier.cpp | 13 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-expr-4.cpp | 13 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-function-params.cpp | 57 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-init.cpp | 18 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-member-class.cpp | 30 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-member-initializers.cpp | 6 | ||||
-rw-r--r-- | test/SemaTemplate/instantiation-default-2.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_nontype.cpp | 33 |
11 files changed, 162 insertions, 22 deletions
diff --git a/test/SemaTemplate/dependent-base-classes.cpp b/test/SemaTemplate/dependent-base-classes.cpp index 600115b56530..d0dd9c98fa71 100644 --- a/test/SemaTemplate/dependent-base-classes.cpp +++ b/test/SemaTemplate/dependent-base-classes.cpp @@ -55,7 +55,7 @@ namespace PR6031 { template<typename T> struct NoDepBase { int foo() { - class NoDepBase::Nested nested; // expected-error{{'Nested' does not name a tag member in the specified scope}} + class NoDepBase::Nested nested; // expected-error{{no class named 'Nested' in 'NoDepBase<T>'}} typedef typename NoDepBase::template MemberTemplate<T>::type type; // expected-error{{'MemberTemplate' following the 'template' keyword does not refer to a template}} \ // FIXME: expected-error{{unqualified-id}} return NoDepBase::a; // expected-error{{no member named 'a' in 'NoDepBase<T>'}} diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 8bc2631e119f..6ee30aa7775a 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -74,12 +74,16 @@ namespace test3 { template<typename T> class X3 { template<typename U, U Value> friend struct X2a; - template<typename U, T Value> friend struct X2b; + + // FIXME: the redeclaration note ends up here because redeclaration + // lookup ends up finding the friend target from X3<int>. + template<typename U, T Value> friend struct X2b; // expected-error {{template non-type parameter has a different type 'long' in template redeclaration}} \ + // expected-note {{previous non-type template parameter with type 'int' is here}} }; X3<int> x3i; // okay - X3<long> x3l; // FIXME: should cause an instantiation-time failure + X3<long> x3l; // expected-note {{in instantiation}} } // PR5716 diff --git a/test/SemaTemplate/instantiate-declref.cpp b/test/SemaTemplate/instantiate-declref.cpp index f883b9361b66..2d27075bd41f 100644 --- a/test/SemaTemplate/instantiate-declref.cpp +++ b/test/SemaTemplate/instantiate-declref.cpp @@ -36,7 +36,7 @@ namespace N { typedef int INT; template struct N::Outer::Inner::InnerTemplate<INT>::VeryInner; -template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{'UeberInner' does not name a tag member}} +template struct N::Outer::Inner::InnerTemplate<INT>::UeberInner; // expected-error{{no struct named 'UeberInner' in 'N::Outer::Inner::InnerTemplate<int>'}} namespace N2 { struct Outer2 { diff --git a/test/SemaTemplate/instantiate-elab-type-specifier.cpp b/test/SemaTemplate/instantiate-elab-type-specifier.cpp new file mode 100644 index 000000000000..e5e10a85cf2f --- /dev/null +++ b/test/SemaTemplate/instantiate-elab-type-specifier.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR5681 +template <class T> struct Base { + struct foo {}; + int foo; +}; + +template <class T> struct Derived : Base<T> { + typedef struct Base<T>::foo type; +}; + +template struct Derived<int>; diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index 92915c7daf17..8cd7342e98eb 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -43,6 +43,19 @@ struct Temporaries0 { 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}} +}; + +template<int N> +struct PR6671 { + void f() { (void)BadX<1>(); } // expected-note 2 {{instantiation}} +}; +template struct PR6671<1>; + // --------------------------------------------------------------------- // new/delete expressions // --------------------------------------------------------------------- diff --git a/test/SemaTemplate/instantiate-function-params.cpp b/test/SemaTemplate/instantiate-function-params.cpp new file mode 100644 index 000000000000..ea8dd7061988 --- /dev/null +++ b/test/SemaTemplate/instantiate-function-params.cpp @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR6619 +template<bool C> struct if_c { }; +template<typename T1> struct if_ { + typedef if_c< static_cast<bool>(T1::value)> almost_type_; // expected-note 7{{in instantiation}} +}; +template <class Model, void (Model::*)()> struct wrap_constraints { }; +template <class Model> +inline char has_constraints_(Model* , // expected-note 4{{while substituting deduced template arguments into function template 'has_constraints_' [with }} \ + // expected-note 3{{candidate template ignored}} + wrap_constraints<Model,&Model::constraints>* = 0); // expected-note 4{{in instantiation}} + +template <class Model> struct not_satisfied { + static const bool value = sizeof( has_constraints_((Model*)0) == 1); // expected-error 3{{no matching function}} +}; +template <class ModelFn> struct requirement_; +template <void(*)()> struct instantiate { +}; +template <class Model> struct requirement_<void(*)(Model)> : if_< not_satisfied<Model> >::type { // expected-error 3{{no type named}} \ + // expected-note 7{{in instantiation}} +}; +template <class Model> struct usage_requirements { +}; +template < typename TT > struct InputIterator { + typedef instantiate< & requirement_<void(*)(usage_requirements<InputIterator> x)>::failed> boost_concept_check1; // expected-note 2{{in instantiation}} +}; +template < typename TT > struct ForwardIterator : InputIterator<TT> { // expected-note 2{{in instantiation}} + typedef instantiate< & requirement_<void(*)(usage_requirements<ForwardIterator> x)>::failed> boost_concept_check2; // expected-note 2 {{in instantiation}} + +}; +typedef instantiate< &requirement_<void(*)(ForwardIterator<char*> x)>::failed> boost_concept_checkX; // expected-error{{no member named}} \ +// expected-note 6{{in instantiation}} + +template<typename T> struct X0 { }; +template<typename R, typename A1> struct X0<R(A1 param)> { }; + +template<typename T, typename A1, typename A2> +void instF0(X0<T(A1)> x0a, X0<T(A2)> x0b) { + X0<T(A1)> x0c; + X0<T(A2)> x0d; +} + +template void instF0<int, int, float>(X0<int(int)>, X0<int(float)>); + +template<typename R, typename A1, R (*ptr)(A1)> struct FuncPtr { }; +template<typename A1, int (*ptr)(A1)> struct FuncPtr<int, A1, ptr> { }; + +template<typename R, typename A1> R unary_func(A1); + +template<typename R, typename A1, typename A2> +void use_func_ptr() { + FuncPtr<R, A1, &unary_func<R, A1> > fp1; + FuncPtr<R, A2, &unary_func<R, A2> > fp2; +}; + +template void use_func_ptr<int, float, double>(); diff --git a/test/SemaTemplate/instantiate-init.cpp b/test/SemaTemplate/instantiate-init.cpp index 16ecc4758ab5..e292aa3c5f76 100644 --- a/test/SemaTemplate/instantiate-init.cpp +++ b/test/SemaTemplate/instantiate-init.cpp @@ -37,3 +37,21 @@ namespace PR6457 { }; B<int> b; } + +namespace PR6657 { + struct X + { + X (int, int) { } + }; + + template <typename> + void f0() + { + X x = X(0, 0); + } + + void f1() + { + f0<int>(); + } +} diff --git a/test/SemaTemplate/instantiate-member-class.cpp b/test/SemaTemplate/instantiate-member-class.cpp index 5d69b50a7606..44f396e47af7 100644 --- a/test/SemaTemplate/instantiate-member-class.cpp +++ b/test/SemaTemplate/instantiate-member-class.cpp @@ -50,3 +50,33 @@ namespace test1 { Registry<int>::node node(0); } } + +// Redeclarations during explicit instantiations. +namespace test2 { + template <typename T> class A { + class Foo; + class Foo { + int foo(); + }; + }; + template class A<int>; + + template <typename T> class B { + class Foo; + class Foo { + typedef int X; + }; + typename Foo::X x; + class Foo; + }; + template class B<int>; + + template <typename T> class C { + class Foo; + class Foo; + }; + template <typename T> class C<T>::Foo { + int x; + }; + template class C<int>; +} diff --git a/test/SemaTemplate/instantiate-member-initializers.cpp b/test/SemaTemplate/instantiate-member-initializers.cpp index eecb445ea923..e0594347f262 100644 --- a/test/SemaTemplate/instantiate-member-initializers.cpp +++ b/test/SemaTemplate/instantiate-member-initializers.cpp @@ -10,14 +10,14 @@ A<int> a0; A<void*> a1; // expected-note{{in instantiation of member function 'A<void *>::A' requested here}} template<typename T> struct B { - // FIXME: This should warn about initialization order - B() : b(1), a(2) { } + B() : b(1), // expected-warning {{member 'b' will be initialized after}} + a(2) { } // expected-note {{field a}} int a; int b; }; -B<int> b0; +B<int> b0; // expected-note {{in instantiation of member function 'B<int>::B' requested here}} template <class T> struct AA { AA(int); }; template <class T> class BB : public AA<T> { diff --git a/test/SemaTemplate/instantiation-default-2.cpp b/test/SemaTemplate/instantiation-default-2.cpp index 4d6756eca376..5a744a0c384a 100644 --- a/test/SemaTemplate/instantiation-default-2.cpp +++ b/test/SemaTemplate/instantiation-default-2.cpp @@ -13,6 +13,6 @@ Constant<int*, &x> *c3; Constant<float (*)(int, double), f> *c4; Constant<float (*)(int, double), &f> *c5; -Constant<float (*)(int, int), f> *c6; // expected-error{{non-type template argument of type 'float (*)(int, double)' cannot be converted to a value of type 'float (*)(int, int)'}} +Constant<float (*)(int, int), f> *c6; // expected-error{{non-type template argument of type 'float (int, double)' cannot be converted to a value of type 'float (*)(int, int)'}} Constant<float, 0> *c7; // expected-note{{while substituting}} diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index 9c20f2a0eb1e..6e4f751d47d1 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -47,10 +47,8 @@ A3<h> *a14_1; A3<&h> *a14_2; A3<f> *a14_3; A3<&f> *a14_4; -A3<h2> *a14_6; // expected-error{{non-type template argument of type 'float (*)(float)' cannot be converted to a value of type 'int (*)(int)'}} -A3<g> *a14_7; // expected-error{{non-type template argument of type '<overloaded function type>' cannot be converted to a value of type 'int (*)(int)'}} -// FIXME: the first error includes the string <overloaded function -// type>, which makes Doug slightly unhappy. +A3<h2> *a14_6; // expected-error{{non-type template argument of type 'float (float)' cannot be converted to a value of type 'int (*)(int)'}} +A3<g> *a14_7; // expected-error{{overloaded function cannot be resolved to a non-type template parameter of type 'int (*)(int)'}} struct Y { } y; @@ -59,17 +57,15 @@ volatile X * X_volatile_ptr; template<X const &AnX> struct A4; // expected-note 2{{template parameter is declared here}} X an_X; A4<an_X> *a15_1; // okay -A4<*X_volatile_ptr> *a15_2; // expected-error{{reference binding of non-type template parameter of type 'X const &' to template argument of type 'X volatile' ignores qualifiers}} +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'}} \ // FIXME: expected-error{{expected unqualified-id}} template<int (&fr)(int)> struct A5; // expected-note 2{{template parameter is declared here}} A5<h> *a16_1; A5<f> *a16_3; -A5<h2> *a16_6; // expected-error{{non-type template argument of type 'float (float)' cannot be converted to a value of type 'int (&)(int)'}} -A5<g> *a14_7; // expected-error{{non-type template argument of type '<overloaded function type>' cannot be converted to a value of type 'int (&)(int)'}} -// FIXME: the first error includes the string <overloaded function -// type>, which makes Doug slightly unhappy. +A5<h2> *a16_6; // expected-error{{non-type template parameter of reference type 'int (&)(int)' cannot bind to template argument of type 'float (float)'}} +A5<g> *a14_7; // expected-error{{overloaded function cannot be resolved to a non-type template parameter of type 'int (&)(int)'}} struct Z { int foo(int); @@ -97,21 +93,21 @@ template<unsigned char C> struct Overflow; // expected-note{{template parameter Overflow<5> *overflow1; // okay Overflow<255> *overflow2; // okay -Overflow<256> *overflow3; // expected-error{{non-type template argument value '256' is too large for template parameter of type 'unsigned char'}} +Overflow<256> *overflow3; // expected-warning{{non-type template argument value '256' truncated to '0' for template parameter of type 'unsigned char'}} template<unsigned> struct Signedness; // expected-note{{template parameter is declared here}} Signedness<10> *signedness1; // okay -Signedness<-10> *signedness2; // expected-error{{non-type template argument provides negative value '-10' for unsigned template parameter of type 'unsigned int'}} +Signedness<-10> *signedness2; // expected-warning{{non-type template argument with value '-10' converted to '4294967286' for unsigned template parameter of type 'unsigned int'}} template<signed char C> struct SignedOverflow; // expected-note 3 {{template parameter is declared here}} SignedOverflow<1> *signedoverflow1; SignedOverflow<-1> *signedoverflow2; SignedOverflow<-128> *signedoverflow3; -SignedOverflow<-129> *signedoverflow4; // expected-error{{non-type template argument value '-129' is too large for template parameter of type 'signed char'}} +SignedOverflow<-129> *signedoverflow4; // expected-warning{{non-type template argument value '-129' truncated to '127' for template parameter of type 'signed char'}} SignedOverflow<127> *signedoverflow5; -SignedOverflow<128> *signedoverflow6; // expected-error{{non-type template argument value '128' is too large for template parameter of type 'signed char'}} -SignedOverflow<(unsigned char)128> *signedoverflow7; // expected-error{{non-type template argument value '128' is too large for template parameter of type 'signed char'}} +SignedOverflow<128> *signedoverflow6; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}} +SignedOverflow<(unsigned char)128> *signedoverflow7; // expected-warning{{non-type template argument value '128' truncated to '-128' for template parameter of type 'signed char'}} // Check canonicalization of template arguments. template<int (*)(int, int)> struct FuncPtr0; @@ -171,3 +167,12 @@ namespace pr6249 { int h(); template int f<int, h>(); } + +namespace PR6723 { + template<unsigned char C> void f(int (&a)[C]); // expected-note 2{{candidate template ignored}} + void g() { + int arr512[512]; + f(arr512); // expected-error{{no matching function for call}} + f<512>(arr512); // expected-error{{no matching function for call}} + } +} |