From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3F073385703A; Mon, 4 Oct 2021 10:31:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F073385703A From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution bug_status Message-ID: In-Reply-To: References: 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 10:31:32 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102589 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #1 from Jonathan Wakely --- (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 <=3D> support in the standard library= at all. Libstdc++ and MSVC do. > Describe the bug >=20 > 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 FooP= tr& > 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. This is the correct behaviour. > Expected behavior >=20 > 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. No. Comparing the two std::map objects has to use <=3D> because there is no= < for std::map in C++20, so you get a synthesized < from the <=3D> for std::map. = And obviously <=3D> for std::map is going to try to use <=3D> for its elements.= So it uses <=3D> for std::pair which uses <=3D> for its members, so it uses <=3D>= for std::shared_ptr. The only < comparison that happens is the one for std::map, after that everything is a three-way comparison.=