Destructors and static array assignment

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 20 08:12:00 PDT 2015


On Monday, 20 July 2015 at 14:56:45 UTC, Benjamin Thaut wrote:
> This bug with "out" and structs is very old:
>
> https://issues.dlang.org/show_bug.cgi?id=6186
>
> It even has 26 votes, but it doesn't seem to be important 
> enough to be fixed.

That bug report certainly paints a more complicated and 
controversial picture on the issue than I would have expected. 
But I think that the issue is pretty much the same as what 
David's bringing up. Certainly, having

S[2] a;
a = S.init;

and

void foo(out S s) {}
S s;
foo(a);

not be consistent seems like a bad idea. In both cases, we're 
dealing with setting the variable to its init value, and having 
that not be the same in all circumstances just seems like it's 
begging for trouble...

The only way that I can see that they would reasonably be 
different would be if out were simply disallowing the variable to 
be anything other than its init value, which might make sense, 
but it wouldn't make sense when explicitly assigning the init 
value to a variable. So, making it so that out requires that the 
variable be its init value is really just sidestepping the issue 
with out while still leaving it elsewhere, so sidestepping it 
with out doesn't really save us from having to solve the problem.

- Jonathan M Davis


More information about the Digitalmars-d mailing list