On Wednesday, 7 January 2015 at 20:25:10 UTC, Meta wrote:
struct Tree
{
    this(string data, Tree[] children...)
    {
        this.data = data;
        this.children = children;

Don't do this without `dup`ing. Quoting the documentation:

An implementation may construct the object or array instance on the stack. Therefore, it is an error to refer to that instance after the variadic function has returned:
[...]
int[] test(int[] a ...)
{
   return a;       // error, array contents invalid after return
   return a[0..1]; // error, array contents invalid after return
   return a.dup;   // ok, since copy is made
}

http://dlang.org/function#variadic

    }

    string data;
    Tree[] children;
}

Reply via email to