Fixed #1946 ('Dereferenced iterator erased' false positive)

This commit is contained in:
Daniel Marjamäki 2010-08-17 18:56:11 +02:00
parent 86f1718b1c
commit 1faaa5471c
2 changed files with 27 additions and 2 deletions

View File

@ -108,6 +108,11 @@ void CheckStl::iterators()
if (!tok2)
break;
}
else if (Token::Match(tok2, "%varid% = %var% ;", iteratorId))
{
validIterator = true;
tok2 = tok2->tokAt(2);
}
else if (!validIterator && Token::Match(tok2, "* %varid%", iteratorId))
{
dereferenceErasedError(tok2, tok2->strAt(1));

View File

@ -57,7 +57,8 @@ private:
TEST_CASE(eraseReturn1);
TEST_CASE(eraseReturn2);
TEST_CASE(eraseGoto);
TEST_CASE(eraseAssign);
TEST_CASE(eraseAssign1);
TEST_CASE(eraseAssign2);
TEST_CASE(eraseErase);
TEST_CASE(eraseByValue);
@ -521,7 +522,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void eraseAssign()
void eraseAssign1()
{
check("void f()\n"
"{\n"
@ -534,6 +535,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
void eraseAssign2()
{
check("void f(list<int> &ints)\n"
"{\n"
" for (list<int>::iterator it = ints.begin(); it != ints.end(); ++it) {\n"
" if (*it == 123) {\n"
" list<int>::iterator copy = it;\n"
" ++copy;\n"
" ints.erase(it);\n"
" it = copy;\n"
" } else {\n"
" it->second = 123;\n"
" ++it;\n"
" }\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void eraseErase()
{
check("void f(std::vector<ints> &ints)\n"