https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102589
Bug ID: 102589 Summary: spaceship: std::map does not use specialised operator< for value Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: gjasny at googlemail dot com Target Milestone: --- Created attachment 51546 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51546&action=edit Testcase Hello, I stumbled over this issue when porting a code base from C++17 to C++20. Both: GNU libstdc++ as well as MSVC STL show the unexpected behaviour. Libc++ seems to do the right thing. Describe the bug Compiling the test case with C++17 works as expected whereas compiling it with C++20 makes the test assumption fail. The reason is that for C++ 20 builds the specialised operator<(const FooPtr& left, const FooPtr& right) is not picked up. Instead the default operator<=> for std::shared_ptr is used which only compares the raw pointers and not the content they point to. Expected behavior I'd expect that with C++17 and C++20 the STL would prefer the specialised operator<(const FooPtr& left, const FooPtr& right) over the synthesised <=> one. That would also align with the strong backwards compatibilities C++ strives for. GCC version g++-11 (Debian 11.2.0-8) 11.2.0 Links Microsoft STL Issue: https://github.com/microsoft/STL/issues/2234 Debian Sid based reproducer: https://github.com/gjasny/map-spaceship-testcase Godbolt: https://godbolt.org/z/objPnjo84 Thanks, Gregor