I tried something like this: foreach(e; scoped!SomeRangeType(args)) { } And my program segment faults. But this works: { auto x = scoped!SomeRangeType(args); foreach(e; x) { } } Shouldn't the range be alive until the end of the loop?