From d2025363d071bd4188387629b35f2378d4cd5a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 7 Oct 2013 17:44:19 +0200 Subject: [PATCH] CheckBool: Fix false positive for '(a != boolexpr || c)' if a is a int --- lib/checkbool.cpp | 4 +--- test/testbool.cpp | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/checkbool.cpp b/lib/checkbool.cpp index c996fdc90..cae0ec492 100644 --- a/lib/checkbool.cpp +++ b/lib/checkbool.cpp @@ -376,8 +376,6 @@ static bool isNonBoolLHSExpr(const Token *tok) --indentlevel; } else if (tok->isNumber()) nonBoolExpr = true; - else if (tok->varId() && isNonBoolStdType(tok->variable())) - nonBoolExpr = true; else if (tok->isArithmeticalOp()) { if (indentlevel == 0) return true; @@ -432,7 +430,7 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt() opTok = tok->tokAt(2); if (Token::Match(opTok, "<|>")) op = opTok->str()[0]; - } else if (Token::Match(tok, "%any% %comp% ! %var%") && isNonBoolLHSExpr(tok)) { + } else if (Token::Match(tok->previous(), "(|&&|%oror% %num% %comp% !")) { numTok = tok; opTok = tok->next(); if (Token::Match(opTok, "<|>")) diff --git a/test/testbool.cpp b/test/testbool.cpp index 4314c8f78..03bc0aa68 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -355,7 +355,7 @@ private: " printf(\"x not equal to 10\");\n" " }\n" "}"); - ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); + ASSERT_EQUALS("", errout.str()); check("void f(int x, bool y) {\n" " if (y != !x) {\n" @@ -383,6 +383,9 @@ private: check("void f() { if (!!a+!!b+!!c>1){} }"); ASSERT_EQUALS("",errout.str()); + + check("void f(int a, int b, int c) { if (a != !b || c) {} }"); + ASSERT_EQUALS("",errout.str()); } void comparisonOfBoolExpressionWithInt3() {