From 2c25f354b2782471bc1b0c5e2ebb0be5c2d9fd48 Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Tue, 26 Nov 2024 23:24:38 +0100 Subject: [PATCH 1/2] Update `hasToString` for `-preview=rvaluerefparam` --- std/format/internal/write.d | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/std/format/internal/write.d b/std/format/internal/write.d index 8b60565d8a1..6fd468d315e 100644 --- a/std/format/internal/write.d +++ b/std/format/internal/write.d @@ -1839,24 +1839,26 @@ template hasToString(T, Char) else static if (is(typeof( (T val) { const FormatSpec!Char f; - static struct S {void put(scope Char s){}} + static struct S + { + @disable this(this); + void put(scope Char s){} + } S s; val.toString(s, f); - static assert(!__traits(compiles, val.toString(s, FormatSpec!Char())), - "force toString to take parameters by ref"); - static assert(!__traits(compiles, val.toString(S(), f)), - "force toString to take parameters by ref"); }))) { enum hasToString = HasToStringResult.customPutWriterFormatSpec; } else static if (is(typeof( (T val) { - static struct S {void put(scope Char s){}} + static struct S + { + @disable this(this); + void put(scope Char s){} + } S s; val.toString(s); - static assert(!__traits(compiles, val.toString(S())), - "force toString to take parameters by ref"); }))) { enum hasToString = HasToStringResult.customPutWriter; @@ -1996,9 +1998,10 @@ template hasToString(T, Char) static assert(hasToString!(G, char) == customPutWriter); static assert(hasToString!(H, char) == customPutWriterFormatSpec); static assert(hasToString!(I, char) == customPutWriterFormatSpec); - static assert(hasToString!(J, char) == hasSomeToString); + static assert(hasToString!(J, char) == hasSomeToString + || hasToString!(J, char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam static assert(hasToString!(K, char) == constCharSinkFormatSpec); - static assert(hasToString!(L, char) == none); + static assert(hasToString!(L, char) == customPutWriterFormatSpec); static if (hasPreviewIn) { static assert(hasToString!(M, char) == inCharSinkFormatSpec); @@ -2105,9 +2108,10 @@ template hasToString(T, Char) static assert(hasToString!(G, char) == customPutWriter); static assert(hasToString!(H, char) == customPutWriterFormatSpec); static assert(hasToString!(I, char) == customPutWriterFormatSpec); - static assert(hasToString!(J, char) == hasSomeToString); + static assert(hasToString!(J, char) == hasSomeToString + || hasToString!(J, char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam static assert(hasToString!(K, char) == constCharSinkFormatSpec); - static assert(hasToString!(L, char) == none); + static assert(hasToString!(L, char) == HasToStringResult.customPutWriterFormatSpec); static if (hasPreviewIn) { static assert(hasToString!(M, char) == inCharSinkFormatSpec); @@ -2125,9 +2129,10 @@ template hasToString(T, Char) static assert(hasToString!(inout(G), char) == customPutWriter); static assert(hasToString!(inout(H), char) == customPutWriterFormatSpec); static assert(hasToString!(inout(I), char) == customPutWriterFormatSpec); - static assert(hasToString!(inout(J), char) == hasSomeToString); + static assert(hasToString!(inout(J), char) == hasSomeToString + || hasToString!(inout(J), char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam static assert(hasToString!(inout(K), char) == constCharSinkFormatSpec); - static assert(hasToString!(inout(L), char) == none); + static assert(hasToString!(inout(L), char) == customPutWriterFormatSpec); static if (hasPreviewIn) { static assert(hasToString!(inout(M), char) == inCharSinkFormatSpec); From bf0ec5a3967c7b0f98b53c961569eb363c9ac43b Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Tue, 26 Nov 2024 23:31:05 +0100 Subject: [PATCH 2/2] Remove ref parameter test of parse() --- std/conv.d | 3 --- 1 file changed, 3 deletions(-) diff --git a/std/conv.d b/std/conv.d index b0ca90757d6..5e0165cb609 100644 --- a/std/conv.d +++ b/std/conv.d @@ -2560,9 +2560,6 @@ Lerr: string s1 = "123"; auto a1 = parse!(int, string, Yes.doCount)(s1); assert(a1.data == 123 && a1.count == 3); - - // parse only accepts lvalues - static assert(!__traits(compiles, parse!int("123"))); } ///