Fixed #5398 (False positive: Scope of variable can be reduced does not account for other variables not reduceable)

This commit is contained in:
Daniel Marjamäki 2016-12-26 14:14:40 +01:00
parent c8bc1c8f0e
commit 770abcf453
2 changed files with 12 additions and 0 deletions

View File

@ -1205,6 +1205,9 @@ void CheckOther::checkVariableScope()
if (!tok->isNumber() && tok->tokType() != Token::eString && tok->tokType() != Token::eChar && !tok->isBoolean())
continue;
}
// bailout if initialized with function call that has possible side effects
if (tok->str() == "(" && Token::simpleMatch(tok->astOperand2(), "("))
continue;
bool reduce = true;
bool used = false; // Don't warn about unused variables
for (; tok && tok != var->scope()->classEnd; tok = tok->next()) {

View File

@ -719,6 +719,15 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // #5398
" bool success = false;\n"
" int notReducable(someClass.getX(&success));\n"
" if (success) {\n"
" foo(notReducable);\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f()\n"
"{\n"
"int foo = 0;\n"