Fixed #1930 (false negative: bad iterators checks fails to detect bugs with preincrement)

This commit is contained in:
Erik Lax 2010-08-13 20:54:31 +02:00 committed by Daniel Marjamäki
parent ab7bb876f9
commit 032d2678aa
2 changed files with 11 additions and 1 deletions

View File

@ -289,7 +289,7 @@ void CheckStl::eraseCheckLoop(const Token *it)
tok2 = 0;
break;
}
else if (Token::simpleMatch(tok, ("erase ( " + it->str() + " )").c_str()))
else if (Token::Match(tok, ("erase ( ++|--| " + it->str() + " )").c_str()))
{
tok2 = tok;
while (NULL != (tok2 = tok2 ? tok2->previous() : 0))

View File

@ -429,6 +429,16 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
check("void f()\n"
"{\n"
" std::list<int>::iterator it = foo.begin();\n"
" while (it != i2)\n"
" {\n"
" foo.erase(++it);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Dangerous iterator usage. After erase the iterator is invalid so dereferencing it or comparing it with another iterator is invalid.\n", errout.str());
}
void eraseBreak()