From 8d5a9893d56a4614c4b07bb12f742e7e51b6cf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 16 Apr 2014 16:04:46 +0200 Subject: [PATCH] Fixed #5682 (False positive: (style) Same expression on both sides of '&&') --- lib/checkother.cpp | 4 +++- test/testother.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ca578ceae..3c7e7b3b6 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2782,7 +2782,9 @@ void CheckOther::checkDuplicateExpression() const Token *ast1 = tok->astOperand1(); while (ast1 && tok->str() == ast1->str()) { if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionpure)) - duplicateExpressionError(ast1->astOperand1(), tok->astOperand2(), tok->str()); + // TODO: warn if variables are unchanged. See #5683 + // Probably the message should be changed to 'duplicate expressions X in condition or something like that'. + ;//duplicateExpressionError(ast1->astOperand1(), tok->astOperand2(), tok->str()); else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionpure)) duplicateExpressionError(ast1->astOperand2(), tok->astOperand2(), tok->str()); if (!isConstExpression(ast1->astOperand2(), _settings->library.functionpure)) diff --git a/test/testother.cpp b/test/testother.cpp index e8a151d82..53bd28c87 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4630,7 +4630,12 @@ private: check("void foo() {\n" " if (x!=2 || y!=3 || x!=2) {}\n" "}"); - ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str()); + TODO_ASSERT_EQUALS("error", "", errout.str()); + + check("void foo() {\n" + " if (x!=2 && (x=y) && x!=2) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); check("void foo() {\n" " if (a && b || a && b) {}\n"