[libc++] Refactor __debug_three_way_comp
authorLouis Dionne <ldionne.2@gmail.com>
Mon, 12 Jun 2023 21:16:32 +0000 (14:16 -0700)
committerLouis Dionne <ldionne.2@gmail.com>
Tue, 13 Jun 2023 21:24:56 +0000 (14:24 -0700)
commit3456b2f60a08a6ab750d58817463a6701a416e3b
treef4011371e9366516776b762c8802fd38f3f27a2b
parent17b7df3daee85c1a4d1d955e558d42b34ce17549
[libc++] Refactor __debug_three_way_comp

This makes __debug_three_way_comp consistent with __debug_less and
in particular gets rid of a potential use-after-move caused by the
use of std::forward. In the previous version of the code, we would
call `__do_compare_assert` after forwarding the arguments into the
comparator, which could end up using the arguments after they've been
moved from.

This also simplifies how we call `__do_compare_assert` by using
`if constexpr` and adds a missing test for proxy iterators in
lexicographical_compare_three_way, which could have found this
issue.

Differential Revision: https://reviews.llvm.org/D152753
libcxx/include/__algorithm/three_way_comp_ref_type.h
libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp
libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp