Fixed #5557 (astIsFloat: better handling of '.')

This commit is contained in:
Daniel Marjamäki 2014-08-15 16:48:53 +02:00
parent d414aa0ae5
commit 364c975701
2 changed files with 7 additions and 0 deletions

View File

@ -34,6 +34,9 @@ namespace {
static bool astIsFloat(const Token *tok, bool unknown) static bool astIsFloat(const Token *tok, bool unknown)
{ {
if (tok->str() == ".")
return astIsFloat(tok->astOperand2(), unknown);
if (tok->astOperand1() && tok->str() != "?" && astIsFloat(tok->astOperand1(),unknown)) if (tok->astOperand1() && tok->str() != "?" && astIsFloat(tok->astOperand1(),unknown))
return true; return true;
if (tok->astOperand2() && astIsFloat(tok->astOperand2(), unknown)) if (tok->astOperand2() && astIsFloat(tok->astOperand2(), unknown))

View File

@ -4983,6 +4983,10 @@ private:
"float f(struct X x) { return x.f == x.f; }"); "float f(struct X x) { return x.f == x.f; }");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct X { int i; };\n"
"int f(struct X x) { return x.i == x.i; }");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout.str());
// #5284 - when type is unknown, assume it's float // #5284 - when type is unknown, assume it's float
check("int f() { return x==x; }"); check("int f() { return x==x; }");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());