https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99791
Bug ID: 99791
Summary: -Wno-system-headers hides enum range Warning
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: listnothrow at gmail dot com
Target Milestone: ---
Created attachment 50478
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50478&action=edit
glimits.h from gcc 10.2.0 (commit 99dee82307f1e163e150c9c810452979994047ce)
When setting enum values using system header defines
like LONG_MAX or ULONG_MAX gcc won't complain about them being out of range of
int,
when compiling with -Wall -Wextra -pedantic
Using -Wsystem-headers will enable the warnings.
Using -save-temps will warn for LONG_MAX but not ULONG_MAX.
The bug can not be reproduced completely using -save-temps,
(LONG_MAX doesn't get annotated as coming from a system header)
I reckon that's a bug too.
To reproduce instead, I copied glimits.h (from gcc 10.2.0 see attached)
to the system include folder.
I hope that's okay in this case.
%cat warn_enum.c
#include <glimits.h>
enum test {
warns_on_save_tmps = LONG_MAX,
doesnt_warn = ULONG_MAX
};
int main(){ return 0; }
%gcc --version
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%gcc -Wall -Wextra -pedantic warn_enum.c
%gcc -Wall -Wextra -pedantic -save-temps warn_enum.c
warn_enum.c:4:20: warning: ISO C restricts enumerator values to range of ‘int’
[-Wpedantic]
4 | warns_save_tmps = LONG_MAX,
| ^~~~~~~~~~
%gcc -Wall -Wextra -pedantic -Wsystem-headers warn_enum.c
warn_enum.c:4:21: warning: ISO C restricts enumerator values to range of ‘int’
[-Wpedantic]
4 | warns_save_tmps = LONG_MAX,
| ^~~~~~~~
In file included from warn_enum.c:1:
warn_enum.c:5:16: warning: ISO C restricts enumerator values to range of ‘int’
[-Wpedantic]
5 | doesnt_warn = ULONG_MAX
|