Steven Schveighoffer wrote:
"Walter Bright" wrote
Jarrett Billingsley wrote:
So my suspicion is correct, then? That is:
scope int delegate() b;
b = { ... };
Will allocate on the heap?
Yes. The scope for delegates takes effect as a parameter storage class,
not a local variable storage class. The reason is because it is the called
function that decides what it's going to do with the delegate.
Why? It would be useful to allow local scope delegates.
The compiler can just forbid passing the delegate to a function which does
not declare its parameter as scope. I assume the compiler knows a variable
is scope since it must prevent escape of the delegate, no? So just use that
information. I thought that was the point of all this...
In order to make that work, the compiler would have to do full escape
analysis, which is a lot of work to implement.