diff options
author | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2009-06-02 17:58:47 +0000 |
commit | ec2b103c267a06a66e926f62cd96767b280f5cf5 (patch) | |
tree | ce7d964cbb5e39695b71481698f10cb099c23d4a /test/SemaTemplate/instantiate-method.cpp | |
download | src-ec2b103c267a06a66e926f62cd96767b280f5cf5.tar.gz src-ec2b103c267a06a66e926f62cd96767b280f5cf5.zip |
Import Clang, at r72732.vendor/clang/clang-r72732
Notes
Notes:
svn path=/vendor/clang/dist/; revision=193326
svn path=/vendor/clang/clang-r72732/; revision=193327; tag=vendor/clang/clang-r72732
Diffstat (limited to 'test/SemaTemplate/instantiate-method.cpp')
-rw-r--r-- | test/SemaTemplate/instantiate-method.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/SemaTemplate/instantiate-method.cpp b/test/SemaTemplate/instantiate-method.cpp new file mode 100644 index 000000000000..daea7465dc12 --- /dev/null +++ b/test/SemaTemplate/instantiate-method.cpp @@ -0,0 +1,74 @@ +// RUN: clang-cc -fsyntax-only -verify %s +template<typename T> +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 2{{argument may not have 'void' type}} +}; + +int identity(int x) { return x; } + +void test(X<int> *xi, int *ip, X<int(int)> *xf) { + xi->f(17); + xi->g(ip); + xf->f(&identity); + xf->g(identity); + X<int>::h(17, 25); + X<int(int)>::h(identity, &identity); +} + +void test_bad() { + X<void> xv; // expected-note{{in instantiation of template class 'class X<void>' requested here}} +} + +template<typename T, typename U> +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<int, long> *oil, int i, long l) { + int &ir = oil->f(i, i); + float &fr = oil->f(i, l); +} + +void test_ovl_bad() { + Overloading<float, float> off; // expected-note{{in instantiation of template class 'class Overloading<float, float>' requested here}} +} + +template<typename T> +class HasDestructor { +public: + virtual ~HasDestructor() = 0; +}; + +int i = sizeof(HasDestructor<int>); // FIXME: forces instantiation, but + // the code below should probably instantiate by itself. +int abstract_destructor[__is_abstract(HasDestructor<int>)? 1 : -1]; + + +template<typename T> +class Constructors { +public: + Constructors(const T&); + Constructors(const Constructors &other); +}; + +void test_constructors() { + Constructors<int> ci1(17); + Constructors<int> ci2 = ci1; +} + + +template<typename T> +struct ConvertsTo { + operator T(); +}; + +void test_converts_to(ConvertsTo<int> ci, ConvertsTo<int *> cip) { + int i = ci; + int *ip = cip; +} |