https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102427
Bug ID: 102427
Summary: -Woverflow only works in constant expressions
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: david at westcontrol dot com
Target Milestone: ---
The "-Woverflow" warning only works with constant expressions. Should it not
also work in cases where the compiler knows the value at compile time, even if
it is not a constant expression?
int foo(void) {
const int a = 534567891;
int b = a * 6;
return b;
}
(With gcc -O2 -Wall -Wextra)
When "a" is declared "const", the compiler warns about the overflow. If the
"const" is removed, the compiler still does the same calculations at compile
time, but does not give a warning even though it knows there was a signed
integer overflow.
Could "-Woverflow" be changed to warn here, when there is clearly undefined
behaviour?