GCC Undefined Behavior Sanitizer
via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 18 16:10:13 PDT 2014
On Saturday, 18 October 2014 at 08:22:25 UTC, monarch_dodra wrote:
> On Friday, 17 October 2014 at 13:44:24 UTC, ketmar via
> Digitalmars-d wrote:
>> On Fri, 17 Oct 2014 09:46:48 +0000
>> via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>> In D (and C++) you would get:
>>>
>>> if (x < ((x+1)&0xffffffff)){…}
>> perfect. nice and straightforward way to do overflow checks.
It wasn't an overflow check as ketmar suggested… It was a check
that should stay true, always for this instantiation. So the
wrong code is bypassed on overflow, possibly missing a
termination. The code would have been correct with an
optimization that set it to true or with a higher resolution
register.
> Besides, the code uses x + 1, so the code is already in
> undefined state. It's just as wrong as the "horrible code with
> UB" we wère trying to avoid in the first place.
>
> So much for convincing me that it's a good idea...
Not sure if you are saying that modulo-arithmetic as a default is
a bad or good idea?
In D and (C++ for uint) it is modulo-arithmetic so it is defined
as a circular type with at discontinuity which makes reasoning
about integers harder.
More information about the Digitalmars-d
mailing list