Thread overview
[Issue 15195] DIP25: Member functions can leak local variables
Oct 12, 2015
timon.gehr@gmx.ch
Oct 21, 2015
Walter Bright
Oct 21, 2015
timon.gehr@gmx.ch
October 12, 2015
https://issues.dlang.org/show_bug.cgi?id=15195

--- Comment #1 from timon.gehr@gmx.ch ---
The compiler actually allocates a closure (so unlike the other DIP25 bug reports, there is no memory corruption here.)

I'm not sure what the intended behaviour is.
The closure is allocated even in the following case:

void foo()@nogc{
    int x;
    struct S{ int bar()@nogc{ return x; } }
    S s;
}

Error: function foo @nogc function allocates a closure with the GC

--
October 21, 2015
https://issues.dlang.org/show_bug.cgi?id=15195

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |performance
                 CC|                            |bugzilla@digitalmars.com
           Severity|normal                      |enhancement

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
Passing the address of a local variable to a nested function causes a closure to be allocated. It's working as designed, though the analysis is unsophisticated and could potentially be improved, so marked as an enhancement request.

--
October 21, 2015
https://issues.dlang.org/show_bug.cgi?id=15195

timon.gehr@gmx.ch changed:

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

--- Comment #3 from timon.gehr@gmx.ch ---
(In reply to Walter Bright from comment #2)
> Passing the address of a local variable to a nested function causes a closure to be allocated. It's working as designed, though the analysis is unsophisticated and could potentially be improved, so marked as an enhancement request.

I have opened https://issues.dlang.org/show_bug.cgi?id=15232.

I'm closing this issue.

--