CheckBool: Fixed false positive for calculation using bool result in rhs

This commit is contained in:
Daniel Marjamäki 2013-10-07 18:01:08 +02:00
parent d2025363d0
commit b81de5494e
2 changed files with 23 additions and 4 deletions

View File

@ -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 <|<=|>|>=

View File

@ -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() {