public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-97965-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97965

            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 = __builtin_nan ("") > 0.0;
constexpr bool b = __builtin_nans ("") > 0.0;
constexpr bool c = __builtin_nan ("") < 0.0;
constexpr bool d = __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 exception
doesn't count, another question is underflow/overflow, another one is invalid
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 clear
as non-negative.

             reply	other threads:[~2020-11-24 10:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 10:21 jakub at gcc dot gnu.org [this message]
2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com
2020-12-08 18:47 ` jason at gcc dot gnu.org
2020-12-08 19:02 ` jakub 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-97965-4@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: link
Be 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).