fix a bug in checkDuplicateBranch where removed type info like signed/unsigned was not checked for difference
This commit is contained in:
parent
30ee9ba6e4
commit
4a50aca7b2
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue