Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Anders Carlsson | 863dbcb | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 2 | |
| 3 | namespace PR5557 { |
| 4 | template <class T> struct A { |
| 5 | A(); |
Douglas Gregor | 159ef1e | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 6 | virtual void anchor(); // expected-note{{instantiation}} |
Anders Carlsson | 863dbcb | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 7 | virtual int a(T x); |
| 8 | }; |
| 9 | template<class T> A<T>::A() {} |
Douglas Gregor | 159ef1e | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 10 | template<class T> void A<T>::anchor() { } |
| 11 | |
Anders Carlsson | 863dbcb | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 12 | template<class T> int A<T>::a(T x) { |
| 13 | return *x; // expected-error{{requires pointer operand}} |
| 14 | } |
| 15 | |
Douglas Gregor | 159ef1e | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 16 | void f(A<int> x) { |
| 17 | x.anchor(); |
| 18 | } |
Anders Carlsson | 863dbcb | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 19 | |
| 20 | template<typename T> |
| 21 | struct X { |
| 22 | virtual void f(); |
| 23 | }; |
| 24 | |
| 25 | template<> |
| 26 | void X<int>::f() { } |
| 27 | } |
Douglas Gregor | 159ef1e | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 28 | |
| 29 | template<typename T> |
| 30 | struct Base { |
| 31 | virtual ~Base() { |
| 32 | int *ptr = 0; |
| 33 | T t = ptr; // expected-error{{cannot initialize}} |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | template<typename T> |
| 38 | struct Derived : Base<T> { |
| 39 | virtual void foo() { } |
| 40 | }; |
| 41 | |
| 42 | template struct Derived<int>; // expected-note{{instantiation}} |
| 43 | |
Douglas Gregor | 4b0f21c | 2010-01-06 20:27:16 +0000 | [diff] [blame] | 44 | template<typename T> |
| 45 | struct HasOutOfLineKey { |
| 46 | HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}} |
| 47 | virtual T *f(float *fp); |
| 48 | }; |
| 49 | |
| 50 | template<typename T> |
| 51 | T *HasOutOfLineKey<T>::f(float *fp) { |
| 52 | return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}} |
| 53 | } |
| 54 | |
| 55 | HasOutOfLineKey<int> out_of_line; |