diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0818086b0ec..0c9674d2d58 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1455,7 +1455,7 @@ bool isUsedAsBool(const Token* const tok, const Settings* settings) return isUsedAsBool(parent); if (parent->isUnaryOp("*")) return isUsedAsBool(parent); - if (Token::Match(parent, "==|!=") && (tok->astSibling()->isNumber() || tok->astSibling()->isLiteral()) && tok->astSibling()->hasKnownIntValue() && + if (Token::Match(parent, "==|!=") && (tok->astSibling()->isNumber() || tok->astSibling()->isKeyword()) && tok->astSibling()->hasKnownIntValue() && tok->astSibling()->values().front().intvalue == 0) return true; if (parent->str() == "(" && astIsRHS(tok) && Token::Match(parent->astOperand1(), "if|while")) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7073d4a9cff..f903dc7a4ad 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3555,7 +3555,7 @@ class TestCondition : public TestFixture { " if (handle) return 1;\n" " else return 0;\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'handle!=0', second condition is always false\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'handle!=nullptr', second condition is always false\n", errout.str()); check("void f(void* x, void* y) {\n" " if (x == nullptr && y == nullptr)\n"