Fixed #7466 (Reference variable does not count side-effects (FP variableScope))

This commit is contained in:
Daniel Marjamäki 2017-03-03 19:07:00 +01:00
parent b5f2fd3c55
commit 59c1c76a97
2 changed files with 10 additions and 1 deletions

View File

@ -1193,7 +1193,7 @@ void CheckOther::checkVariableScope()
if (tok->str() == "(") {
forHead = true;
break;
} else if (tok->str() == "{" || tok->str() == ";" || tok->str() == "}")
} else if (Token::Match(tok, "[;{}]"))
break;
}
if (forHead)
@ -1208,6 +1208,8 @@ void CheckOther::checkVariableScope()
// bailout if initialized with function call that has possible side effects
if (tok->str() == "(" && Token::simpleMatch(tok->astOperand2(), "("))
continue;
if (Token::simpleMatch(tok, "=") && 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

@ -732,6 +732,13 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(Test &test) {\n"
" int& x = test.getData();\n"
" if (test.process())\n"
" x = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f()\n"
"{\n"
"int foo = 0;\n"