assert(object) calls invariant and crash

Michel Fortin michel.fortin at michelf.com
Tue Feb 16 14:11:24 PST 2010


For some reason this creates an access violation:

	Object o;
	assert(o);

Apparently it's by design. This expression is calling o's invariant, it 
does not check for null as I'd expect. But o is null so calling 
invariant just crashes.

According to an old bug report, things have been working like this for 
a long time.
<http://d.puremagic.com/issues/show_bug.cgi?id=796>

It works according to spec:
<http://www.digitalmars.com/d/2.0/class.html#Invariant>

I wonder how many time I wrote the above assertion thinking I was just 
checking for null...


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list