From 13cf12dfda5d9564ea2f63dfbeee0f1d129af94c Mon Sep 17 00:00:00 2001 From: Jack Stouffer Date: Fri, 9 Mar 2018 14:21:06 -0500 Subject: [PATCH] Fix Issue 18166 - std.array.replace should be usable in @safe for dstrings --- std/array.d | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/std/array.d b/std/array.d index dd707de99..77d2038d3 100644 --- a/std/array.d +++ b/std/array.d @@ -2268,7 +2268,14 @@ if (isInputRange!Range && copy(stuff, retval[from .. from + stuff.length]); retval[from + stuff.length .. $] = subject[to .. $]; - return cast(T[]) retval; + static if (is(T == const) || is(T == immutable)) + { + return () @trusted { return cast(T[]) retval; } (); + } + else + { + return cast(T[]) retval; + } } else { @@ -2362,6 +2369,13 @@ if (isInputRange!Range && assert(replace(d, 5, 10, "⁴³²¹⁰"d) == "⁰¹²³⁴⁴³²¹⁰"d); } +// Issue 18166 +@safe pure unittest +{ + auto str = replace("aaaaa"d, 1, 4, "***"d); + assert(str == "a***a"); +} + /++ Replaces elements from `array` with indices ranging from `from` (inclusive) to `to` (exclusive) with the range `stuff`. Expands or