public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102589] spaceship: std::map does not use specialised operator< for value Date: Mon, 04 Oct 2021 10:31:32 +0000 [thread overview] Message-ID: <bug-102589-4-getGh34PHu@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-102589-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102589 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Gregor Jasny from comment #0) > 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. Probably because it doesn't implement <=> support in the standard library at all. Libstdc++ and MSVC do. > 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 assumption is wrong. > 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. This is the correct behaviour. > 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. No. Comparing the two std::map objects has to use <=> because there is no < for std::map in C++20, so you get a synthesized < from the <=> for std::map. And obviously <=> for std::map is going to try to use <=> for its elements. So it uses <=> for std::pair which uses <=> for its members, so it uses <=> for std::shared_ptr. The only < comparison that happens is the one for std::map, after that everything is a three-way comparison.
next prev parent reply other threads:[~2021-10-04 10:31 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-04 9:47 [Bug libstdc++/102589] New: " gjasny at googlemail dot com 2021-10-04 10:31 ` redi at gcc dot gnu.org [this message] 2021-10-04 10:39 ` [Bug libstdc++/102589] " redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102589-4-getGh34PHu@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).