Fix issue 9714: FP invalidContainer related to auto and std::string::insert (#2660)

This commit is contained in:
Paul Fultz II 2020-05-23 00:13:55 -05:00 committed by GitHub
parent 526abd4b52
commit 6162ebd608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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;

View File

@ -4123,6 +4123,15 @@ private:
" *it;\n"
"}\n",true);
ASSERT_EQUALS("", errout.str());
// #9714
check("void f() {\n"
" auto v = std::vector<std::string>();\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() {