diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 2ad185208..e6ea9c2b9 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3349,7 +3349,7 @@ void CheckOther::checkDuplicateExpression() // Experimental implementation for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { - if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "[+*=]")) { + if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "[+-*/%=]")) { if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1())) continue; if (isSameExpression(tok->astOperand1(), tok->astOperand2(), constStandardFunctions)) diff --git a/test/testother.cpp b/test/testother.cpp index 47bb5a83a..68c7c067d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4703,16 +4703,14 @@ private: check("void fun() {\n" " return a && a ||\n" " b == b &&\n" - " c - c &&\n" " d > d &&\n" " e < e &&\n" " f ;\n" "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n" "[test.cpp:3] -> [test.cpp:3]: (style) Same expression on both sides of '=='.\n" - "[test.cpp:4] -> [test.cpp:4]: (style) Same expression on both sides of '-'.\n" - "[test.cpp:5] -> [test.cpp:5]: (style) Same expression on both sides of '>'.\n" - "[test.cpp:6] -> [test.cpp:6]: (style) Same expression on both sides of '<'.\n", errout.str()); + "[test.cpp:4] -> [test.cpp:4]: (style) Same expression on both sides of '>'.\n" + "[test.cpp:5] -> [test.cpp:5]: (style) Same expression on both sides of '<'.\n", errout.str()); check("void foo() {\n" " return a && a;\n" @@ -4790,6 +4788,15 @@ private: "}"); ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&&'.\n", 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()); + + check("void foo() {\n" + " if (a / 1000 / 1000) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void duplicateIf1() { // ticket 3689 ( avoid false positive )