From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 16EC53858001; Tue, 26 Jan 2021 18:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16EC53858001 From: "gcc@nicholas-schwab.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/98842] optional's spaceship operations generates wrong code when operator== is not present Date: Tue, 26 Jan 2021 18:56:27 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc@nicholas-schwab.de 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: cc 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: Tue, 26 Jan 2021 18:56:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98842 gcc@nicholas-schwab.de changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |gcc@nicholas-schwab.de --- Comment #1 from gcc@nicholas-schwab.de --- Three problem lies in the concept three_way_comparable_with. It uses __detail::__weakly_eq_cmp_with that requires u =3D=3D t. Due to paper P1185 operator=3D=3D will not lookup operator<=3D>. Therefore having only operato= r<=3D> defined does not suffice to fulfill __detail::__weakly_eq_cmp. Hence the fi= rst of these two templates is SFINAE'D out and the second is taken.=20 template _Up> constexpr compare_three_way_result_t<_Tp, _Up> operator<=3D>(const optional<_Tp>& __x, const optional<_Up>& __y) template constexpr compare_three_way_result_t<_Tp, _Up> operator<=3D>(const optional<_Tp>& __x, const _Up& __v)=20 The second will however compare false whenever the left hand side is empty.= =20 The standard requires that three_way_comparable_with also requires weakly_equality_comparable. Hence the implementation of this concept is correct. However this might be a defect in the standard.=20 Note that the standard also wants three_way_comparable_with<_Tp> for the se= cond template (http://eel.is/c++draft/optional#comp.with.t-25). So the second template above is non-confirming. But it seems to me that a comparison betw= een two optionals then is always ambiguous, so this should be a defect.=