[Issue 23031] New: importC: hex character escapes should be variable length

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 17 13:17:31 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23031

          Issue ID: 23031
           Summary: importC: hex character escapes should be variable
                    length
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: duser at neet.fi
                CC: duser at neet.fi

#include <assert.h>
_Static_assert(sizeof("\x1") == 2, ""); // Error: escape hex sequence has 1 hex
digits instead of 2
_Static_assert(sizeof("\x20") == 2, "");
_Static_assert(sizeof("\x020") == 2, ""); // fails, parsed as [0x02, '0']
_Static_assert(sizeof("\x0020") == 2, ""); // fails, parsed as [0x00, '2', '0']
int main()
{ 
        assert( "\x1"[0] == 1 ); // Error: escape hex sequence has 1 hex digits
instead of 2
        assert( "\x20"[0] == 0x20 );
        assert( "\x020"[0] == 0x20 );
        assert( "\x0020"[0] == 0x20 );
}

http://port70.net/~nsz/c/c11/n1570.html#6.4.4.4p7

> 7. Each octal or hexadecimal escape sequence is the longest sequence of characters that can constitute the escape sequence.

octal escapes are 1-3 characters, hex ones are 1-infinity
("hexadecimal-escape-sequence" in the syntax listing is recursive)

--


More information about the Digitalmars-d-bugs mailing list