https://issues.dlang.org/show_bug.cgi?id=16455
--- Comment #4 from [email protected] --- (In reply to apham from comment #2) > Based on this https://dlang.org/spec/function.html#closures and the code, > the struct var is not moving anywhere and not out of scope, so it must work The NodeRange struct may be moved during construction (constructed at one location, then moved to the target location). If this happens, it invalidates the internal pointer you set up in the constructor. Returning from `children` may mean another copy/move. There are no hard rules here. The compiler has some leeway. From <https://dlang.org/spec/struct.html> (second paragraph): > A struct is defined to not have an identity; that is, the implementation is > free to make bit copies of the struct as convenient. (In reply to apham from comment #3) > need to move the setting "doPopFront = &doMove;" out of constructor to make > it work. Can move it to empty() to complete the initialization Note that any copy/move of the struct will still invalidate the pointer. And as far as I understand, the compiler may assume that the struct does not point to itself. So you may run into trouble, even when you have no explicit copy/move in your code. --
