public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/102589] New: spaceship: std::map does not use specialised operator< for value
@ 2021-10-04  9:47 gjasny at googlemail dot com
  2021-10-04 10:31 ` [Bug libstdc++/102589] " redi at gcc dot gnu.org
  2021-10-04 10:39 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: gjasny at googlemail dot com @ 2021-10-04  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-04 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04  9:47 [Bug libstdc++/102589] New: spaceship: std::map does not use specialised operator< for value gjasny at googlemail dot com
2021-10-04 10:31 ` [Bug libstdc++/102589] " redi at gcc dot gnu.org
2021-10-04 10:39 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).