| Issue |
171015
|
| Summary |
[clang] `NaN != NaN` should be `false`, but is `true`
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
eisenwave
|
Clang defines `__STDC_IEC_60559_BFP__` (although incorrectly as `201404L`, 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, Clang should reject the following program, but accepts it (https://godbolt.org/z/zq1v6x5jo):
```cpp
#include <math.h>
constexpr float n = NAN;
static_assert(__STDC_IEC_60559_BFP__); // OK
static_assert(n != n); // should fail if the previous passes
```
I'm not really sure if this is fixable. Clang 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.
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123036
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs