[OT] The Usual Arithmetic Confusions
Dukc
ajieskola at gmail.com
Thu Feb 3 21:23:10 UTC 2022
On Thursday, 3 February 2022 at 21:01:30 UTC, Ola Fosheim Grøstad
wrote:
> On Thursday, 3 February 2022 at 20:56:04 UTC, Dukc wrote:
>> We could allow undefined behaviour only in `@system` code, and
>> realistically,
>
> How exactly is this relevant for @safe?
We cannot allow undefined behaviour in `@safe` code. That means
that any integer that would have undefined semantics for
overflows could not be used at `@safe`.
Well, asserting no overflow would be fine. With a `-release`
switch, it'd behave like the c++ signed int. But not otherwise.
In fact this is already doable:
```D
import core.checkedint;
bool check;
auto x = mulu(a,b,check);
assert(!check);
```
Not sure if the compiler will take advantage of overflow being
undefined behaviour here in release mode, though.
More information about the Digitalmars-d
mailing list