Fixed #5284 (duplicateExpression falsely reported by members of a union in some circumstances)

This commit is contained in:
Daniel Marjamäki 2014-01-02 16:58:07 +01:00
parent cb40e83261
commit 372c29c24e
2 changed files with 9 additions and 5 deletions

View File

@ -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);
}
//---------------------------------------------------------------------------

View File

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