diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index ad40c6265..2aac7d250 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -131,6 +131,10 @@ void CheckStl::iterators() { validIterator = true; } + else if (tok2->str() == "else") + { + validIterator = true; + } } } } diff --git a/test/teststl.cpp b/test/teststl.cpp index bbb2996fd..52736cfa1 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -56,6 +56,7 @@ private: TEST_CASE(eraseContinue); TEST_CASE(eraseReturn1); TEST_CASE(eraseReturn2); + TEST_CASE(eraseReturn3); TEST_CASE(eraseGoto); TEST_CASE(eraseAssign1); TEST_CASE(eraseAssign2); @@ -513,6 +514,26 @@ private: ASSERT_EQUALS("", errout.str()); } + void eraseReturn3() + { + check("void f()\n" + "{\n" + " std::vector foo;\n" + " std::vector::iterator it;\n" + " for (it = foo.begin(); it != foo.end(); ++it)\n" + " {\n" + " if (somecondition) {\n" + " if (*it == 1)\n" + " foo.erase(it);\n" + " else\n" + " *it = 0;\n" + " return;\n" + " }\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void eraseGoto() { check("void f()\n"