mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
fix issue 20937 - std.range.array of a lengthless range with indirection is not @safe
This commit is contained in:
parent
7d739d9fea
commit
c5c559343d
1 changed files with 16 additions and 2 deletions
18
std/array.d
18
std/array.d
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue