From 30d3643bb8c5d92b3f8e4f58538f6635aa09a406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 4 Sep 2020 18:56:12 +0200 Subject: [PATCH] Fixed #9851 (FP virtualDestructor - private virtual dtor) --- lib/checkclass.cpp | 13 +++++-------- test/testclass.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 7d17519ac..f513a3285 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1608,14 +1608,11 @@ void CheckClass::virtualDestructor() if (scope->definedType->derivedFrom.empty()) { if (printInconclusive) { const Function *destructor = scope->getDestructor(); - if (destructor) { - if (!((destructor->hasVirtualSpecifier() && destructor->access == AccessControl::Public) || - (destructor->access == AccessControl::Protected))) { - for (const Function &func : scope->functionList) { - if (func.hasVirtualSpecifier()) { - inconclusiveErrors.push_back(destructor); - break; - } + if (destructor && !destructor->hasVirtualSpecifier() && destructor->access == AccessControl::Public) { + for (const Function &func : scope->functionList) { + if (func.hasVirtualSpecifier()) { + inconclusiveErrors.push_back(destructor); + break; } } } diff --git a/test/testclass.cpp b/test/testclass.cpp index e2f0c8087..eaa197725 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2531,6 +2531,13 @@ private: " ~Base(){}\n" "};\n", true); ASSERT_EQUALS("", errout.str()); + + checkVirtualDestructor("class C {\n" + "private:\n" + " C();\n" + " virtual ~C();\n" + "};\n", true); + ASSERT_EQUALS("", errout.str()); } void checkNoMemset(const char code[]) {