Skip to content

Commit 9ece849

Browse files
authored
Fix 10467: FP mismatchingContainers with array of vectors (#3453)
1 parent b0b3f7e commit 9ece849

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

lib/valueflow.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,11 +3621,17 @@ static void valueFlowLifetimeFunction(Token *tok, TokenList *tokenlist, ErrorLog
36213621
if (i->container != returnContainer)
36223622
continue;
36233623
const Token * const argTok = args[argnr - 1];
3624+
bool forward = false;
3625+
for (ValueFlow::Value val : argTok->values()) {
3626+
if (!val.isLifetimeValue())
3627+
continue;
3628+
val.errorPath.emplace_back(argTok, "Passed to '" + tok->str() + "'.");
3629+
setTokenValue(tok->next(), val, settings);
3630+
forward = true;
3631+
}
36243632
// Check if lifetime is available to avoid adding the lifetime twice
3625-
ValueFlow::Value val = getLifetimeObjValue(argTok);
3626-
if (val.tokvalue) {
3627-
LifetimeStore{argTok, "Passed to '" + tok->str() + "'.", ValueFlow::Value::LifetimeKind::Iterator}.byVal(
3628-
tok->next(), tokenlist, errorLogger, settings);
3633+
if (forward) {
3634+
valueFlowForwardLifetime(tok, tokenlist, errorLogger, settings);
36293635
break;
36303636
}
36313637
}

test/teststl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,16 @@ class TestStl : public TestFixture {
17041704
" if (c.end() == d.end()) {}\n"
17051705
"}\n");
17061706
ASSERT_EQUALS("", errout.str());
1707+
1708+
// #10467
1709+
check("void f(std::array<std::vector<int>, N>& A) {\n"
1710+
" for (auto& a : A) {\n"
1711+
" auto it = std::find_if(a.begin(), a.end(), \n"
1712+
" [](auto i) { return i == 0; });\n"
1713+
" if (it != a.end()) {}\n"
1714+
" }\n"
1715+
"}\n");
1716+
ASSERT_EQUALS("", errout.str());
17071717
}
17081718

17091719
// Dereferencing invalid pointer

0 commit comments

Comments
 (0)