www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2148] New: Incorrect local closure detection when closure is used as local alias parameter

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

           Summary: Incorrect local closure detection when closure is used
                    as local alias parameter
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: brunodomedeiros+bugz gmail.com


Check the following code:
---   ---
import std.stdio;

template foo(alias magicFn) {
        int foo() {
                return magicFn();
        }
}


int delegate() myfunc()
{
        int num = 2;
        int nestedFunc() { return num; };

        //return &nestedFunc; 
        return &foo!(nestedFunc);
}


void main(string[] args) {
        auto dg = myfunc();
        writeln("Dg result:", dg()); // prints garbage
}
---- ----
Running this will print garbage, because the compiler thinks nestedFunc is a
local closure (a closure that does not escape the enclosing scope), and thus
will not allocate num on the heap.


-- 
Jun 10 2008
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2148


Don <clugdbug yahoo.com.au> changed:

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



My patch for bug 1841 fixes this.

*** This issue has been marked as a duplicate of issue 1841 ***

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