Fixed #9851 (FP virtualDestructor - private virtual dtor)

This commit is contained in:
Daniel Marjamäki 2020-09-04 18:56:12 +02:00
parent 040da4ff32
commit 30d3643bb8
2 changed files with 12 additions and 8 deletions

View File

@ -1608,14 +1608,11 @@ void CheckClass::virtualDestructor()
if (scope->definedType->derivedFrom.empty()) { if (scope->definedType->derivedFrom.empty()) {
if (printInconclusive) { if (printInconclusive) {
const Function *destructor = scope->getDestructor(); const Function *destructor = scope->getDestructor();
if (destructor) { if (destructor && !destructor->hasVirtualSpecifier() && destructor->access == AccessControl::Public) {
if (!((destructor->hasVirtualSpecifier() && destructor->access == AccessControl::Public) || for (const Function &func : scope->functionList) {
(destructor->access == AccessControl::Protected))) { if (func.hasVirtualSpecifier()) {
for (const Function &func : scope->functionList) { inconclusiveErrors.push_back(destructor);
if (func.hasVirtualSpecifier()) { break;
inconclusiveErrors.push_back(destructor);
break;
}
} }
} }
} }

View File

@ -2531,6 +2531,13 @@ private:
" ~Base(){}\n" " ~Base(){}\n"
"};\n", true); "};\n", true);
ASSERT_EQUALS("", errout.str()); 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[]) { void checkNoMemset(const char code[]) {