Spec on casting to integer with smaller range than value
kinke
noone at nowhere.com
Sat Mar 28 17:13:31 UTC 2020
On Saturday, 28 March 2020 at 15:47:04 UTC, Dennis wrote:
> Which would make `cast(int) someFloat` not allowed in @safe
> code.
In LLVM lingo, the out-of-bounds cast wouldn't be undefined
behavior per se, but yield a 'poison' value, whose later usage
might eventually trigger undefined behavior, depending on what
exactly you're doing with it.
> Safe functions are functions that are statically checked to
> exhibit no possibility of undefined behavior.
If that's really the ultimate goal, then these casts would
probably need a prefixed bounds check in @safe code, just like an
array bounds check (incl. omitting it if it can be statically
determined to fit).
More information about the Digitalmars-d
mailing list