segfault in invariant { assert(super); }

SimonN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 22 20:29:31 PST 2015


On Monday, 21 December 2015 at 20:29:14 UTC, Steven Schveighoffer 
wrote:
>> 1) Is this recursion expected?
> Yes. assert calls the virtual invariant function, which in the 
> case of super is equivalent to this. So you are essentially 
> calling assert(this).

>> 2) The example is a dustmite'd version of this:
> It seems like something you shouldn't do. AFAIK, invariant 
> should not call any public functions on your existing class.

Thanks for the reply! Yeah, this helps for a clearer picture of 
what's happening.

In particular, even though all invariants of a class hierarchy 
are tested instead of only the most-subclassed-one, triggering 
the invariant check remains virtual. I didn't know that.

Even if Base.f() is const, it's not allowed inside 
Derived.invariant(). This is again understandable: By OOP 
principles, Derived shouldn't impose further restrictions on Base 
than what Base imposes on itself already.

> (good idea to file an enhancement report).

For that, I was trying earlier today to find the exact instances 
of when there is a warning, and when there is not. I didn't get 
warnings to come up consistently. (Even the case I described in 
question 2 doens't always give a warning.) I'd have to take a 
look at this some time again.

-- Simon


More information about the Digitalmars-d-learn mailing list