[Issue 5541] New: Disallow escaping of references to stack-allocated memory

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 7 13:07:51 PST 2011


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

           Summary: Disallow escaping of references to stack-allocated
                    memory
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2011-02-07 13:05:29 PST ---
This is D2 code:


struct Foo {
    int x;
}
Foo* bar() {
    Foo f = Foo(1);
    return &f;
}
void main() {}


DMD 2.051 raises a compile-time error:
test.d(6): Error: escaping reference to local f


But this code compiles and runs with no errors with DMD 2.051. I think DMD has
to statically disallow code like this too:


struct Foo {
    int x;
}
Foo* bar() {
    return &(Foo(1));
}
void main() {}

-- 
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