Fixed #2481 (false positive with 'break;': After insert, the iterator '*' may be invalid)

This commit is contained in:
Daniel Marjamäki 2011-01-19 21:00:46 +01:00
parent b1b8ea6457
commit 70eadb37bd
2 changed files with 17 additions and 1 deletions

View File

@ -642,7 +642,7 @@ void CheckStl::pushback()
}
}
else if (tok2->str() == "return")
else if (tok2->str() == "return" || tok2->str() == "break")
{
invalidIterator.clear();
}

View File

@ -222,6 +222,22 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// Ticket #2481
check("void foo(std::vector<int> &r)\n"
"{\n"
" std::vector<int>::iterator aI = r.begin();\n"
" while(aI != r.end())\n"
" {\n"
" if (*aI == 0)\n"
" {\n"
" r.insert(aI, 42);\n"
" break;\n"
" }\n"
" ++aI;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Execution path checking..
check("void foo(std::vector<int> &r, int c)\n"
"{\n"