p5.cpp 1.4 KB

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