[Issue 19993] Reference to delegate after return statement causes unnecessary closure allocation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 29 20:15:48 UTC 2019


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

--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
This also affects delegates passed as arguments to template sequence
parameters. A reference to a different, non-delegate element of the same
sequence parameter can cause a closure to be allocated, as in the following
example:

---

auto call(Args...)() {
    return Args[0]();
    pragma(msg, typeof(Args[1]));
}

@nogc void main() {
    int acc = 0;
    call!(() => acc += 1, "hello");
}

---

As before, if the pragma(msg) is moved before the return statement in `call`,
the program compiles and runs without error.

--


More information about the Digitalmars-d-bugs mailing list