Skip to content

<algorithm>: use _Verify_ranges_do_not_overlap function in more places #5472

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
AlexGuteniev opened this issue May 5, 2025 · 0 comments
Open
Labels
enhancement Something can be improved

Comments

@AlexGuteniev
Copy link
Contributor

AlexGuteniev commented May 5, 2025

During #5471 I've noticed interesting function _Verify_ranges_do_not_overlap. This one is used in std::swap_ranges to check [alg.swap]/2 precondition:

The two ranges [first1, last1) and [first2, last2) do not overlap

When IDL = 2, and this precondition is not satisfied, it traps with "ranges should not overlap each other".

We can use it in more places. Specifically, meow_copy / meow_copy_if.

Sometimes overlapping won't hurt, but for example with remove_cpy and unique_copy (#5355) the output may be very surprising if there's an overlap, and the input range leads a bit; this would resemble similar memcpy UB manifestation.

Note that the function has plain error message, not smartass Standard citing. I doubt that it is worth citing the Standard, as we need to propagate different messages to a potentially-user-defined trap. We've been propagating only literals there so far, and propagating literals from all potential _Verify_ranges_do_not_overlap call sites would mean macroizing these call sites, which seems to be much of abomination for this purpose. Still, if it is desired, _Verify_ranges_do_not_overlap can be turn into bool returning, and put into a macro that traps with citing message.

@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
None yet
Development

No branches or pull requests

2 participants