www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22776] New: string literal printing fails on


          Issue ID: 22776
           Summary: string literal printing fails on
                    non-ASCII/non-printable chars
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

When dmd prints a string literal in an error message it doesn't handle
non-trivial cases properly:
"before \0 after";

Error: declaration expected, not `"before "`
Error: declaration expected, not `"\x0a"`

It truncates at zero bytes and uses \x00 codes for everything non-printable,
even when there are more readable escape sequences available (most commonly \n
for \x0A).

non-ASCII code units in wstrings and dstrings also get messed up in semantic

pragma(msg, "\u1234"w.stringof); // "\x34\x12"w
pragma(msg, "\u1234"d.stringof); // "\x34\x12"d

The lexer handles these correctly by emitting \u sequences instead of \x

Feb 15 2022