Bug 6186

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 2 11:56:42 PDT 2013


On Wed, Oct 02, 2013 at 08:26:22PM +0200, Benjamin Thaut wrote:
> Am 02.10.2013 20:23, schrieb Maxim Fomin:
> >
> >For me the bug is invalid since out parameter is implicitly ref and
> >it has nothing to do with initialization (you better think about it
> >as an assignment). This means there are no reasons to call
> >destructor.
> 
> In my eyes the bug is clearly not invalid because it caused memory
> leaks for me. If you have a struct which is a wrapper to a malloced
> buffer, and you pass it to a function which takes the struct as out
> parameter, the destructor will never be called because the memory will
> simply be reinitialized and the memory will leak. In my eyes this is a
> clear struct lifetime bug.

I agree.

This is one area of D that I'm not very impressed with, actually. It is
a minefield full of hazards.  Once your type has a dtor, you can expect
to run into a lot of similar bugs everwhere -- dtors not getting called
at the right places, can't up them in an AA without hitting bugs,
unclear semantics of when/where/how dtors should be called, unclear
semantics on state of member variables, etc.. Just witness, e.g., the
issues we have with emplace and destroy. I suspect it's because most D
code doesn't use dtors, or only uses them in very limited contexts, so
dtor-related code is not well-tested.

I wish these issues can be addressed with a consistent approach rather
than the current ad hoc approach of "there's a fire here let's put in
this hack to fix it, there's another fire over there but we don't know
what to do so we're just going to ignore it". But it doesn't seem to be
the priority right now. :-(


T

-- 
Today's society is one of specialization: as you grow, you learn more
and more about less and less. Eventually, you know everything about
nothing.


More information about the Digitalmars-d mailing list