Deprecate implicit conversion between signed and unsigned integers
An Pham
home at home.com
Tue May 14 12:28:15 UTC 2024
On Sunday, 12 May 2024 at 13:32:36 UTC, Paul Backus wrote:
> D inherited these implicit conversions from C and C++, where
> they are widely regarded as a source of bugs.
>
Just focus on sign vs unsign is not good enough. Sometime you
need to specify a range of values. There is module std.CheckedInt
which
1. Should extend it to be a runtime system module which does not
need to 'import'
2. Add range template parameters Checked!(int, X, Y, ...) like
Checked!(int, -5, 200, ...)
which only hold values from -5 to 200 inclusively
3. Extend language to allow implicit passing parameter void
foo(Checked!(int, X, Y, ...) z)
and can be called by foo(10) is ok but foo(1000) should failed
More information about the dip.ideas
mailing list