Skip to content

Commit 757620f

Browse files
Fix #13108 FP invalidContainer when constructing container from iterators (danmar#6811)
1 parent 74ec570 commit 757620f

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

cfg/std.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7683,6 +7683,23 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
76837683
<not-uninit/>
76847684
</arg>
76857685
</function>
7686+
<!-- template< class BidirIt, class UnaryPred > BidirIt partition( BidirIt first, BidirIt last, UnaryPred p ); -->
7687+
<!-- template< class BidirIt, class UnaryPred > BidirIt stable_partition( BidirIt first, BidirIt last, UnaryPred p ); -->
7688+
<function name="std::partition,std::stable_partition">
7689+
<returnValue type="iterator" container="1"/>
7690+
<noreturn>false</noreturn>
7691+
<arg nr="1">
7692+
<not-uninit/>
7693+
<iterator container="1" type="first"/>
7694+
</arg>
7695+
<arg nr="2">
7696+
<not-uninit/>
7697+
<iterator container="1" type="last"/>
7698+
</arg>
7699+
<arg nr="3">
7700+
<not-uninit/>
7701+
</arg>
7702+
</function>
76867703
<!-- template< class InputIt, class OutputIt > OutputIt copy( InputIt first, InputIt last, OutputIt d_first ); -->
76877704
<function name="std::copy">
76887705
<returnValue type="iterator" container="2"/>

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ static void valueFlowLifetimeConstructor(Token* tok, const TokenList& tokenlist,
19711971
if (args.size() == 1 && vt.container->view && astIsContainerOwned(args.front())) {
19721972
LifetimeStore{args.front(), "Passed to container view.", ValueFlow::Value::LifetimeKind::SubObject}
19731973
.byRef(tok, tokenlist, errorLogger, settings);
1974-
} else if (args.size() == 2 && astIsIterator(args[0]) && astIsIterator(args[1])) {
1974+
} else if (args.size() == 2 && (astIsIterator(args[0]) || astIsIterator(args[1]))) {
19751975
LifetimeStore::forEach(
19761976
tokenlist,
19771977
errorLogger,

test/teststl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6308,6 +6308,15 @@ class TestStl : public TestFixture {
63086308
"}\n",
63096309
true);
63106310
ASSERT_EQUALS("", errout_str());
6311+
6312+
check("void f(std::vector<int>& v) {\n" // #13108
6313+
" auto it = unknown(v);\n"
6314+
" auto w = std::vector<int>{ it, v.end() };\n"
6315+
" v.erase(it, v.end());\n"
6316+
" for (const auto& i : w) {}\n"
6317+
"}\n",
6318+
true);
6319+
ASSERT_EQUALS("", errout_str());
63116320
}
63126321

63136322
void invalidContainerLoop() {

0 commit comments

Comments
 (0)