[Issue 6111] New: Escaping reference to local variable not detected

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 5 19:49:50 PDT 2011


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

           Summary: Escaping reference to local variable not detected
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bugzilla at digitalmars.com


--- Comment #0 from Walter Bright <bugzilla at digitalmars.com> 2011-06-05 19:45:21 PDT ---
import std.algorithm, std.stdio;

auto mymap()
{
    int x = 42;
    int fun(int a) { return x + a; }
    return map!fun([1, 2, 3, 4, 5]);
}

void main()
{
    writeln(mymap());
}

This should print [43, 44, 45, 46, 47], but prints garbage because x should be
allocated on the heap rather than the stack. The compiler needs to be better at
detecting local escapes.

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