Lack of optimisation with returning address of inner functions

Jackel jackel894_394 at gmail.com
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 https://d.godbolt.org/z/x4rhbe

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.

https://d.godbolt.org/z/6f87aT

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

     pure nothrow @safe int example.bar():
             mov     eax, 25
             ret




More information about the Digitalmars-d mailing list