18fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -verify %s 2dd6e6918SDaniel Dunbar 3dd6e6918SDaniel Dunbar // If the object being deleted has incomplete class type at the point of 4dd6e6918SDaniel Dunbar // deletion and the complete class has a non-trivial destructor or a 5dd6e6918SDaniel Dunbar // deallocation function, the behavior is undefined. 6dd6e6918SDaniel Dunbar 7dd6e6918SDaniel Dunbar // The trivial case. 8dd6e6918SDaniel Dunbar class T0; // expected-note {{forward declaration}} f0(T0 * a)9dd6e6918SDaniel Dunbarvoid f0(T0 *a) { delete a; } // expected-warning {{deleting pointer to incomplete type}} 10dd6e6918SDaniel Dunbar class T0 { ~T0(); }; 11dd6e6918SDaniel Dunbar 12dd6e6918SDaniel Dunbar // The trivial case, inside a template instantiation. 13dd6e6918SDaniel Dunbar template<typename T> ~T1_AT1_A143155f573SJohn McCallstruct T1_A { T *x; ~T1_A() { delete x; } }; // expected-warning {{deleting pointer to incomplete type}} 15dd6e6918SDaniel Dunbar class T1_B; // expected-note {{forward declaration}} f0()16dd6e6918SDaniel Dunbarvoid f0() { T1_A<T1_B> x; } // expected-note {{in instantiation of member function}} 17dd6e6918SDaniel Dunbar 18dd6e6918SDaniel Dunbar // This case depends on when we check T2_C::f0. 19dd6e6918SDaniel Dunbar class T2_A; 20dd6e6918SDaniel Dunbar template<typename T> f0T2_B21dd6e6918SDaniel Dunbarstruct T2_B { void f0(T *a) { delete a; } }; f0T2_C22dd6e6918SDaniel Dunbarstruct T2_C { T2_B<T2_A> x; void f0(T2_A *a) { x.f0(a); } }; f0(T2_A * a)23dd6e6918SDaniel Dunbarvoid f0(T2_A *a) { T2_C x; x.f0(a); } 24dd6e6918SDaniel Dunbar class T2_A { }; 25dd6e6918SDaniel Dunbar 26dd6e6918SDaniel Dunbar // An alternate version of the same. 27dd6e6918SDaniel Dunbar class T3_A; 28dd6e6918SDaniel Dunbar template<typename T> 29*fa778138SDouglas Gregor struct T3_B { f0T3_B30*fa778138SDouglas Gregor void f0(T *a) { 31*fa778138SDouglas Gregor delete a; // expected-error{{calling a private destructor of class 'T3_A'}} 32*fa778138SDouglas Gregor } 33*fa778138SDouglas Gregor }; 34*fa778138SDouglas Gregor 35*fa778138SDouglas Gregor struct T3_C { 36*fa778138SDouglas Gregor T3_B<T3_A> x; f0T3_C37*fa778138SDouglas Gregor void f0(T3_A *a) { 38*fa778138SDouglas Gregor x.f0(a); // expected-note{{in instantiation of member function 'T3_B<T3_A>::f0' requested here}} 39*fa778138SDouglas Gregor } 40*fa778138SDouglas Gregor }; 41*fa778138SDouglas Gregor f0(T3_A * a)42dd6e6918SDaniel Dunbarvoid f0(T3_A *a) { T3_C x; x.f0(a); } 43*fa778138SDouglas Gregor class T3_A { 44*fa778138SDouglas Gregor private: 45*fa778138SDouglas Gregor ~T3_A(); // expected-note{{declared private here}} 46*fa778138SDouglas Gregor }; 47