Fix 11381: FP derefInvalidIteratorRedundantCheck when updating iterator using std::tie (#4659)

This commit is contained in:
Paul Fultz II 2022-12-20 13:29:19 -06:00 committed by GitHub
parent 7506b4ab52
commit f8132ea022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -2361,7 +2361,8 @@ bool isVariableChangedByFunctionCall(const Token *tok, int indirect, const Setti
if (indirect > 0 && requireInit && requireNonNull)
return true;
}
if (Token::simpleMatch(tok->tokAt(-2), "std :: tie"))
return true;
// if the library says 0 is invalid
// => it is assumed that parameter is an in parameter (TODO: this is a bad heuristic)
if (indirect == 0 && requireNonNull)

View File

@ -4658,6 +4658,17 @@ private:
" return s.end();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Consider using std::find_if algorithm instead of a raw loop.\n", errout.str());
// #11381
check("int f(std::map<int, int>& map) {\n"
" auto it = map.find(1);\n"
" if (it == map.end()) {\n"
" bool bInserted;\n"
" std::tie(it, bInserted) = map.emplace(1, 42);\n"
" }\n"
" return debug_valueflow(it)->second;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void dereferenceInvalidIterator2() {