Skip to content

fix(stl): return the immediate successor from flat_map and flat_set erase #4522

Closed

Description

@zackees

Context

flat_map::erase and flat_set::erase compute pos + 1 before the backing vector shifts elements left. The returned iterator therefore skips the immediate successor. Erasing the last element returns the old end, which is beyond the new end. The backing vector erase already returns the correct index.

Repro: erase begin() from {1,2,3}; expected iterator to 2, actual iterator to 3.

Proposal

Return the iterator at the erased index after deletion, matching standard erase semantics.

Acceptance criteria

  • Add focused RED→GREEN tests for first, middle, and last erasures in both containers.
  • Cover iterator and const_iterator overloads; last-element erasure returns the new end().

Decisions

  • Combine map and set because they contain the same defect and should share one API contract.
  • Priority: medium; erase-while-iterating can silently skip entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions