STL: fixed false positive when using erase

This commit is contained in:
Daniel Marjamäki 2010-01-23 22:03:38 +01:00
parent 43c8fe895c
commit 4d7ac2f82e
2 changed files with 13 additions and 2 deletions

View File

@ -64,7 +64,7 @@ void CheckStl::iterators()
iteratorsError(tok2, tok->strAt(2), tok2->strAt(2)); iteratorsError(tok2, tok->strAt(2), tok2->strAt(2));
tok2 = tok2->tokAt(6); tok2 = tok2->tokAt(6);
} }
else if (Token::Match(tok2, "%var% . insert|erase ( %varid%", iteratorId)) else if (Token::Match(tok2, "%var% . insert|erase ( %varid% )|,", iteratorId))
{ {
if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".") if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".")
iteratorsError(tok2, tok->strAt(2), tok2->str()); iteratorsError(tok2, tok->strAt(2), tok2->str());

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(STLSizeNoErr); TEST_CASE(STLSizeNoErr);
TEST_CASE(erase); TEST_CASE(erase);
TEST_CASE(erase2); TEST_CASE(erase2);
TEST_CASE(erase3);
TEST_CASE(eraseBreak); TEST_CASE(eraseBreak);
TEST_CASE(eraseReturn); TEST_CASE(eraseReturn);
TEST_CASE(eraseGoto); TEST_CASE(eraseGoto);
@ -290,7 +291,6 @@ private:
" std::list<int>::iterator i = ints.begin();\n" " std::list<int>::iterator i = ints.begin();\n"
" i = ints.erase(i);\n" " i = ints.erase(i);\n"
" *i = 0;\n" " *i = 0;\n"
" \n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
@ -310,6 +310,17 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void erase3()
{
check("static void f(std::list<abc> &foo)\n"
"{\n"
" std::list<abc>::iterator it = foo.begin();\n"
" foo.erase(it->a);\n"
" if (it->b);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void eraseBreak() void eraseBreak()
{ {
check("void f()\n" check("void f()\n"