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