On Wednesday, 30 October 2013 at 07:49:48 UTC, Jacob Carlborg
wrote:
On 2013-10-29 22:57, Ali Çehreli wrote:
Imagine someone decides to return a lambda from foo() instead:
auto foo()
{
S s = S(1);
return {}; // <-- Should 's' be immortal now?
}
Too subtle for my taste! :)
Of course not. "s" is never referred to in the returned
delegate.
Yes, only variables actually referenced by a nested fiction are
placed in the nested context.
I agree that the fact that an object's destructor is not run at
the end of the parent function should ideally be more easily
visible, but given the inherently implicit nature of D's
closures, I'm not sure we can do much about that.
David