[Bug c/68193] New: _Generic -Woverflow false alarm

eggert at gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Nov 2 23:46:00 GMT 2015


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

            Bug ID: 68193
           Summary: _Generic -Woverflow false alarm
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at gnu dot org
  Target Milestone: ---

I ran into this problem when developing Gnulib code.  This is with GCC 5.2.0 on
x86-64.  Compile the following program t.c with 'gcc -Wall t.c':

int
main (void)
{
  int i = 0;
  int j = _Generic (i,
                    int: 0,
                    long int: (i = (long int) 9223372036854775808UL));
  return i + j;
}

GCC generates the bogus warning:

t.c: In function 'main':
t.c:7:22: warning: overflow in implicit constant conversion [-Woverflow]
       long int: (i = (long int) 9223372036854775808UL));
                      ^

The warning is bogus because the corresponding expression is not evaluated, as
per the semantics of _Generic.

Add 1 to that big constant, changing it to 9223372036854775809UL, and the bogus
warning goes away.  So it's possible that there are two bugs here, one having
to do with bogus warnings in unevaluated _Generic subexpressions, the other
having to do with (unsigned long) LONG_MIN.


More information about the Gcc-bugs mailing list