Fixed #1930 (false negative: bad iterators checks fails to detect bugs with preincrement)
This commit is contained in:
parent
ab7bb876f9
commit
032d2678aa
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue