Fixed #4356 (False positive at variable initialization)
This commit is contained in:
parent
09eed80938
commit
79cd601ae7
|
@ -722,6 +722,9 @@ void CheckOther::checkRedundantAssignment()
|
||||||
}
|
}
|
||||||
it->second = tok;
|
it->second = tok;
|
||||||
}
|
}
|
||||||
|
if (Token::simpleMatch(tok->tokAt(2), "0 ;"))
|
||||||
|
varAssignments.erase(tok->varId());
|
||||||
|
else
|
||||||
varAssignments[tok->varId()] = tok;
|
varAssignments[tok->varId()] = tok;
|
||||||
memAssignments.erase(tok->varId());
|
memAssignments.erase(tok->varId());
|
||||||
} else if (tok->next()->type() == Token::eIncDecOp || (tok->previous()->type() == Token::eIncDecOp && !Token::Match(tok->next(), ".|[|("))) { // Variable incremented/decremented
|
} else if (tok->next()->type() == Token::eIncDecOp || (tok->previous()->type() == Token::eIncDecOp && !Token::Match(tok->next(), ".|[|("))) { // Variable incremented/decremented
|
||||||
|
|
|
@ -1696,6 +1696,12 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void switchRedundantOperationTest() {
|
||||||
|
|
Loading…
Reference in New Issue