Another bug?

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 30 04:22:50 PST 2017


On 01/30/2017 12:55 PM, Jack Applegame wrote:
> Code:
>
> import std.stdio;
> struct Foo {
>     int val = 0;
>         ~this() {
>         writefln("destruct %s", val);
>     }
> }
>
> void bar(ARGS...)() {
>     ARGS args;
>     args[0].val = 1;
>     writefln("val = %s", args[0].val);
> }
>
> void main() {
>     bar!Foo();
> }
>
> Excpected output:
> val = 1
> destruct 1
>
> But got:
> destruct 0
> val = 1
>
> It seems that the compiler destructs 'args' immediately after
> definition, not at the end of the function.

Yup, looks like a (pretty bad) bug to me.


More information about the Digitalmars-d-learn mailing list