From f8132ea0224b2c03d6342d2d142e00a9b9b9d498 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 20 Dec 2022 13:29:19 -0600 Subject: [PATCH] Fix 11381: FP derefInvalidIteratorRedundantCheck when updating iterator using std::tie (#4659) --- lib/astutils.cpp | 3 ++- test/teststl.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0de86bb27..4d3c0f241 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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) diff --git a/test/teststl.cpp b/test/teststl.cpp index 5bbaf39b4..a818b4b58 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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& 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() {