Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3577,11 +3577,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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,16 @@ class TestStl : public TestFixture {
" if (c.end() == d.end()) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// #10467
check("void f(std::array<std::vector<int>, 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
Expand Down