Fixed #5063 (False positive for comparisonOfBoolWithInvalidComparator)
This commit is contained in:
parent
c234cace6d
commit
9f23b7a1b4
|
@ -438,20 +438,21 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
|
|||
}
|
||||
|
||||
// boolean result in lhs compared with <|<=|>|>=
|
||||
else if (Token::Match(tok,"<|<=|>|>=")) {
|
||||
else if (tok->isComparisonOp() && !Token::Match(tok,"==|!=") && !isNonBoolLHSExpr(tok->previous())) {
|
||||
const Token *lhs = tok;
|
||||
while (NULL != (lhs = lhs->previous())) {
|
||||
if (lhs->isName() || lhs->isNumber())
|
||||
if ((lhs->isName() && !Token::Match(lhs,"or|and")) || lhs->isNumber())
|
||||
continue;
|
||||
if (Token::Match(lhs,"[+-*/.]"))
|
||||
if (lhs->isArithmeticalOp())
|
||||
continue;
|
||||
if (Token::Match(lhs, ")|]")) {
|
||||
lhs = lhs->previous();
|
||||
if (Token::Match(lhs->link()->previous(), "%var% ("))
|
||||
lhs = lhs->link();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (Token::Match(lhs,"<|<=|>|>=")) {
|
||||
if (lhs && (lhs->isComparisonOp() || lhs->str() == "!")) {
|
||||
if (_tokenizer->isCPP() && tok->str() == ">" &&
|
||||
(Token::Match(lhs->previous(), "%var% <") || lhs->str() == ">"))
|
||||
continue;
|
||||
|
|
|
@ -369,6 +369,11 @@ private:
|
|||
" return (!y == !x);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("int f(int a) {\n"
|
||||
" return (x()+1 == !a);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolExpressionWithInt3() {
|
||||
|
@ -385,12 +390,33 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean value using relational operator (<, >, <= or >=).\n", errout.str());
|
||||
|
||||
check("void f(int a, int b, int c) {\n"
|
||||
" return (a > b) < c;\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
|
||||
check("void f(int a, int b, int c) {\n"
|
||||
" return x(a > b) < c;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(int a, int b, int c) {\n"
|
||||
" return a > b == c;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// templates
|
||||
check("struct Tokenizer { TokenList list; };\n"
|
||||
"void Tokenizer::f() {\n"
|
||||
" std::list<Token*> locationList;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5063 - or
|
||||
check("void f() {\n"
|
||||
" return a > b or c < d;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void checkComparisonOfFuncReturningBool1() {
|
||||
|
|
Loading…
Reference in New Issue