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 (#6811)
  • Loading branch information
chrchr-github authored Sep 19, 2024
1 parent 74ec570 commit 757620f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7683,6 +7683,23 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<not-uninit/>
</arg>
</function>
<!-- template< class BidirIt, class UnaryPred > BidirIt partition( BidirIt first, BidirIt last, UnaryPred p ); -->
<!-- template< class BidirIt, class UnaryPred > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPred p ); -->
<function name="std::partition,std::stable_partition">
<returnValue type="iterator" container="1"/>
<noreturn>false</noreturn>
<arg nr="1">
<not-uninit/>
<iterator container="1" type="first"/>
</arg>
<arg nr="2">
<not-uninit/>
<iterator container="1" type="last"/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!-- template< class InputIt, class OutputIt > OutputIt copy( InputIt first, InputIt last, OutputIt d_first ); -->
<function name="std::copy">
<returnValue type="iterator" container="2"/>
Expand Down
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 757620f

Please sign in to comment.