diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index e23d2f319..0127875b4 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -3621,11 +3621,17 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog if (i->container != returnContainer) continue; const Token * const argTok = args[argnr - 1]; + bool forward = false; + for (ValueFlow::Value val : argTok->values()) { + if (!val.isLifetimeValue()) + continue; + val.errorPath.emplace_back(argTok, "Passed to '" + tok->str() + "'."); + setTokenValue(tok->next(), val, settings); + forward = true; + } // Check if lifetime is available to avoid adding the lifetime twice - ValueFlow::Value val = getLifetimeObjValue(argTok); - if (val.tokvalue) { - LifetimeStore{argTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Iterator}.byVal( - tok->next(), tokenlist, errorLogger, settings); + if (forward) { + valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings); break; } } diff --git a/test/teststl.cpp b/test/teststl.cpp index e523690db..261a10c78 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1704,6 +1704,16 @@ private: " if (c.end() == d.end()) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10467 + check("void f(std::array, N>& A) {\n" + " for (auto& a : A) {\n" + " auto it = std::find_if(a.begin(), a.end(), \n" + " [](auto i) { return i == 0; });\n" + " if (it != a.end()) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // Dereferencing invalid pointer