diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 8c70c952d..9186e67c8 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -291,7 +291,20 @@ void CheckStl::eraseCheckLoop(const Token *it) break; } else if (Token::simpleMatch(tok, ("erase ( " + it->str() + " )").c_str())) + { tok2 = tok; + while (tok2 = tok2 ? tok2->previous() : 0) + { + if (Token::Match(tok2, "[;{}]")) + break; + else if (tok2->str() == "=") + tok2 = 0; + else + tok2 = tok2->previous(); + } + if (tok2) + tok2 = tok; + } } // Write error message.. diff --git a/test/teststl.cpp b/test/teststl.cpp index 9d13fc798..f7d6e2a42 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -53,6 +53,7 @@ private: TEST_CASE(erase3); TEST_CASE(erase4); TEST_CASE(eraseBreak); + TEST_CASE(eraseContinue); TEST_CASE(eraseReturn1); TEST_CASE(eraseReturn2); TEST_CASE(eraseGoto); @@ -443,6 +444,23 @@ private: ASSERT_EQUALS("", errout.str()); } + void eraseContinue() + { + check("void f(std::vector &ints)\n" + "{\n" + " std::vector::iterator it;\n" + " std::vector::iterator jt = ints.begin();\n" + " for (it = ints.begin(); it != ints.end(); it = jt) {\n" + " ++jt;\n" + " if (*it == 1) {\n" + " jt = ints.erase(it);\n" + " continue;\n" + " }\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void eraseReturn1() { check("void f()\n"