How to strip struct/class invariants?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 6 06:18:07 PDT 2015
On 7/5/15 8:15 AM, Artem Tarasov wrote:
> OK, so there was an old bug fixed in 2.067
> (https://issues.dlang.org/show_bug.cgi?id=4421) so that now unions
> apparently can't contain a struct that has invariants. It kinda makes
> sense, although I don't see why the invariants can be simply ignored, as
> they don't have as much importance as destructors/postblits.
More importantly, invariants are only called when you call members of a
struct (or assert it). It requires actual usage of the particular union
member. So already the programmer has indicated that member is valid by
using it.
It is NOT valid to arbitrarily pick one member of the union and call its
invariant (or call all of them).
I think this is an incorrect position D has taken -- Invariants should
be called when calling members of a struct in a union. If an implicit
choice must be made, then it should be an error. But it's easy to make
the invariant call explicit.
-Steve
More information about the Digitalmars-d-learn
mailing list