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