Skip to content
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

Make container iterator operations defend against expected<any, T>-like types #4860

Closed

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Jul 24, 2024

Closes #4847.

This PR attempts to make container iterators defend against "overly convertible" operator- and comparison operators. Currently only const T& in comparisons and subtraction is handled. Forwarding reference parameters (T&& and its friends) may be too aggressive to be defended.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner July 24, 2024 17:22
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Jul 24, 2024
@StephanTLavavej StephanTLavavej self-assigned this Jul 24, 2024
@StephanTLavavej StephanTLavavej added the decision needed We need to choose something before working on this label Aug 12, 2024
@StephanTLavavej StephanTLavavej removed their assignment Aug 12, 2024
@StephanTLavavej
Copy link
Member

@CaseyCarter and I talked about this at the weekly maintainer meeting, and we're uncomfortable with merging this change. It injects a lot of overload complexity into STL iterators, with the potential to harm throughput and/or mess up other overload resolution scenarios. The underlying cause (at least for MSVC's STL, I dunno about libstdc++) is our undesirable "modifiable iterators inherit from const iterators" scheme, which we already know causes conformance issues and which I had already fixed in our decade-old stranded WCFB02 branch (by making our modifiable/const checked/unchecked iterators all unrelated instantiations of a single unified template per container).

Although libstdc++'s bug report came from a real program, we're unsure how common uses of expected<any, Err> will be. It's also concerning that pathological types (with forwarding references, as you presented) cause an even more difficult-to-solve problem in the library, with no Standardese clearly forbidding them.

We only have vague ideas about what we want to see happen here. Ideally vNext will happen, and we'll be able to fix our long-standing iterator wackiness and eliminate the true root cause of this problem. It would also be nice if LWG clearly said whether expected<any, Err> and/or pathological types like your any_convertible_subtractable example are required to be tolerated by STL containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working decision needed We need to choose something before working on this
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

STL: expected<any, T> and its friends can break container iterator comparison
2 participants