https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123209
Bug ID: 123209
Summary: std::ranges::less incorrectly prefers built-in pointer
comparison over user-defined operator<=> when implicit
conversion to pointer exists
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: rogerio.souza at gmail dot com
Target Milestone: ---
Created attachment 63089
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63089&action=edit
Testcase
In C++20, std::ranges::less is required to use the built-in pointer total order
only if the expression t < u would normally resolve to a built-in pointer
comparison.
In the case of a class with both operator<=> and an implicit conversion to
const char*, the expression t < u is not ambiguous; it correctly matches the
synthesized operator< from <=>. However, libstdc++ detects the implicit
conversion to pointer and incorrectly routes the call to the
pointer-total-order logic, bypassing the user's lexicographical comparison. Is
this behavior really expected.
Snippet available at https://godbolt.org/z/8WvfeTq89
Attached is the C++ testcase file.
Regards,
Rogerio