Probable bug in MSVC with compile-time NaN comparison

Viewed 130

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.

0 Answers
Related