From a8cdd15738268c363559a4e24a942b8180ce1c5b Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 6 Sep 2012 16:30:10 +0200 Subject: [PATCH] Fixed false positive #4077. --- lib/checkstl.cpp | 5 +++++ test/teststl.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) 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"