Fixed #4485 (False positive: Same expression of '-' when checking if float is inf)

This commit is contained in:
Daniel Marjamäki 2013-01-31 17:29:31 +01:00
parent bd7e3cbac5
commit e2faed355b
2 changed files with 7 additions and 3 deletions

View File

@ -3176,7 +3176,8 @@ void CheckOther::checkDuplicateExpression()
if (Token::Match(tok, ",|=|return|(|&&|%oror% %var% %comp%|- %var% )|&&|%oror%|;|,") &&
tok->strAt(1) == tok->strAt(3)) {
// float == float and float != float are valid NaN checks
if (Token::Match(tok->tokAt(2), "==|!=") && tok->next()->varId()) {
// float - float is a valid Inf check
if (Token::Match(tok->tokAt(2), "==|!=|-") && tok->next()->varId()) {
const Variable * var = symbolDatabase->getVariableFromVarId(tok->next()->varId());
if (var && var->typeStartToken() == var->typeEndToken()) {
if (Token::Match(var->typeStartToken(), "float|double"))

View File

@ -5181,8 +5181,8 @@ private:
ASSERT_EQUALS("", errout.str());
}
void duplicateExpression2() { // ticket #2730
check("int main()\n"
void duplicateExpression2() { // check if float is NaN or Inf
check("int main()\n" // ticket #2730
"{\n"
" long double ldbl;\n"
" double dbl, in;\n"
@ -5199,6 +5199,9 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Passing value -1.0 to sqrtl() leads to undefined result.\n"
"[test.cpp:8]: (error) Passing value -1.0 to sqrt() leads to undefined result.\n"
"[test.cpp:9]: (error) Passing value -1.0 to sqrtf() leads to undefined result.\n", errout.str());
check("float f(float x) { return x-x; }"); // ticket #4485 (Inf)
ASSERT_EQUALS("", errout.str());
}
void duplicateExpression3() {