http://d.puremagic.com/issues/show_bug.cgi?id=9270

           Summary: Undetected ref escape of local slice
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from [email protected] 2013-01-05 00:50:19 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to