Lack of optimisation with returning address of inner functions

Jackel jackel894_394 at
Fri Sep 4 02:12:38 UTC 2020

On Friday, 4 September 2020 at 01:13:53 UTC, Cecil Ward wrote:
> For the LDC version, see

Not sure what your intention here is, but you are returning a 
delegate. You aren't actually calling it. There could be side 
effects, eg it has to create the context for the delegate. Which 
another function could access the delegate's data. So it can't 
simply optimize it out in this case.

When you actually call the function though, it does just narrow 
down to returning 25.

     auto bar() { return test2()(); }

     pure nothrow @safe int
             mov     eax, 25

More information about the Digitalmars-d mailing list