diff --git a/lib/checkother.cpp b/lib/checkother.cpp index a174c3eb3..90c5b023e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3359,6 +3359,11 @@ void CheckOther::complexDuplicateExpressionCheck(const std::listastOperand1() && astIsFloat(tok->astOperand1())) + return true; + if (tok->astOperand2() && astIsFloat(tok->astOperand2())) + return true; + // TODO: check function calls, struct members, arrays, etc also return tok->variable() && Token::Match(tok->variable()->typeStartToken(), "float|double"); } diff --git a/test/testother.cpp b/test/testother.cpp index d664a2d30..297eb49f6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4872,6 +4872,13 @@ private: check("float f(float x) { return x-x; }"); // ticket #4485 (Inf) ASSERT_EQUALS("", errout.str()); + + check("float f(float x) { return (X double)x == (X double)x; }", NULL, false, false, false, false); + ASSERT_EQUALS("", errout.str()); + + check("struct X { float f; };\n" + "float f(struct X x) { return x.f == x.f; }"); + ASSERT_EQUALS("", errout.str()); } void duplicateExpression3() {