1 // RUN: %clang_cc1 -verify -std=c++11 %s -Wno-defaulted-function-deleted -triple x86_64-linux-gnu
7 ~DeletedDtor() = delete; // expected-note 5 {{deleted here}}
9 class InaccessibleDtor
{
10 ~InaccessibleDtor() = default;
13 // A defaulted destructor for a class X is defined as deleted if:
15 // -- X is a union-like class that has a variant member with a non-trivial
19 NonTrivDtor n
; // expected-note {{destructor of 'A1' is implicitly deleted because variant field 'n' has a non-trivial destructor}}
21 A1 a1
; // expected-error {{deleted function}}
25 NonTrivDtor n
; // expected-note {{because variant field 'n' has a non-trivial destructor}}
28 A2 a2
; // expected-error {{deleted function}}
31 NonTrivDtor n
[3]; // expected-note {{because variant field 'n' has a non-trivial destructor}}
33 A3 a3
; // expected-error {{deleted function}}
37 NonTrivDtor n
[3]; // expected-note {{because variant field 'n' has a non-trivial destructor}}
40 A4 a4
; // expected-error {{deleted function}}
42 // -- any of the non-static data members has class type M (or array thereof) and
43 // M has a deleted or inaccessible destructor.
46 DeletedDtor a
; // expected-note {{because field 'a' has a deleted destructor}}
48 B1 b1
; // expected-error {{deleted function}}
51 InaccessibleDtor a
; // expected-note {{because field 'a' has an inaccessible destructor}}
53 B2 b2
; // expected-error {{deleted function}}
56 DeletedDtor a
[4]; // expected-note {{because field 'a' has a deleted destructor}}
58 B3 b3
; // expected-error {{deleted function}}
61 InaccessibleDtor a
[4]; // expected-note {{because field 'a' has an inaccessible destructor}}
63 B4 b4
; // expected-error {{deleted function}}
66 union { // expected-note-re {{because field 'B5::(anonymous union at {{.+}})' has a deleted destructor}}
67 DeletedDtor a
; // expected-note {{because field 'a' has a deleted destructor}}
70 B5 b5
; // expected-error {{deleted function}}
73 union { // expected-note-re {{because field 'B6::(anonymous union at {{.+}})' has a deleted destructor}}
74 InaccessibleDtor a
; // expected-note {{because field 'a' has an inaccessible destructor}}
77 B6 b6
; // expected-error {{deleted function}}
79 // -- any direct or virtual base class has a deleted or inaccessible destructor.
80 struct C1
: DeletedDtor
{ C1(); } c1
; // expected-error {{deleted function}} expected-note {{base class 'DeletedDtor' has a deleted destructor}}
81 struct C2
: InaccessibleDtor
{ C2(); } c2
; // expected-error {{deleted function}} expected-note {{base class 'InaccessibleDtor' has an inaccessible destructor}}
82 struct C3
: virtual DeletedDtor
{ C3(); } c3
; // expected-error {{deleted function}} expected-note {{base class 'DeletedDtor' has a deleted destructor}}
83 struct C4
: virtual InaccessibleDtor
{ C4(); } c4
; // expected-error {{deleted function}} expected-note {{base class 'InaccessibleDtor' has an inaccessible destructor}}
85 // -- for a virtual destructor, lookup of the non-array deallocation function
86 // results in an ambiguity or a function that is deleted or inaccessible.
88 void operator delete(void*); // expected-note {{here}}
90 virtual ~D1() = default; // expected-note 2{{here}}
92 struct D2
: D1
{ // expected-note 2{{virtual destructor requires an unambiguous, accessible 'operator delete'}} \
93 // expected-error {{deleted function '~D2' cannot override a non-deleted}}
94 // implicitly-virtual destructor
95 } d2
; // expected-error {{deleted function}}
96 struct D3
{ // expected-note {{virtual destructor requires an unambiguous, accessible 'operator delete'}}
97 virtual ~D3() = default; // expected-note {{explicitly defaulted function was implicitly deleted here}}
98 void operator delete(void*, double = 0.0);
99 void operator delete(void*, char = 0);
100 } d3
; // expected-error {{deleted function}}
101 struct D4
{ // expected-note {{virtual destructor requires an unambiguous, accessible 'operator delete'}}
102 virtual ~D4() = default; // expected-note {{implicitly deleted here}}
103 void operator delete(void*) = delete;
104 } d4
; // expected-error {{deleted function}}
106 ~D5(); // ok (but not definable)
108 D5::~D5() {} // expected-error {{'operator delete' is a private member of 'D1'}}
110 ~D6() = delete; // expected-error {{deleted function '~D6' cannot override a non-deleted}}