On 09/02/2011 11:49 PM, Andrej Mitrovic wrote:
On 9/2/11, Vladimir Panteleev<[email protected]>  wrote:
On Fri, 02 Sep 2011 22:11:50 +0300, Andrej Mitrovic
<[email protected]>  wrote:

So maybe this type of conversion is impossible in the first place due
to how arguments are passed?

Yes. The default value is pushed on the stack at the call site.

Yeah, I should have thought more before I posted. The default value is
not "tied" to the function, the values are inserted by the compiler at
the call site, doh. :)

The solution is this:

void main()
{
    auto foo = (int x = 10){ /* */ }
    void delegate() bar = { return foo(); }
}

the compiler could in theory just automatically insert a thunk like this.

Related: I think that function pointers should implicitly decay to delegates. This would allow the compiler to optimize some delegate literals to function pointers if they don't access the outer scope, without breaking any code that wants to use such a function literal as a delegate.

Reply via email to