Bug 71803 - Wpedantic: enumerator value is not an integer constant expression
Summary: Wpedantic: enumerator value is not an integer constant expression
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2016-07-07 21:23 UTC by Johan Förberg
Modified: 2016-07-07 21:55 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Johan Förberg 2016-07-07 21:23:27 UTC
This concerns GCC 6.1.1 running on Arch Linux amd64. The following code will produce a warning if compiled with -Wpedantic:

    enum { TEST = 1 << 31 };

The warning is:

    warning: enumerator value for ‘TEST’ is not an integer constant expression [-Wpedantic]

But if I instead write 

    enum { TEST = 1 << 30 };

There is no warning.

This is unforunate since e.g. the glib/gio headers contain such enums, so they will add warnings to the compile if using -Wpedantic.

I don't feel that this warning is motivated. According to the C11 standard (final draft, page 106), an integer constant expression "shall have integer type and shall only have operands that are integer constants", which by my understanding this expression satisfies.

Thanks for you attention,
Comment 1 Andrew Pinski 2016-07-07 21:55:09 UTC
1 << 31

is not a constant integral expression in C99/C90/C11 since you are overflowing the 1 to the sign bit.  If you want 1 << 31, then you can use "(int)(1u << 31)" or if you want unsigned then you can just do 1u << 31.