Same expression: don't warn for same expressions when there is assignment

This commit is contained in:
Daniel Marjamäki 2014-05-09 06:16:27 +02:00
parent 69fbf50081
commit cb43bee10d
2 changed files with 7 additions and 1 deletions

View File

@ -114,7 +114,7 @@ bool isSameExpression(const Token *tok1, const Token *tok2, const std::set<std::
if (t1 != end1 || t2 != end2) if (t1 != end1 || t2 != end2)
return false; return false;
} }
if (Token::Match(tok1, "++|--")) if (Token::Match(tok1, "++|--") || tok1->isAssignmentOp())
return false; return false;
if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal
const Token *t1 = tok1->next(); const Token *t1 = tok1->next();

View File

@ -4974,6 +4974,12 @@ private:
" if (*a-- != b || *a-- != b) {}\n" " if (*a-- != b || *a-- != b) {}\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// assignment
check("void f() {\n"
" while (*(a+=2)==*(b+=2) && *(a+=2)==*(b+=2)) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void duplicateExpression5() { // #3749 - macros with same values void duplicateExpression5() { // #3749 - macros with same values