My colleague was doing some basic experiments with NaN and was puzzled by the behavior on Visual Studio that did not match his expectations. After discussion, it seems that he uncovered a probable compiler bug in MSVC 2019.
This code snippet fails to compile on MSVC, but is fine on Clang and GCC:
#include <limits>
int main()
{
static_assert(!(1 < std::numeric_limits<double>::quiet_NaN()), "compiler bug?");
}
Demo: https://godbolt.org/z/xGdqd5
Il seems that the problem concerns compile-time comparison of a constant with std::numeric_limits<double>::quiet_NaN()
, something not really useful in real life.
The comparison >
and <
is always false if quiet_NaN
is compared with a variable as expected by IEEE-754.
std::numeric_limits<double>::has_quiet_NaN == true
before, though for msvc it seems to hold – Denimfalse
for the following:std::cout << std::boolalpha << (1 < std::numeric_limits<double>::quiet_NaN()) << std::endl;
. So it looks like a bug. – Menderesfalse
. So why would it be a bug? – Mastoid/fp:strict
where, even though the Standard does not require it, Microsoft claims strict adherence. – Beaner