diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
commit | 4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2 (patch) | |
tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /test/SemaTemplate | |
parent | d7279c4c177bca357ef96ff1379fd9bc420bfe83 (diff) |
Notes
Diffstat (limited to 'test/SemaTemplate')
19 files changed, 260 insertions, 19 deletions
diff --git a/test/SemaTemplate/array-to-pointer-decay.cpp b/test/SemaTemplate/array-to-pointer-decay.cpp new file mode 100644 index 0000000000000..072c0e52edc6d --- /dev/null +++ b/test/SemaTemplate/array-to-pointer-decay.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct mystruct { + int member; +}; + +template <int i> +int foo() { + mystruct s[1]; + return s->member; +} + +int main() { + foo<1>(); +} + +// PR7405 +struct hb_sanitize_context_t { + int start; +}; +template <typename Type> static bool sanitize() { + hb_sanitize_context_t c[1]; + return !c->start; +} +bool closure = sanitize<int>(); diff --git a/test/SemaTemplate/attributes.cpp b/test/SemaTemplate/attributes.cpp index b696c5cd98401..f4c1887c25e2c 100644 --- a/test/SemaTemplate/attributes.cpp +++ b/test/SemaTemplate/attributes.cpp @@ -1,8 +1,21 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -template<int N> -struct X { - struct __attribute__((__aligned__((N)))) Aligned { }; // expected-error{{'aligned' attribute requires integer constant}} +namespace attribute_aligned { + template<int N> + struct X { + char c[1] __attribute__((__aligned__((N)))); // expected-error {{alignment is not a power of 2}} + }; - int __attribute__((__address_space__(N))) *ptr; // expected-error{{attribute requires 1 argument(s)}} -}; + template <bool X> struct check { + int check_failed[X ? 1 : -1]; // expected-error {{array size is negative}} + }; + + template <int N> struct check_alignment { + typedef check<N == sizeof(X<N>)> t; // expected-note {{in instantiation}} + }; + + check_alignment<1>::t c1; + check_alignment<2>::t c2; + check_alignment<3>::t c3; // expected-note 2 {{in instantiation}} + check_alignment<4>::t c4; +} diff --git a/test/SemaTemplate/class-template-ctor-initializer.cpp b/test/SemaTemplate/class-template-ctor-initializer.cpp index fd9417c795f6f..81a5e2b9c6624 100644 --- a/test/SemaTemplate/class-template-ctor-initializer.cpp +++ b/test/SemaTemplate/class-template-ctor-initializer.cpp @@ -31,3 +31,25 @@ struct TmplD : Tmpl<char>, TmplB<char> { TmplB<char>() {} }; +namespace PR7259 { + class Base { + public: + Base() {} + }; + + template <class ParentClass> + class Derived : public ParentClass { + public: + Derived() : Base() {} + }; + + class Final : public Derived<Base> { + }; + + int + main (void) + { + Final final(); + return 0; + } +} diff --git a/test/SemaTemplate/deduction.cpp b/test/SemaTemplate/deduction.cpp index 8d00bb796e946..25ffb67492a56 100644 --- a/test/SemaTemplate/deduction.cpp +++ b/test/SemaTemplate/deduction.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // Template argument deduction with template template parameters. template<typename T, template<T> class A> @@ -98,3 +98,10 @@ namespace PR6257 { void f(const X<A>& a); void test(A& a) { (void)f(a); } } + +// PR7463 +namespace PR7463 { + const int f (); // expected-warning{{type qualifier on return type has no effect}} + template <typename T_> void g (T_&); // expected-note{{T_ = int}} + void h (void) { g(f()); } // expected-error{{no matching function for call}} +} diff --git a/test/SemaTemplate/dependent-type-identity.cpp b/test/SemaTemplate/dependent-type-identity.cpp index feffdcf369599..731013c86387e 100644 --- a/test/SemaTemplate/dependent-type-identity.cpp +++ b/test/SemaTemplate/dependent-type-identity.cpp @@ -86,3 +86,15 @@ namespace PR6851 { template <bool w> S< S<w>::cond && 1 > N::foo() { } } + +namespace PR7460 { + template <typename T> + struct TemplateClass2 + { + enum { SIZE = 100 }; + static T member[SIZE]; + }; + + template <typename T> + T TemplateClass2<T>::member[TemplateClass2<T>::SIZE]; +} diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index fa1b3e0001c48..6fe7f69cdd5fd 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -40,3 +40,13 @@ namespace cvquals { template void f<const volatile int>(int *); } + +namespace PR7239 { + template<class E> class A { }; + class B { + void f() { + A<int>* x; + x->A<int>::~A<int>(); + } + }; +} diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp index 1f6ede67a5225..999521e91e5f2 100644 --- a/test/SemaTemplate/example-dynarray.cpp +++ b/test/SemaTemplate/example-dynarray.cpp @@ -1,4 +1,4 @@ -// RUN: %clang -emit-llvm -S -o %t %s +// RUN: %clangxx -emit-llvm -c -o - %s #include <stddef.h> #include <stdlib.h> #include <assert.h> diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index de51f0992baa3..3a1446e8dd673 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -83,3 +83,16 @@ namespace explicit_instantiation_after_implicit_instantiation { void test1() { (void)&X0<1>::x; } template struct X0<1>; } + +namespace PR7622 { // expected-note{{to match this}} + template<typename,typename=int> + struct basic_streambuf; + + // FIXME: Very poor recovery here. + template<typename,typename> + struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \ + // expected-error{{ expected member name or ';' after declaration specifiers}} + template struct basic_streambuf<int>; // expected-error{{explicit instantiation of 'basic_streambuf' in class scope}} +} // expected-error{{expected ';' after struct}} + +//expected-error{{expected '}'}} diff --git a/test/SemaTemplate/ext-vector-type.cpp b/test/SemaTemplate/ext-vector-type.cpp index 3973102b92e7b..7334e88e9267d 100644 --- a/test/SemaTemplate/ext-vector-type.cpp +++ b/test/SemaTemplate/ext-vector-type.cpp @@ -20,7 +20,7 @@ int test_make2() { template<typename T, unsigned Length> struct make3 { - typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector type 's'}} + typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}} }; struct s {}; @@ -42,7 +42,7 @@ int test_make4() { typedef int* int_ptr; template<unsigned Length> struct make5 { - typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector type}} + typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}} }; template<int Length> diff --git a/test/SemaTemplate/instantiate-field.cpp b/test/SemaTemplate/instantiate-field.cpp index a260635778ca2..d825cd7cc613c 100644 --- a/test/SemaTemplate/instantiate-field.cpp +++ b/test/SemaTemplate/instantiate-field.cpp @@ -81,3 +81,12 @@ namespace PR7123 { sort(x,x); } } + +namespace PR7355 { + template<typename T1> class A { + class D; // expected-note{{declared here}} + D d; //expected-error{{implicit instantiation of undefined member 'PR7355::A<int>::D'}} + }; + + A<int> ai; // expected-note{{in instantiation of}} +} diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index 1bda43000b2a5..a293e9a788dec 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -39,11 +39,11 @@ template struct X3<int>; template <typename T> struct X4 { T f() const { - return; // expected-warning{{non-void function 'f' should return a value}} + return; // expected-error{{non-void function 'f' should return a value}} } T g() const { - return 1; // expected-warning{{void function 'g' should not return a value}} + return 1; // expected-error{{void function 'g' should not return a value}} } }; diff --git a/test/SemaTemplate/instantiate-function-2.cpp b/test/SemaTemplate/instantiate-function-2.cpp index afca358784442..ebc0ef3a9f961 100644 --- a/test/SemaTemplate/instantiate-function-2.cpp +++ b/test/SemaTemplate/instantiate-function-2.cpp @@ -20,3 +20,14 @@ namespace PR7184 { template void f<int>(); } + +namespace UsedAttr { + template<typename T> + void __attribute__((used)) foo() { + T *x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + } + + void bar() { + foo<int>(); // expected-note{{instantiation of}} + } +} diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp index ae8425e716ee6..24a3f317e636f 100644 --- a/test/SemaTemplate/instantiate-member-template.cpp +++ b/test/SemaTemplate/instantiate-member-template.cpp @@ -156,3 +156,36 @@ namespace PR6239 { }; } + +namespace PR7587 { + template<typename> class X0; + template<typename> struct X1; + template<typename> class X2; + + template<typename T> class X3 + { + template< + template<typename> class TT, + typename U = typename X1<T>::type + > + struct Inner { + typedef X2<TT<typename X1<T>::type> > Type; + }; + + const typename Inner<X0>::Type minCoeff() const; + }; + + template<typename T> class X3<T*> + { + template< + template<typename> class TT, + typename U = typename X1<T>::type + > + struct Inner { + typedef X2<TT<typename X1<T>::type> > Type; + }; + + const typename Inner<X0>::Type minCoeff() const; + }; + +} diff --git a/test/SemaTemplate/instantiate-objc-1.mm b/test/SemaTemplate/instantiate-objc-1.mm index 92d0d6c95080a..2780f8e579783 100644 --- a/test/SemaTemplate/instantiate-objc-1.mm +++ b/test/SemaTemplate/instantiate-objc-1.mm @@ -45,3 +45,4 @@ template <typename T> struct EncodeTest { template struct EncodeTest<int>; template struct EncodeTest<double>; +template struct EncodeTest<wchar_t>; diff --git a/test/SemaTemplate/member-function-template.cpp b/test/SemaTemplate/member-function-template.cpp index aea62855c2255..44954ed881abd 100644 --- a/test/SemaTemplate/member-function-template.cpp +++ b/test/SemaTemplate/member-function-template.cpp @@ -85,3 +85,19 @@ namespace TTP { void test_f(X<3> x, Y<int> y) { x.f(y); } } + +namespace PR7387 { + template <typename T> struct X {}; + + template <typename T1> struct S { + template <template <typename> class TC> void foo(const TC<T1>& arg); + }; + + template <typename T1> template <template <typename> class TC> + void S<T1>::foo(const TC<T1>& arg) {} + + void test(const X<int>& x) { + S<int> s; + s.foo(x); + } +} diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp index 54e615b4ab692..12ab48680915b 100644 --- a/test/SemaTemplate/nested-name-spec-template.cpp +++ b/test/SemaTemplate/nested-name-spec-template.cpp @@ -21,7 +21,8 @@ namespace N { } M::Promote<int>::type *ret_intptr3(int* ip) { return ip; } - M::template Promote<int>::type *ret_intptr4(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}} } N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; } @@ -71,3 +72,19 @@ namespace N1 { } template<typename T> T N1::f0() { } + +namespace PR7385 { + template< typename > struct has_xxx0 + { + template< typename > struct has_xxx0_introspect + { + template< typename > struct has_xxx0_substitute ; + template< typename V > + int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 ); + }; + static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}} + typedef int type; + }; + + has_xxx0<int>::type t; // expected-note{{instantiation of}} +} diff --git a/test/SemaTemplate/self-comparison.cpp b/test/SemaTemplate/self-comparison.cpp new file mode 100644 index 0000000000000..50ab660e651b9 --- /dev/null +++ b/test/SemaTemplate/self-comparison.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template <int A, int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); +} +template <int A, int B> struct S1 { + void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +template <int A, int B> struct S2 { + template <typename T> T foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +struct S3 { + template <int A, int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +template <int A> struct S4 { + template <int B> void foo() { + (void)(A == A); // expected-warning {{self-comparison always evaluates to true}} + (void)(A == B); + } +}; + +const int N = 42; +template <int X> void foo2() { + (void)(X == N); + (void)(N == X); +} + +void test() { + foo<1, 1>(); + S1<1, 1> s1; s1.foo(); + S2<1, 1> s2; s2.foo<void>(); + S3 s3; s3.foo<1, 1>(); + S4<1> s4; s4.foo<1>(); + foo2<N>(); +} diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 8dfb60d707189..5a313bf2256a2 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -27,7 +27,8 @@ 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>, + typename make_pair::template apply<int, float>, // expected-warning{{'template' keyword outside of a template}} \ + // expected-warning{{'typename' occurs outside of a template}} make_pair::apply<int, float> >::value? 1 : -1]; diff --git a/test/SemaTemplate/typename-specifier.cpp b/test/SemaTemplate/typename-specifier.cpp index 3f6fe343f5079..4c788f6a8a3cd 100644 --- a/test/SemaTemplate/typename-specifier.cpp +++ b/test/SemaTemplate/typename-specifier.cpp @@ -15,19 +15,22 @@ namespace N { int i; -typename N::A::type *ip1 = &i; -typename N::B::type *ip2 = &i; // expected-error{{no type named 'type' in 'N::B'}} -typename N::C::type *ip3 = &i; // expected-error{{typename specifier refers to non-type member 'type'}} +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}} void test(double d) { - typename N::A::type f(typename N::A::type(a)); // expected-warning{{parentheses were disambiguated as a function declarator}} + typename N::A::type f(typename N::A::type(a)); // expected-warning{{parentheses were disambiguated as a function declarator}} \ + // expected-warning 2{{'typename' occurs outside of a template}} int five = f(5); using namespace N; - for (typename A::type i = 0; i < 10; ++i) + for (typename A::type i = 0; i < 10; ++i) // expected-warning{{'typename' occurs outside of a template}} five += 1; - const typename N::A::type f2(d); + const typename N::A::type f2(d); // expected-warning{{'typename' occurs outside of a template}} } namespace N { |