On 7/30/2014 6:38 PM, Daniel Gibson wrote:
I'm in favor of a "harmless" assert().
In C(++) I sometimes use things like
assert(x != NULL);
if(x != NULL) {
x->foo = 42;
// ...
}
I have that assertion to hopefully find bugs during development and fix them.
However, no program is bug free and so it's totally possible that x *is* NULL in
some circumstance in the wild (in a "release" mode binary), so I want to make
sure it doesn't explode if that happens but handle the problem more gracefully.
It would be rather unfortunate if the compiler removed that second check in
release mode because the assertion made it assume that x can't be NULL.
Your code is doomed to having problems using assert this way.
The behavior you desire here is easily handled by creating your own template to
exhibit it. See the implementation of enforce() for how to do it.