[Issue 519] Invariant not called from autogenerated class/struct constructor/destructor

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jan 15 08:03:23 PST 2015


https://issues.dlang.org/show_bug.cgi?id=519

--- Comment #18 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Martin Nowak from comment #17)
> (In reply to Andrei Alexandrescu from comment #16)
> > I stated this elsewhere, just making sure I don't forget: probably we don't
> > want to invoke invariants during the GC cycle.
> 
> Walter has a different opinion on this, I don't follow his argument though.
> http://forum.dlang.org/post/m753hk$pt2$1@digitalmars.com
> 
> Currently it can't be done, because the calls to the invariant are embedded
> into the generated destructor function.

Well a simple invariant would be:

assert(this.parent.child is this);

which would be placed in some child node, or could be moved in parent like
this:

assert(this.child.parent is this);

The invariant involves two objects no matter where you put it.

> Also the invariant is called twice, before and after running the destructor.
> The latter forces one to perform additional cleanup, e.g. setting pointers
> to null.

That's definitely a problem. Invariants are not supposed to hold after
destruction.

--


More information about the Digitalmars-d-bugs mailing list