From 372c29c24e7da16a533cdf1554937ced19e1b5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 2 Jan 2014 16:58:07 +0100 Subject: [PATCH] Fixed #5284 (duplicateExpression falsely reported by members of a union in some circumstances) --- lib/checkother.cpp | 2 +- test/testother.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 10f7fb3a1..326529e3e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2860,7 +2860,7 @@ static bool astIsFloat(const Token *tok) return true; // TODO: check function calls, struct members, arrays, etc also - return tok->variable() && Token::Match(tok->variable()->typeStartToken(), "float|double"); + return !tok->variable() || Token::findmatch(tok->variable()->typeStartToken(), "float|double", tok->variable()->typeEndToken()->next(), 0); } //--------------------------------------------------------------------------- diff --git a/test/testother.cpp b/test/testother.cpp index 65ebc8521..ac7e2c5ec 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4591,12 +4591,12 @@ private: } void duplicateExpression1() { - check("void foo() {\n" + check("void foo(int a) {\n" " if (a == a) { }\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout.str()); - check("void fun() {\n" + check("void fun(int b) {\n" " return a && a ||\n" " b == b &&\n" " d > d &&\n" @@ -4618,12 +4618,12 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str()); - check("void foo() {\n" + check("void foo(int b) {\n" " f(a,b == b);\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout.str()); - check("void foo() {\n" + check("void foo(int b) {\n" " f(b == b, a);\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '=='.\n", errout.str()); @@ -4760,6 +4760,10 @@ private: check("struct X { float f; };\n" "float f(struct X x) { return x.f == x.f; }"); ASSERT_EQUALS("", errout.str()); + + // #5284 - when type is unknown, assume it's float + check("int f() { return x==x; }"); + ASSERT_EQUALS("", errout.str()); } void duplicateExpression3() {