diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 849b03566..37b9700f2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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()) { diff --git a/test/testother.cpp b/test/testother.cpp index 52bc145ad..1fbca242a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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"