STL: fixed false negative when erasing invalidated iterator
This commit is contained in:
parent
6371327487
commit
9cd8bd842e
|
@ -30,6 +30,11 @@ CheckStl instance;
|
|||
|
||||
|
||||
// Error message for bad iterator usage..
|
||||
void CheckStl::invalidIteratorError(const Token *tok, const std::string &iteratorName)
|
||||
{
|
||||
reportError(tok, Severity::error, "invalidIterator", "Invalid iterator: " + iteratorName);
|
||||
}
|
||||
|
||||
void CheckStl::iteratorsError(const Token *tok, const std::string &container1, const std::string &container2)
|
||||
{
|
||||
reportError(tok, Severity::error, "iterators", "Same iterator is used with both " + container1 + " and " + container2);
|
||||
|
@ -66,6 +71,9 @@ void CheckStl::iterators()
|
|||
}
|
||||
else if (Token::Match(tok2, "%var% . insert|erase ( %varid% )|,", iteratorId))
|
||||
{
|
||||
if (!validIterator)
|
||||
invalidIteratorError(tok2, tok2->strAt(4));
|
||||
|
||||
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".")
|
||||
{
|
||||
// skip error message if container is a set..
|
||||
|
|
|
@ -117,6 +117,7 @@ private:
|
|||
void eraseCheckLoop(const Token *it);
|
||||
|
||||
void stlOutOfBoundsError(const Token *tok, const std::string &num, const std::string &var);
|
||||
void invalidIteratorError(const Token *tok, const std::string &iteratorName);
|
||||
void iteratorsError(const Token *tok, const std::string &container1, const std::string &container2);
|
||||
void mismatchingContainersError(const Token *tok);
|
||||
void eraseError(const Token *tok);
|
||||
|
@ -128,6 +129,7 @@ private:
|
|||
|
||||
void getErrorMessages()
|
||||
{
|
||||
invalidIteratorError(0, "iterator");
|
||||
iteratorsError(0, "container1", "container2");
|
||||
mismatchingContainersError(0);
|
||||
dereferenceErasedError(0, "iter");
|
||||
|
|
|
@ -437,8 +437,7 @@ private:
|
|||
" ints.erase(iter);\n"
|
||||
" ints.erase(iter);\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Erasing invalid iterator\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Invalid iterator: iter\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue