Skip to content

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

@AlexGuteniev

Description

@AlexGuteniev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improvedfixedSomething works now, yay!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions