Hans Wennborg | c9bd88e | 2014-01-14 19:35:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -triple %ms_abi_triple -DMSABI -fsyntax-only -verify %s |
Anders Carlsson | 8e0317b | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 3 | |
| 4 | namespace PR5557 { |
| 5 | template <class T> struct A { |
| 6 | A(); |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 7 | virtual void anchor(); |
Anders Carlsson | 8e0317b | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 8 | virtual int a(T x); |
| 9 | }; |
| 10 | template<class T> A<T>::A() {} |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 11 | template<class T> void A<T>::anchor() { } |
| 12 | |
Anders Carlsson | 8e0317b | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 13 | template<class T> int A<T>::a(T x) { |
| 14 | return *x; // expected-error{{requires pointer operand}} |
| 15 | } |
| 16 | |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 17 | void f(A<int> x) { |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 18 | x.anchor(); // expected-note{{instantiation}} |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 19 | } |
Anders Carlsson | 8e0317b | 2009-12-07 08:29:39 +0000 | [diff] [blame] | 20 | |
| 21 | template<typename T> |
| 22 | struct X { |
| 23 | virtual void f(); |
| 24 | }; |
| 25 | |
| 26 | template<> |
| 27 | void X<int>::f() { } |
| 28 | } |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 29 | |
| 30 | template<typename T> |
| 31 | struct Base { |
| 32 | virtual ~Base() { |
| 33 | int *ptr = 0; |
| 34 | T t = ptr; // expected-error{{cannot initialize}} |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | template<typename T> |
| 39 | struct Derived : Base<T> { |
John McCall | f857e0b | 2010-03-16 05:36:30 +0000 | [diff] [blame] | 40 | virtual void foo() { } |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
John McCall | f857e0b | 2010-03-16 05:36:30 +0000 | [diff] [blame] | 43 | template struct Derived<int>; // expected-note {{in instantiation of member function 'Base<int>::~Base' requested here}} |
Douglas Gregor | 0a0f04d | 2010-01-06 04:44:19 +0000 | [diff] [blame] | 44 | |
Douglas Gregor | ccecc1b | 2010-01-06 20:27:16 +0000 | [diff] [blame] | 45 | template<typename T> |
| 46 | struct HasOutOfLineKey { |
Reid Kleckner | 4e32604 | 2014-07-16 00:30:59 +0000 | [diff] [blame] | 47 | HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}} |
Douglas Gregor | ccecc1b | 2010-01-06 20:27:16 +0000 | [diff] [blame] | 48 | virtual T *f(float *fp); |
| 49 | }; |
| 50 | |
| 51 | template<typename T> |
| 52 | T *HasOutOfLineKey<T>::f(float *fp) { |
| 53 | return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}} |
| 54 | } |
| 55 | |
Reid Kleckner | 4e32604 | 2014-07-16 00:30:59 +0000 | [diff] [blame] | 56 | HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::HasOutOfLineKey' requested here}} |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 57 | |
| 58 | namespace std { |
| 59 | class type_info; |
| 60 | } |
| 61 | |
| 62 | namespace PR7114 { |
| 63 | class A { virtual ~A(); }; // expected-note{{declared private here}} |
| 64 | |
| 65 | template<typename T> |
| 66 | class B { |
| 67 | public: |
| 68 | class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}} |
| 69 | static Inner i; |
| 70 | static const unsigned value = sizeof(i) == 4; |
| 71 | }; |
| 72 | |
| 73 | int f() { return B<int>::value; } |
| 74 | |
Hans Wennborg | 9125b08 | 2014-01-13 19:48:13 +0000 | [diff] [blame] | 75 | #ifdef MSABI |
| 76 | void test_typeid(B<float>::Inner bfi) { // expected-note{{implicit destructor}} |
| 77 | (void)typeid(bfi); |
| 78 | #else |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 79 | void test_typeid(B<float>::Inner bfi) { |
Richard Smith | f24e6e7 | 2013-06-13 03:34:55 +0000 | [diff] [blame] | 80 | (void)typeid(bfi); // expected-note{{implicit destructor}} |
Hans Wennborg | 9125b08 | 2014-01-13 19:48:13 +0000 | [diff] [blame] | 81 | #endif |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | template<typename T> |
| 85 | struct X : A { |
| 86 | void f() { } |
| 87 | }; |
| 88 | |
Hans Wennborg | 9125b08 | 2014-01-13 19:48:13 +0000 | [diff] [blame] | 89 | void test_X(X<int> &xi, X<float> &xf) { |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 90 | xi.f(); |
| 91 | } |
| 92 | } |
Eli Friedman | f8cab73 | 2013-06-20 01:47:05 +0000 | [diff] [blame] | 93 | |
| 94 | namespace DynamicCast { |
| 95 | struct Y {}; |
| 96 | template<typename T> struct X : virtual Y { |
| 97 | virtual void foo() { T x; } // expected-error {{variable has incomplete type 'void'}} |
| 98 | }; |
| 99 | template<typename T> struct X2 : virtual Y { |
| 100 | virtual void foo() { T x; } |
| 101 | }; |
| 102 | Y* f(X<void>* x) { return dynamic_cast<Y*>(x); } // expected-note {{in instantiation of member function 'DynamicCast::X<void>::foo' requested here}} |
| 103 | Y* f2(X<void>* x) { return dynamic_cast<Y*>(x); } |
| 104 | } |
Reid Kleckner | 4e32604 | 2014-07-16 00:30:59 +0000 | [diff] [blame] | 105 | |
| 106 | namespace avoid_using_vtable { |
| 107 | // We shouldn't emit the vtable for this code, in any ABI. If we emit the |
| 108 | // vtable, we emit an implicit virtual dtor, which calls ~RefPtr, which requires |
| 109 | // a complete type for DeclaredOnly. |
| 110 | // |
| 111 | // Previously we would reference the vtable in the MS C++ ABI, even though we |
| 112 | // don't need to emit either the ctor or the dtor. In the Itanium C++ ABI, the |
| 113 | // 'trace' method is the key function, so even though we use the vtable, we |
| 114 | // don't emit it. |
| 115 | |
| 116 | template <typename T> |
| 117 | struct RefPtr { |
| 118 | T *m_ptr; |
| 119 | ~RefPtr() { m_ptr->deref(); } |
| 120 | }; |
| 121 | struct DeclaredOnly; |
| 122 | struct Base { |
| 123 | virtual ~Base(); |
| 124 | }; |
| 125 | |
| 126 | struct AvoidVTable : Base { |
| 127 | RefPtr<DeclaredOnly> m_insertionStyle; |
| 128 | virtual void trace(); |
| 129 | AvoidVTable(); |
| 130 | }; |
| 131 | // Don't call the dtor, because that will emit an implicit dtor, and require a |
| 132 | // complete type for DeclaredOnly. |
| 133 | void foo() { new AvoidVTable; } |
| 134 | } |
| 135 | |
| 136 | namespace vtable_uses_incomplete { |
| 137 | // Opposite of the previous test that avoids a vtable, this one tests that we |
| 138 | // use the vtable when the ctor is defined inline. |
| 139 | template <typename T> |
| 140 | struct RefPtr { |
| 141 | T *m_ptr; |
| 142 | ~RefPtr() { m_ptr->deref(); } // expected-error {{member access into incomplete type 'vtable_uses_incomplete::DeclaredOnly'}} |
| 143 | }; |
| 144 | struct DeclaredOnly; // expected-note {{forward declaration of 'vtable_uses_incomplete::DeclaredOnly'}} |
| 145 | struct Base { |
| 146 | virtual ~Base(); |
| 147 | }; |
| 148 | |
| 149 | struct UsesVTable : Base { |
| 150 | RefPtr<DeclaredOnly> m_insertionStyle; |
| 151 | virtual void trace(); |
| 152 | UsesVTable() {} // expected-note {{in instantiation of member function 'vtable_uses_incomplete::RefPtr<vtable_uses_incomplete::DeclaredOnly>::~RefPtr' requested here}} |
| 153 | }; |
| 154 | } |