diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fefb858d5..953f66ef0 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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; diff --git a/test/testother.cpp b/test/testother.cpp index d827d2c97..c1b56f528 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {