From 12f046d6cb903ebc073e55c507f8b24950899a1e Mon Sep 17 00:00:00 2001 From: Sebastiaan Koppe Date: Mon, 29 Jul 2019 13:46:14 +0200 Subject: [PATCH] fix Issue 20088 - Make TempStringNoAlloc a template --- src/core/internal/string.d | 4 ++-- test/betterc/Makefile | 2 +- test/betterc/src/test20088.d | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/betterc/src/test20088.d diff --git a/src/core/internal/string.d b/src/core/internal/string.d index dc08a15e75..90fd648507 100644 --- a/src/core/internal/string.d +++ b/src/core/internal/string.d @@ -53,7 +53,7 @@ char[] unsignedToTempString()(ulong value, return scope char[] buf, uint radix = return buf[i .. $]; } -private struct TempStringNoAlloc +private struct TempStringNoAlloc() { // need to handle 65 bytes for radix of 2 with negative sign. private char[65] _buf = void; @@ -79,7 +79,7 @@ Returns: */ auto unsignedToTempString()(ulong value, uint radix = 10) @safe { - TempStringNoAlloc result = void; + TempStringNoAlloc!() result = void; result._len = unsignedToTempString(value, result._buf, radix).length & 0xff; return result; } diff --git a/test/betterc/Makefile b/test/betterc/Makefile index 01f67590d7..318a500fb0 100644 --- a/test/betterc/Makefile +++ b/test/betterc/Makefile @@ -1,6 +1,6 @@ include ../common.mak -TESTS:=test18828 test19416 test19421 test19561 +TESTS:=test18828 test19416 test19421 test19561 test20088 .PHONY: all clean all: $(addprefix $(ROOT)/,$(addsuffix ,$(TESTS))) diff --git a/test/betterc/src/test20088.d b/test/betterc/src/test20088.d new file mode 100644 index 0000000000..a809041c87 --- /dev/null +++ b/test/betterc/src/test20088.d @@ -0,0 +1,14 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20088 + +struct S { + int i; +} + +extern(C) int main() @nogc nothrow pure +{ + S[2] s = [S(1),S(2)]; + void[] v = cast(void[])s; + S[] p = cast(S[])v; // cast of void[] to S[] triggers __ArrayCast template function + return 0; +}