Nick Lewycky | 2a5f99e | 2010-11-25 00:35:20 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Nick Lewycky | 2a5f99e | 2010-11-25 00:35:20 +0000 | [diff] [blame] | 2 | |
Nick Lewycky | 8155910 | 2011-05-31 07:58:42 +0000 | [diff] [blame] | 3 | namespace PR8640 { |
| 4 | template<class T1> struct C1 { |
| 5 | virtual void c1() { |
| 6 | T1 t1 = 3; // expected-error {{cannot initialize a variable}} |
| 7 | } |
| 8 | }; |
| 9 | |
| 10 | template<class T2> struct C2 { |
| 11 | void c2() { |
| 12 | new C1<T2>(); // expected-note {{in instantiation of member function}} |
| 13 | } |
| 14 | }; |
| 15 | |
| 16 | void f() { |
| 17 | C2<int*> c2; |
| 18 | c2.c2(); // expected-note {{in instantiation of member function}} |
Nick Lewycky | 2a5f99e | 2010-11-25 00:35:20 +0000 | [diff] [blame] | 19 | } |
Nick Lewycky | 2a5f99e | 2010-11-25 00:35:20 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Douglas Gregor | 7884403 | 2011-04-22 22:25:37 +0000 | [diff] [blame] | 22 | namespace PR9325 { |
| 23 | template<typename T> |
| 24 | class Target |
| 25 | { |
| 26 | public: |
| 27 | virtual T Value() const |
| 28 | { |
| 29 | return 1; // expected-error{{cannot initialize return object of type 'int *' with an rvalue of type 'int'}} |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | template<typename T> |
| 34 | struct Provider |
| 35 | { |
| 36 | static Target<T> Instance; |
| 37 | }; |
| 38 | |
| 39 | template<typename T> |
| 40 | Target<T> Provider<T>::Instance; // expected-note{{in instantiation of}} |
| 41 | |
| 42 | void f() |
| 43 | { |
| 44 | Target<int*>* traits = &Provider<int*>::Instance; |
| 45 | } |
Nick Lewycky | 8155910 | 2011-05-31 07:58:42 +0000 | [diff] [blame] | 46 | } |
Douglas Gregor | 7884403 | 2011-04-22 22:25:37 +0000 | [diff] [blame] | 47 | |
Nick Lewycky | 8155910 | 2011-05-31 07:58:42 +0000 | [diff] [blame] | 48 | namespace PR10020 { |
| 49 | struct MG { |
| 50 | virtual void Accept(int) = 0; |
| 51 | }; |
| 52 | |
| 53 | template <typename Type> |
| 54 | struct GMG : MG { |
| 55 | void Accept(int i) { |
| 56 | static_cast<Type *>(0)->Accept(i); // expected-error{{member reference base}} |
| 57 | } |
| 58 | static GMG* Method() { return &singleton; } // expected-note{{in instantiation of}} |
| 59 | static GMG singleton; |
| 60 | }; |
| 61 | |
| 62 | template <typename Type> |
| 63 | GMG<Type> GMG<Type>::singleton; |
| 64 | |
| 65 | void test(void) { |
| 66 | GMG<int>::Method(); // expected-note{{in instantiation of}} |
| 67 | } |
Douglas Gregor | 7884403 | 2011-04-22 22:25:37 +0000 | [diff] [blame] | 68 | } |