digitalmars.D.learn - Escaping ref to stack mem sometimes allowed in safe?
- Nick Sabalausky (11/11) Oct 14 2016 This compiles. Is it supposed to?
- Steven Schveighoffer (8/16) Oct 14 2016 Yes, this still is a problem, but Walter has a fix in the works.
- Jonathan M Davis via Digitalmars-d-learn (8/19) Oct 17 2016 It's a long-standing bug:
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?
Oct 14 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
Oct 14 2016
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
Oct 17 2016