Destructors and static array assignment
Benjamin Thaut via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jul 20 07:56:44 PDT 2015
On Monday, 20 July 2015 at 14:51:57 UTC, Jonathan M Davis wrote:
> 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
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.
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d
mailing list