CheckBool: Fixed false positive for calculation using bool result in rhs
This commit is contained in:
parent
d2025363d0
commit
b81de5494e
|
@ -431,11 +431,24 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
|
||||||
if (Token::Match(opTok, "<|>"))
|
if (Token::Match(opTok, "<|>"))
|
||||||
op = opTok->str()[0];
|
op = opTok->str()[0];
|
||||||
} else if (Token::Match(tok->previous(), "(|&&|%oror% %num% %comp% !")) {
|
} else if (Token::Match(tok->previous(), "(|&&|%oror% %num% %comp% !")) {
|
||||||
|
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;
|
numTok = tok;
|
||||||
opTok = tok->next();
|
opTok = tok->next();
|
||||||
if (Token::Match(opTok, "<|>"))
|
if (Token::Match(opTok, "<|>"))
|
||||||
op = opTok->str()[0]=='>'?'<':'>';
|
op = opTok->str()[0]=='>'?'<':'>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// boolean result in lhs compared with <|<=|>|>=
|
// boolean result in lhs compared with <|<=|>|>=
|
||||||
else if (tok->isComparisonOp() && !Token::Match(tok,"==|!=") && !isNonBoolLHSExpr(tok->previous())) {
|
else if (tok->isComparisonOp() && !Token::Match(tok,"==|!=") && !isNonBoolLHSExpr(tok->previous())) {
|
||||||
|
|
|
@ -386,6 +386,12 @@ private:
|
||||||
|
|
||||||
check("void f(int a, int b, int c) { if (a != !b || c) {} }");
|
check("void f(int a, int b, int c) { if (a != !b || c) {} }");
|
||||||
ASSERT_EQUALS("",errout.str());
|
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() {
|
void comparisonOfBoolExpressionWithInt3() {
|
||||||
|
|
Loading…
Reference in New Issue