Skip to content

[hive.erasure]/2 Have erase_if reevaluate end() LWG4318 #8162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

birbacher
Copy link
Contributor

The defining code must not cache the end-iterator. In case the last element of the sequence is removed, the past-the-end iterator will be invalidated. This will trigger UB in the loop condition. Instead, re-evaluate end() each time.

The defining code must not cache the end-iterator. In case the last
element of the sequence is removed, the past-the-end iterator will be
invalidated. This will trigger UB in the loop condition. Instead,
re-evaluate end() each time.
@tkoeppe
Copy link
Contributor

tkoeppe commented Aug 15, 2025

This seems like a normative change. @jwakely?

@birbacher
Copy link
Contributor Author

At least it doesn't change the intended behaviour, I'd say. But if you reject, we'll file it as an NB comment.

@tkoeppe
Copy link
Contributor

tkoeppe commented Aug 15, 2025

I don't want to make that call unilaterally, but if there's agreement from LWG that it's an obvious oversight, I'd be OK to handle it editorially.

@jwakely
Copy link
Member

jwakely commented Aug 16, 2025

This seems badly normative to me, the current code is broken and avoiding repeated calls to end() doesn't seem like a critical part of the effects. If it really matters, we could continue caching it and do last = c.end(); after erasing an element.

Please just file an LWG issue, there's no reason to wait for the NB ballot.

@Dani-Hub
Copy link
Member

We have now LWG 4318 for this.

@jensmaurer jensmaurer changed the title [hive.erasure]/2 Have erase_if reevaluate end() [hive.erasure]/2 Have erase_if reevaluate end() LWG4318 Aug 17, 2025
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.

4 participants