From 0d87de91457c3bf2338b997555694953d45e17a4 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Tue, 10 Sep 2024 13:50:56 +0200 Subject: [PATCH] rule-of-three: Fix destructor not being found and thus causing false positive This works fine in clang 14, but apparently not in later versions The false positive caused a CI failure in https://invent.kde.org/libraries/qca/-/merge_requests/116 --- src/checks/level2/rule-of-three.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/checks/level2/rule-of-three.cpp b/src/checks/level2/rule-of-three.cpp index 6996ee1e..f18ff999 100644 --- a/src/checks/level2/rule-of-three.cpp +++ b/src/checks/level2/rule-of-three.cpp @@ -56,7 +56,14 @@ void RuleOfThree::VisitDecl(clang::Decl *decl) CXXConstructorDecl *copyCtor = Utils::copyCtor(record); CXXMethodDecl *copyAssign = Utils::copyAssign(record); - CXXDestructorDecl *destructor = record->getDestructor(); + CXXDestructorDecl *destructor = nullptr; + // Getting the destructor using record->getDestructor() does not work for later clang versions, e.g. clang 16 + for (auto *decl : record->decls()) { + if (auto *destructorDecl = dyn_cast(decl)) { + destructor = destructorDecl; + break; + } + } const bool dtorDefaultedByUser = destructor && destructor->isDefaulted() && !destructor->isImplicit(); const bool hasUserCopyCtor = copyCtor && copyCtor->isUserProvided(); -- GitLab