A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Aug 14 00:04:55 UTC 2020


On Thu, Aug 13, 2020 at 11:54:57PM +0000, mw via Digitalmars-d wrote:
> On Thursday, 13 August 2020 at 23:47:30 UTC, Walter Bright wrote:
[...]
> > The thing about checkedint is there are several different behaviors
> > one might choose as responses to overflow. There is no
> > one-size-fits-all, if we did pick one we'll inevitably have
> > complaints.
[...]
> If we choose this approach, the hook can also have its own command
> line option to let the user in explicit full control of what the
> integer operation behavior s/he really wants for his/her application.
[...]

The application can just use CheckedInt instantiated with whatever
preferences it wants to. Define an alias to that in a common module and
import that, and you're good to go:

	alias Int = CheckInt!(... /* whatever settings you want here */);
	...
	Int i, j;
	Int k = i + j; // etc.

What we do *not* want is a compiler switch that will silently change the
meaning of existing code. Imagine the chaos if you compiled your
application with -int-behaviour=blahblah, and suddenly all of your dub
dependencies start misbehaving because their code was written with the
standard rules in mind, and subtly changing that causes massive breakage
of their internal logic. Or worse, silent, subtle breakage in rare
corner cases, of the kind that introduces security holes without a
single warning, the kind that cyber-criminals love to exploit.


T

-- 
Political correctness: socially-sanctioned hypocrisy.


More information about the Digitalmars-d mailing list