[Issue 17800] [2.076] "static foreach" allocates closures in GC without reason
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 4 08:56:35 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=17800
timon.gehr at gmx.ch changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |timon.gehr at gmx.ch
--- Comment #2 from timon.gehr at gmx.ch ---
The closure allocation error is not a bug in the `static foreach`
implementation. Reduced test case:
---
struct S{
enum N=1;
}
void foo(S v) @nogc{
enum x=()=>v.N;
}
---
Workaround:
---
int foo(S v)@nogc{
enum x=typeof(v).N;
}
---
The second case is due to an oversight on my side.
It can be worked around using an alias:
struct S{
enum N = 1;
}
S foo(S v)@nogc{
alias R=typeof(return);
static foreach(_;0..R.N){ }
return S.init;
}
--
More information about the Digitalmars-d-bugs
mailing list