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

            Bug ID: 123036
           Summary: NaN != NaN should be true, but fails
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

GCC defines __STDC_IEC_60559_BFP__ (although incorrectly as 1, not as 202311L),
so I assume this is meant to indicate conformance with Annex F.

N3220 Table F.2: Operation binding shows that the ISO/IEC 60559 operation
"compareQuietNotEqual" is mapped to "!=". "compareQuietNotEqual" is simply the
negation of "compareQuietEqual" (see ISO/IEC 60559:2020 Table 5.1), not a
separate comparison. The relation is true for operands that are in an unordered
relationship, like NaNs.

Therefore, GCC should reject the following program, but accepts it
(https://godbolt.org/z/Y9M3o37Yr):

    #include <math.h>
    constexpr float n = NAN;
    static_assert(__STDC_IEC_60559_BFP__); // OK
    static_assert(n != n);                 // should pass if the previous
passes

I'm not really sure if this is fixable. GCC has implemented the
non-60559-compliant "NaN comparisons are always false" behavior for so long, it
seems implausible to just change the result of the comparison now. Pretty sure
that comparing "x != x" is a C idiom for detecting NaNs.

Maybe __STDC_IEC_60559_BFP__ should not be defined then, or only defined if the
user provides a flag, or idk.

Reply via email to