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

            Bug ID: 87585
           Summary: Improve diagnostics message of -Woverflow
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: msebor at gcc dot gnu.org
  Target Milestone: ---

As of r248431 Martin improved the warning and now I can see:

$  cat char.C
int main(int argc, char **argv)
{
  char c = -160;
}

$ gcc char.C 
char.C: In function ‘int main(int, char**)’:
char.C:3:13: warning: overflow in conversion from ‘int’ to ‘char’ changes value
from ‘-160’ to ‘'`'’ [-Woverflow]
   char c = -160;
             ^~~

which is a parade of apostrophes :)

C FE does better:

gcc -x c char.C 
char.C: In function ‘main’:
char.C:3:12: warning: overflow in conversion from ‘int’ to ‘char’ changes value
from ‘-160’ to ‘96’ [-Woverflow]
   char c = -160;
            ^

And please note difference in underlined pointer. IMHO we should ideally do
what clang does:

$ clang char.C 
char.C:3:12: warning: implicit conversion from 'int' to 'char' changes value
from -160 to 96 [-Wconstant-conversion]
  char c = -160;
       ~   ^~~~

Reply via email to