diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index f1a908fa1..44a89b7e5 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -827,7 +827,7 @@ void CheckStl::invalidContainer() continue; ErrorPath ep; // Check the iterator is created before the change - if (reaches(val.tokvalue, tok, library, &ep)) { + if (val.tokvalue != tok && reaches(val.tokvalue, tok, library, &ep)) { v = &val; errorPath = ep; return true; diff --git a/test/teststl.cpp b/test/teststl.cpp index 8654a6a69..96206e495 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -4123,6 +4123,15 @@ private: " *it;\n" "}\n",true); ASSERT_EQUALS("", errout.str()); + + // #9714 + check("void f() {\n" + " auto v = std::vector();\n" + " std::string x;\n" + " v.push_back(x.insert(0, \"x\"));\n" + " v.push_back(\"y\");\n" + "}\n",true); + ASSERT_EQUALS("", errout.str()); } void invalidContainerLoop() {