On Saturday, 22 January 2022 at 14:23:32 UTC, Adam Ruppe wrote:
You can't forward to a local variable. Local variables will be a copy of the tuple. forward only actually works if sent *directly* to another function call.

There's a bunch of things in D that only work in function parameter lists and not local variables. This is one of them.

Thanks,
Why local variable of type tuple call destructors immediately after initialization?

```d
import std.stdio : writeln;
import std.meta : AliasSeq;

struct Foo{
        int i;

    this(int i){
        this.i = i;
        writeln("ctor(", i, "): ", cast(void*)&this);
    }

    ~this(){
        writeln("dtor(", i, "): ", cast(void*)&this);
        i *= -1;
    }
}


void main(){
    {
        AliasSeq!(Foo, Foo) tup;

        static foreach(alias x; tup)
writeln("check(", x.i, "): ", cast(void*)&x); //x is destructed
    }
}

```

Print:
```
dtor(0): 7FFF30D76868
dtor(0): 7FFF30D76858
check(0): 7FFF30D76858     //dangling?
check(0): 7FFF30D76868     //dangling?
```

Reply via email to