[Issue 21800] Unused lambda causes unnecessary closure allocation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 10 14:02:45 UTC 2021


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

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla at gmail.com
            Summary|Unused delegate template    |Unused lambda causes
                   |parameter scope incorrectly |unnecessary closure
                   |inferred                    |allocation

--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
Simplified example:

---
void main() @nogc
{
    int x;
    void ignore() { alias F = () => x; }
}
---

Interestingly, replacing the lambda with a named function gets rid of the
closure allocation:

---
void main() @nogc
{
    int x;
    void ignore() { auto F() { return x; } }
}
---

The above workaround also works for the original example.

--


More information about the Digitalmars-d-bugs mailing list