AST: Improved 'same expression on both sides of operator' checking for nested operators

This commit is contained in:
Daniel Marjamäki 2013-11-15 06:35:46 +01:00
parent 203d3e916b
commit d1721b9d1b
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -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 )