digitalmars.D.bugs - [Issue 18827] New: scope delegate literal allocates GC closure
- d-bugmail puremagic.com (38/38) May 04 2018 https://issues.dlang.org/show_bug.cgi?id=18827
https://issues.dlang.org/show_bug.cgi?id=18827 Issue ID: 18827 Summary: scope delegate literal allocates GC closure Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: major Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: code dawg.eu cat > bug.d << CODE int func(int delegate(int) dg) { return dg(2); } int templ(alias dg)() { return dg(2); } void bar() { int a = 3; scope dg = (int x) => x * a; func(dg); // does not allocate closure, GOOD templ!((int x) scope => x * a)(); // does not allocate closure, GOOD func((int x) scope => x * a); // does allocate closure, BAD } CODE Passing a delegate literal with scoped context should never allocate a closure, but it does when the delegate is being passed by value. With DIP1000 escaping of the context within the delegate should be statically forbidden, right now it depends on programming correctness. Still an explicit scope should disable allocations anyhow, though prolly mark the delegates as unsafe. --
May 04 2018