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.
8class T0; // expected-note {{forward declaration}}
9void f0(T0 *a) { delete a; } // expected-warning {{deleting pointer to incomplete type}}
10class T0 { ~T0(); };
11
12// The trivial case, inside a template instantiation.
13template<typename T>
14struct T1_A { T *x; ~T1_A() { delete x; } }; // expected-warning {{deleting pointer to incomplete type}}
15class T1_B; // expected-note {{forward declaration}}
16void 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.
19class T2_A;
20template<typename T>
21struct T2_B { void f0(T *a) { delete a; } };
22struct T2_C { T2_B<T2_A> x; void f0(T2_A *a) { x.f0(a); } };
23void f0(T2_A *a) { T2_C x; x.f0(a); }
24class T2_A { };
25
26// An alternate version of the same.
27class T3_A;
28template<typename T>
29struct T3_B {
30  void f0(T *a) {
31    delete a; // expected-error{{calling a private destructor of class 'T3_A'}}
32  }
33};
34
35struct 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
42void f0(T3_A *a) { T3_C x; x.f0(a); }
43class T3_A {
44private:
45  ~T3_A(); // expected-note{{declared private here}}
46};
47