diff options
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r-- | test/SemaTemplate/address-spaces.cpp | 86 | ||||
-rw-r--r-- | test/SemaTemplate/deduction-crash.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/dependent-template-recover.cpp | 42 | ||||
-rw-r--r-- | test/SemaTemplate/destructor-template.cpp | 7 | ||||
-rw-r--r-- | test/SemaTemplate/explicit-instantiation.cpp | 9 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-cast.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-expr-4.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-function-1.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-member-class.cpp | 23 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-member-template.cpp | 44 | ||||
-rw-r--r-- | test/SemaTemplate/instantiate-try-catch.cpp | 2 | ||||
-rw-r--r-- | test/SemaTemplate/issue150.cpp | 107 | ||||
-rw-r--r-- | test/SemaTemplate/nested-name-spec-template.cpp | 41 | ||||
-rw-r--r-- | test/SemaTemplate/resolve-single-template-id.cpp | 80 | ||||
-rw-r--r-- | test/SemaTemplate/temp_arg_template.cpp | 9 | ||||
-rw-r--r-- | test/SemaTemplate/typename-specifier-4.cpp | 8 |
16 files changed, 452 insertions, 14 deletions
diff --git a/test/SemaTemplate/address-spaces.cpp b/test/SemaTemplate/address-spaces.cpp new file mode 100644 index 0000000..eda03db --- /dev/null +++ b/test/SemaTemplate/address-spaces.cpp @@ -0,0 +1,86 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template<typename T, typename U> +struct is_same { + static const bool value = false; +}; + +template<typename T> +struct is_same<T, T> { + static const bool value = true; +}; + +typedef int __attribute__((address_space(1))) int_1;; +typedef int __attribute__((address_space(2))) int_2;; +typedef int __attribute__((address_space(1))) *int_1_ptr; +typedef int_2 *int_2_ptr; + +// Check that we maintain address spaces through template argument +// deduction from a type. +template<typename T> +struct remove_pointer { + typedef T type; +}; + +template<typename T> +struct remove_pointer<T *> { + typedef T type; +}; + +int check_remove0[is_same<remove_pointer<int_1_ptr>::type, int_1>::value? 1 : -1]; +int check_remove1[is_same<remove_pointer<int_2_ptr>::type, int_2>::value? 1 : -1]; +int check_remove2[is_same<remove_pointer<int_2_ptr>::type, int>::value? -1 : 1]; +int check_remove3[is_same<remove_pointer<int_2_ptr>::type, int_1>::value? -1 : 1]; + +template<typename T> +struct is_pointer_in_address_space_1 { + static const bool value = false; +}; + +template<typename T> +struct is_pointer_in_address_space_1<T __attribute__((address_space(1))) *> { + static const bool value = true; +}; + +int check_ptr_in_as1[is_pointer_in_address_space_1<int_1_ptr>::value? 1 : -1]; +int check_ptr_in_as2[is_pointer_in_address_space_1<int_2_ptr>::value? -1 : 1]; +int check_ptr_in_as3[is_pointer_in_address_space_1<int*>::value? -1 : 1]; + +// Check that we maintain address spaces through template argument +// deduction for a call. +template<typename T> +void accept_any_pointer(T*) { + T *x = 1; // expected-error{{cannot initialize a variable of type '__attribute__((address_space(1))) int *' with an rvalue of type 'int'}} \ + // expected-error{{cannot initialize a variable of type '__attribute__((address_space(3))) int *' with an rvalue of type 'int'}} +} + +void test_accept_any_pointer(int_1_ptr ip1, int_2_ptr ip2) { + static __attribute__((address_space(3))) int array[17]; + accept_any_pointer(ip1); // expected-note{{in instantiation of}} + accept_any_pointer(array); // expected-note{{in instantiation of}} +} + +template<typename T> struct identity {}; + +template<typename T> +identity<T> accept_arg_in_address_space_1(__attribute__((address_space(1))) T &ir1); + +template<typename T> +identity<T> accept_any_arg(T &ir1); + +void test_arg_in_address_space_1() { + static int __attribute__((address_space(1))) int_1; + identity<int> ii = accept_arg_in_address_space_1(int_1); + identity<int __attribute__((address_space(1)))> ii2 = accept_any_arg(int_1); +} + +// Partial ordering +template<typename T> int &order1(__attribute__((address_space(1))) T&); +template<typename T> float &order1(T&); + +void test_order1() { + static __attribute__((address_space(1))) int i1; + int i; + int &ir = order1(i1); + float &fr = order1(i); +} diff --git a/test/SemaTemplate/deduction-crash.cpp b/test/SemaTemplate/deduction-crash.cpp index 8f4b728..ec97311 100644 --- a/test/SemaTemplate/deduction-crash.cpp +++ b/test/SemaTemplate/deduction-crash.cpp @@ -4,7 +4,7 @@ // Note that the error count below doesn't matter. We just want to // make sure that the parser doesn't crash. -// CHECK: 15 errors +// CHECK: 13 errors template<a> struct int_; diff --git a/test/SemaTemplate/dependent-template-recover.cpp b/test/SemaTemplate/dependent-template-recover.cpp index e91ffb5..3c01f65 100644 --- a/test/SemaTemplate/dependent-template-recover.cpp +++ b/test/SemaTemplate/dependent-template-recover.cpp @@ -16,3 +16,45 @@ struct X { (*t).f2<0>(); // expected-error{{expected expression}} } }; + +namespace PR9401 { + // From GCC PR c++/45558 + template <typename S, typename T> + struct C + { + template <typename U> + struct B + { + template <typename W> + struct E + { + explicit E(const W &x) : w(x) {} + const W &w; + }; + }; + }; + + struct F; + template <typename X> + struct D + { + D() {} + }; + + const D<F> g; + template <typename S, typename T> + struct A + { + template <typename U> + struct B : C<S, T>::template B<U> + { + typedef typename C<S, T>::template B<U> V; + static const D<typename V::template E<D<F> > > a; + }; + }; + + template <typename S, typename T> + template <typename U> + const D<typename C<S, T>::template B<U>::template E<D<F> > > + A<S, T>::B<U>::a = typename C<S, T>::template B<U>::template E<D<F> >(g); +} diff --git a/test/SemaTemplate/destructor-template.cpp b/test/SemaTemplate/destructor-template.cpp index 6fe7f69..07beda4 100644 --- a/test/SemaTemplate/destructor-template.cpp +++ b/test/SemaTemplate/destructor-template.cpp @@ -50,3 +50,10 @@ namespace PR7239 { } }; } + +namespace PR7904 { + struct Foo { + template <int i> ~Foo() {} // expected-error{{destructor cannot be declared as a template}} + }; + Foo f; +} diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index ffec3c2..63016fd 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -88,15 +88,12 @@ 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}} +namespace PR7622 { 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 '}'}} + template struct basic_streambuf<int>; +} diff --git a/test/SemaTemplate/instantiate-cast.cpp b/test/SemaTemplate/instantiate-cast.cpp index abf1b3c..b3babf1 100644 --- a/test/SemaTemplate/instantiate-cast.cpp +++ b/test/SemaTemplate/instantiate-cast.cpp @@ -63,7 +63,7 @@ template struct DynamicCast0<Base*, A>; // expected-note{{instantiation}} template<typename T, typename U> struct ReinterpretCast0 { void f(T t) { - (void)reinterpret_cast<U>(t); // expected-error{{constness}} + (void)reinterpret_cast<U>(t); // expected-error{{qualifiers}} } }; diff --git a/test/SemaTemplate/instantiate-expr-4.cpp b/test/SemaTemplate/instantiate-expr-4.cpp index 74eb5e5..521d218 100644 --- a/test/SemaTemplate/instantiate-expr-4.cpp +++ b/test/SemaTemplate/instantiate-expr-4.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s // --------------------------------------------------------------------- // C++ Functional Casts diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index dbd1e69..688d009 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s template<typename T, typename U> struct X0 { void f(T x, U y) { diff --git a/test/SemaTemplate/instantiate-member-class.cpp b/test/SemaTemplate/instantiate-member-class.cpp index f1bdf3e..74c2609 100644 --- a/test/SemaTemplate/instantiate-member-class.cpp +++ b/test/SemaTemplate/instantiate-member-class.cpp @@ -1,5 +1,28 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +namespace PR8965 { + template<typename T> + struct X { + typedef int type; + + T field; // expected-note{{in instantiation of member class}} + }; + + template<typename T> + struct Y { + struct Inner; + + typedef typename X<Inner>::type // expected-note{{in instantiation of template class}} + type; // expected-note{{not-yet-instantiated member is declared here}} + + struct Inner { + typedef type field; // expected-error{{no member 'type' in 'PR8965::Y<int>'; it has not yet been instantiated}} + }; + }; + + Y<int> y; // expected-note{{in instantiation of template class}} +} + template<typename T> class X { public: diff --git a/test/SemaTemplate/instantiate-member-template.cpp b/test/SemaTemplate/instantiate-member-template.cpp index e2f7275..4c74f5f 100644 --- a/test/SemaTemplate/instantiate-member-template.cpp +++ b/test/SemaTemplate/instantiate-member-template.cpp @@ -215,3 +215,47 @@ namespace PR8489 { c.F(); // expected-error{{no matching member function}} } } + +namespace rdar8986308 { + template <bool> struct __static_assert_test; + template <> struct __static_assert_test<true> {}; + template <unsigned> struct __static_assert_check {}; + + namespace std { + + template <class _Tp, class _Up> + struct __has_rebind + { + private: + struct __two {char _; char __;}; + template <class _Xp> static __two __test(...); + template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0); + public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; + }; + + } + + template <class T> struct B1 {}; + + template <class T> + struct B + { + template <class U> struct rebind {typedef B1<U> other;}; + }; + + template <class T, class U> struct D1 {}; + + template <class T, class U> + struct D + { + template <class V> struct rebind {typedef D1<V, U> other;}; + }; + + int main() + { + typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<B<int>, double>::value))>)> __t64; + typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<D<char, int>, double>::value))>)> __t64; + } + +} diff --git a/test/SemaTemplate/instantiate-try-catch.cpp b/test/SemaTemplate/instantiate-try-catch.cpp index f1ffd063..1c6c26f 100644 --- a/test/SemaTemplate/instantiate-try-catch.cpp +++ b/test/SemaTemplate/instantiate-try-catch.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fexceptions -fsyntax-only -std=c++0x -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -std=c++0x -verify %s template<typename T> struct TryCatch0 { void f() { diff --git a/test/SemaTemplate/issue150.cpp b/test/SemaTemplate/issue150.cpp new file mode 100644 index 0000000..af3b93c --- /dev/null +++ b/test/SemaTemplate/issue150.cpp @@ -0,0 +1,107 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Core issue 150: Template template parameters and default arguments + +template<typename T, typename U> +struct is_same { + static const bool value = false; +}; + +template<typename T> +struct is_same<T, T> { + static const bool value = true; +}; + +namespace PR9353 { + template<class _T, class Traits> class IM; + + template <class T, class Trt, + template<class _T, class Traits = int> class IntervalMap> + void foo(IntervalMap<T,Trt>* m) { typedef IntervalMap<int> type; } + + void f(IM<int, int>* m) { foo(m); } +} + +namespace PR9400 { + template<template <typename T, typename = T > class U> struct A + { + template<int> U<int> foo(); + }; + + template <typename T, typename = T> + struct s { + }; + + void f() { + A<s> x; + x.foo<2>(); + } +} + +namespace MultiReplace { + template<typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X { + typedef TT<Z> type; + }; + + template<typename T, typename = int, typename = float> + struct Y { }; + + int check0[is_same<X<int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; +} + +namespace MultiReplacePartial { + template<typename First, typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X { + typedef TT<Z> type; + }; + + template<typename Z, + template<typename T, typename U = T *, typename V = U const> class TT> + struct X<int, Z, TT> { + typedef TT<Z> type; + }; + + template<typename T, typename = int, typename = float> + struct Y { }; + + int check0[is_same<X<int, int, Y>::type, Y<int, int*, int* const> >::value? 1 : -1]; +} + +namespace PR9016 { + template<typename > struct allocator ; + template<typename > struct less ; + + template<class T, template<class> class Compare, class Default, + template<class> class Alloc> + struct interval_set { }; + + template <class X, template<class> class = less> struct interval_type_default { + typedef X type; + }; + + template <class T, + template<class _T, template<class> class Compare = PR9016::less, + class = typename interval_type_default<_T,Compare>::type, + template<class> class = allocator> class IntervalSet> + struct ZZZ + { + IntervalSet<T> IntervalSetT; + }; + + template <class T, + template<class _T, template<class> class Compare = PR9016::less, + class = typename interval_type_default<_T,Compare>::type, + template<class> class = allocator> class IntervalSet> + void int40() + { + IntervalSet<T> IntervalSetT; + } + + void test() { + ZZZ<int, interval_set> zzz; + int40<int, interval_set>(); + } +} diff --git a/test/SemaTemplate/nested-name-spec-template.cpp b/test/SemaTemplate/nested-name-spec-template.cpp index 9c72845..635687d 100644 --- a/test/SemaTemplate/nested-name-spec-template.cpp +++ b/test/SemaTemplate/nested-name-spec-template.cpp @@ -99,3 +99,44 @@ namespace PR7725 { } }; } + +namespace PR9226 { + template<typename a> + void nt() // expected-note{{function template 'nt' declared here}} + { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \ + // expected-error{{expected unqualified-id}} + + template<typename T> + void f(T*); // expected-note{{function template 'f' declared here}} + + template<typename T> + void f(T*, T*); // expected-note{{function template 'f' declared here}} + + void g() { + f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}} + } // expected-error{{expected unqualified-id}} + + struct X { + template<typename T> void f(); // expected-note{{function template 'f' declared here}} + }; + + template<typename T, typename U> + struct Y { + typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}} + }; + + Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}} +} + +namespace PR9449 { + template <typename T> + struct s; // expected-note{{template is declared here}} + + template <typename T> + void f() { + int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \ + // expected-error{{following the 'template' keyword}} + } + + template void f<int>(); // expected-note{{in instantiation of}} +} diff --git a/test/SemaTemplate/resolve-single-template-id.cpp b/test/SemaTemplate/resolve-single-template-id.cpp new file mode 100644 index 0000000..ef0a763 --- /dev/null +++ b/test/SemaTemplate/resolve-single-template-id.cpp @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +namespace std { + class type_info {}; +} + +void one() { } +void two() { } // expected-note 3{{candidate}} +void two(int) { } // expected-note 3{{candidate}} + +template<class T> void twoT() { } // expected-note 5{{candidate}} +template<class T> void twoT(int) { } // expected-note 5{{candidate}} + +template<class T> void oneT() { } +template<class T, class U> void oneT(U) { } +/* +The target can be + an object or reference being initialized (8.5, 8.5.3), + the left side of an assignment (5.17), + a parameter of a function (5.2.2), + a parameter of a user-defined operator (13.5), + the return value of a function, operator function, or conversion (6.6.3), + an explicit type conversion (5.2.3, 5.2.9, 5.4), or + a non-type template-parameter (14.3.2) +*/ +//#include <typeinfo> +template<void (*p)(int)> struct test { }; + +int main() +{ + one; // expected-warning {{expression result unused}} + two; // expected-error {{cannot resolve overloaded function 'two' from context}} + oneT<int>; // expected-warning {{expression result unused}} + twoT<int>; // expected-error {{cannot resolve overloaded function 'twoT' from context}} + typeid(oneT<int>); // expected-warning{{expression result unused}} + sizeof(oneT<int>); // expected-warning {{expression result unused}} + sizeof(twoT<int>); //expected-error {{cannot resolve overloaded function 'twoT' from context}} + decltype(oneT<int>)* fun = 0; + + *one; // expected-warning {{expression result unused}} + *oneT<int>; // expected-warning {{expression result unused}} + *two; //expected-error {{cannot resolve overloaded function 'two' from context}} + *twoT<int>; //expected-error {{cannot resolve overloaded function 'twoT' from context}} + !oneT<int>; // expected-warning {{expression result unused}} + +oneT<int>; // expected-warning {{expression result unused}} + -oneT<int>; //expected-error {{invalid argument type}} + oneT<int> == 0; // expected-warning {{expression result unused}} + 0 == oneT<int>; // expected-warning {{expression result unused}} + 0 != oneT<int>; // expected-warning {{expression result unused}} + (false ? one : oneT<int>); // expected-warning {{expression result unused}} + void (*p1)(int); p1 = oneT<int>; + + int i = (int) (false ? (void (*)(int))twoT<int> : oneT<int>); //expected-error {{incompatible operand}} + (twoT<int>) == oneT<int>; //expected-error {{cannot resolve overloaded function 'twoT' from context}} + bool b = oneT<int>; + void (*p)() = oneT<int>; + test<oneT<int> > ti; + void (*u)(int) = oneT<int>; + + b = (void (*)()) twoT<int>; + + one < one; //expected-warning {{self-comparison always evaluates to false}} \ + //expected-warning {{expression result unused}} + + oneT<int> < oneT<int>; //expected-warning {{self-comparison always evaluates to false}} \ + //expected-warning {{expression result unused}} + + two < two; //expected-error {{cannot resolve overloaded function 'two' from context}} + twoT<int> < twoT<int>; //expected-error {{cannot resolve overloaded function 'twoT' from context}} + oneT<int> == 0; // expected-warning {{expression result unused}} + +} + +struct rdar9108698 { + template<typename> void f(); +}; + +void test_rdar9108698(rdar9108698 x) { + x.f<int>; // expected-error{{a bound member function may only be called}} +} diff --git a/test/SemaTemplate/temp_arg_template.cpp b/test/SemaTemplate/temp_arg_template.cpp index 944acac..9c34089 100644 --- a/test/SemaTemplate/temp_arg_template.cpp +++ b/test/SemaTemplate/temp_arg_template.cpp @@ -30,9 +30,12 @@ template<typename T> void f(int); A<f> *a9; // expected-error{{must be a class template}} -// FIXME: The code below is ill-formed, because of the evil digraph '<:'. -// We should provide a much better error message than we currently do. -// A<::N::Z> *a10; +// 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 '< ::'?}} + +// Do not do a digraph correction here. +A<: :N::Z> *a11; // expected-error{{expected expression}} \ + expected-error{{C++ requires a type specifier for all declarations}} // PR7807 namespace N { diff --git a/test/SemaTemplate/typename-specifier-4.cpp b/test/SemaTemplate/typename-specifier-4.cpp index 38045e0..44cf966 100644 --- a/test/SemaTemplate/typename-specifier-4.cpp +++ b/test/SemaTemplate/typename-specifier-4.cpp @@ -154,3 +154,11 @@ namespace rdar8740998 { xi.f(); } } + +namespace rdar9068589 { + // From GCC PR c++/13950 + template <class T> struct Base {}; + template <class T> struct Derived: public Base<T> { + typename Derived::template Base<double>* p1; + }; +} |