Escaping ref to stack mem sometimes allowed in @safe?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 14 14:14:38 PDT 2016


On 10/14/16 4:49 PM, Nick Sabalausky wrote:
> This compiles. Is it supposed to?
>
> @safe ubyte[] foo()
> {
>     ubyte[512] buf;
>     auto slice = buf[0..$];
>     // Escaping reference to stack memory, right?
>     return slice;
> }

Yes, this still is a problem, but Walter has a fix in the works.

https://issues.dlang.org/show_bug.cgi?id=8838

This one is also fun:

ubyte[512] foo();

ubyte[] x = foo(); // compiles, but never is correct. Ever.

https://issues.dlang.org/show_bug.cgi?id=12625

-Steve


More information about the Digitalmars-d-learn mailing list