Fixed #4434 (false positive: (style) Mismatching assignment and comparison, comparison 'pen!=-1' is always true.)

This commit is contained in:
Daniel Marjamäki 2012-12-27 15:40:00 +01:00
parent 7da155c8ba
commit 2e0a9c4b33
2 changed files with 10 additions and 0 deletions

View File

@ -86,6 +86,8 @@ bool CheckAssignIf::assignIfParseScope(const Token * const assignTok,
const MathLib::bigint num) const MathLib::bigint num)
{ {
for (const Token *tok2 = startTok; tok2; tok2 = tok2->next()) { for (const Token *tok2 = startTok; tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "%varid% =", varid))
return true;
if (Token::Match(tok2, "[(,] &| %varid% [,)]", varid)) if (Token::Match(tok2, "[(,] &| %varid% [,)]", varid))
return true; return true;
if (tok2->str() == "}") if (tok2->str() == "}")

View File

@ -154,6 +154,14 @@ private:
" if (y==8);\n" // non-local variable => no error " if (y==8);\n" // non-local variable => no error
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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() { void compare() {