Safety/purity and assert/enforce error messages
bearophile
bearophileHUGS at lycos.com
Thu Sep 12 12:12:18 PDT 2013
H. S. Teoh:
> In phobos git HEAD, std.format has been made pure @safe nothrow
> (and
> CTFE-able), so you should be able to write your assert as:
>
> assert(condition, format("x = %s, blahblah", x));
With the latest DMD from updated GIT head:
import std.string: format;
void main() pure nothrow {
string x = "hello";
bool condition = true;
assert(condition, format("x = %s, blahblah", x));
}
It gives:
test.d(5): Error: 'std.string.format!(char, string).format' is
not nothrow
test.d(2): Error: function 'D main' is nothrow yet may throw
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list