digitalmars.D.learn - Invalid code gen with closures?
- Justin Whear (22/22) Dec 16 2011 It's not a reduced test case, but the following program seg faults:
It's not a reduced test case, but the following program seg faults:
import std.stdio,
std.algorithm,
std.range;
void main()
{
int i = 1;
auto arr = zip([0, 1, 2], ["A", "B", "C"]);
// Works fine
writeln(
filter!((a){ return a[0] > 1; })(arr)
);
// Seg faults
writeln(
filter!((a){ return a[0] > i; })(arr)
);
}
The only difference between the two delegate literals is that the second
references a variable (i) in the enclosing scope, while the first only
compares against a literal. This is leads me to suspect bad code for the
closure which is being created. Curiously, I've only been able to reproduce
this when using std.range.zip as the range to operate on.
Dec 16 2011








Justin Whear <justin economicmodeling.com>