[Issue 14771] Hidden @nogc violation around closure creation
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 30 06:57:53 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14771
ag0aep6g at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ag0aep6g at gmail.com
--- Comment #2 from ag0aep6g at gmail.com ---
A variant is to make makeS a template instead of S.foo:
----
struct S(alias f)
{
auto foo() { return f(0); }
}
auto makeS()() @nogc
{
int x = 10;
S!(a => x) s;
return s;
}
void main() @nogc
{
auto s = makeS();
}
----
Compiles, but shouldn't.
Some change in 2.068's Phobos makes it possible to accidentally do this with
std.algorithm.map:
----
import std.algorithm: equal, map;
import std.range: only;
auto foo()(int[] a, immutable int b)
{
return a.map!(x => x + b);
}
void main() @nogc
{
int[3] test = [1,2,3];
assert(test[].foo(3).equal(only(4,5,6)));
}
----
I've seen this twice recently:
http://forum.dlang.org/post/xpdntswucmqboejhxiit@forum.dlang.org
http://forum.dlang.org/post/mrv0td$ci6$1@digitalmars.com
--
More information about the Digitalmars-d-bugs
mailing list