stl dangerous usage of erase: Added test cases about using return and goto

This commit is contained in:
Daniel Marjamäki 2009-02-11 16:20:32 +00:00
parent ba3752feb6
commit f4a3119c18
2 changed files with 30 additions and 1 deletions

View File

@ -188,7 +188,7 @@ void CheckStl::eraseCheckLoop(const Token *it)
if (indentlevel < 0) if (indentlevel < 0)
break; break;
} }
else if (Token::simpleMatch(tok, "break ;") || Token::simpleMatch(tok, (it->str() + " =").c_str())) else if (Token::Match(tok, "break|return|goto") || Token::simpleMatch(tok, (it->str() + " =").c_str()))
{ {
tok2 = 0; tok2 = 0;
break; break;

View File

@ -42,6 +42,8 @@ private:
TEST_CASE(STLSizeNoErr); TEST_CASE(STLSizeNoErr);
TEST_CASE(erase); TEST_CASE(erase);
TEST_CASE(eraseBreak); TEST_CASE(eraseBreak);
TEST_CASE(eraseReturn);
TEST_CASE(eraseGoto);
TEST_CASE(eraseAssign); TEST_CASE(eraseAssign);
} }
@ -171,6 +173,33 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void eraseReturn()
{
checkErase("void f()\n"
"{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n"
" foo.erase(it);\n"
" return;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void eraseGoto()
{
checkErase("void f()\n"
"{\n"
" for (it = foo.begin(); it != foo.end(); ++it)\n"
" {\n"
" foo.erase(it);\n"
" goto abc;\n"
" }\n"
"bar:\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void eraseAssign() void eraseAssign()
{ {
checkErase("void f()\n" checkErase("void f()\n"