http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47701
Summary: separate warning to detect c99 enum constraint
violation
Product: gcc
Version: 4.4.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
C99 6.7.2.2 states:
The expression that defines the value of an enumeration constant shall be an
integer constant expression that has a value representable as an int.
Obviously, gcc has an extension that any integral value can be used, and
-pedantic can detect that this extension was utilized:
$ cat foo.c
enum { a = 0x100000001LL };
int main(void) { return a; }
$ gcc -Wall -Wextra -std=c99 -fdiagnostics-show-option foo.c -o foo
$ gcc -Wall -Wextra -std=c99 -pedantic -fdiagnostics-show-option foo.c -o foo
foo.c:1: warning: ISO C restricts enumerator values to range of ‘int’
[-pedantic]
$ ./foo; echo $?
1
However, -pedantic is a rather heavy hammer; I would love to have a dedicated
-W option, independent of -pedantic, for detecting just the issue of using an
integer constant outside the range of int, to be sure that I don't fall foul of
something like failure to compiler, or worse behavior like silent enum
truncation, on other compilers that don't implement the same extension as gcc.