flagging unsigned subtraction assigned to bigger signed number?
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Tue May 20 16:43:30 UTC 2025
Counter proposal: throw data flow analysis at it, rather than change the
language.
It would be able to catch things like:
```d
int[] array = [1, 2];
size_t offset;
foreach(i; 0 .. array.length) {
offset = i + 1;
}
array[offset]; // Error out of bounds!
```
But not:
```d
void func(int[] array, size_t offset) {
array[offset];
}
```
To catch the second would require false positives to be acceptable, and
the default pain tolerance for the D community is lower.
Yes this is more complex to implement than a language change, but the
support can be improved over time, it isn't fixed, and we can have the
slower DFA that will error out in the latter example.
More information about the Digitalmars-d
mailing list