diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 80f35eba2..d09772590 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1509,7 +1509,7 @@ void CheckOther::checkComparisonOfBoolWithInt() std::map 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; diff --git a/test/testother.cpp b/test/testother.cpp index 77136e807..89c5f9299 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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()); }