From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/SemaTemplate/instantiate-method.cpp | 177 +++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 clang/test/SemaTemplate/instantiate-method.cpp (limited to 'clang/test/SemaTemplate/instantiate-method.cpp') diff --git a/clang/test/SemaTemplate/instantiate-method.cpp b/clang/test/SemaTemplate/instantiate-method.cpp new file mode 100644 index 0000000..363115d --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-method.cpp @@ -0,0 +1,177 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template +class X { +public: + void f(T x); // expected-error{{argument may not have 'void' type}} + void g(T*); + + static int h(T, T); // expected-error {{argument may not have 'void' type}} +}; + +int identity(int x) { return x; } + +void test(X *xi, int *ip, X *xf) { + xi->f(17); + xi->g(ip); + xf->f(&identity); + xf->g(identity); + X::h(17, 25); + X::h(identity, &identity); +} + +void test_bad() { + X xv; // expected-note{{in instantiation of template class 'X' requested here}} +} + +template +class Overloading { +public: + int& f(T, T); // expected-note{{previous declaration is here}} + float& f(T, U); // expected-error{{functions that differ only in their return type cannot be overloaded}} +}; + +void test_ovl(Overloading *oil, int i, long l) { + int &ir = oil->f(i, i); + float &fr = oil->f(i, l); +} + +void test_ovl_bad() { + Overloading off; // expected-note{{in instantiation of template class 'Overloading' requested here}} +} + +template +class HasDestructor { +public: + virtual ~HasDestructor() = 0; +}; + +int i = sizeof(HasDestructor); // FIXME: forces instantiation, but + // the code below should probably instantiate by itself. +int abstract_destructor[__is_abstract(HasDestructor)? 1 : -1]; + + +template +class Constructors { +public: + Constructors(const T&); + Constructors(const Constructors &other); +}; + +void test_constructors() { + Constructors ci1(17); + Constructors ci2 = ci1; +} + + +template +struct ConvertsTo { + operator T(); +}; + +void test_converts_to(ConvertsTo ci, ConvertsTo cip) { + int i = ci; + int *ip = cip; +} + +// PR4660 +template struct A0 { operator T*(); }; +template struct A1; + +int *a(A0 &x0, A1 &x1) { + int *y0 = x0; + int *y1 = x1; // expected-error{{no viable conversion}} +} + +struct X0Base { + int &f(); + int& g(int); + static double &g(double); +}; + +template +struct X0 : X0Base { +}; + +template +struct X1 : X0 { + int &f2() { + return X0Base::f(); + } +}; + +void test_X1(X1 x1i) { + int &ir = x1i.f2(); +} + +template +struct X2 : X0Base, U { + int &f2() { return X0Base::f(); } +}; + +template +struct X3 { + void test(T x) { + double& d1 = X0Base::g(x); + } +}; + + +template struct X3; + +// Don't try to instantiate this, it's invalid. +namespace test1 { + template class A {}; + template class B { + void foo(A &a) // expected-error {{no member named 'Undeclared' in namespace 'test1'}} + {} + }; + template class B; +} + +namespace PR6947 { + template< class T > + struct X { + int f0( ) + { + typedef void ( X::*impl_fun_ptr )( ); + impl_fun_ptr pImpl = &X::template + f0_impl1; + } + private: + int f1() { + } + template< class Processor> + void f0_impl1( ) + { + } + }; + + char g0() { + X pc; + pc.f0(); + } + +} + +namespace PR7022 { + template + struct X1 + { + typedef int state_t( ); + state_t g ; + }; + + template < typename U = X1 > struct X2 + { + X2( U = U()) + { + } + }; + + void m(void) + { + typedef X2<> X2_type; + X2_type c; + } + +} -- cgit v1.2.3