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

--- Comment #2 from Keith Thompson <Keith.S.Thompson at gmail dot com> ---
Andrew, did you use "-std=c17 -pedantic-errors"? Both gcc and clang
correctly diagnose "enum { toobig = 0x7fffffff * 2U + 1U };".

I'm seeing weird behavior that I don't understand. Replacing the UINT_MAX
macro by its expansion seems to change the behavior. Perhaps I'm missing
something obvious?

$ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 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.

$ cat -n c.c
     1  #include <limits.h>
     2  enum { toobig    = (0x7fffffff * 2U + 1U) };
     3  enum { toobigtoo = UINT_MAX };
$ gcc -std=c17 -pedantic-errors -c c.c
c.c:2:20: error: ISO C restricts enumerator values to range of ‘int’
[-Wpedantic]
    2 | enum { toobig    = (0x7fffffff * 2U + 1U) };
      |                    ^
$ gcc -E c.c | tail -n 6
enum { toobig = (0x7fffffff * 2U + 1U) };
enum { toobigtoo =
# 3 "c.c" 3 4
                  (0x7fffffff * 2U + 1U)
# 3 "c.c"
                           };
$

Reply via email to