Bug 9685 – Context pointer of struct isn't copied when a closure is passed by alias

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-10T22:43:00Z
Last change time
2015-03-25T03:45:37Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
deadalnix

Comments

Comment #0 by deadalnix — 2013-03-10T22:43:49Z
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.
Comment #1 by john.loughran.colvin — 2015-02-16T14:52:59Z
Apparently this is a the same bug, see http://forum.dlang.org/post/[email protected] 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 */ }
Comment #2 by john.loughran.colvin — 2015-02-16T15:02:11Z
This doesn't happen with ldc 0.15.1 Observed in dmd git HEAD, 2.066.1 and 2.065.0
Comment #3 by k.hara.pg — 2015-02-17T15:08:51Z
Comment #4 by github-bugzilla — 2015-02-18T02:29:09Z
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
Comment #5 by github-bugzilla — 2015-02-21T09:11:42Z
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
Comment #6 by k.hara.pg — 2015-03-25T03:45:37Z
*** Issue 10963 has been marked as a duplicate of this issue. ***