compile-time checked format strings
Adam D. Ruppe
destructionator at gmail.com
Sat Jan 13 19:40:09 UTC 2018
On Saturday, 13 January 2018 at 19:15:49 UTC, kdevel wrote:
> dmd checks the types but does not count the arguments.
so note that dmd doesn't actually do any checks here - it is all
done in library code.
The implementation is amusingly simple:
https://github.com/dlang/phobos/blob/master/std/format.d#L5803
try format(...) catch(Exception) trigger compile time error.
But, since float format doesn't work at compile time, this method
doesn't actually work to catch any float-related problems except
mismatching format characters!
For ints, it catches all that, but for float, it just bails out
of the check as soon as it actually *succeeds* - because that
kills CTFE.
We should just put in a fake stub float printer to hack this past
for checking purposes.
More information about the Digitalmars-d-learn
mailing list