diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 3509386ca..e6f61e3be 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -964,6 +964,13 @@ void CheckStl::missingComparison() incrementToken = 0; else if (tok3->str() == "break" || tok3->str() == "return") incrementToken = 0; + else if (Token::Match(tok3, "%varid% = %var% . insert ( ++| %varid% ++| ,", iteratorId)) + { + // skip insertion.. + tok3 = tok3->tokAt(6)->link(); + if (!tok3) + break; + } } if (incrementToken) missingComparisonError(incrementToken, tok2->tokAt(16)); diff --git a/test/teststl.cpp b/test/teststl.cpp index 15b68fd36..af08ebd0d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -102,6 +102,7 @@ private: TEST_CASE(missingInnerComparison3); // no FP when there is iterator shadowing TEST_CASE(missingInnerComparison4); // no FP when "break;" is used TEST_CASE(missingInnerComparison5); // Ticket #2154 - FP + TEST_CASE(missingInnerComparison6); // #2643 - 'it=foo.insert(++it,0);' // catch common problems when using the string::c_str() function TEST_CASE(cstr); @@ -1250,6 +1251,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void missingInnerComparison6() + { + check("void f(std::string &s) {\n" + " for(string::iterator it = s.begin(); it != s.end(); it++) {\n" + " it = s.insert(++it, 0);\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void cstr() { check("void f() {\n"