https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82296
Thomas Koenig <tkoenig at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-09-22
CC| |tkoenig at gcc dot gnu.org
Ever confirmed|0 |1
Severity|normal |enhancement
--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
You have...
#define ARRAYSIZE 5
union {
int numbers[ARRAYSIZE];
int dummy[ARRAYSIZE+1];
} gMyUnion;
and then
if (gMyUnion.numbers[i] > 5)
return 1;
if (i == ARRAYSIZE)
fatal_error();
i++;
The compiler is assuming that you never exceed the
bounds of gMyUnion.numbers. Threfore, i can never be 5,
and the call to fatal_error can never happen.
Change .numbers to .dummy, or move the check for i
before the other statement, and the change will not happen.
Is the compiler right to do so? Yes.
Should it warn if asked? IMHO yes (and it doesn't appear
to do so).
Confirmed as an enhancement request.