Comparing bool with int: Fixed false positives
This commit is contained in:
parent
8213a15b2a
commit
8e94e2261b
|
@ -1509,7 +1509,7 @@ void CheckOther::checkComparisonOfBoolWithInt()
|
|||
|
||||
std::map<unsigned int, bool> boolvars; // Contains all declarated standard type variables and indicates whether its a bool or not.
|
||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]") && tok->next()->isStandardType()) { // Declaration of standard type variable
|
||||
if (Token::Match(tok, "[{};(,] %type% %var% [;=,)]") && tok->next()->isStandardType() && tok->tokAt(2)->varId() > 0) { // Declaration of standard type variable
|
||||
boolvars[tok->tokAt(2)->varId()] = (tok->strAt(1) == "bool");
|
||||
} else if (Token::Match(tok, "%var% >|>=|==|!=|<=|< %num%")) { // Comparing variable with number
|
||||
const Token *varTok = tok;
|
||||
|
|
|
@ -3026,7 +3026,12 @@ private:
|
|||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
|
||||
|
||||
|
||||
check("typedef int (*func)(bool invert);\n"
|
||||
"void x(int, func f);\n"
|
||||
"void foo(int error) {\n"
|
||||
" if (error == ABC) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue