Fixed #2356 (False positive reported with iterator deletion)

This commit is contained in:
Daniel Marjamäki 2010-12-24 10:33:48 +01:00
parent 18fd12006a
commit 335d164cdf
3 changed files with 10 additions and 9 deletions

View File

@ -45,11 +45,6 @@ void CheckStl::dereferenceErasedError(const Token *tok, const std::string &itern
reportError(tok, Severity::error, "eraseDereference", "Dereferenced iterator '" + itername + "' has been erased");
}
void CheckStl::eraseByValueError(const Token *tok, const std::string &containername, const std::string &itername)
{
reportError(tok, Severity::error, "eraseByValue", "Iterator '" + itername + "' becomes invalid when deleted by value from '" + containername + "'");
}
void CheckStl::iterators()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -125,7 +120,7 @@ void CheckStl::iterators()
}
else if (Token::Match(tok2, "%var% . erase ( * %varid%", iteratorId) && tok2->varId() == containerId)
{
eraseByValueError(tok2, tok2->strAt(0), tok2->strAt(5));
// eraseByValueError(tok2, tok2->strAt(0), tok2->strAt(5));
}
else if (Token::Match(tok2, "return|break ;"))
{

View File

@ -152,7 +152,6 @@ private:
void stlBoundriesError(const Token *tok, const std::string &container_name);
void if_findError(const Token *tok, bool str);
void sizeError(const Token *tok);
void eraseByValueError(const Token *tok, const std::string &containername, const std::string &itername);
void redundantIfRemoveError(const Token *tok);
void getErrorMessages()
@ -170,7 +169,6 @@ private:
if_findError(0, true);
string_c_strError(0);
sizeError(0);
eraseByValueError(0, "container", "iterator");
redundantIfRemoveError(0);
}

View File

@ -668,7 +668,15 @@ private:
" foo.erase(*it);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\n", errout.str());
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterator 'it' becomes invalid when deleted by value from 'foo'\n", errout.str());
check("void f()\n"
"{\n"
" std::set<int> foo;\n"
" std::set<int> it = foo.begin();\n"
" foo.erase(*it);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}