[Issue 9270] New: Undetected ref escape of local slice

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 5 00:50:21 PST 2013


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: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 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: -------


More information about the Digitalmars-d-bugs mailing list