Fix endian issue when printing hex string literals

This commit is contained in:
Dennis Korpel 2024-03-15 11:15:07 +01:00 committed by The Dlang Bot
parent 2a7a9c459a
commit 55dcc3dc82
3 changed files with 5 additions and 4 deletions

View file

@ -2281,7 +2281,8 @@ private void expressionPrettyPrint(Expression e, ref OutBuffer buf, ref HdrGenSt
{ {
buf.writeByte('x'); buf.writeByte('x');
buf.writeByte('"'); buf.writeByte('"');
buf.writeHexString(e.peekData, true); foreach (i; 0 .. e.len)
buf.printf("%0*llX", e.sz, e.getIndex(i));
buf.writeByte('"'); buf.writeByte('"');
if (e.postfix) if (e.postfix)
buf.writeByte(e.postfix); buf.writeByte(e.postfix);

View file

@ -12,8 +12,8 @@ fail_compilation/hexstring.d(38): Error: array cast from `string` to `immutable(
fail_compilation/hexstring.d(39): Error: array cast from `string` to `immutable(uint[])` is not supported at compile time fail_compilation/hexstring.d(39): Error: array cast from `string` to `immutable(uint[])` is not supported at compile time
fail_compilation/hexstring.d(39): perhaps remove postfix `c` from hex string fail_compilation/hexstring.d(39): perhaps remove postfix `c` from hex string
fail_compilation/hexstring.d(40): Error: hex string with `dstring` type needs to be multiple of 4 bytes, not 5 fail_compilation/hexstring.d(40): Error: hex string with `dstring` type needs to be multiple of 4 bytes, not 5
fail_compilation/hexstring.d(41): Error: cannot implicitly convert expression `x"44332211"d` of type `dstring` to `immutable(float[])` fail_compilation/hexstring.d(41): Error: cannot implicitly convert expression `x"11223344"d` of type `dstring` to `immutable(float[])`
fail_compilation/hexstring.d(42): Error: cannot implicitly convert expression `x"2211"w` of type `wstring` to `immutable(ubyte[])` fail_compilation/hexstring.d(42): Error: cannot implicitly convert expression `x"1122"w` of type `wstring` to `immutable(ubyte[])`
fail_compilation/hexstring.d(28): Error: cannot implicitly convert expression `x"123F"` of type `string` to `ubyte[]` fail_compilation/hexstring.d(28): Error: cannot implicitly convert expression `x"123F"` of type `string` to `ubyte[]`
--- ---
*/ */

View file

@ -263,7 +263,7 @@ void testHexstring()
// Test printing StringExp with size 8 // Test printing StringExp with size 8
enum toStr(immutable ulong[] v) = v.stringof; enum toStr(immutable ulong[] v) = v.stringof;
static assert(toStr!y == `x"88776655443322119900FFEEDDCCBBAA"`); static assert(toStr!y == `x"1122334455667788AABBCCDDEEFF0099"`);
// Hex string postfixes // Hex string postfixes
// https://issues.dlang.org/show_bug.cgi?id=24363 // https://issues.dlang.org/show_bug.cgi?id=24363