fix a bug in checkDuplicateBranch where removed type info like signed/unsigned was not checked for difference

This commit is contained in:
Robert Reif 2011-04-10 09:57:09 -04:00
parent 30ee9ba6e4
commit 4a50aca7b2
2 changed files with 29 additions and 1 deletions

View File

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

View File

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