mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
Fix issue 24018: set length manually via runtime function. (#15354)
* Fix issue 24018: make `array.length = n` `@system` if default construction is disabled on the array type. This is needed as there is otherwise no good way to resize an array of non-constructable elements in user code at all. * Fix issue 24018: instead of calling `array.length =`, call the runtime function that implements `array.length =` instead. This skips the check for the element type being constructable, which is correct because concatenation doesn't expose unconstructed memory anyway.
This commit is contained in:
parent
a612593c4d
commit
9bf123c704
2 changed files with 26 additions and 1 deletions
10
compiler/test/compilable/issue24018.d
Normal file
10
compiler/test/compilable/issue24018.d
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
@disable this();
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
S[] s;
|
||||||
|
s = s ~ s;
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ module core.internal.array.concatenation;
|
||||||
*/
|
*/
|
||||||
Tret _d_arraycatnTX(Tret, Tarr...)(auto ref Tarr froms) @trusted
|
Tret _d_arraycatnTX(Tret, Tarr...)(auto ref Tarr froms) @trusted
|
||||||
{
|
{
|
||||||
|
import core.internal.array.capacity : _d_arraysetlengthTImpl;
|
||||||
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
|
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
|
||||||
import core.lifetime : copyEmplace;
|
import core.lifetime : copyEmplace;
|
||||||
import core.stdc.string : memcpy;
|
import core.stdc.string : memcpy;
|
||||||
|
@ -38,7 +39,21 @@ Tret _d_arraycatnTX(Tret, Tarr...)(auto ref Tarr froms) @trusted
|
||||||
|
|
||||||
if (totalLen == 0)
|
if (totalLen == 0)
|
||||||
return res;
|
return res;
|
||||||
res.length = totalLen;
|
|
||||||
|
// We cannot use this, because it refuses to work if the array type has disabled default construction.
|
||||||
|
// res.length = totalLen;
|
||||||
|
// Call the runtime function directly instead.
|
||||||
|
// TODO: once `__arrayAlloc` is templated, call that instead.
|
||||||
|
version (D_ProfileGC)
|
||||||
|
{
|
||||||
|
// TODO: forward file, line, name from _d_arraycatnTXTrace
|
||||||
|
_d_arraysetlengthTImpl!(typeof(res))._d_arraysetlengthTTrace(
|
||||||
|
__FILE__, __LINE__, "_d_arraycatnTX", res, totalLen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_d_arraysetlengthTImpl!(typeof(res))._d_arraysetlengthT(res, totalLen);
|
||||||
|
}
|
||||||
|
|
||||||
/* Currently, if both a postblit and a cpctor are defined, the postblit is
|
/* Currently, if both a postblit and a cpctor are defined, the postblit is
|
||||||
* used. If this changes, the condition below will have to be adapted.
|
* used. If this changes, the condition below will have to be adapted.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue