Skip to content

Conversation

@NylteJ
Copy link

@NylteJ NylteJ commented Aug 17, 2025

This PR audits and updates all calls to to_address (or _To_address) to ensure that both to_address(i) and to_address(i + (s - i)) (which should be equivalent to the standard-mandated to_address(i + ranges::distance(i, s))) are evaluated before using the pointer converted from the iterator. Fixes #5295.

Additional Notes:

  1. For algorithms accepting an iterator pair [i, s), this change evaluates only to_address(s) instead of to_address(i + (s - i)).
    While the proposal specifies converting [i, s) to [to_address(i), to_address(i + (s - i))) (implying at least one operator+ invocation before conversion), iterator requirements guarantee that i + (s - i) must be equal to s, and functions like ranges::advance also do not actually "advance" the iterator in this case.
    Based on the proposal’s intent, this should not affect iterator validation: if i + (s - i) is invalid, then s is already invalid and should have been checked before the library call.
    This could be revised later if necessary.

  2. The constructors of string_view and span, as well as the implementation of views::counted, are intentionally unchanged, as the standard explicitly specifies their behavior ([string.view.cons]/9, 13, [span.cons]/6, 11, 19, [range.counted]/2.1). This may be worth submitting as a potential defect.

  3. Added some previously missing static_casts to pass the tests.

@NylteJ NylteJ requested a review from a team as a code owner August 17, 2025 18:09
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Aug 17, 2025
@NylteJ

This comment was marked as off-topic.

@NylteJ NylteJ changed the title Implement P3349R1 Implement P3349R1 Converting Contiguous Iterators To Pointers Aug 17, 2025
@StephanTLavavej StephanTLavavej self-assigned this Aug 18, 2025
@StephanTLavavej StephanTLavavej added the cxx26 C++26 feature label Aug 18, 2025
@AlexGuteniev

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx26 C++26 feature

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

P3349R1 Converting Contiguous Iterators To Pointers

4 participants