Thread overview
[Issue 22723] Cannot allocate a slice on heap
Feb 01, 2022
Temtaime
Feb 02, 2022
Basile-z
Feb 02, 2022
Basile-z
Dec 17, 2022
Iain Buclaw
February 01, 2022
https://issues.dlang.org/show_bug.cgi?id=22723

Temtaime <temtaime@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Cannot allocate a slice     |Cannot allocate a slice on
                   |                            |heap

--
February 01, 2022
https://issues.dlang.org/show_bug.cgi?id=22723

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg
           Severity|major                       |normal

--- Comment #1 from moonlightsentinel@disroot.org ---
Allocating slices by themselves is explicitly disallowed due to the ambiguitee possibilitly IIUC (you almost always want to allocate the actual array). run.dlang.io shows the degradation of the error message:

Up to      2.078.1: Failure with output: onlineapp.d(3): Error: new can only
create structs, dynamic arrays or class objects, not ubyte[]'s
2.079.1 to 2.090.1: Failure with output: onlineapp.d(3): Error: new can only
create structs, dynamic arrays or class objects, not `ubyte[]`'s
2.091.1 to 2.093.1: Failure with output: onlineapp.d(3): Error: cannot create a
`ubyte[]` with `new`
Since      2.094.1: Failure with output: onlineapp.d(3): Error: missing length
argument for array

The error message probably complain about the type + suggest adding a length (which should be the solution in most cases)

--
February 02, 2022
https://issues.dlang.org/show_bug.cgi?id=22723

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #2 from Basile-z <b2.temp@gmx.com> ---
Isn't the issue more like a request to have a way to allocate the slice payload on the heap ? Maybe a druntime template should be added for that rare usage, e.g

```
auto newHeapArray(T)()
{
    import core.memory : GC;

    alias RT = T[];
    return cast(RT*) GC.malloc(RT.sizeof, 0, typeid(T[]));
}
```

--
February 02, 2022
https://issues.dlang.org/show_bug.cgi?id=22723

--- Comment #3 from Basile-z <b2.temp@gmx.com> ---
better with calloc of course

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22723

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=22723

--- Comment #4 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18082

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--