AST: Fixed 'same expression' false positives (git merge --squash s, <<, >>)

This commit is contained in:
Daniel Marjamäki 2013-11-20 16:18:09 +01:00
parent 1798fc3645
commit e8eeb90adb
2 changed files with 10 additions and 2 deletions

View File

@ -3378,12 +3378,12 @@ 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))
duplicateExpressionError(tok, tok, tok->str());
else if (tok->astOperand1() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), constStandardFunctions))
else if (tok->astOperand1() && tok->astOperand2() && tok->str() == tok->astOperand1()->str() && isSameExpression(tok->astOperand2(), tok->astOperand1()->astOperand2(), constStandardFunctions))
duplicateExpressionError(tok->astOperand2(), tok->astOperand2(), tok->str());
}
}

View File

@ -4812,6 +4812,14 @@ private:
" if (a / 1000 / 1000) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" if (a << 1 << 1) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int f() { return !!y; }"); // No FP
ASSERT_EQUALS("", errout.str());
}
void duplicateIf1() { // ticket 3689 ( avoid false positive )