Skip to content

Commit

Permalink
Fixed #5682 (False positive: (style) Same expression on both sides of…
Browse files Browse the repository at this point in the history
… '&&')
  • Loading branch information
danmar committed Apr 16, 2014
1 parent 5c116c6 commit 8d5a989
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4630,7 +4630,12 @@ class TestOther : public TestFixture {
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"
Expand Down

0 comments on commit 8d5a989

Please sign in to comment.