NotNull pointers
Christian Kamm
kamm-incasoftware at removethis.de
Tue Aug 30 07:58:29 PDT 2011
I want to point out the following bug in the example, because it's *such* a
common problem and, in my opinion, one of D's warts:
Walter Bright wrote:
> this(P q)
> {
> assert(q);
> p = q;
> }
Try
auto d = NotNull!Object(null);
you'll get a segmentation fault and not an assert. That's because
assert(someclass) does not check if someclass is non-null at all, it
verifies its invariant instead!
All the asserts should be assert(q !is null);.
More information about the Digitalmars-d
mailing list