Question of delegate literals and return from function(GDC,DMD,LDC)

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Jan 31 15:16:28 PST 2009


On Sat, Jan 31, 2009 at 5:36 PM, amaury pouly <amaury.pouly at gmail.com> wrote:

> My question is the following: is this a bug of GDC/LDC or is this the expected behaviour ? The second solution must always work but I'm unsure about the first one. Indeed, the specification says that a delegate shall not reference a stack parameter which is logical but it says nothing about function arguments.

In D1, returning nested functions from the function that defined them
is undefined behavior.  If you're using DMD1 and it's working, you
just got lucky.  The compilers could detect this better, but more
generally it's a problem of escape analysis and there will always be
cases where they get it wrong.

But in D2, it's legal and will create a closure.  If you're using
DMD2, that's why it's working.



More information about the Digitalmars-d mailing list