[Bug c/59753] New: Missing -Woverflow warning with signed constant conversion between T_MAX+1 and UT_MAX

vincent-gcc at vinc17 dot net gcc-bugzilla@gcc.gnu.org
Fri Jan 10 10:19:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59753

            Bug ID: 59753
           Summary: Missing -Woverflow warning with signed constant
                    conversion between T_MAX+1 and UT_MAX
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net

When writing "int d = some_signed_constant;", one expects a -Woverflow warning
if some_signed_constant > INT_MAX, but one actually gets a warning only if
some_signed_constant > UINT_MAX. Similarly for other types, such as char and
short.

For instance, with the following program, one expects 6 warnings, but one only
gets 2.

#include <stdio.h>
int main (void)
{
  short a = 32768;
  short b = 65535;
  short c = 65536;
  int d = 2147483648;
  int e = 4294967295;
  int f = 4294967296;
  printf ("%d %d %d %d %d %d\n", a, b, c, d, e, f);
  return 0;
}

$ gcc-snapshot tst.c -o tst
tst.c: In function 'main':
tst.c:6:3: warning: overflow in implicit constant conversion [-Woverflow]
   short c = 65536;
   ^
tst.c:9:3: warning: overflow in implicit constant conversion [-Woverflow]
   int f = 4294967296;
   ^

This occurs with:
gcc (Debian 20131201-1) 4.9.0 20131201 (experimental) [trunk revision 205573]
and older versions (4.7 and 4.8 at least).



More information about the Gcc-bugs mailing list