diff --git a/std/random.d b/std/random.d index c0cf7e13b43..29a0b542013 100644 --- a/std/random.d +++ b/std/random.d @@ -2017,7 +2017,7 @@ Returns: return a `ref` to the $(D range element), otherwise it will return a copy. */ -auto ref choice(Range, RandomGen = Random)(auto ref Range range, +auto ref inout(ElementType!Range) choice(Range, RandomGen = Random)(inout auto ref Range range, ref RandomGen urng) if (isRandomAccessRange!Range && hasLength!Range && isUniformRNG!RandomGen) { @@ -2055,6 +2055,13 @@ auto ref choice(Range)(auto ref Range range) "Choice did not return a valid element from the given Range"); } +@safe unittest // issue 18631 +{ + const a = [0,1,2]; + auto r = choice(a); + auto s = choice(cast(const)[0,1,2]); +} + @safe unittest { import std.algorithm.searching : canFind;