https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108798
Bug ID: 108798
Summary: -Woverflow fails to catch int8_t i=128;
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: divinity76 at gmail dot com
Target Milestone: ---
-Woverflow fails to catch int8_t i=128;
int8_t has a range of -128 to 127,
yet following code:
```c
#include
int main(){
int8_t i=128;
(void)i;
return 0;
}
```
compiled with:
gcc prog.c -Woverflow
does not produce any warnings. I expected something like:
prog.c:3:15: warning: overflow in conversion from 'int' to 'int8_t' {aka
'signed char'} changes value from '128' to '-128' [-Woverflow]
Interestingly, compiling it with:
gcc prog.c -Woverflow -Wpedantic
catches the error. Also, increasing it to 256 or above also catches the error.
(but anywhere from 128 to 255 is not caught without -Wpedantic, it seems)
Tested with gcc 12.1.0 (released 2022-05-06) and gcc "13.0.1 20230214
(experimental)"