From e784901303292df867872294204dc1df6cd2af15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 1 Aug 2016 21:53:43 +0200 Subject: [PATCH] Fixed #6971 (False positive duplicateExpressionTernary - cast ignored) --- lib/astutils.cpp | 7 ++++++- test/testother.cpp | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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() {