Fixed #7466 (Reference variable does not count side-effects (FP variableScope))
This commit is contained in:
parent
b5f2fd3c55
commit
59c1c76a97
|
@ -1193,7 +1193,7 @@ void CheckOther::checkVariableScope()
|
||||||
if (tok->str() == "(") {
|
if (tok->str() == "(") {
|
||||||
forHead = true;
|
forHead = true;
|
||||||
break;
|
break;
|
||||||
} else if (tok->str() == "{" || tok->str() == ";" || tok->str() == "}")
|
} else if (Token::Match(tok, "[;{}]"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (forHead)
|
if (forHead)
|
||||||
|
@ -1208,6 +1208,8 @@ void CheckOther::checkVariableScope()
|
||||||
// bailout if initialized with function call that has possible side effects
|
// bailout if initialized with function call that has possible side effects
|
||||||
if (tok->str() == "(" && Token::simpleMatch(tok->astOperand2(), "("))
|
if (tok->str() == "(" && Token::simpleMatch(tok->astOperand2(), "("))
|
||||||
continue;
|
continue;
|
||||||
|
if (Token::simpleMatch(tok, "=") && Token::simpleMatch(tok->astOperand2(), "("))
|
||||||
|
continue;
|
||||||
bool reduce = true;
|
bool reduce = true;
|
||||||
bool used = false; // Don't warn about unused variables
|
bool used = false; // Don't warn about unused variables
|
||||||
for (; tok && tok != var->scope()->classEnd; tok = tok->next()) {
|
for (; tok && tok != var->scope()->classEnd; tok = tok->next()) {
|
||||||
|
|
|
@ -732,6 +732,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
"int foo = 0;\n"
|
"int foo = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue