From 6162ebd60859247bcd9fdd64ed5fd6b1873ad78f Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 23 May 2020 00:13:55 -0500 Subject: [PATCH] Fix issue 9714: FP invalidContainer related to auto and std::string::insert (#2660) --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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() {