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

            Bug ID: 77572
           Summary: wrong value for extended ASCII characters in
                    diagnostics
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Similar to bug 77520, when quoting string literals in diagnostics using the %qE
directive, GCC sign-extends characters with values in excess of CHAR_MAX (when
char is signed), resulting in nonsensical escape sequences such as the program
below.

In addition to correcting the %qc and %qs directives to avoid sign-extending
characters, the fix for bug 77520 also changed the base of printed characters
from octal to hexadecimal.  For consistency and better readability, a fix for
this patch should do the same (alternatively, if octal is preferred, the %qc
and %qs directives should be changed to octal).

$ cat z.C && /build/gcc-trunk-git/gcc/xgcc -B /build/gcc-trunk-git/gcc/ -S
-Wall z.C
constexpr int i = "\x0_\x01_\x7f_\x80_\xff";

z.C:1:19: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
 constexpr int i = "\x0_\x01_\x7f_\x80_\xff";
                   ^~~~~~~~~~~~~~~~~~~~~~~~~
z.C:1:19: error: ‘(int)((const
char*)"\000_\001_\177_\37777777600_\37777777777"’ is not a constant expression

Reply via email to