assert(0) behavior
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue Aug 4 13:43:56 PDT 2015
On 8/4/15 4:23 PM, Walter Bright wrote:
> On 8/4/2015 4:53 AM, Steven Schveighoffer wrote:
>> Any assert(0) in druntime or phobos with a message printed is an
>> error. It's
>> compiled in release mode.
>
> When you're debugging phobos, you aren't compiling in release mode.
Unless you aren't debugging it, but an assert is still triggering. I
want to stress, the bug that was found in core.time was environmental,
and without the end user debugging it for us, we would never have known
what this was, because the message wasn't printed.
I should say, any assert(0) with a message printed that is possible to
trigger in release mode is an error. If you can ensure it's only
possible to trigger when compiled in debug mode (or for unit tests),
then assert(0, msg) is fine.
> But I've also been of the opinion, not widely shared, that any
> programmer supplied messages in asserts are pointless.
They can be helpful for context if it's not obvious what should have
triggered the assert.
for example:
assert(x > y, "x: " ~ x.toString() ~ ", y: " ~ y.toString());
-Steve
More information about the Digitalmars-d
mailing list