www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19993] New: Reference to delegate after return statement

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 puremagic.com
          Reporter: snarwin+bugzilla 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.

--
Jun 22 2019