Destructors and static array assignment

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 20 07:51:56 PDT 2015


On Monday, 20 July 2015 at 14:18:33 UTC, David Nadlinger wrote:
> Am I missing something here, or is this a major bug in struct 
> lifetime handling?
>
> I understand why this happens from the DMD source, but it 
> almost seems like it was deliberately written this way; thus 
> the question.

Purposeful or not, I don't see how it could be anything other 
than a bug. It fundamentally breaks your ability to control 
what's going on with the construction or destruction of an 
object. And a quick check seems to indicate that out parameters 
have the same problem. If I add this function

     void foo(out S s)
     {
     }

and then this to the end of main

     {
         S s;
         foo(s);
     }

it fails to hit the assertion. The dtorCount in 1, which I think 
is correct, since the out param is a reference to s and thus 
shouldn't destroy it, but it _should_ assign to it, and it looks 
like it's just bitblitting S.init rather than assigning it S.init.

- Jonathan M Davis


More information about the Digitalmars-d mailing list