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