Fixed #4356 (False positive at variable initialization)

This commit is contained in:
Daniel Marjamäki 2012-11-15 07:48:45 +01:00
parent 09eed80938
commit 79cd601ae7
2 changed files with 10 additions and 1 deletions

View File

@ -722,7 +722,10 @@ void CheckOther::checkRedundantAssignment()
}
it->second = tok;
}
varAssignments[tok->varId()] = tok;
if (Token::simpleMatch(tok->tokAt(2), "0 ;"))
varAssignments.erase(tok->varId());
else
varAssignments[tok->varId()] = tok;
memAssignments.erase(tok->varId());
} else if (tok->next()->type() == Token::eIncDecOp || (tok->previous()->type() == Token::eIncDecOp && !Token::Match(tok->next(), ".|[|("))) { // Variable incremented/decremented
varAssignments[tok->varId()] = tok;

View File

@ -1696,6 +1696,12 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // Ticket #4356
" int x = 0;\n" // <- ignore assignment with 0
" x = 3;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void switchRedundantOperationTest() {