Skip to content

Commit

Permalink
Fix #13108 FP invalidContainer when constructing container from itera…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
chrchr-github committed Sep 18, 2024
1 parent d8debc2 commit 9a5bf66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ static void valueFlowLifetimeConstructor(Token* tok, const TokenList& tokenlist,
if (args.size() == 1 && vt.container->view && astIsContainerOwned(args.front())) {
LifetimeStore{args.front(), "Passed to container view.", ValueFlow::Value::LifetimeKind::SubObject}
.byRef(tok, tokenlist, errorLogger, settings);
} else if (args.size() == 2 && astIsIterator(args[0]) && astIsIterator(args[1])) {
} else if (args.size() == 2 && (astIsIterator(args[0]) || astIsIterator(args[1]))) {
LifetimeStore::forEach(
tokenlist,
errorLogger,
Expand Down
9 changes: 9 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6308,6 +6308,15 @@ class TestStl : public TestFixture {
"}\n",
true);
ASSERT_EQUALS("", errout_str());

check("void f(std::vector<int>& v) {\n" // #13108
" auto it = unknown(v);\n"
" auto w = std::vector<int>{ it, v.end() };\n"
" v.erase(it, v.end());\n"
" for (const auto& i : w) {}\n"
"}\n",
true);
ASSERT_EQUALS("", errout_str());
}

void invalidContainerLoop() {
Expand Down

0 comments on commit 9a5bf66

Please sign in to comment.