From 4a50aca7b2ba92a22c1115dccb04f1c14910b97c Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sun, 10 Apr 2011 09:57:09 -0400 Subject: [PATCH] fix a bug in checkDuplicateBranch where removed type info like signed/unsigned was not checked for difference --- lib/checkother.cpp | 20 +++++++++++++++++++- test/testother.cpp | 10 ++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3e36559c9..7269abc2d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3045,10 +3045,28 @@ void CheckOther::checkIncorrectStringCompare() static const std::string stringifyTokens(const Token *start, const Token *end) { const Token *tok = start; - std::string stringified = tok->str(); + std::string stringified; + + if (tok->isUnsigned()) + stringified.append("unsigned "); + else if (tok->isSigned()) + stringified.append("signed "); + + if (tok->isLong()) + stringified.append("long "); + + stringified.append(tok->str()); while (tok && tok->next() && tok != end) { + if (tok->isUnsigned()) + stringified.append("unsigned "); + else if (tok->isSigned()) + stringified.append("signed "); + + if (tok->isLong()) + stringified.append("long "); + tok = tok->next(); stringified.append(" "); stringified.append(tok->str()); diff --git a/test/testother.cpp b/test/testother.cpp index 77f74ee9a..bdc105a00 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2476,6 +2476,16 @@ private: " b = 1;\n" "}"); ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style) Found duplicate branches for if and else.\n", errout.str()); + + check("int f(int signed, unsigned char value) {\n" + " int ret;\n" + " if (signed)\n" + " ret = (signed char)value;\n" + " else\n" + " ret = (unsigned char)value;\n" + " return ret;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } };