From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C33073857C4E; Mon, 4 Oct 2021 09:47:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C33073857C4E From: "gjasny at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102589] New: spaceship: std::map does not use specialised operator< for value Date: Mon, 04 Oct 2021 09:47:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gjasny at googlemail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 09:47:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102589 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=3D51546&action=3Dedit Testcase Hello, I stumbled over this issue when porting a code base from C++17 to C++20. Bo= th: GNU libstdc++ as well as MSVC STL show the unexpected behaviour. Libc++ see= ms to do the right thing. Describe the bug Compiling the test case with C++17 works as expected whereas compiling it w= ith 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<= =3D> 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 <= =3D> 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-testca= se Godbolt: https://godbolt.org/z/objPnjo84 Thanks, Gregor=