Fix FP unusedVar with side effects in destructor (#4212)

This commit is contained in:
chrchr-github 2022-06-14 09:55:22 +02:00 committed by GitHub
parent 6f5a5fd947
commit 6d22d6a8ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -1535,7 +1535,7 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)
// Non-empty constructors => possible side effects
for (const Function& f : type->classScope->functionList) {
if (!f.isConstructor())
if (!f.isConstructor() && !f.isDestructor())
continue;
if (f.argDef && Token::simpleMatch(f.argDef->link(), ") ="))
continue; // ignore default/deleted constructors

View File

@ -536,6 +536,16 @@ private:
" F f;\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage(
"struct S {\n"
" static void f() { std::cout << \"f()\"; }\n"
" ~S() { f(); }\n"
"};\n"
"void g() {\n"
" S s;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void cleanFunction() {