https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98829
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is likely GCC canonicalizing the NaN somewhere and your is_value
doing a 1:1 bit comparison. In particular we optimize MyNAN::value to
MyNAN::value ()
{
<bb 2> [local count: 1073741824]:
return Nan;
but ::is_value is
MyNAN::is_value (double d)
{
long unsigned int _2;
bool _3;
<bb 2> [local count: 1073741824]:
_2 = VIEW_CONVERT_EXPR<long unsigned int>(d_1(D));
_3 = _2 == 9218868437227407042;
return _3;
MyNAN::value is optimized by CSE via native_encode/interpret.
I'm not sure why -O2 vs. -O3 makes a difference in the end but I think
your program is ill-formed.