unusedScopedObject: Don't warn for void statements (#4370)

* Fix unusedScopedObject FPs

* Simplify

* Simplify

* Fix test

* Don't warn for void statements

* Format
This commit is contained in:
chrchr-github 2022-08-17 19:45:46 +02:00 committed by GitHub
parent e9f1665d4f
commit 4a64e20592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -2062,7 +2062,8 @@ void CheckOther::checkMisusedScopedObject()
&& Token::Match(tok->linkAt(2), ")|} ; !!}")
&& (!tok->next()->function() || // is not a function on this scope
tok->next()->function()->isConstructor()) // or is function in this scope and it's a ctor
&& !Token::simpleMatch(tok->tokAt(2)->astParent(), ";")) { // for loop condition
&& !Token::simpleMatch(tok->tokAt(2)->astParent(), ";") // for loop condition
&& tok->next()->str() != "void") {
if (const Token* arg = tok->tokAt(2)->astOperand2()) {
if (!isConstStatement(arg, mTokenizer->isCPP()))
continue;

View File

@ -5060,6 +5060,12 @@ private:
" float (*p);\n"
"}\n", "test.cpp");
ASSERT_EQUALS("", errout.str());
check("int f(int i) {\n"
" void();\n"
" return i;\n"
"}\n", "test.cpp");
ASSERT_EQUALS("", errout.str());
}
void trac2084() {