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 )