compilerplugins/clang/test/trivialdestructor.cxx |   24 +++++++++++++++++++++++
 compilerplugins/clang/trivialdestructor.cxx      |    4 ---
 2 files changed, 24 insertions(+), 4 deletions(-)

New commits:
commit 25fee1f66ba42c0b6828409bfd2c2e822c1f7eb6
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon Mar 14 22:14:22 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Tue Mar 15 13:41:02 2022 +0100

    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 <sberg...@redhat.com>

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();
 }
 

Reply via email to