Bug 14982 – nogc inconsistency

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-30T12:01:00Z
Last change time
2017-07-15T05:07:04Z
Assigned to
nobody
Creator
john.loughran.colvin

Comments

Comment #0 by john.loughran.colvin — 2015-08-30T12:01:44Z
import std.algorithm, std.range; auto foo(int[] a, immutable int b) @nogc //Fails { return a.map!(x => x + b); } auto bar(R)(R a, immutable int b) @nogc //OK { return a.map!(x => x + b); } auto baz(int[] a, immutable int b) @nogc //OK { return bar(a, b); } Foo cannot be made @nogc: Error: function nogctest.foo @nogc function allocates a closure with the GC
Comment #1 by ag0aep6g — 2015-08-30T13:43:25Z
I think this is a duplicate of issue 14771. That is, bar shouldn't compile. The delegate uses a local variable and is returned from the function, so it needs a closure. Where does that closure go if not on the GC heap?
Comment #2 by john.loughran.colvin — 2017-07-13T16:35:44Z
Seems to have been fixed at some point
Comment #3 by dlang-bugzilla — 2017-07-15T05:07:04Z
Just to confirm, by "fixed" you mean that all three now consistently fail to compile? FWIW, the change seems to have been accidental: the second and third function compiled before and don't compile after https://github.com/dlang/dmd/pull/5271.