diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 01560de82..861088d31 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -178,7 +178,12 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2 if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal const Token *t1 = tok1->next(); const Token *t2 = tok2->next(); - while (t1 && t2 && t1->str() == t2->str() && (t1->isName() || t1->str() == "*")) { + while (t1 && t2 && + t1->str() == t2->str() && + t1->isLong() == t2->isLong() && + t1->isUnsigned() == t2->isUnsigned() && + t1->isSigned() == t2->isSigned() && + (t1->isName() || t1->str() == "*")) { t1 = t1->next(); t2 = t2->next(); } diff --git a/test/testother.cpp b/test/testother.cpp index e62758c93..821088a50 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3815,6 +3815,11 @@ private: " return A ? x : z;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f(unsigned char c) {\n" + " x = y ? (signed char)c : (unsigned char)c;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkSignOfUnsignedVariable() {