This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Fixes string_view comparison operators.
ClosedPublic

Authored by Mordante on Aug 6 2022, 5:33 AM.

Details

Reviewers
philnik
huixie90
Group Reviewers
Restricted Project
Commits
rG70074cf3972b: [libc++] Fixes string_view comparison operators.
Summary

While implementing operator<=> for string_view (D130295) @philnik
pointed out common_type should be type_identity. Since it was an
existing issue that wasn't addressed.

This addresses the issue for both the new and existing equality and
comparison operators. The test is based on the example posted in
D130295.

Diff Detail

Event Timeline

Mordante created this revision.Aug 6 2022, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2022, 5:33 AM
Mordante requested review of this revision.Aug 6 2022, 5:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2022, 5:33 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
huixie90 accepted this revision as: huixie90.Aug 8 2022, 9:44 AM
huixie90 added a subscriber: huixie90.

LGTM

libcxx/test/std/strings/string.view/string.view.comparison/common_type_specialization.pass.cpp
10

question : why !stdlib=libc++

Mordante marked an inline comment as done.Aug 8 2022, 10:00 AM

Thanks for the review!

libcxx/test/std/strings/string.view/string.view.comparison/common_type_specialization.pass.cpp
10

libc++ provides string_view in all language Standards, other vendors only in C++17. So this disables the testing before C++17 when the library isn't libc++.

philnik accepted this revision.Aug 8 2022, 10:14 AM

LGTM % nit.

libcxx/test/std/strings/string.view/string.view.comparison/common_type_specialization.pass.cpp
13
36

You didn't have to keep my quick-n-diry implementation, but I guess it should be fine. Maybe add a static_assert(sizeof(char_wrapper) == 1) for my sanity? Unless it's guaranteed by the standard. In that case I'd be interested where that is guaranteed.

This revision is now accepted and ready to land.Aug 8 2022, 10:14 AM
Mordante marked 2 inline comments as done.Aug 10 2022, 10:31 AM

Thanks for the reviews!

libcxx/test/std/strings/string.view/string.view.comparison/common_type_specialization.pass.cpp
36

I'm sure it's guaranteed by the Standard, just not sure where ;-) But I'll add a static_assert.

This revision was automatically updated to reflect the committed changes.