Re: Escaping ref to stack mem sometimes allowed in @safe?
On Friday, October 14, 2016 16:49:44 Nick Sabalausky via Digitalmars-d-learn 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; > } > > Or is the escaping reference detection not intended to be 100%? Or > something else I'm missing? > > Should I file @ bugzilla? It's a long-standing bug: https://issues.dlang.org/show_bug.cgi?id=8838 But Walter has been working on @safety issues recently (particularly with regards to stuff like parameters escaping, because of DIP1000), so a fix should finally be coming. - Jonathan M Davis
Re: Escaping ref to stack mem sometimes allowed in @safe?
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
Escaping ref to stack mem sometimes allowed in @safe?
This compiles. Is it supposed to? @safe ubyte[] foo() { ubyte[512] buf; auto slice = buf[0..$]; // Escaping reference to stack memory, right? return slice; } Or is the escaping reference detection not intended to be 100%? Or something else I'm missing? Should I file @ bugzilla?