diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-26 09:11:52 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-26 09:11:52 +0000 |
commit | 921bd20dddf5080cdb36f39c0162eb63b2d5325e (patch) | |
tree | 8a00bb24a57086351d6591c9be484e55a727543e /clang/test | |
parent | af3c2090b4158f9ed56320553d10506e9838cb6e (diff) | |
download | bcm5719-llvm-921bd20dddf5080cdb36f39c0162eb63b2d5325e.tar.gz bcm5719-llvm-921bd20dddf5080cdb36f39c0162eb63b2d5325e.zip |
Ensure that we delete destructors in the right cases. Specifically:
- variant members with nontrivial destructors make the containing class's
destructor deleted
- check for a virtual destructor after checking for overridden methods in the
base class(es)
- check for an inaccessible operator delete for a class with a virtual
destructor.
Do not try to call an anonymous union field's destructor from the destructor of
the containing class.
llvm-svn: 151483
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/CXX/special/class.dtor/p5-0x.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/clang/test/CXX/special/class.dtor/p5-0x.cpp b/clang/test/CXX/special/class.dtor/p5-0x.cpp new file mode 100644 index 00000000000..cb7038aa9c4 --- /dev/null +++ b/clang/test/CXX/special/class.dtor/p5-0x.cpp @@ -0,0 +1,103 @@ +// RUN: %clang_cc1 -verify -std=c++11 %s + +struct NonTrivDtor { + ~NonTrivDtor(); +}; +struct DeletedDtor { + ~DeletedDtor() = delete; +}; +class InaccessibleDtor { + ~InaccessibleDtor() = default; +}; + +// A defaulted destructor for a class X is defined as deleted if: + +// -- X is a union-like class that has a variant member with a non-trivial +// destructor. +union A1 { // expected-note {{here}} + A1(); + NonTrivDtor n; +}; +A1 a1; // expected-error {{deleted function}} +struct A2 { // expected-note {{here}} + A2(); + union { + NonTrivDtor n; + }; +}; +A2 a2; // expected-error {{deleted function}} +union A3 { // expected-note {{here}} + A3(); + NonTrivDtor n[3]; +}; +A3 a3; // expected-error {{deleted function}} +struct A4 { // expected-note {{here}} + A4(); + union { + NonTrivDtor n[3]; + }; +}; +A4 a4; // expected-error {{deleted function}} + +// -- any of the non-static data members has class type M (or array thereof) and +// M has a deleted or inaccessible destructor. +struct B1 { // expected-note {{here}} + B1(); + DeletedDtor a; +}; +B1 b1; // expected-error {{deleted function}} +struct B2 { // expected-note {{here}} + B2(); + InaccessibleDtor a; +}; +B2 b2; // expected-error {{deleted function}} +struct B3 { // expected-note {{here}} + B3(); + DeletedDtor a[4]; +}; +B3 b3; // expected-error {{deleted function}} +struct B4 { // expected-note {{here}} + B4(); + InaccessibleDtor a[4]; +}; +B4 b4; // expected-error {{deleted function}} +union B5 { // expected-note {{here}} + B5(); + union { + DeletedDtor a; + }; +}; +B5 b5; // expected-error {{deleted function}} +union B6 { // expected-note {{here}} + B6(); + union { + InaccessibleDtor a; + }; +}; +B6 b6; // expected-error {{deleted function}} + +// -- any direct or virtual base class has a deleted or inaccessible destructor. +struct C1 : DeletedDtor { C1(); } c1; // expected-error {{deleted function}} expected-note {{here}} +struct C2 : InaccessibleDtor { C2(); } c2; // expected-error {{deleted function}} expected-note {{here}} +struct C3 : virtual DeletedDtor { C3(); } c3; // expected-error {{deleted function}} expected-note {{here}} +struct C4 : virtual InaccessibleDtor { C4(); } c4; // expected-error {{deleted function}} expected-note {{here}} + +// -- for a virtual destructor, lookup of the non-array deallocation function +// results in an ambiguity or a function that is deleted or inaccessible. +class D1 { + void operator delete(void*); +public: + virtual ~D1() = default; +} d1; // ok +struct D2 : D1 { // expected-note {{deleted here}} + // implicitly-virtual destructor +} d2; // expected-error {{deleted function}} +struct D3 { + virtual ~D3() = default; // expected-note {{deleted here}} + void operator delete(void*, double = 0.0); + void operator delete(void*, char = 0); +} d3; // expected-error {{deleted function}} +struct D4 { + virtual ~D4() = default; // expected-note {{deleted here}} + void operator delete(void*) = delete; +} d4; // expected-error {{deleted function}} |