From d1721b9d1bc2340175090b4fddd6c4408927ccfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 15 Nov 2013 06:35:46 +0100 Subject: [PATCH] AST: Improved 'same expression on both sides of operator' checking for nested operators --- lib/checkother.cpp | 2 ++ test/testother.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c81af18cf..d74b37298 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3348,6 +3348,8 @@ void CheckOther::checkDuplicateExpression() continue; if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions)) duplicateExpressionError(tok, tok, tok->str()); + else if (tok->astOperand1() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), constStandardFunctions)) + duplicateExpressionError(tok->astOperand2(), tok->astOperand2(), tok->str()); } } continue; diff --git a/test/testother.cpp b/test/testother.cpp index 8ab7516f4..661c45d4f 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4779,6 +4779,12 @@ private: check("int f(int x) { return x+x; }"); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " if (a && b && b) {}\n" + "}"); + ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", errout.str()); + } void duplicateIf1() { // ticket 3689 ( avoid false positive )