https://issues.dlang.org/show_bug.cgi?id=14653
--- Comment #4 from Ketmar Dark <[email protected]> --- a simplified sample: =================== import std.stdio : writeln; struct SomeRangeType { int a; alias front = a; void popFront () { ++a; } @property bool empty () { return (a >= 2); } } auto wrapit () { static struct Wrapper { SomeRangeType rng; alias rng this; @disable this (this); ~this () { writeln("wrapper dtor"); } } return Wrapper(SomeRangeType()); } void main () { writeln("before foreach"); foreach (auto e; wrapit()) { writeln("in foreach; e=", e); } writeln("after foreach"); } =================== this prints: --- before foreach wrapper dtor in foreach; e=0 in foreach; e=1 after foreach -- what i expected it to print: --- before foreach in foreach; e=0 in foreach; e=1 wrapper dtor after foreach --- --
