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
2 changes: 2 additions & 0 deletions cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8201,6 +8201,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<noreturn>false</noreturn>
<use-retval/>
<leak-ignore/>
<container yields="iterator"/>
<arg nr="1" direction="in">
<not-uninit/>
</arg>
Expand All @@ -8215,6 +8216,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<noreturn>false</noreturn>
<use-retval/>
<leak-ignore/>
<container yields="iterator"/>
<arg nr="1" direction="in">
<not-uninit/>
</arg>
Expand Down
5 changes: 3 additions & 2 deletions lib/checkassert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ void CheckAssert::assertWithSideEffects()
continue;
if (tmp->str() == "get" && Token::simpleMatch(tmp->astParent(), ".") && astIsSmartPointer(tmp->astParent()->astOperand1()))
continue;
if (f->containerYield == Library::Container::Yield::START_ITERATOR || // bailout for std::begin/end
f->containerYield == Library::Container::Yield::END_ITERATOR)
if (f->containerYield == Library::Container::Yield::START_ITERATOR || // bailout for std::begin/end/prev/next
f->containerYield == Library::Container::Yield::END_ITERATOR ||
f->containerYield == Library::Container::Yield::ITERATOR)
continue;
sideEffectInAssertError(tmp, mSettings->library.getFunctionName(tmp));
}
Expand Down
6 changes: 6 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5041,3 +5041,9 @@ void assertWithSideEffect_std_begin(const std::vector<std::string>& v) {
return a.size() < b.size();
})); // cppcheck-suppress checkLibraryNoReturn
}

void assertWithSideEffect_std_prev_next(const std::vector<int>& v, std::vector<int>::const_iterator it) {
assert(std::prev(it, 1) == v.begin());
// cppcheck-suppress checkLibraryNoReturn
assert(std::next(it, 1) == v.end());
}
2 changes: 1 addition & 1 deletion test/testautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,7 @@ class TestAutoVariables : public TestFixture {
" return std::next(it);\n"
"}");
ASSERT_EQUALS(
"[test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'x' that will be invalid when returning.\n",
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning iterator to local container 'x' that will be invalid when returning.\n",
errout_str());

check("auto f() {\n"
Expand Down