public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency
@ 2020-11-24 10:21 jakub at gcc dot gnu.org
  2020-11-24 21:39 ` [Bug c++/97965] " joseph at codesourcery dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-11-24 10:21 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-08 19:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 10:21 [Bug c++/97965] New: constexpr evaluation vs. NaNs inconsistency jakub at gcc dot gnu.org
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

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).