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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jun 22 12:12:38 UTC 2019


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

          Issue ID: 19993
           Summary: Reference to delegate after return statement causes
                    unnecessary closure allocation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

auto call(alias dg)() {
    return dg();
    pragma(msg, typeof(dg));
}

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

---

The program above fails to compile with the following error:

Error: function `D main` is @nogc yet allocates closures with the GC

However, if the pragma(msg) is moved before the return statement in `call`,
there is no error.

--


More information about the Digitalmars-d-bugs mailing list