Skip to content

mismatchingContainers: detect mismatched iterator ranges passed to container member functions - #9042

Open
tropibyte wants to merge 1 commit into
cppcheck-opensource:mainfrom
tropibyte:mismatching-range-insert
Open

tropibyte wants to merge 1 commit into
cppcheck-opensource:mainfrom
tropibyte:mismatching-range-insert

Conversation

@tropibyte

Copy link
Copy Markdown
  • Checks iterator ranges passed to insert, assign, append and replace of a container, so ints2.insert(it1, it2) with iterators from different containers is now reported. insert(hint, value) on associative containers, where the first iterator belongs to the container itself, is excluded.
  • Library container detection now recognizes nested iterator types of non-template containers and std::span (std::string::iterator, std::span<int>::iterator), so such variables get an iterator value type. std::span<int>::size_type is no longer treated as a container.
  • Replaces the stale TODO in CheckStl::iterators() with a pointer to mismatchingContainers(), which now does that check.
  • Tests: converts the TODO_ASSERT in TestStl::iterator6 and five in TestLibrary, and adds positive and negative cases.

There is no Trac ticket for this yet. Could one of you file one? Once it exists I'll add Fix #NNNNN to the commit title.

…ntainer member functions

Iterator ranges passed to insert(), assign(), append() and replace() of a
container were not checked, so 'ints2.insert(it1, it2)' with iterators from
two different containers went unreported (TODO in TestStl::iterator6).

To support this, library container detection now recognizes nested iterator
types of non-template containers and of std::span, e.g. std::string::iterator
and std::span<int>::iterator. The stale TODO in CheckStl::iterators() now
points at mismatchingContainers(), which performs the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant