diff --git a/src/checkstl.cpp b/src/checkstl.cpp index 918d067ea..d3265f31c 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -66,7 +66,7 @@ void CheckStl::iterators() } else if (Token::Match(tok2, "%var% . insert|erase ( %varid%", iteratorId)) { - if (tok2->varId() != containerId) + if (tok2->varId() != containerId && tok2->tokAt(5)->str() != ".") iteratorsError(tok2, tok->strAt(2), tok2->str()); else if (tok2->strAt(2) == std::string("erase")) validIterator = false; diff --git a/test/teststl.cpp b/test/teststl.cpp index 917f8914a..394b76d88 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -37,6 +37,7 @@ private: TEST_CASE(iterator1); TEST_CASE(iterator2); TEST_CASE(iterator3); + TEST_CASE(iterator4); TEST_CASE(dereference); TEST_CASE(dereference_member); @@ -120,6 +121,20 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with both l1 and l2\n", errout.str()); } + void iterator4() + { + check("void foo(std::vector &test)\n" + "{\n" + " std::set result;\n" + " for (std::vector::const_iterator cit = test.begin();\n" + " cit != test.end();\n" + " ++cit)\n" + " {\n" + " result.insert(cit->size());\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } // Dereferencing invalid pointer void dereference()