Fixed #5398 (False positive: Scope of variable can be reduced does not account for other variables not reduceable)
This commit is contained in:
parent
c8bc1c8f0e
commit
770abcf453
|
@ -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()) {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue