From 4d7ac2f82e122bff58b07aa9cf511d8e6eb3f3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 23 Jan 2010 22:03:38 +0100 Subject: [PATCH] STL: fixed false positive when using erase --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 511e6c20a..c71b91e4b 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -64,7 +64,7 @@ void CheckStl::iterators() iteratorsError(tok2, tok->strAt(2), tok2->strAt(2)); tok2 = tok2->tokAt(6); } - else if (Token::Match(tok2, "%var% . insert|erase ( %varid%", iteratorId)) + else if (Token::Match(tok2, "%var% . insert|erase ( %varid% )|,", iteratorId)) { if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".") iteratorsError(tok2, tok->strAt(2), tok2->str()); diff --git a/test/teststl.cpp b/test/teststl.cpp index 0190ac452..69fdb8e79 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -47,6 +47,7 @@ private: TEST_CASE(STLSizeNoErr); TEST_CASE(erase); TEST_CASE(erase2); + TEST_CASE(erase3); TEST_CASE(eraseBreak); TEST_CASE(eraseReturn); TEST_CASE(eraseGoto); @@ -290,7 +291,6 @@ private: " std::list::iterator i = ints.begin();\n" " i = ints.erase(i);\n" " *i = 0;\n" - " \n" "}\n"); ASSERT_EQUALS("", errout.str()); @@ -310,6 +310,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void erase3() + { + check("static void f(std::list &foo)\n" + "{\n" + " std::list::iterator it = foo.begin();\n" + " foo.erase(it->a);\n" + " if (it->b);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void eraseBreak() { check("void f()\n"