Bug 2148 – Incorrect local closure detection when closure is used as local alias parameter

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-06-10T12:06:00Z
Last change time
2015-06-09T01:19:25Z
Keywords
wrong-code
Assigned to
nobody
Creator
bruno.do.medeiros+deebugz

Comments

Comment #0 by bruno.do.medeiros+deebugz — 2008-06-10T12:06:52Z
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.
Comment #1 by clugdbug — 2013-01-26T02:22:01Z
My patch for bug 1841 fixes this. *** This issue has been marked as a duplicate of issue 1841 ***