Fixed #2488 (false positive with updating iterator in a for loop)
This commit is contained in:
parent
10d2909c7c
commit
87e3e9e703
|
@ -284,9 +284,13 @@ public:
|
||||||
while (indentlevel > 0 && 0 != (tok = tok->next()))
|
while (indentlevel > 0 && 0 != (tok = tok->next()))
|
||||||
{
|
{
|
||||||
if (tok->str() == "(")
|
if (tok->str() == "(")
|
||||||
++indentlevel;
|
tok = tok->link();
|
||||||
else if (tok->str() == ")")
|
else if (tok->str() == ")")
|
||||||
--indentlevel;
|
break;
|
||||||
|
|
||||||
|
// reassigning iterator in loop head
|
||||||
|
else if (Token::Match(tok, "%var% =") && tok->str() == it->str())
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! Token::simpleMatch(tok, ") {"))
|
if (! Token::simpleMatch(tok, ") {"))
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
TEST_CASE(erase3);
|
TEST_CASE(erase3);
|
||||||
TEST_CASE(erase4);
|
TEST_CASE(erase4);
|
||||||
TEST_CASE(erase5);
|
TEST_CASE(erase5);
|
||||||
|
TEST_CASE(erase6);
|
||||||
TEST_CASE(eraseBreak);
|
TEST_CASE(eraseBreak);
|
||||||
TEST_CASE(eraseContinue);
|
TEST_CASE(eraseContinue);
|
||||||
TEST_CASE(eraseReturn1);
|
TEST_CASE(eraseReturn1);
|
||||||
|
@ -502,6 +503,20 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:8]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:8]: (error) Dangerous iterator usage after erase()-method.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void erase6()
|
||||||
|
{
|
||||||
|
check("void f() {\n"
|
||||||
|
" std::vector<int> vec(3);\n"
|
||||||
|
" std::vector<int>::iterator it;\n"
|
||||||
|
" std::vector<int>::iterator itEnd = vec.end();\n"
|
||||||
|
" for (it = vec.begin(); it != itEnd; it = vec.begin(), itEnd = vec.end())\n"
|
||||||
|
" {\n"
|
||||||
|
" vec.erase(it);\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void eraseBreak()
|
void eraseBreak()
|
||||||
{
|
{
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
|
Loading…
Reference in New Issue