[Bug c/103123] incorrect or misleading warning "floating constant exceeds range of ..." in ISO C11 and C17

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Mon Nov 8 08:58:59 GMT 2021


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

--- Comment #4 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Andrew Pinski from comment #1)
> This is warning and can be turned off, -Woverflow is on by default.

The warning can be turned off, but there are 2 issues:

1. The message "floating constant exceeds range" is incorrect, since according
to the C standard, it doesn't. Different wording should be used, such as
"floating constant overflows", since this is the apparent behavior, where
"overflows" has the IEEE 754 meaning: the value is larger than DBL_MAX + 1/2
ulp in magnitude (0x1.fffffffffffff8p1023 triggers the warning, but
0x1.fffffffffffff7p1023 doesn't).

2. -Woverflow also enables warnings for kinds of overflows that correspond to
undefined behavior (contrary to the above one). For instance, INT_MAX + INT_MAX
triggers an "integer overflow in expression of type ‘int’ results in ‘-’
[-Woverflow]" warning. Contrary to the issue in floating point, which just
loses precision (but the behavior is well-defined), the one on integers makes a
program completely erratic, thus is much more an issue in practice. Thus one
generally wants the warning for integer overflows, but for floating-point
overflows, it depends.


More information about the Gcc-bugs mailing list