From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8D933854834; Tue, 24 Nov 2020 10:21:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8D933854834 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency Date: Tue, 24 Nov 2020 10:21:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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 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: Tue, 24 Nov 2020 10:21:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97965 Bug ID: 97965 Summary: constexpr evaluation vs. NaNs inconsistency Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- constexpr bool a =3D __builtin_nan ("") > 0.0; constexpr bool b =3D __builtin_nans ("") > 0.0; constexpr bool c =3D __builtin_nan ("") < 0.0; constexpr bool d =3D __builtin_nans ("") < 0.0; strangely accepts the < 0.0 comparisons and rejects the > 0.0 comparisons. clang++ accepts all of them. IMHO either we should accept all of them, or = just the ones not involving SNaNs, or reject all of them, it is unclear what exceptions appart from division by zero (and does that apply to floating point?) should cause constexpr evaluation to fail (I'd hope inexact excepti= on doesn't count, another question is underflow/overflow, another one is inval= id operations that from non-NaN operands create NaN, another one are operations with NaNs, another one are operations with SNaNs). Seems the reason why < 0.0 is accepted is fold_binary_loc uses tree_expr_nonnegative_warnv_p on the NaN REAL_CST which in the end uses tree_single_nonnegative_warnv_p which uses !REAL_VALUE_NEGATIVE. While NaNs have a sign in the representation, it shouldn't affect behavior = of the comparisons, so I think we should never treat NaNs with the sign bit cl= ear as non-negative.=