false poitive - invalid iterator after break
This commit is contained in:
parent
66227c4da0
commit
b8d233f1a2
|
@ -69,6 +69,8 @@ void CheckStl::iterators()
|
|||
|
||||
// the validIterator flag says if the iterator has a valid value or not
|
||||
bool validIterator = true;
|
||||
|
||||
// When "validatingToken" is reached the validIterator is set to true
|
||||
const Token* validatingToken = 0;
|
||||
|
||||
// counter for { and }
|
||||
|
@ -166,7 +168,7 @@ void CheckStl::iterators()
|
|||
// bailout handling. Assume that the iterator becomes valid if we see return/break.
|
||||
// TODO: better handling
|
||||
else if (Token::Match(tok2, "return|break")) {
|
||||
validatingToken = Token::findsimplematch(tok->next(), ";");
|
||||
validatingToken = Token::findsimplematch(tok2->next(), ";");
|
||||
}
|
||||
|
||||
// bailout handling. Assume that the iterator becomes valid if we see else.
|
||||
|
|
|
@ -46,6 +46,7 @@ private:
|
|||
TEST_CASE(iterator12);
|
||||
|
||||
TEST_CASE(dereference);
|
||||
TEST_CASE(dereference_break); // #3644 - handle "break"
|
||||
TEST_CASE(dereference_member);
|
||||
|
||||
TEST_CASE(STLSize);
|
||||
|
@ -383,6 +384,23 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:7]: (error) Dereferenced iterator 'iter' has been erased\n", errout.str());
|
||||
}
|
||||
|
||||
void dereference_break() { // #3644
|
||||
check("void f(std::vector<int> &ints) {\n"
|
||||
" std::vector<int>::iterator iter;\n"
|
||||
" for (iter=ints.begin();iter!=ints.end();++iter) {\n"
|
||||
" if (*iter == 2) {\n"
|
||||
" ints.erase(iter);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" if (*iter == 3) {\n"
|
||||
" ints.erase(iter);\n"
|
||||
" break;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void dereference_member() {
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue