CheckBool: Fixed false positive for calculation using bool result in rhs
This commit is contained in:
parent
d2025363d0
commit
b81de5494e
|
@ -431,10 +431,23 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
|
|||
if (Token::Match(opTok, "<|>"))
|
||||
op = opTok->str()[0];
|
||||
} else if (Token::Match(tok->previous(), "(|&&|%oror% %num% %comp% !")) {
|
||||
numTok = tok;
|
||||
opTok = tok->next();
|
||||
if (Token::Match(opTok, "<|>"))
|
||||
op = opTok->str()[0]=='>'?'<':'>';
|
||||
const Token *rhs = tok->tokAt(3);
|
||||
while (rhs) {
|
||||
if (rhs->str() == "!") {
|
||||
if (Token::simpleMatch(rhs, "! ("))
|
||||
rhs = rhs->next()->link();
|
||||
rhs = rhs->next();
|
||||
} else if (rhs->isName() || rhs->isNumber())
|
||||
rhs = rhs->next();
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (Token::Match(rhs, "&&|%oror%|)")) {
|
||||
numTok = tok;
|
||||
opTok = tok->next();
|
||||
if (Token::Match(opTok, "<|>"))
|
||||
op = opTok->str()[0]=='>'?'<':'>';
|
||||
}
|
||||
}
|
||||
|
||||
// boolean result in lhs compared with <|<=|>|>=
|
||||
|
|
|
@ -386,6 +386,12 @@ private:
|
|||
|
||||
check("void f(int a, int b, int c) { if (a != !b || c) {} }");
|
||||
ASSERT_EQUALS("",errout.str());
|
||||
|
||||
check("void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }");
|
||||
ASSERT_EQUALS("",errout.str());
|
||||
|
||||
check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }");
|
||||
TODO_ASSERT_EQUALS("error","",errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolExpressionWithInt3() {
|
||||
|
|
Loading…
Reference in New Issue