assert(condition[, message]) patch

Don Clugston dac at nospam.com.au
Fri Jun 2 00:51:10 PDT 2006


Sean Kelly wrote:
> pragma wrote:
>>
>> Another way to look at it is in the use of static assert().  With the
>> compile-time regexp processor(s) out there, they halt on static 
>> assert() and
>> then cough up some rudimentary explaination as to *why* using 
>> pragma(msg).  I
>> wouldn't even consider either implementation usable without the 
>> msg/assert
>> idiom, so I don't really use them apart from each other.  In fact, 
>> I'll argue
>> that its impossible to meaningfully extend the compiler/D-grammar through
>> templates without using the two together; the library user just 
>> wouldn't have a
>> clue otherwise.

[ie, just like C++!]
That's my experience too. It's possible to have excellent usability now 
that we have sudden-death static asserts.


> Good point.  If this change were made, would it apply to static assert 
> as well?  It would certainly be nice.

The case for a message in static assert is very much stronger than for 
assert.
(a) You don't have a debugger -- there's no way of finding what's going 
on apart from seeing the assert.
(b) The message is always for the programmer, not the end user.
(c) Established practice is to use pragma(msg) with static assert(0).

My code is littered with:

static if (!cond) {
   pragma(msg, "xxx");
   static assert(0);
}

It would be so much cleaner to replace this with
static assert(cond, "xxx");
(and it would accentuate the superiority of D templates over C++).



More information about the Digitalmars-d mailing list