diff options
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r-- | test/SemaTemplate/alignas.cpp | 23 | ||||
-rw-r--r-- | test/SemaTemplate/class-template-id.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/default-expr-arguments-2.cpp | 4 | ||||
-rw-r--r-- | test/SemaTemplate/default-expr-arguments.cpp | 19 | ||||
-rw-r--r-- | test/SemaTemplate/dependent-names.cpp | 23 | ||||
-rw-r--r-- | test/SemaTemplate/derived.cpp | 18 | ||||
-rw-r--r-- | test/SemaTemplate/destructor-template.cpp | 19 | ||||
-rw-r--r-- | test/SemaTemplate/example-dynarray.cpp | 1 | ||||
-rw-r--r-- | test/SemaTemplate/friend-template.cpp | 20 | ||||
-rw-r--r-- | test/SemaTemplate/fun-template-def.cpp | 8 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-init.cpp | 4 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-member-initializers.cpp | 16 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-type.cpp | 13 | ||||
-rw-r--r-- | test/SemaTemplate/operator-template.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/recursive-template-instantiation.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_nontype.cpp | 16 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_nontype_cxx11.cpp | 10 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_type.cpp | 4 |
19 files changed, 194 insertions, 12 deletions
diff --git a/test/SemaTemplate/alignas.cpp b/test/SemaTemplate/alignas.cpp new file mode 100644 index 0000000..8a1f96e --- /dev/null +++ b/test/SemaTemplate/alignas.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +// expected-no-diagnostics +using size_t = decltype(sizeof(0)); + +template<typename T, typename U> +constexpr T max(T t, U u) { return t > u ? t : u; } + +template<typename T, typename ...Ts> +constexpr auto max(T t, Ts ...ts) -> decltype(max(t, max(ts...))) { + return max(t, max(ts...)); +} + +template<typename...T> struct my_union { + alignas(T...) char buffer[max(sizeof(T)...)]; +}; + +struct alignas(8) A { char c; }; +struct alignas(4) B { short s; }; +struct C { char a[16]; }; + +static_assert(sizeof(my_union<A, B, C>) == 16, ""); +static_assert(alignof(my_union<A, B, C>) == 8, ""); diff --git a/test/SemaTemplate/class-template-id.cpp b/test/SemaTemplate/class-template-id.cpp index b674537..5bbc70c 100644 --- a/test/SemaTemplate/class-template-id.cpp +++ b/test/SemaTemplate/class-template-id.cpp @@ -40,7 +40,7 @@ typedef N::C<float> c2; // PR5655 template<typename T> struct Foo { }; // expected-note{{template is declared here}} -void f(void) { Foo bar; } // expected-error{{use of class template Foo requires template arguments}} +void f(void) { Foo bar; } // expected-error{{use of class template 'Foo' requires template arguments}} // rdar://problem/8254267 template <typename T> class Party; diff --git a/test/SemaTemplate/default-expr-arguments-2.cpp b/test/SemaTemplate/default-expr-arguments-2.cpp index 378999d..0379494 100644 --- a/test/SemaTemplate/default-expr-arguments-2.cpp +++ b/test/SemaTemplate/default-expr-arguments-2.cpp @@ -10,9 +10,9 @@ namespace PR6733 { bar(int x = kSomeConst) {} }; - // CHECK: void f() + // CHECK: FunctionDecl{{.*}}f 'void (void)' void f() { - // CHECK: bar<int> tmp = + // CHECK: VarDecl{{.*}}tmp 'bar<int>' // CHECK: CXXDefaultArgExpr{{.*}}'int' bar<int> tmp; } diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index 1eefa9f..14b072a 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -303,3 +303,22 @@ namespace PR12581 { { } } + +namespace PR13758 { + template <typename T> struct move_from { + T invalid; + }; + template <class K> + struct unordered_map { + explicit unordered_map(int n = 42); + unordered_map(move_from<K> other); + }; + template<typename T> + void StripedHashTable() { + new unordered_map<void>(); + new unordered_map<void>; + } + void tt() { + StripedHashTable<int>(); + } +} diff --git a/test/SemaTemplate/dependent-names.cpp b/test/SemaTemplate/dependent-names.cpp index efa4d28..eb75e69 100644 --- a/test/SemaTemplate/dependent-names.cpp +++ b/test/SemaTemplate/dependent-names.cpp @@ -346,3 +346,26 @@ namespace rdar12629723 { virtual void foo() { } }; } + +namespace test_reserved_identifiers { + template<typename A, typename B> void tempf(A a, B b) { + a + b; // expected-error{{call to function 'operator+' that is neither visible in the template definition nor found by argument-dependent lookup}} + } + namespace __gnu_cxx { struct X {}; } + namespace ns { struct Y {}; } + void operator+(__gnu_cxx::X, ns::Y); // expected-note{{or in namespace 'test_reserved_identifiers::ns'}} + void test() { + __gnu_cxx::X x; + ns::Y y; + tempf(x, y); // expected-note{{in instantiation of}} + } +} + +// This test must live in the global namespace. +struct PR14695_X {}; +// FIXME: This note is bogus; it is the using directive which would need to move +// to prior to the call site to fix the problem. +namespace PR14695_A { void PR14695_f(PR14695_X); } // expected-note {{'PR14695_f' should be declared prior to the call site or in the global namespace}} +template<typename T> void PR14695_g(T t) { PR14695_f(t); } // expected-error {{call to function 'PR14695_f' that is neither visible in the template definition nor found by argument-dependent lookup}} +using namespace PR14695_A; +template void PR14695_g(PR14695_X); // expected-note{{requested here}} diff --git a/test/SemaTemplate/derived.cpp b/test/SemaTemplate/derived.cpp index 1fb9401..7b91f9a 100644 --- a/test/SemaTemplate/derived.cpp +++ b/test/SemaTemplate/derived.cpp @@ -10,3 +10,21 @@ void test() { Foo2(vector2<int*>()); // expected-error{{no matching function for call to 'Foo2'}} Foo(vector<int*>()); // expected-error{{no matching function for call to 'Foo'}} } + +namespace rdar13267210 { + template < typename T > class A { + BaseTy; // expected-error{{C++ requires a type specifier for all declarations}} + }; + + template < typename T, int N > class C: A < T > {}; + + class B { + C<long, 16> ExternalDefinitions; + C<long, 64> &Record; + + void AddSourceLocation(A<long> &R); // expected-note{{passing argument to parameter 'R' here}} + void AddTemplateKWAndArgsInfo() { + AddSourceLocation(Record); // expected-error{{non-const lvalue reference to type}} + } + }; +} diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index 07beda4..6806c24 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -57,3 +57,22 @@ namespace PR7904 { }; Foo f; } + +namespace rdar13140795 { + template <class T> class shared_ptr {}; + + template <typename T> struct Marshal { + static int gc(); + }; + + + template <typename T> int Marshal<T>::gc() { + shared_ptr<T> *x; + x->template shared_ptr<T>::~shared_ptr(); + return 0; + } + + void test() { + Marshal<int>::gc(); + } +} diff --git a/test/SemaTemplate/example-dynarray.cpp b/test/SemaTemplate/example-dynarray.cpp index 999521e..266d2d4 100644 --- a/test/SemaTemplate/example-dynarray.cpp +++ b/test/SemaTemplate/example-dynarray.cpp @@ -1,4 +1,5 @@ // RUN: %clangxx -emit-llvm -c -o - %s +// XFAIL: hexagon #include <stddef.h> #include <stdlib.h> #include <assert.h> diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 9acbfdc..8a47877 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -302,3 +302,23 @@ namespace PR12585 { H<int> h1; // ok H<char> h2; // expected-note {{instantiation}} } + +// Ensure that we can still instantiate a friend function template +// after the friend declaration is instantiated during the delayed +// parsing of a member function, but before the friend function has +// been parsed. +namespace rdar12350696 { + template <class T> struct A { + void foo() { + A<int> a; + } + template <class U> friend void foo(const A<U> & a) { + int array[sizeof(T) == sizeof(U) ? -1 : 1]; // expected-error {{negative size}} + } + }; + + void test() { + A<int> b; + foo(b); // expected-note {{in instantiation}} + } +} diff --git a/test/SemaTemplate/fun-template-def.cpp b/test/SemaTemplate/fun-template-def.cpp index 0427781..2d515b4 100644 --- a/test/SemaTemplate/fun-template-def.cpp +++ b/test/SemaTemplate/fun-template-def.cpp @@ -46,3 +46,11 @@ T f1(T t1, U u1, int i1) return u1; } + +template<typename T> +void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: restrict requires a pointer or reference ('int' is invalid}} + +void f3() { + f2<int*>(0); + f2<int>(0); // expected-error {{no matching function for call to 'f2'}} +} diff --git a/test/SemaTemplate/instantiate-init.cpp b/test/SemaTemplate/instantiate-init.cpp index 612a0b7..6a1a57c 100644 --- a/test/SemaTemplate/instantiate-init.cpp +++ b/test/SemaTemplate/instantiate-init.cpp @@ -78,7 +78,7 @@ namespace PR7985 { template<int N> struct integral_c { }; template <typename T, int N> - integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: failed template argument deduction}} + integral_c<N> array_lengthof(T (&x)[N]) { return integral_c<N>(); } // expected-note 2{{candidate template ignored: could not match 'T [N]' against 'const Data<}} template<typename T> struct Data { @@ -94,7 +94,7 @@ namespace PR7985 { const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}} template<> - Data<float*> Description<float*>::data[]; + const Data<float*> Description<float*>::data[]; void test() { integral_c<1> ic1 = array_lengthof(Description<int>::data); diff --git a/test/SemaTemplate/instantiate-member-initializers.cpp b/test/SemaTemplate/instantiate-member-initializers.cpp index 45503b3..6386206 100644 --- a/test/SemaTemplate/instantiate-member-initializers.cpp +++ b/test/SemaTemplate/instantiate-member-initializers.cpp @@ -25,3 +25,19 @@ public: BB() : AA<T>(1) {} }; BB<int> x; + +struct X { + X(); +}; +template<typename T> +struct Y { + Y() : x() {} + X x; +}; +Y<int> y; + +template<typename T> struct Array { + int a[3]; + Array() : a() {} +}; +Array<int> s; diff --git a/test/SemaTemplate/instantiate-type.cpp b/test/SemaTemplate/instantiate-type.cpp index f5d0270..2440a38 100644 --- a/test/SemaTemplate/instantiate-type.cpp +++ b/test/SemaTemplate/instantiate-type.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s int* f(int); float *f(...); @@ -15,3 +15,14 @@ X<int>::typeof_type &iptr1 = iptr0; X<int>::typeof_expr &iptr2 = iptr0; X<float*>::typeof_expr &fptr1 = fptr0; + +namespace rdar13094134 { + template <class> + class X { + typedef struct { + Y *y; // expected-error{{unknown type name 'Y'}} + } Y; + }; + + X<int> xi; +} diff --git a/test/SemaTemplate/operator-template.cpp b/test/SemaTemplate/operator-template.cpp index 777b0f5..30d6ccf 100644 --- a/test/SemaTemplate/operator-template.cpp +++ b/test/SemaTemplate/operator-template.cpp @@ -2,7 +2,7 @@ // Make sure we accept this template<class X>struct A{typedef X Y;}; -template<class X>bool operator==(A<X>,typename A<X>::Y); // expected-note{{candidate template ignored: failed template argument deduction}} +template<class X>bool operator==(A<X>,typename A<X>::Y); // expected-note{{candidate template ignored: could not match 'A<type-parameter-0-0>' against 'B<int> *'}} int a(A<int> x) { return operator==(x,1); } diff --git a/test/SemaTemplate/recursive-template-instantiation.cpp b/test/SemaTemplate/recursive-template-instantiation.cpp index d6a0b24..fe37060 100644 --- a/test/SemaTemplate/recursive-template-instantiation.cpp +++ b/test/SemaTemplate/recursive-template-instantiation.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -template<typename T> void f(T* t) { // expected-note{{failed template argument deduction}} +template<typename T> void f(T* t) { // expected-note{{could not match 'T *' against 'int'}} f(*t); // expected-error{{no matching function}}\ // expected-note 3{{requested here}} } diff --git a/test/SemaTemplate/temp_arg.cpp b/test/SemaTemplate/temp_arg.cpp index 5a4c8fc..052c19e 100644 --- a/test/SemaTemplate/temp_arg.cpp +++ b/test/SemaTemplate/temp_arg.cpp @@ -10,7 +10,7 @@ A<int, 0, X> * a1; A<float, 1, X, double> *a2; // expected-error{{too many template arguments for class template 'A'}} A<float, 1> *a3; // expected-error{{too few template arguments for class template 'A'}} -A a3; // expected-error{{use of class template A requires template arguments}} +A a3; // expected-error{{use of class template 'A' requires template arguments}} namespace test0 { template <class t> class foo {}; diff --git a/test/SemaTemplate/temp_arg_nontype.cpp b/test/SemaTemplate/temp_arg_nontype.cpp index 747ddcc..210b5e4 100644 --- a/test/SemaTemplate/temp_arg_nontype.cpp +++ b/test/SemaTemplate/temp_arg_nontype.cpp @@ -3,7 +3,7 @@ template<int N> struct A; // expected-note 5{{template parameter is declared her A<0> *a0; -A<int()> *a1; // expected-error{{template argument for non-type template parameter is treated as type 'int ()'}} +A<int()> *a1; // expected-error{{template argument for non-type template parameter is treated as function type 'int ()'}} A<int> *a2; // expected-error{{template argument for non-type template parameter must be an expression}} @@ -323,3 +323,17 @@ namespace PR10579 { template <int& I> struct PR10766 { static int *ip; }; template <int& I> int* PR10766<I>::ip = &I; + +namespace rdar13000548 { + template<typename R, typename U, R F> + U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}} + + int g(int); + int y[3]; + void test() + { + f<int(int), int (*)(int), g>(); // expected-note{{in instantiation of}} + f<int[3], int*, y>(); // expected-note{{in instantiation of}} + } + +} diff --git a/test/SemaTemplate/temp_arg_nontype_cxx11.cpp b/test/SemaTemplate/temp_arg_nontype_cxx11.cpp new file mode 100644 index 0000000..d773c64 --- /dev/null +++ b/test/SemaTemplate/temp_arg_nontype_cxx11.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s + +namespace PR15360 { + template<typename R, typename U, R F> + U f() { return &F; } // expected-error{{cannot take the address of an rvalue of type 'int (*)(int)'}} expected-error{{cannot take the address of an rvalue of type 'int *'}} + void test() { + f<int(int), int(*)(int), nullptr>(); // expected-note{{in instantiation of}} + f<int[3], int*, nullptr>(); // expected-note{{in instantiation of}} + } +} diff --git a/test/SemaTemplate/temp_arg_type.cpp b/test/SemaTemplate/temp_arg_type.cpp index 3970942..637b563 100644 --- a/test/SemaTemplate/temp_arg_type.cpp +++ b/test/SemaTemplate/temp_arg_type.cpp @@ -4,7 +4,7 @@ template<typename T> class A; // expected-note 2 {{template parameter is declare // [temp.arg.type]p1 A<0> *a1; // expected-error{{template argument for template type parameter must be a type}} -A<A> *a2; // expected-error{{use of class template A requires template arguments}} +A<A> *a2; // expected-error{{use of class template 'A' requires template arguments}} A<int> *a3; A<int()> *a4; @@ -19,7 +19,7 @@ A<function_tpl> a7; // expected-error{{template argument for template type para namespace ns { template<typename T> class B {}; // expected-note{{template is declared here}} } -A<ns::B> a8; // expected-error{{use of class template ns::B requires template arguments}} +A<ns::B> a8; // expected-error{{use of class template 'ns::B' requires template arguments}} // [temp.arg.type]p2 void f() { |