diff --git a/std/array.d b/std/array.d index 494fa297b4b..e7dada5e6f4 100644 --- a/std/array.d +++ b/std/array.d @@ -650,6 +650,7 @@ if (isInputRange!Values && isInputRange!Keys) alias ValueElement = ElementType!Values; static if (hasElaborateDestructor!ValueElement) ValueElement.init.__xdtor(); + cast(void) values.front; }))) { () @trusted { @@ -790,6 +791,20 @@ if (isInputRange!Values && isInputRange!Keys) assert(assocArray(1.iota, [UnsafeElement()]) == [0: UnsafeElement()]); } +@safe unittest +{ + struct ValueRange + { + string front () const @system { int* ptr = cast(int*)42; *ptr = 42; return null; } + @safe: + void popFront() {} + bool empty() const { return false; } + } + int[] keys; + ValueRange values; + static assert(!__traits(compiles, assocArray(keys, values))); +} + /** Construct a range iterating over an associative array by key/value tuples.