View mode: basic / threaded / horizontal-split · Log in · Help
February 16, 2010
assert(object) calls invariant and crash
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@michelf.com
http://michelf.com/
Top | Discussion index | About this forum | D home