Comment #0 by bearophile_hugs — 2013-01-05T00:50:19Z
(This is a borderline enhancement request.)
ref int[] foo() {
static int[5] data;
return data[0 .. 4];
}
void main() {
import std.stdio;
writeln(foo().length);
}
This program compiles with no errors or warnings (dmd 2.061), but it's wrong code, because the data slice local to foo() gets lost when the stack frame of foo() is popped out of the stack. Compiling that program with "-O" prints something like:
1635172
So in this case I suggest to generate a escape local variable error at compile time.
Comment #1 by yebblies — 2013-01-06T18:45:08Z
*** This issue has been marked as a duplicate of issue 2486 ***