diff --git a/src/checkstl.cpp b/src/checkstl.cpp index a9b14038e..9c4d20b65 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -188,7 +188,7 @@ void CheckStl::eraseCheckLoop(const Token *it) if (indentlevel < 0) break; } - else if (Token::simpleMatch(tok, "break ;") || Token::simpleMatch(tok, (it->str() + " =").c_str())) + else if (Token::Match(tok, "break|return|goto") || Token::simpleMatch(tok, (it->str() + " =").c_str())) { tok2 = 0; break; diff --git a/test/teststl.cpp b/test/teststl.cpp index fa2007aa3..ec8f5d2b5 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -42,6 +42,8 @@ private: TEST_CASE(STLSizeNoErr); TEST_CASE(erase); TEST_CASE(eraseBreak); + TEST_CASE(eraseReturn); + TEST_CASE(eraseGoto); TEST_CASE(eraseAssign); } @@ -171,6 +173,33 @@ private: ASSERT_EQUALS("", errout.str()); } + void eraseReturn() + { + checkErase("void f()\n" + "{\n" + " for (it = foo.begin(); it != foo.end(); ++it)\n" + " {\n" + " foo.erase(it);\n" + " return;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + + void eraseGoto() + { + checkErase("void f()\n" + "{\n" + " for (it = foo.begin(); it != foo.end(); ++it)\n" + " {\n" + " foo.erase(it);\n" + " goto abc;\n" + " }\n" + "bar:\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void eraseAssign() { checkErase("void f()\n"