Bug 17590 – Unnecessary GC alloc on returning static local struct
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-03T20:41:27Z
Last change time
2017-08-16T13:23:18Z
Keywords
industry
Assigned to
No Owner
Creator
johanengelen
Comments
Comment #0 by johanengelen — 2017-07-03T20:41:27Z
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.