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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
David, thanks for looking into this!  It never occurred to me that what GCC
prints is actually a string of octal numbers representing the first 7 bytes of
the wide string literal.

Either printing L"\x12345678\x00" as you suggest or even nothing (as some
compilers do) would, IMO, be better than the sequence of an odd number of octal
characters.

Here are few examples of what other compilers print:

x.C:1:19: error: cannot initialize a variable of type 'const wchar_t' with an
      lvalue of type 'const wchar_t [2]'
constexpr wchar_t s = L"\x12345678";
                  ^   ~~~~~~~~~~~~~
1 error generated.

The EDG front end:

"x.C", line 1: error: a value of type "const wchar_t *" cannot be used to
          initialize an entity of type "const wchar_t"
  constexpr wchar_t s = L"\x12345678";
                        ^

IBM XLC++ (where wchar_t is 2 bytes);
"t.C", line 1.23: 1540-0812 (W) The escape sequence "\x12345678" is out of
range. Value is truncated.
"t.C", line 1.21: 1540-0132 (S) The expression must be a constant expression.
"t.C", line 1.23: 1540-0257 (S) An object or reference of type "const wchar_t"
cannot be initialized with an expression of type "const wchar_t [2]".

Intel ICC:
t.C: error: a value of type "const wchar_t *" cannot be used to initialize an
entity of type "const wchar_t"
constexpr wchar_t c = L"\x12345678";
                      ^

Oracle CC:
"x.C", line 1: Error: Cannot use const wchar_t[2] to initialize const wchar_t.
1 Error(s) detected.

Reply via email to