On 02-09-2012 13:39, Peter Alexander wrote:
The language spec says:

"The compiler may optionally not evaluate assert expressions at all."

In practice, this means that it depends on compiler flags. For DMD,
assert expressions are ignored in -release.

Sometimes, I want to do things only when asserts are being compiled, for
example:

version(release) {} else import std.format;
assert(x == 0, format("x is %d, not 0", x));


I have two problems with this:

1. It's ugly to use the version... else syntax.
2. It's tied to the fact that DMD doesn't compile asserts in release.

What I would prefer:

version(assert) import std.format;


Of course, version(assert) is compiled when asserts are compiled.

This makes the intent clear, and removes coupling with particular
compiler options.

Thoughts?

(Sorry, managed to reply directly via email with the previous message.)

Yes: https://github.com/D-Programming-Language/dmd/pull/1099

(If that's accepted, I'll send patches to GDC and LDC as well.)

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to