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

            Bug ID: 80731
           Summary: poor -Woverflow warnings, missing detail
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

For the program below GCC emits three -Woverflow warnings, each slightly
differently worded, and each lacking in interesting or relevant detail.  The
second warning is also inaccurate (the integer is truncated, but because it's
unsigned to begin with, it's unclear to what unsigned type it is converted).

$ cat t.c && gcc -O2 -S -Wall t.c
enum { X = 123456789 };

char c = X;

enum __attribute__ ((packed)) E { e3 = 3 };

enum E e = X;

void f (void)
{
  switch (0)
  case X * X: ;
}
t.c:3:10: warning: overflow in implicit constant conversion [-Woverflow]
 char c = X;
          ^
t.c:7:12: warning: large integer implicitly truncated to unsigned type
[-Woverflow]
 enum E e = X;
            ^
t.c: In function ‘f’:
t.c:12:10: warning: integer overflow in expression [-Woverflow]
   case X * X: ;
          ^


The warnings would be more useful if they included additional detail, such as
the type and value of the expressions.  For example, consider Clang output:

t.c:3:10: warning: implicit conversion from 'int' to 'char' changes value from
      123456789 to 21 [-Wconstant-conversion]
char c = X;
     ~   ^
t.c:7:12: warning: implicit conversion from 'int' to 'enum E' changes value
from
      123456789 to 21 [-Wconstant-conversion]
enum E e = X;
       ~   ^
t.c:12:10: warning: overflow in expression; result is -1757895751 with type
      'int' [-Winteger-overflow]
  case X * X: ;
         ^
t.c:11:11: warning: no case matching constant switch condition '0'
  switch (0)
          ^
4 warnings generated.

Reply via email to