diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-30 20:53:28 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-30 20:53:28 +0000 |
commit | 6c4c36c4ed1007143f5b8655eb68b313a7e12e76 (patch) | |
tree | 0a912935dcb75afa09172e2aabf7b40a71653f2e /test/CXX | |
parent | 0f30a12ce7b3d4d86c9ca9072f587da77c8eef34 (diff) |
PR10217: Provide diagnostics explaining why an implicitly-deleted special
member function is deleted.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp | 4 | ||||
-rw-r--r-- | test/CXX/special/class.copy/implicit-move.cpp | 6 | ||||
-rw-r--r-- | test/CXX/special/class.copy/p11.0x.copy.cpp | 36 | ||||
-rw-r--r-- | test/CXX/special/class.copy/p11.0x.move.cpp | 4 | ||||
-rw-r--r-- | test/CXX/special/class.ctor/p5-0x.cpp | 59 | ||||
-rw-r--r-- | test/CXX/special/class.dtor/p5-0x.cpp | 55 |
6 files changed, 87 insertions, 77 deletions
diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp index 47efde2db0..7764980e34 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp @@ -8,7 +8,7 @@ private: protected: struct Inner { int m; }; public: - bool &br; + bool &br; // expected-note {{default constructor of 'Aggr' is implicitly deleted because field 'br' of reference type 'bool &' would not be initialized}} }; bool b; Aggr ag = { b }; @@ -54,7 +54,7 @@ struct NonAggr5 : Aggr { // expected-note 3 {{candidate constructor}} }; NonAggr5 na5 = { b }; // expected-error {{no matching constructor for initialization of 'NonAggr5'}} template<typename...BaseList> -struct MaybeAggr5a : BaseList... {}; // expected-note {{defined here}} +struct MaybeAggr5a : BaseList... {}; // expected-note {{default constructor of 'MaybeAggr5a<Aggr>' is implicitly deleted because base class 'Aggr' has a deleted default constructor}} MaybeAggr5a<> ma5a0 = {}; // ok MaybeAggr5a<Aggr> ma5a1 = {}; // expected-error {{call to implicitly-deleted default constructor of 'MaybeAggr5a<Aggr>'}} diff --git a/test/CXX/special/class.copy/implicit-move.cpp b/test/CXX/special/class.copy/implicit-move.cpp index cc39af97ae..9ff6f48fad 100644 --- a/test/CXX/special/class.copy/implicit-move.cpp +++ b/test/CXX/special/class.copy/implicit-move.cpp @@ -87,9 +87,9 @@ private: ~PrivateDestructor() noexcept; }; -struct InheritsPrivateDestructor : PrivateDestructor {}; // expected-note{{defined here}} -struct ContainsPrivateDestructor { // expected-note{{defined here}} - PrivateDestructor pd; +struct InheritsPrivateDestructor : PrivateDestructor {}; // expected-note{{base class 'PrivateDestructor' has an inaccessible destructor}} +struct ContainsPrivateDestructor { + PrivateDestructor pd; // expected-note{{field 'pd' has an inaccessible destructor}} }; struct NonTrivialCopyOnly { diff --git a/test/CXX/special/class.copy/p11.0x.copy.cpp b/test/CXX/special/class.copy/p11.0x.copy.cpp index cbe62b41cb..b2b4f6a87f 100644 --- a/test/CXX/special/class.copy/p11.0x.copy.cpp +++ b/test/CXX/special/class.copy/p11.0x.copy.cpp @@ -7,16 +7,16 @@ struct NonTrivial { // A defaulted copy constructor for a class X is defined as deleted if X has: // -- a variant member with a non-trivial corresponding constructor -union DeletedNTVariant { // expected-note{{here}} - NonTrivial NT; +union DeletedNTVariant { + NonTrivial NT; // expected-note{{copy constructor of union 'DeletedNTVariant' is implicitly deleted because field 'NT' has a non-trivial copy constructor}} DeletedNTVariant(); }; DeletedNTVariant DVa; DeletedNTVariant DVb(DVa); // expected-error{{call to implicitly-deleted copy constructor}} -struct DeletedNTVariant2 { // expected-note{{here}} +struct DeletedNTVariant2 { union { - NonTrivial NT; + NonTrivial NT; // expected-note{{copy constructor of union 'DeletedNTVariant2' is implicitly deleted because field 'NT' has a non-trivial copy constructor}} }; DeletedNTVariant2(); }; @@ -34,8 +34,8 @@ private: friend struct HasAccess; }; -struct HasNoAccess { // expected-note{{here}} - NoAccess NA; +struct HasNoAccess { + NoAccess NA; // expected-note{{copy constructor of 'HasNoAccess' is implicitly deleted because field 'NA' has an inaccessible copy constructor}} }; HasNoAccess HNAa; HasNoAccess HNAb(HNAa); // expected-error{{call to implicitly-deleted copy constructor}} @@ -55,16 +55,16 @@ struct Ambiguity { Ambiguity(volatile Ambiguity&); }; -struct IsAmbiguous { // expected-note{{here}} +struct IsAmbiguous { NonConst NC; - Ambiguity A; + Ambiguity A; // expected-note 2{{copy constructor of 'IsAmbiguous' is implicitly deleted because field 'A' has multiple copy constructors}} IsAmbiguous(); }; IsAmbiguous IAa; IsAmbiguous IAb(IAa); // expected-error{{call to implicitly-deleted copy constructor}} -struct Deleted { // expected-note{{here}} - IsAmbiguous IA; +struct Deleted { + IsAmbiguous IA; // expected-note{{copy constructor of 'Deleted' is implicitly deleted because field 'IA' has a deleted copy constructor}} }; Deleted Da; Deleted Db(Da); // expected-error{{call to implicitly-deleted copy constructor}} @@ -72,17 +72,17 @@ Deleted Db(Da); // expected-error{{call to implicitly-deleted copy constructor}} // -- a direct or virtual base class B that cannot be copied because overload // resolution results in an ambiguity or a function that is deleted or // inaccessible -struct AmbiguousCopyBase : Ambiguity { // expected-note {{here}} +struct AmbiguousCopyBase : Ambiguity { // expected-note 2{{copy constructor of 'AmbiguousCopyBase' is implicitly deleted because base class 'Ambiguity' has multiple copy constructors}} NonConst NC; }; extern AmbiguousCopyBase ACBa; AmbiguousCopyBase ACBb(ACBa); // expected-error {{deleted copy constructor}} -struct DeletedCopyBase : AmbiguousCopyBase {}; // expected-note {{here}} +struct DeletedCopyBase : AmbiguousCopyBase {}; // expected-note {{copy constructor of 'DeletedCopyBase' is implicitly deleted because base class 'AmbiguousCopyBase' has a deleted copy constructor}} extern DeletedCopyBase DCBa; DeletedCopyBase DCBb(DCBa); // expected-error {{deleted copy constructor}} -struct InaccessibleCopyBase : NoAccess {}; // expected-note {{here}} +struct InaccessibleCopyBase : NoAccess {}; // expected-note {{copy constructor of 'InaccessibleCopyBase' is implicitly deleted because base class 'NoAccess' has an inaccessible copy constructor}} extern InaccessibleCopyBase ICBa; InaccessibleCopyBase ICBb(ICBa); // expected-error {{deleted copy constructor}} @@ -94,8 +94,8 @@ private: friend struct HasAccessDtor; }; -struct HasNoAccessDtor { // expected-note{{here}} - NoAccessDtor NAD; +struct HasNoAccessDtor { + NoAccessDtor NAD; // expected-note{{copy constructor of 'HasNoAccessDtor' is implicitly deleted because field 'NAD' has an inaccessible destructor}} HasNoAccessDtor(); ~HasNoAccessDtor(); }; @@ -108,14 +108,14 @@ struct HasAccessDtor { HasAccessDtor HADa; HasAccessDtor HADb(HADa); -struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{here}} +struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has an inaccessible destructor}} }; extern HasNoAccessDtorBase HNADBa; HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}} // -- a non-static data member of rvalue reference type -struct RValue { // expected-note{{here}} - int && ri = 1; +struct RValue { + int && ri = 1; // expected-note{{copy constructor of 'RValue' is implicitly deleted because field 'ri' is of rvalue reference type 'int &&'}} }; RValue RVa; RValue RVb(RVa); // expected-error{{call to implicitly-deleted copy constructor}} diff --git a/test/CXX/special/class.copy/p11.0x.move.cpp b/test/CXX/special/class.copy/p11.0x.move.cpp index 5315b060a0..3e9cc6b662 100644 --- a/test/CXX/special/class.copy/p11.0x.move.cpp +++ b/test/CXX/special/class.copy/p11.0x.move.cpp @@ -82,7 +82,7 @@ InaccessibleMoveBase::InaccessibleMoveBase(InaccessibleMoveBase&&) = default; // // -- any direct or virtual base class or non-static data member of a type with // a destructor that is deleted or inaccessible struct NoAccessDtor { - NoAccessDtor(NoAccessDtor&&); + NoAccessDtor(NoAccessDtor&&); // expected-note{{copy constructor is implicitly deleted because 'NoAccessDtor' has a user-declared move constructor}} private: ~NoAccessDtor(); friend struct HasAccessDtor; @@ -100,7 +100,7 @@ struct HasAccessDtor { }; HasAccessDtor::HasAccessDtor(HasAccessDtor&&) = default; -struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{here}} +struct HasNoAccessDtorBase : NoAccessDtor { // expected-note{{copy constructor of 'HasNoAccessDtorBase' is implicitly deleted because base class 'NoAccessDtor' has a deleted copy constructor}} }; extern HasNoAccessDtorBase HNADBa; HasNoAccessDtorBase HNADBb(HNADBa); // expected-error{{implicitly-deleted copy constructor}} diff --git a/test/CXX/special/class.ctor/p5-0x.cpp b/test/CXX/special/class.ctor/p5-0x.cpp index 6f43446674..ceb47d8f3b 100644 --- a/test/CXX/special/class.ctor/p5-0x.cpp +++ b/test/CXX/special/class.ctor/p5-0x.cpp @@ -2,9 +2,9 @@ struct DefaultedDefCtor1 {}; struct DefaultedDefCtor2 { DefaultedDefCtor2() = default; }; -struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; +struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; // expected-note {{explicitly marked deleted here}} class PrivateDefCtor { PrivateDefCtor() = default; public: PrivateDefCtor(int); }; -struct DeletedDtor { ~DeletedDtor() = delete; }; +struct DeletedDtor { ~DeletedDtor() = delete; }; // expected-note 4{{explicitly marked deleted here}} class PrivateDtor { ~PrivateDtor() = default; }; class Friend { Friend() = default; ~Friend() = default; @@ -21,7 +21,7 @@ int n; // - X is a union-like class that has a variant member with a non-trivial // default constructor, -union Deleted1a { UserProvidedDefCtor u; }; // expected-note {{defined here}} +union Deleted1a { UserProvidedDefCtor u; }; // expected-note {{default constructor of union 'Deleted1a' is implicitly deleted because field 'u' has a non-trivial default constructor}} Deleted1a d1a; // expected-error {{implicitly-deleted default constructor}} union NotDeleted1a { DefaultedDefCtor1 nu; }; NotDeleted1a nd1a; @@ -30,13 +30,15 @@ NotDeleted1b nd1b; // - any non-static data member with no brace-or-equal-initializer is of // reference type, -class Deleted2a { // expected-note {{defined here}} - Deleted2a() = default; // expected-note {{declared here}} +class Deleted2a { + // FIXME: We should explain that the function was implicitly deleted as a + // result of being defaulted, and why. + Deleted2a() = default; // expected-note 4{{explicitly marked deleted here}} int &a; }; Deleted2a d2a; // expected-error {{implicitly-deleted default constructor}} -struct Deleted2b { // expected-note {{here}} - int &&b; +struct Deleted2b { + int &&b; // expected-note {{default constructor of 'Deleted2b' is implicitly deleted because field 'b' of reference type 'int &&' would not be initialized}} }; Deleted2b d2b; // expected-error {{deleted default constructor}} class NotDeleted2a { int &a = n; }; @@ -49,13 +51,13 @@ NotDeleted2c nd2c; // - any non-variant non-static data member of const qualified type (or array // thereof) with no brace-or-equal-initializer does not have a user-provided // default constructor, -class Deleted3a { const int a; }; // expected-note {{here}} \ +class Deleted3a { const int a; }; // expected-note {{because field 'a' of const-qualified type 'const int' would not be initialized}} \ expected-warning {{does not declare any constructor}} \ expected-note {{will never be initialized}} Deleted3a d3a; // expected-error {{implicitly-deleted default constructor}} -class Deleted3b { const DefaultedDefCtor1 a[42]; }; // expected-note {{here}} +class Deleted3b { const DefaultedDefCtor1 a[42]; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtor1' would not be initialized}} Deleted3b d3b; // expected-error {{implicitly-deleted default constructor}} -class Deleted3c { const DefaultedDefCtor2 a; }; // expected-note {{defined here}} +class Deleted3c { const DefaultedDefCtor2 a; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtor2' would not be initialized}} Deleted3c d3c; // expected-error {{implicitly-deleted default constructor}} class NotDeleted3a { const int a = 0; }; NotDeleted3a nd3a; @@ -74,14 +76,21 @@ NotDeleted3g nd3g; // - X is a union and all of its variant members are of const-qualified type (or // array thereof), -union Deleted4a { const int a; const int b; const UserProvidedDefCtor c; }; // expected-note {{here}} +union Deleted4a { + const int a; + const int b; + const UserProvidedDefCtor c; // expected-note {{because field 'c' has a non-trivial default constructor}} +}; Deleted4a d4a; // expected-error {{implicitly-deleted default constructor}} union NotDeleted4a { const int a; int b; }; NotDeleted4a nd4a; // - X is a non-union class and all members of any anonymous union member are of // const-qualified type (or array thereof), -struct Deleted5a { union { const int a; }; union { int b; }; }; // expected-note {{here}} +struct Deleted5a { + union { const int a; }; // expected-note {{because all data members of an anonymous union member are const-qualified}} + union { int b; }; +}; Deleted5a d5a; // expected-error {{implicitly-deleted default constructor}} struct NotDeleted5a { union { const int a; int b; }; union { const int c; int d; }; }; NotDeleted5a nd5a; @@ -91,17 +100,17 @@ NotDeleted5a nd5a; // M has no default constructor or overload resolution as applied to M's default // constructor results in an ambiguity or in a function that is deleted or // inaccessible from the defaulted default constructor, or -struct Deleted6a : Deleted2a {}; // expected-note {{here}} +struct Deleted6a : Deleted2a {}; // expected-note {{because base class 'Deleted2a' has a deleted default constructor}} Deleted6a d6a; // expected-error {{implicitly-deleted default constructor}} -struct Deleted6b : virtual Deleted2a {}; // expected-note {{here}} +struct Deleted6b : virtual Deleted2a {}; // expected-note {{because base class 'Deleted2a' has a deleted default constructor}} Deleted6b d6b; // expected-error {{implicitly-deleted default constructor}} -struct Deleted6c { Deleted2a a; }; // expected-note {{here}} +struct Deleted6c { Deleted2a a; }; // expected-note {{because field 'a' has a deleted default constructor}} Deleted6c d6c; // expected-error {{implicitly-deleted default constructor}} -struct Deleted6d { DeletedDefCtor a; }; // expected-note {{here}} +struct Deleted6d { DeletedDefCtor a; }; // expected-note {{because field 'a' has a deleted default constructor}} Deleted6d d6d; // expected-error {{implicitly-deleted default constructor}} struct NotDeleted6a { DeletedDefCtor a = 0; }; NotDeleted6a nd6a; -struct Deleted6e { PrivateDefCtor a; }; // expected-note {{here}} +struct Deleted6e { PrivateDefCtor a; }; // expected-note {{because field 'a' has an inaccessible default constructor}} Deleted6e d6e; // expected-error {{implicitly-deleted default constructor}} struct NotDeleted6b { PrivateDefCtor a = 0; }; NotDeleted6b nd6b; @@ -111,21 +120,21 @@ NotDeleted6c nd6c; // - any direct or virtual base class or non-static data member has a type with // a destructor that is deleted or inaccessible from the defaulted default // constructor. -struct Deleted7a : DeletedDtor {}; // expected-note {{here}} +struct Deleted7a : DeletedDtor {}; // expected-note {{because base class 'DeletedDtor' has a deleted destructor}} Deleted7a d7a; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7b : virtual DeletedDtor {}; // expected-note {{here}} +struct Deleted7b : virtual DeletedDtor {}; // expected-note {{because base class 'DeletedDtor' has a deleted destructor}} Deleted7b d7b; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7c { DeletedDtor a; }; // expected-note {{here}} +struct Deleted7c { DeletedDtor a; }; // expected-note {{because field 'a' has a deleted destructor}} Deleted7c d7c; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7d { DeletedDtor a = {}; }; // expected-note {{here}} +struct Deleted7d { DeletedDtor a = {}; }; // expected-note {{because field 'a' has a deleted destructor}} Deleted7d d7d; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7e : PrivateDtor {}; // expected-note {{here}} +struct Deleted7e : PrivateDtor {}; // expected-note {{base class 'PrivateDtor' has an inaccessible destructor}} Deleted7e d7e; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7f : virtual PrivateDtor {}; // expected-note {{here}} +struct Deleted7f : virtual PrivateDtor {}; // expected-note {{base class 'PrivateDtor' has an inaccessible destructor}} Deleted7f d7f; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7g { PrivateDtor a; }; // expected-note {{here}} +struct Deleted7g { PrivateDtor a; }; // expected-note {{field 'a' has an inaccessible destructor}} Deleted7g d7g; // expected-error {{implicitly-deleted default constructor}} -struct Deleted7h { PrivateDtor a = {}; }; // expected-note {{here}} +struct Deleted7h { PrivateDtor a = {}; }; // expected-note {{field 'a' has an inaccessible destructor}} Deleted7h d7h; // expected-error {{implicitly-deleted default constructor}} struct NotDeleted7i : Friend {}; NotDeleted7i d7i; diff --git a/test/CXX/special/class.dtor/p5-0x.cpp b/test/CXX/special/class.dtor/p5-0x.cpp index cb7038aa9c..19aa119064 100644 --- a/test/CXX/special/class.dtor/p5-0x.cpp +++ b/test/CXX/special/class.dtor/p5-0x.cpp @@ -4,7 +4,7 @@ struct NonTrivDtor { ~NonTrivDtor(); }; struct DeletedDtor { - ~DeletedDtor() = delete; + ~DeletedDtor() = delete; // expected-note 5 {{deleted here}} }; class InaccessibleDtor { ~InaccessibleDtor() = default; @@ -14,73 +14,74 @@ class InaccessibleDtor { // -- X is a union-like class that has a variant member with a non-trivial // destructor. -union A1 { // expected-note {{here}} +union A1 { A1(); - NonTrivDtor n; + NonTrivDtor n; // expected-note {{destructor of union 'A1' is implicitly deleted because field 'n' has a non-trivial destructor}} }; A1 a1; // expected-error {{deleted function}} -struct A2 { // expected-note {{here}} +struct A2 { A2(); union { - NonTrivDtor n; + NonTrivDtor n; // expected-note {{because field 'n' has a non-trivial destructor}} }; }; A2 a2; // expected-error {{deleted function}} -union A3 { // expected-note {{here}} +union A3 { A3(); - NonTrivDtor n[3]; + NonTrivDtor n[3]; // expected-note {{because field 'n' has a non-trivial destructor}} }; A3 a3; // expected-error {{deleted function}} -struct A4 { // expected-note {{here}} +struct A4 { A4(); union { - NonTrivDtor n[3]; + NonTrivDtor n[3]; // expected-note {{because field 'n' has a non-trivial destructor}} }; }; 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}} +struct B1 { B1(); - DeletedDtor a; + DeletedDtor a; // expected-note {{because field 'a' has a deleted destructor}} }; B1 b1; // expected-error {{deleted function}} -struct B2 { // expected-note {{here}} +struct B2 { B2(); - InaccessibleDtor a; + InaccessibleDtor a; // expected-note {{because field 'a' has an inaccessible destructor}} }; B2 b2; // expected-error {{deleted function}} -struct B3 { // expected-note {{here}} +struct B3 { B3(); - DeletedDtor a[4]; + DeletedDtor a[4]; // expected-note {{because field 'a' has a deleted destructor}} }; B3 b3; // expected-error {{deleted function}} -struct B4 { // expected-note {{here}} +struct B4 { B4(); - InaccessibleDtor a[4]; + InaccessibleDtor a[4]; // expected-note {{because field 'a' has an inaccessible destructor}} }; B4 b4; // expected-error {{deleted function}} -union B5 { // expected-note {{here}} +union B5 { B5(); - union { - DeletedDtor a; + // FIXME: Describe the anonymous union member better than ''. + union { // expected-note {{because field '' has a deleted destructor}} + DeletedDtor a; // expected-note {{because field 'a' has a deleted destructor}} }; }; B5 b5; // expected-error {{deleted function}} -union B6 { // expected-note {{here}} +union B6 { B6(); - union { - InaccessibleDtor a; + union { // expected-note {{because field '' has a deleted destructor}} + InaccessibleDtor a; // expected-note {{because field 'a' has an inaccessible destructor}} }; }; 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}} +struct C1 : DeletedDtor { C1(); } c1; // expected-error {{deleted function}} expected-note {{base class 'DeletedDtor' has a deleted destructor}} +struct C2 : InaccessibleDtor { C2(); } c2; // expected-error {{deleted function}} expected-note {{base class 'InaccessibleDtor' has an inaccessible destructor}} +struct C3 : virtual DeletedDtor { C3(); } c3; // expected-error {{deleted function}} expected-note {{base class 'DeletedDtor' has a deleted destructor}} +struct C4 : virtual InaccessibleDtor { C4(); } c4; // expected-error {{deleted function}} expected-note {{base class 'InaccessibleDtor' has an inaccessible destructor}} // -- for a virtual destructor, lookup of the non-array deallocation function // results in an ambiguity or a function that is deleted or inaccessible. |