[Issue 24838] @nogc lambda shouldn't allocate closure when lambda refers only to 'this'

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Oct 30 15:20:35 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24838

Richard (Rikki) Andrew Cattermole <alphaglosined at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alphaglosined at gmail.com
         Resolution|---                         |WONTFIX

--- Comment #1 from Richard (Rikki) Andrew Cattermole <alphaglosined at gmail.com> ---
This is a misunderstanding of what ``@nogc`` is.

It is a linting tool. It guarantees that no GC allocation will take place
within the function.

The reason why the compiler is not putting the closure on the stack is because
it could escape the call stack. Mark the delegate parameter in
``acceptsCallback`` as ``scope`` and this will work.

Without the escaping guarantees, using the GC is the correct solution in this
situation, and therefore should error.

--


More information about the Digitalmars-d-bugs mailing list