Delegate is left with a destroyed stack object

Lionello Lunesu lionello at lunesu.remove.com
Wed Oct 30 03:25:12 PDT 2013


On 10/30/13, 10:56, David Nadlinger wrote:
> ---
> void main() {
>    import std.stdio;
>
>    void delegate()[] dgs;
>    foreach (i; 0 .. 5) dgs ~= { writeln(i); };
>
>    foreach (dg; dgs) dg();
> }
> ---
>
> If structs behaved like you want them to, the snippet would (have to)
> print 0, 1, 2, 3, 4 as well,

Did NOT know that. Thanks for letting me know :)

> and tht's definitely too big a language change to consider at this stage.

Well, that's a separate issue, whether to change the language or not. 
It's still valuable to discuss unexpected behavior when one runs into it.

L.


More information about the Digitalmars-d mailing list