From a53f14da2529aa6bca0023d6b8726791ceda3ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 22 Feb 2017 21:13:36 +0100 Subject: [PATCH] Fixed #7925 (False Positive identical condition) --- lib/astutils.cpp | 8 ++++++++ test/testcondition.cpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 9b91cd97c..1974caa4a 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -149,6 +149,14 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2 } if (macro && (tok1->isExpandedMacro() || tok2->isExpandedMacro())) return false; + if (tok1->isComplex() != tok2->isComplex()) + return false; + if (tok1->isLong() != tok2->isLong()) + return false; + if (tok1->isUnsigned() != tok2->isUnsigned()) + return false; + if (tok1->isSigned() != tok2->isSigned()) + return false; if (tok1->isName() && tok1->next()->str() == "(" && tok1->str() != "sizeof") { if (!tok1->function() && !Token::Match(tok1->previous(), ".|::") && pure && !library.isFunctionConst(tok1->str(), true) && !tok1->isAttributeConst() && !tok1->isAttributePure()) return false; diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 32292ab7f..225eb37d7 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -564,6 +564,12 @@ private: " else if (x == 40) {}\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str()); + + check("void f(int x) {\n" + " if (x == sizeof(double)) {}\n" + " else { if (x == sizeof(long double)) {} }" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkBadBitmaskCheck() {