Douglas Gregor | a689727 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
Douglas Gregor | a689727 | 2009-03-23 23:06:20 +0000 | [diff] [blame] | 2 | template<typename T> |
| 3 | class X { |
| 4 | public: |
| 5 | void f(T); // expected-error{{argument may not have 'void' type}} |
| 6 | // FIXME: source location isn't very good, because we're |
| 7 | // instantiating the type. Could we do better? |
| 8 | void g(T*); |
| 9 | |
| 10 | static int h(T, T); // expected-error 2{{argument may not have 'void' type}} |
| 11 | }; |
| 12 | |
| 13 | int identity(int x) { return x; } |
| 14 | |
| 15 | void test(X<int> *xi, int *ip, X<int(int)> *xf) { |
| 16 | xi->f(17); |
| 17 | xi->g(ip); |
| 18 | xf->f(&identity); |
| 19 | xf->g(identity); |
| 20 | X<int>::h(17, 25); |
| 21 | X<int(int)>::h(identity, &identity); |
| 22 | } |
| 23 | |
| 24 | void test_bad() { |
| 25 | X<void> xv; // expected-note{{in instantiation of template class 'class X<void>' requested here}} |
| 26 | } |
| 27 | |
| 28 | template<typename T, typename U> |
| 29 | class Overloading { |
| 30 | public: |
| 31 | int& f(T, T); // expected-note{{previous declaration is here}} |
| 32 | float& f(T, U); // expected-error{{functions that differ only in their return type cannot be overloaded}} |
| 33 | }; |
| 34 | |
| 35 | void test_ovl(Overloading<int, long> *oil, int i, long l) { |
| 36 | int &ir = oil->f(i, i); |
| 37 | float &fr = oil->f(i, l); |
| 38 | } |
| 39 | |
| 40 | void test_ovl_bad() { |
| 41 | Overloading<float, float> off; // expected-note{{in instantiation of template class 'class Overloading<float, float>' requested here}} |
| 42 | } |
Douglas Gregor | 467b1c9 | 2009-03-24 00:15:49 +0000 | [diff] [blame^] | 43 | |
| 44 | template<typename T> |
| 45 | class HasDestructor { |
| 46 | virtual ~HasDestructor() = 0; |
| 47 | }; |
| 48 | |
| 49 | int i = sizeof(HasDestructor<int>); // FIXME: forces instantiation, but |
| 50 | // the code below should probably instantiate by itself. |
| 51 | int abstract_destructor[__is_abstract(HasDestructor<int>)? 1 : -1]; |