module structfail; auto get(alias fun)() { struct Foo { size_t data; @property auto clone() { return Foo(data); } } return Foo(0); } void main() { uint a = 42; auto bar = get!(() => a)(); auto qux = bar.clone; import std.stdio; writeln("bar context pointer :", (cast(void**) &bar)[1]); writeln("qux context pointer :", (cast(void**) &qux)[1]); } qux have a garbage context pointer.
Apparently this is a the same bug, see http://forum.dlang.org/post/crhogpikareipbtyswhu@forum.dlang.org import std.stdio; struct MapResult(alias fun) { @property int front() {return fun();} @property auto save() {return typeof(this)();} } void main() { int ys_length = 4; auto dg = {return MapResult!({return ys_length;})();}; writeln(dg().front); /* 4, correct */ writeln(dg().save.front); /* garbage */ }
This doesn't happen with ldc 0.15.1 Observed in dmd git HEAD, 2.066.1 and 2.065.0
https://github.com/D-Programming-Language/dmd/pull/4418
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7c7f173611f827572ce783e8941ea8e10aae58f4 fix Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias https://github.com/D-Programming-Language/dmd/commit/e99cc05b0e61272d0d88759452d6887669555100 Merge pull request #4418 from 9rnsr/fix9685 Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias
Commits pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7c7f173611f827572ce783e8941ea8e10aae58f4 fix Issue 9685 - Context pointer of struct isn't copied when a closure is passed by alias https://github.com/D-Programming-Language/dmd/commit/e99cc05b0e61272d0d88759452d6887669555100 Merge pull request #4418 from 9rnsr/fix9685
*** Issue 10963 has been marked as a duplicate of this issue. ***