CheckBool: Fix false positive for '(a != boolexpr || c)' if a is a int
This commit is contained in:
parent
83f9503839
commit
d2025363d0
|
@ -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, "<|>"))
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue