compilerplugins/clang/trivialdestructor.cxx | 43 +++++++--------------------- 1 file changed, 11 insertions(+), 32 deletions(-)
New commits: commit c11464f54837306c32054202a1d13b796b8dcb0b Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Mon Mar 14 22:25:23 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Tue Mar 15 14:41:28 2022 +0100 Simplify loplugin:trivialdestructor The recursive checking of (non-virtual) bases and the checking of all virtual bases were unnecessary. It suffices to just check whether all the direct (virtual and non-virtual) bases have trivial destructors. (And FieldHasTrivialDestructor*Body* was a misnomer, as it actually checks whether the corresponding type has a trivial destructor.) Change-Id: I8a70e18eea4b629ad56577fa885f51925f9d7dde Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131608 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/compilerplugins/clang/trivialdestructor.cxx b/compilerplugins/clang/trivialdestructor.cxx index 09c0f9adcaed..5db1bbab705f 100644 --- a/compilerplugins/clang/trivialdestructor.cxx +++ b/compilerplugins/clang/trivialdestructor.cxx @@ -36,9 +36,8 @@ public: bool VisitCXXDestructorDecl(CXXDestructorDecl const*); private: - bool HasTrivialDestructorBody(const CXXRecordDecl* BaseClassDecl, - const CXXRecordDecl* MostDerivedClassDecl); - bool FieldHasTrivialDestructorBody(const FieldDecl* Field); + bool HasTrivialDestructorBody(const CXXRecordDecl* ClassDecl); + bool FieldHasTrivialDestructor(const FieldDecl* Field); }; bool TrivialDestructor::VisitCXXDestructorDecl(CXXDestructorDecl const* destructorDecl) @@ -58,7 +57,7 @@ bool TrivialDestructor::VisitCXXDestructorDecl(CXXDestructorDecl const* destruct if (isInUnoIncludeFile( compiler.getSourceManager().getSpellingLoc(destructorDecl->getLocation()))) return true; - if (!HasTrivialDestructorBody(destructorDecl->getParent(), destructorDecl->getParent())) + if (!HasTrivialDestructorBody(destructorDecl->getParent())) return true; report(DiagnosticsEngine::Warning, "no need for explicit destructor decl", @@ -77,45 +76,25 @@ bool TrivialDestructor::VisitCXXDestructorDecl(CXXDestructorDecl const* destruct return true; } -bool TrivialDestructor::HasTrivialDestructorBody(const CXXRecordDecl* BaseClassDecl, - const CXXRecordDecl* MostDerivedClassDecl) +bool TrivialDestructor::HasTrivialDestructorBody(const CXXRecordDecl* ClassDecl) { - if (BaseClassDecl != MostDerivedClassDecl && !BaseClassDecl->hasTrivialDestructor()) - return false; - // Check fields. - for (const auto* field : BaseClassDecl->fields()) - if (!FieldHasTrivialDestructorBody(field)) + for (const auto* field : ClassDecl->fields()) + if (!FieldHasTrivialDestructor(field)) return false; - // Check non-virtual bases. - for (const auto& I : BaseClassDecl->bases()) + // Check bases. + for (const auto& I : ClassDecl->bases()) { - if (I.isVirtual()) - continue; - if (!I.getType()->isRecordType()) - continue; - const CXXRecordDecl* NonVirtualBase = I.getType()->getAsCXXRecordDecl(); - if (NonVirtualBase && !HasTrivialDestructorBody(NonVirtualBase, MostDerivedClassDecl)) + const CXXRecordDecl* Base = I.getType()->getAsCXXRecordDecl(); + if (!Base->hasTrivialDestructor()) return false; } - if (BaseClassDecl == MostDerivedClassDecl) - { - // Check virtual bases. - for (const auto& I : BaseClassDecl->vbases()) - { - if (!I.getType()->isRecordType()) - continue; - const CXXRecordDecl* VirtualBase = I.getType()->getAsCXXRecordDecl(); - if (VirtualBase && !HasTrivialDestructorBody(VirtualBase, MostDerivedClassDecl)) - return false; - } - } return true; } -bool TrivialDestructor::FieldHasTrivialDestructorBody(const FieldDecl* Field) +bool TrivialDestructor::FieldHasTrivialDestructor(const FieldDecl* Field) { QualType FieldBaseElementType = compiler.getASTContext().getBaseElementType(Field->getType());