[Issue 17590] New: Unnecessary GC alloc on returning static local struct

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jul 3 13:41:27 PDT 2017


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

          Issue ID: 17590
           Summary: Unnecessary GC alloc on returning static local struct
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johanengelen at weka.io

The following code does not compile:

```
auto foo(int a, bool b) @nogc {
    static struct SInside {}

    SInside res;

    lazyfun(a);

    return res;
}


void lazyfun(scope lazy int a) @nogc;
```

Because the return type is a local struct, the frontend thinks a GC allocated
closure is needed. But, the local struct is static, so no reference to the
local frame and a closure is not needed.

--


More information about the Digitalmars-d-bugs mailing list