diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-03-14 22:14:22 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-03-15 13:41:02 +0100 |
commit | 25fee1f66ba42c0b6828409bfd2c2e822c1f7eb6 (patch) | |
tree | bf0ace258c49808049099a497cae10136a8320fd /compilerplugins | |
parent | 5e6ee5503bcfdf47327a019e7ff172a378939d31 (diff) |
loplugin:trivialdestructor: Remove spurious anonymous union special case
No idea what this "The destructor for an implicit anonymous union member is
never invoked" block was meant to be good for.
If a union-like class X has a variant member Y with a non-trivial destructor, an
(implicitly-declared) defaulted destructor of X would be defined as deleted, so
we must not warn about a user-provided destructor of X with an empty body. But
that is already covered by the fact that the anonymous union of which Y is a
member will have a non-trivial destructor if Y has a non-trivial destructor.
Change-Id: Ia30381a07fadd3132f5595575716c6c5097fa34d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131576
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/test/trivialdestructor.cxx | 24 | ||||
-rw-r--r-- | compilerplugins/clang/trivialdestructor.cxx | 4 |
2 files changed, 24 insertions, 4 deletions
diff --git a/compilerplugins/clang/test/trivialdestructor.cxx b/compilerplugins/clang/test/trivialdestructor.cxx index 98bf8262f29e..b6ba4e968193 100644 --- a/compilerplugins/clang/test/trivialdestructor.cxx +++ b/compilerplugins/clang/test/trivialdestructor.cxx @@ -30,4 +30,28 @@ struct S3 ~S3() = delete; }; +struct S4 +{ + union { + int i; + float f; + }; + // expected-error@+1 {{no need for explicit destructor decl [loplugin:trivialdestructor]}} + ~S4() {} +}; + +struct Nontrivial +{ + ~Nontrivial(); +}; + +struct S5 +{ + union { + int i; + Nontrivial n; + }; + ~S5() {} +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/trivialdestructor.cxx b/compilerplugins/clang/trivialdestructor.cxx index 7ec54045dea7..09c0f9adcaed 100644 --- a/compilerplugins/clang/trivialdestructor.cxx +++ b/compilerplugins/clang/trivialdestructor.cxx @@ -125,10 +125,6 @@ bool TrivialDestructor::FieldHasTrivialDestructorBody(const FieldDecl* Field) CXXRecordDecl* FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl()); - // The destructor for an implicit anonymous union member is never invoked. - if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion()) - return false; - return FieldClassDecl->hasTrivialDestructor(); } |