Fixed #4434 (false positive: (style) Mismatching assignment and comparison, comparison 'pen!=-1' is always true.)
This commit is contained in:
parent
7da155c8ba
commit
2e0a9c4b33
|
@ -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() == "}")
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in New Issue