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() {