Reduced code: ------ import std.stdio; class Wrapper { typeof(stdin.byLine()) src; } void main() { auto x = new Wrapper(); x.src = stdin.byLine(); } ------ Compiled with git HEAD, upon program exit, the following error is triggered: ------ core.exception.InvalidMemoryOperationError@src/core/exception.d(693): Invalid memory operation ------ Commenting out the second line in main() makes the problem go away. Works with older releases of dmd toolchain.
See also issue 15821. It's very similar which suggests that there's a dmd/druntime bug beneath.
It boils down to this: ---- alias T = void*; struct RefCounted { T* _store; this(int dummy) { import core.memory : GC; import core.stdc.stdlib : malloc; _store = cast(T*)malloc(T.sizeof); GC.addRange(&_store, T.sizeof); } ~this() { assert(_store !is null); import core.memory : GC; GC.removeRange(&_store); } } void main() { auto a = new RefCounted(0); } ---- I don't know if there's anything wrong with this usage of GC.addRange/GC.removeRange. If there is, this is a bug in std.typecons.RefCounted. If there's not, it's a druntime/dmd issue.
*** This issue has been marked as a duplicate of issue 15822 ***