[Issue 3578] Impossible to run a struct invariant using assert(s)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Oct 16 16:07:36 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3578
--- Comment #3 from Leandro Lucarella <llucax at gmail.com> 2010-10-16 16:06:59 PDT ---
(In reply to comment #2)
> It's undocumented, but struct invariants are fired on pointers:
> --------------------
> struct S
> {
> invariant() { assert(0); } // (3)
> }
> void main()
> {
> S s;
> assert(&s);
> }
> --------------------
> % dmd -run test.d
> core.exception.AssertError at test(3): Assertion failure
> --------------------
>
> Though it's non-intuitive, I find it reasonable considering that structs can
> define opCast to bool. assert(s) would be ambiguous if s had both invariant
> and opCast!bool.
I never expected that, but it makes sense as you mention.
I guess this behavior should be documented in the specs.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list