diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 67366d70b..62b44b31a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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")) diff --git a/test/testother.cpp b/test/testother.cpp index b766bf05a..1462e6dd2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {