digitalmars.D - Re: Question of delegate literals and return from
- Amaury Pouly <amaury.pouly gmail.com> Feb 01 2009
Jarrett Billingsley Wrote: Thank you for your answer. I was using D1 so I'm quite lucky with dmd :)On Sat, Jan 31, 2009 at 5:36 PM, amaury pouly <amaury.pouly 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.
Feb 01 2009