D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14982 - nogc inconsistency
Summary: nogc inconsistency
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-30 12:01 UTC by John Colvin
Modified: 2017-07-15 05:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description John Colvin 2015-08-30 12:01:44 UTC
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 ag0aep6g 2015-08-30 13:43:25 UTC
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 John Colvin 2017-07-13 16:35:44 UTC
Seems to have been fixed at some point
Comment 3 Vladimir Panteleev 2017-07-15 05:07:04 UTC
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.