[Bug c/105156] New: No diagnostic for `enum { toobig = UINT_MAX }`

Keith.S.Thompson at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Apr 4 21:50:14 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105156

            Bug ID: 105156
           Summary: No diagnostic for `enum { toobig = UINT_MAX }`
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Keith.S.Thompson at gmail dot com
  Target Milestone: ---

Source file:
```
#include <limits.h>
enum { toobig = UINT_MAX };
```

gcc version 11.2.0 on Ubuntu 20.04.4, x86_64

INT_MAX is 2147483647
UINT_MAX is 4294967295

The C11 and C17 standards both have the following constraint in 6.7.2.2:

> The expression that defines the value of an enumeration constant shall
> be an integer constant expression that has a value representable as an int.

"gcc -std=c17 -pedantic-errors -c c.c" does not produce a diagnostic for the
above source file.

If I replace UINT_MAX by 4294967295 I get a correct diagnostic:
c.c:3:18: error: ISO C restricts enumerator values to range of ‘int’
[-Wpedantic]
    3 | enum { toobig2 = 4294967295 };
      |     

"gcc -E" indicates that the macro UINT_MAX expands to (0x7fffffff * 2U + 1U)


More information about the Gcc-bugs mailing list