Invalid code gen with closures?

Justin Whear justin at
Fri Dec 16 14:00:35 PST 2011

It's not a reduced test case, but the following program seg faults:

import std.stdio,

void main()
 	int i = 1;
	auto arr = zip([0, 1, 2], ["A", "B", "C"]);

	// Works fine
		filter!((a){ return a[0] > 1; })(arr)

	// Seg faults
		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 as the range to operate on.

More information about the Digitalmars-d-learn mailing list