[Optimization] Speculatively not calling invariant on class objects
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 13 11:41:46 PDT 2015
On 8/13/15 2:25 PM, Iain Buclaw via Digitalmars-d wrote:
>
> class A { invariant { } }
> class B : A { }
> class C : B { invariant { } }
>
> B b = new C(); // We can only discover that 'b' is a C object at runtime.
>
> I thought invariant was like ctor/dtor, the most derived
> automatically calls the base version.
>
>
> Nope, it only calls it's own invariants. Calling all derived invariants
> is what _d_invariant is for.
I envisioned C.invariant would inject a call to A.invariant, and that
invariant would occupy a vtable slot.
-Steve
More information about the Digitalmars-d
mailing list