diff --git a/lib/checkassignif.cpp b/lib/checkassignif.cpp index ed9fef11a..197367025 100644 --- a/lib/checkassignif.cpp +++ b/lib/checkassignif.cpp @@ -86,6 +86,8 @@ bool CheckAssignIf::assignIfParseScope(const Token * const assignTok, const MathLib::bigint num) { for (const Token *tok2 = startTok; tok2; tok2 = tok2->next()) { + if (Token::Match(tok2, "%varid% =", varid)) + return true; if (Token::Match(tok2, "[(,] &| %varid% [,)]", varid)) return true; if (tok2->str() == "}") diff --git a/test/testassignif.cpp b/test/testassignif.cpp index dfec2c86f..9bf4dd26d 100644 --- a/test/testassignif.cpp +++ b/test/testassignif.cpp @@ -154,6 +154,14 @@ private: " if (y==8);\n" // non-local variable => no error "}"); ASSERT_EQUALS("", errout.str()); + + // #4434 : false positive: ?: + check("void f(int x) {\n" + " x = x & 1;\n" + " x = x & 1 ? 1 : -1;\n" + " if(x != -1) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void compare() {