dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Thu Nov 11 07:58:54 UTC 2021
On Thursday, 11 November 2021 at 01:31:46 UTC, Elronnd wrote:
> I agree this should be required. If you want something which
> is not valid UTF-8, _do not put it into a string_. Use ubyte[].
Exactly.
> Go further: require a runtime check on cast from ubyte[] to
> char[] (expensive), and on slicing char[] (cheap). (If you
> abuse unions you are on your own; but obviously that is not
> allowed in @safe code, so has the same limitations as e.g.
> boundschecking.)
The compiler could do such checks in an extra-solid-debug-mode.
That could certainly improve unit-testing and other testing. In
such a mode you could also do overflow checks for signed integers
(if they are changed so they don't wrap).
More information about the Digitalmars-d
mailing list