diff options
author | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
---|---|---|
committer | Carlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au> | 2012-10-15 17:10:06 +1100 |
commit | be1de4be954c80875ad4108e0a33e8e131b2f2c0 (patch) | |
tree | 1fbbecf276bf7c7bdcbb4dd446099d6d90eaa516 /clang/test/CXX/expr/expr.unary/expr.delete | |
parent | c4626a62754862d20b41e8a46a3574264ea80e6d (diff) | |
parent | f1bd2e48c5324d3f7cda4090c87f8a5b6f463ce2 (diff) |
Merge branch 'master' of ssh://bitbucket.org/czan/honours
Diffstat (limited to 'clang/test/CXX/expr/expr.unary/expr.delete')
-rw-r--r-- | clang/test/CXX/expr/expr.unary/expr.delete/p5.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/clang/test/CXX/expr/expr.unary/expr.delete/p5.cpp b/clang/test/CXX/expr/expr.unary/expr.delete/p5.cpp new file mode 100644 index 0000000..ecb2918 --- /dev/null +++ b/clang/test/CXX/expr/expr.unary/expr.delete/p5.cpp @@ -0,0 +1,46 @@ +// RUN: %clang_cc1 -verify %s + +// If the object being deleted has incomplete class type at the point of +// deletion and the complete class has a non-trivial destructor or a +// deallocation function, the behavior is undefined. + +// The trivial case. +class T0; // expected-note {{forward declaration}} +void f0(T0 *a) { delete a; } // expected-warning {{deleting pointer to incomplete type}} +class T0 { ~T0(); }; + +// The trivial case, inside a template instantiation. +template<typename T> +struct T1_A { T *x; ~T1_A() { delete x; } }; // expected-warning {{deleting pointer to incomplete type}} +class T1_B; // expected-note {{forward declaration}} +void f0() { T1_A<T1_B> x; } // expected-note {{in instantiation of member function}} + +// This case depends on when we check T2_C::f0. +class T2_A; +template<typename T> +struct T2_B { void f0(T *a) { delete a; } }; +struct T2_C { T2_B<T2_A> x; void f0(T2_A *a) { x.f0(a); } }; +void f0(T2_A *a) { T2_C x; x.f0(a); } +class T2_A { }; + +// An alternate version of the same. +class T3_A; +template<typename T> +struct T3_B { + void f0(T *a) { + delete a; // expected-error{{calling a private destructor of class 'T3_A'}} + } +}; + +struct T3_C { + T3_B<T3_A> x; + void f0(T3_A *a) { + x.f0(a); // expected-note{{in instantiation of member function 'T3_B<T3_A>::f0' requested here}} + } +}; + +void f0(T3_A *a) { T3_C x; x.f0(a); } +class T3_A { +private: + ~T3_A(); // expected-note{{declared private here}} +}; |