<algorithm>
: use _Verify_ranges_do_not_overlap
function in more places
#5472
Labels
enhancement
Something can be improved
During #5471 I've noticed interesting function
_Verify_ranges_do_not_overlap
. This one is used instd::swap_ranges
to check [alg.swap]/2 precondition: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
andunique_copy
(#5355) the output may be very surprising if there's an overlap, and the input range leads a bit; this would resemble similarmemcpy
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 intobool
returning, and put into a macro that traps with citing message.The text was updated successfully, but these errors were encountered: