[Bug c/79479] -Woverflow false alarm in unreachable expression
eggert at gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Feb 13 19:07:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79479
--- Comment #7 from Paul Eggert <eggert at gnu dot org> ---
> the translation of a program that contains an overflowing constant expression has undefined behavior
Sure, but the programs in question do not contain constant expressions in sense
of the C standard. They contain expressions that consist entirely of constants,
which is a different thing. For example, assuming 32-bit int the following
program contains the constant expression 'INT_MAX + 1' and the C standard
requires a diagnostic for the overflow:
#include <limits.h>
int F (void) {
if (0) {
static int too_big = INT_MAX + 1;
return too_big != 0;
}
return 0;
}
In contrast, the following program is valid C code and its behavior is
well-defined because 'INT_MAX + 1' is not a constant expression (in the
C-standard sense) and it is never evaluated:
#include <limits.h>
int G (void) {
if (0) {
int too_big = INT_MAX + 1;
return too_big != 0;
}
return 0;
}
This bug report is about the latter kind of program. In practice these are
often useful programs and GCC's overflow diagnostics are false alarms.
More information about the Gcc-bugs
mailing list