AST: Improved astIsFloat handling of expressions

This commit is contained in:
Daniel Marjamäki 2013-11-25 04:26:15 +01:00
parent abdf2bb9d4
commit da540a3bb3
2 changed files with 12 additions and 0 deletions

View File

@ -3359,6 +3359,11 @@ void CheckOther::complexDuplicateExpressionCheck(const std::list<const Function*
static bool astIsFloat(const Token *tok)
{
if (tok->astOperand1() && 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");
}

View File

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