diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 67717a4f3..492288875 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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)); diff --git a/test/teststl.cpp b/test/teststl.cpp index 48ceeb654..78eb73acb 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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 >& l) {\n" + " std::list::const_iterator i;\n" + " bar(i);\n" + " cout << *i;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void eraseErase() { check("void f(std::vector &ints)\n" "{\n"