www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4451] New: Escaping reference to local array error for slices

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4451

           Summary: Escaping reference to local array error for slices
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



A D2 program that currently (dmd v2.047) compiles:


int[] foo() {
    int[10] stackArray;
    int[] dynArray = stackArray[1 .. 5];
    return dynArray;
}
void main() {}


In this case the compiler can give an error like:
Error: escaping reference to local arr

Like the one given with the code:

int[] foo() {
    int[10] arr;
    return arr;
}
void main() {}


Currently (dmd v2.047) even this compiles:

int[] foo() {
    int[10] arr;
    return arr[];
}
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 13 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4451


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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