www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17590] New: Unnecessary GC alloc on returning static local


          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 puremagic.com
          Reporter: johanengelen weka.io

The following code does not compile:

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

    SInside res;


    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.

Jul 03 2017