Fixed #5682 (False positive: (style) Same expression on both sides of '&&')

This commit is contained in:
Daniel Marjamäki 2014-04-16 16:04:46 +02:00
parent 5c116c622d
commit 8d5a9893d5
2 changed files with 9 additions and 2 deletions

View File

@ -2782,7 +2782,9 @@ void CheckOther::checkDuplicateExpression()
const Token *ast1 = tok->astOperand1(); const Token *ast1 = tok->astOperand1();
while (ast1 && tok->str() == ast1->str()) { while (ast1 && tok->str() == ast1->str()) {
if (isSameExpression(ast1->astOperand1(), tok->astOperand2(), _settings->library.functionpure)) 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)) else if (isSameExpression(ast1->astOperand2(), tok->astOperand2(), _settings->library.functionpure))
duplicateExpressionError(ast1->astOperand2(), tok->astOperand2(), tok->str()); duplicateExpressionError(ast1->astOperand2(), tok->astOperand2(), tok->str());
if (!isConstExpression(ast1->astOperand2(), _settings->library.functionpure)) if (!isConstExpression(ast1->astOperand2(), _settings->library.functionpure))

View File

@ -4630,7 +4630,12 @@ private:
check("void foo() {\n" check("void foo() {\n"
" if (x!=2 || y!=3 || x!=2) {}\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" check("void foo() {\n"
" if (a && b || a && b) {}\n" " if (a && b || a && b) {}\n"