www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6111] New: Escaping reference to local variable not detected

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bugzilla digitalmars.com



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: -------
Jun 05 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6111




15:57:49 PDT ---
Reduced test case:

import std.c.stdio;

auto mymap()
{
    int x = 42;
    int fun(int a) { return x + a; }

    auto map()(int r)
    {
        struct Result
        {
            int _input;

            int back()
        {
        return fun(_input);
        }

            this(int input)
            {
                _input = input;
            }
        }

        return Result(r);
    }

    return map(1);
} 

void main()
{
    printf("%d\n", mymap().back());
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6111


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



17:23:56 PDT ---
https://github.com/D-Programming-Language/dmd/commit/20510a31133327d768ae5335c5fbfc3e611a1213

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