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: [email protected]
          Reporter: [email protected]

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.

--

Reply via email to