From ceca6be22bb6f1f4a36b00f8534abb58c5088a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 11 Jan 2014 15:15:01 +0100 Subject: [PATCH] Fixed #5334 (False positive: same expression on both sides of '||') --- lib/checkother.cpp | 3 +++ test/testother.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7dd067319..f8cc4782d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -67,6 +67,9 @@ static bool isSameExpression(const Token *tok1, const Token *tok2, const std::se else if (tok1->function() && !tok1->function()->isConst) return false; } + if ((Token::Match(tok1, "%var% <") && tok1->next()->link()) || + (Token::Match(tok2, "%var% <") && tok2->next()->link())) + return false; if (Token::Match(tok1, "++|--")) return false; if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal diff --git a/test/testother.cpp b/test/testother.cpp index ac7e2c5ec..8b83bf95e 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3695,6 +3695,13 @@ private: ); ASSERT_EQUALS("", errout.str()); + // #5334 + check("void f(C *src) {\n" + " if (x(src) || x(src))\n" + " a++;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void f(int x) {\n" " if ((x == 1) && (x == 0x00000001))\n" " a++;\n"