Now really fixed #4604.

This commit is contained in:
PKEuS 2013-05-09 15:39:33 +02:00
parent 881b47e79d
commit fb480ebb0a
2 changed files with 20 additions and 10 deletions

View File

@ -664,9 +664,7 @@ void CheckOther::checkRedundantAssignment()
}
it->second = tok;
}
if (Token::simpleMatch(tok->tokAt(2), "0 ;"))
varAssignments.erase(tok->varId());
else
if (!Token::simpleMatch(tok->tokAt(2), "0 ;") || (tok->variable() && tok->variable()->nameToken() != tok->tokAt(-2)))
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

View File

@ -1756,12 +1756,6 @@ private:
" }\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // Ticket #4356
" int x = 0;\n" // <- ignore assignment with 0
" x = 3;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
}
void switchRedundantOperationTest() {
@ -5803,6 +5797,24 @@ private:
" return x + 1;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // Ticket #4356
" int x = 0;\n" // <- ignore assignment with 0
" x = 3;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" int i = 54;\n"
" i = 0;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
check("void f() {\n"
" int i = 54;\n"
" i = 1;\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (performance) Variable 'i' is reassigned a value before the old one has been used.\n", errout.str());
}
void redundantMemWrite() {
@ -6165,4 +6177,4 @@ private:
}
};
REGISTER_TEST(TestOther)
REGISTER_TEST(TestOther)