Fixed #6662 (False positive assignIfError (assignment in while condition))

This commit is contained in:
Daniel Marjamäki 2015-06-20 16:23:16 +02:00
parent 272cc55ab8
commit 1d49334398
2 changed files with 19 additions and 0 deletions

View File

@ -143,6 +143,9 @@ bool CheckCondition::assignIfParseScope(const Token * const assignTok,
else if (op == "!=" && (num & num2) != ((bitop=='&') ? num2 : num))
assignIfError(assignTok, tok2, condition, true);
}
if (Token::Match(tok2, "%varid% %op%", varid) && tok2->next()->isAssignmentOp()) {
return true;
}
}
bool ret1 = assignIfParseScope(assignTok, end->tokAt(2), varid, islocal, bitop, num);

View File

@ -255,6 +255,22 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(int a) {\n" // #6662
" int x = a & 1;\n"
" while (x <= 4) {\n"
" if (x != 5) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (style) Mismatching assignment and comparison, comparison 'x!=5' is always true.\n", errout.str());
check("void f(int a) {\n" // #6662
" int x = a & 1;\n"
" while ((x += 4) < 10) {\n"
" if (x != 5) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void mismatchingBitAnd() {