Fixed #1107 (False positive: Dangerous usage of erase, when using std::list)

This commit is contained in:
Daniel Marjamäki 2009-12-18 20:55:51 +01:00
parent 8665b36f54
commit 69a98d81fc
2 changed files with 19 additions and 2 deletions

View File

@ -220,7 +220,7 @@ void CheckStl::eraseCheckLoop(const Token *it)
return;
// Parse loop..
// Error if it contains "erase(it)" but neither "break;" nor "it="
// Error if it contains "erase(it)" but neither "break;", "=it" nor "it="
indentlevel = 0;
const Token *tok2 = 0;
while (0 != (tok = tok->next()))
@ -233,7 +233,9 @@ void CheckStl::eraseCheckLoop(const Token *it)
if (indentlevel <= 0)
break;
}
else if (Token::Match(tok, "break|return|goto") || Token::simpleMatch(tok, (it->str() + " =").c_str()))
else if (Token::Match(tok, "break|return|goto") ||
Token::simpleMatch(tok, (it->str() + " =").c_str()) ||
Token::simpleMatch(tok, ("= " + it->str()).c_str()))
{
tok2 = 0;
break;

View File

@ -46,6 +46,7 @@ private:
TEST_CASE(STLSize);
TEST_CASE(STLSizeNoErr);
TEST_CASE(erase);
TEST_CASE(erase2);
TEST_CASE(eraseBreak);
TEST_CASE(eraseReturn);
TEST_CASE(eraseGoto);
@ -289,6 +290,20 @@ private:
}
void erase2()
{
check("static void f()\n"
"{\n"
" for (it = foo.begin(); it != foo.end(); it = next)\n"
" {\n"
" next = it;\n"
" next++;\n"
" foo.erase(it);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void eraseBreak()
{
check("void f()\n"