Fixed false positive #4077.

This commit is contained in:
PKEuS 2012-09-06 16:30:10 +02:00
parent 1c7027140a
commit a8cdd15738
2 changed files with 15 additions and 0 deletions

View File

@ -154,6 +154,11 @@ void CheckStl::iterators()
tok2 = tok2->tokAt(2);
}
// Passing iterator to function. Iterator might be initialized
else if (Token::Match(tok2, "%varid% ,|)", iteratorId)) {
validIterator = true;
}
// Dereferencing invalid iterator?
else if (!validIterator && Token::Match(tok2, "* %varid%", iteratorId)) {
dereferenceErasedError(tok2, tok2->strAt(1));

View File

@ -67,6 +67,7 @@ private:
TEST_CASE(eraseAssign1);
TEST_CASE(eraseAssign2);
TEST_CASE(eraseAssign3);
TEST_CASE(eraseAssignByFunctionCall);
TEST_CASE(eraseErase);
TEST_CASE(eraseByValue);
@ -868,6 +869,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void eraseAssignByFunctionCall() {
check("void f(std::list<list<int> >& l) {\n"
" std::list<foo>::const_iterator i;\n"
" bar(i);\n"
" cout << *i;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void eraseErase() {
check("void f(std::vector<ints> &ints)\n"
"{\n"