www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9270] New: Undetected ref escape of local slice

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs 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: -------
Jan 05 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9270


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE


--- Comment #1 from yebblies <yebblies gmail.com> 2013-01-07 13:45:08 EST ---
*** This issue has been marked as a duplicate of issue 2486 ***

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