Feature request: assert expressions should live inside version(assert)

Tommi tommitissari at hotmail.com
Sun Jul 7 06:56:59 PDT 2013


On Sunday, 7 July 2013 at 13:42:52 UTC, Tommi wrote:
> Then, yet another solution (a code breaking one) would be to 
> make it so that only literally saying:
> assert(0);
> or
> assert(false);
> or
> assert(null);
>
> ...would exhibit that special assert behaviour.
>
> Anything else would be semantically runtime-evaluated and no 
> other forms of assert would remain in release builds. For 
> example, this kind of an assert would be compiled out of 
> existence in release mode:
>
> enum bool cond = false;
> assert(cond);

The programmer can always work around this new behaviour.

Old code:

enum bool shouldHalt = someExpression();
assert(shouldHalt);

New code:

enum bool shouldHalt = someExpression();
static if (shouldHalt) assert(0);


More information about the Digitalmars-d mailing list