xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/defaulted-private-dtor.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -verify -std=c++11 %s -fcxx-exceptions
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc class BadDtor {
4*f4a2713aSLionel Sambuc   // A private, but nonetheless trivial, destructor.
5*f4a2713aSLionel Sambuc   ~BadDtor() = default; // expected-note 9{{here}}
6*f4a2713aSLionel Sambuc   friend class K;
7*f4a2713aSLionel Sambuc };
f()8*f4a2713aSLionel Sambuc void f() {
9*f4a2713aSLionel Sambuc   BadDtor *p = new BadDtor[3]; // expected-error {{private destructor}}
10*f4a2713aSLionel Sambuc   delete [] p; // expected-error {{private destructor}}
11*f4a2713aSLionel Sambuc   const BadDtor &dd2 = BadDtor(); // expected-error {{private destructor}}
12*f4a2713aSLionel Sambuc   BadDtor dd; // expected-error {{private destructor}}
13*f4a2713aSLionel Sambuc   throw dd; // expected-error {{private destructor}}
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc struct V {
16*f4a2713aSLionel Sambuc   V();
17*f4a2713aSLionel Sambuc   BadDtor bd; // expected-note {{inaccessible destructor}}
18*f4a2713aSLionel Sambuc };
19*f4a2713aSLionel Sambuc V v; // expected-error {{deleted function}}
20*f4a2713aSLionel Sambuc struct W : BadDtor { // expected-note {{inaccessible destructor}}
21*f4a2713aSLionel Sambuc   W();
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc W w; // expected-error {{deleted function}}
24*f4a2713aSLionel Sambuc struct X : BadDtor { // expected-error {{private destructor}}
~XX25*f4a2713aSLionel Sambuc   ~X() {}
26*f4a2713aSLionel Sambuc };
27*f4a2713aSLionel Sambuc struct Y {
28*f4a2713aSLionel Sambuc   BadDtor dd; // expected-error {{private destructor}}
~YY29*f4a2713aSLionel Sambuc   ~Y() {}
30*f4a2713aSLionel Sambuc };
31*f4a2713aSLionel Sambuc struct Z : virtual BadDtor { // expected-error {{private destructor}}
~ZZ32*f4a2713aSLionel Sambuc   ~Z() {}
33*f4a2713aSLionel Sambuc };
34*f4a2713aSLionel Sambuc BadDtor dd; // expected-error {{private destructor}}
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc class K : BadDtor {
f()37*f4a2713aSLionel Sambuc   void f() {
38*f4a2713aSLionel Sambuc     BadDtor *p = new BadDtor[3];
39*f4a2713aSLionel Sambuc     delete [] p;
40*f4a2713aSLionel Sambuc     const BadDtor &dd2 = BadDtor();
41*f4a2713aSLionel Sambuc     BadDtor dd;
42*f4a2713aSLionel Sambuc     throw dd;
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc     {
45*f4a2713aSLionel Sambuc       BadDtor x;
46*f4a2713aSLionel Sambuc       goto dont_call_dtor;
47*f4a2713aSLionel Sambuc     }
48*f4a2713aSLionel Sambuc dont_call_dtor:
49*f4a2713aSLionel Sambuc     ;
50*f4a2713aSLionel Sambuc   }
51*f4a2713aSLionel Sambuc   struct Z : virtual BadDtor {
~ZK::Z52*f4a2713aSLionel Sambuc     ~Z() {}
53*f4a2713aSLionel Sambuc   };
54*f4a2713aSLionel Sambuc   BadDtor dd;
55*f4a2713aSLionel Sambuc   ~K();
56*f4a2713aSLionel Sambuc };
57