fix issue 20937 - std.range.array of a lengthless range with indirection is not @safe

This commit is contained in:
Ate Eskola 2021-08-17 22:47:39 +03:00
parent 7d739d9fea
commit c5c559343d

View file

@ -259,6 +259,19 @@ if (isPointer!Range && isIterable!(PointerTarget!Range) && !isAutodecodableStrin
)));
}
// https://issues.dlang.org/show_bug.cgi?id=20937
@safe pure nothrow unittest
{
struct S {int* x;}
struct R
{
immutable(S) front;
bool empty;
@safe pure nothrow void popFront(){empty = true;}
}
R().array;
}
/**
Convert a narrow autodecoding string to an array type that fully supports
random access. This is handled as a special case and always returns an array
@ -3492,13 +3505,14 @@ if (isDynamicArray!A)
}
else
{
import core.internal.lifetime : emplaceRef;
import core.lifetime : emplace;
ensureAddable(1);
immutable len = _data.arr.length;
auto bigData = (() @trusted => _data.arr.ptr[0 .. len + 1])();
emplaceRef!(Unqual!T)(bigData[len], cast() item);
auto itemUnqual = (() @trusted => & cast() item)();
emplace(&bigData[len], *itemUnqual);
//We do this at the end, in case of exceptions
_data.arr = bigData;
}