Fixed #4356 (False positive at variable initialization)
This commit is contained in:
parent
09eed80938
commit
79cd601ae7
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue