This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Refactor __debug_three_way_comp
ClosedPublic

Authored by ldionne on Jun 12 2023, 2:20 PM.

Details

Summary

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.

Diff Detail

Event Timeline

ldionne created this revision.Jun 12 2023, 2:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2023, 2:20 PM
ldionne requested review of this revision.Jun 12 2023, 2:20 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
philnik added inline comments.Jun 12 2023, 2:45 PM
libcxx/include/__algorithm/three_way_comp_ref_type.h
38–45

I might have missed it, but I can't find any reason why we need this overload in the old threads. Do you have any reasoning for having this overload?

ldionne marked an inline comment as done.Jun 13 2023, 10:57 AM
ldionne added inline comments.
libcxx/include/__algorithm/three_way_comp_ref_type.h
38–45

I'm not sure TBH. The tests seem to pass, and I do think it should be sufficient to use const&. I'll do it in a follow-up.

ldionne marked an inline comment as done.Jun 13 2023, 11:00 AM
ldionne added inline comments.
libcxx/include/__algorithm/three_way_comp_ref_type.h
38–45

Actually some of our tests fail when I remove it.

ldionne updated this revision to Diff 530991.Jun 13 2023, 11:02 AM

Update formatting.

philnik accepted this revision.Jun 13 2023, 12:16 PM

LGTM with comment.

libcxx/include/__algorithm/three_way_comp_ref_type.h
38–45

Weird. I think this should be investigated and a comment added here, since it's not obvious.

This revision is now accepted and ready to land.Jun 13 2023, 12:16 PM
ldionne added inline comments.Jun 13 2023, 2:24 PM
libcxx/include/__algorithm/three_way_comp_ref_type.h
38–45
This revision was automatically updated to reflect the committed changes.