diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ba0383de4..5d4eafa5e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()) { diff --git a/test/testother.cpp b/test/testother.cpp index 7be95ee33..419c666aa 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"