[Issue 3578] Impossible to run a struct invariant using assert(s)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 16 12:02:45 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3578


Shin Fujishiro <rsinfu at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rsinfu at gmail.com


--- Comment #2 from Shin Fujishiro <rsinfu at gmail.com> 2010-10-16 12:02:06 PDT ---
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.

-- 
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