Make -preview=intpromote not suck

Paul Backus snarwin at gmail.com
Wed Oct 28 15:13:35 UTC 2020


On Wednesday, 28 October 2020 at 14:52:28 UTC, Steven 
Schveighoffer wrote:
>
> I don't know if this is OK or correct. For example
>
> short c = a * b; => lots of truncation gonna happen.

This sort of thing is still allowed with -preview=intpromote, for 
types that are int-sized or larger:

     int a = int.max, b = int.max;
     int c = a*b; // compiles and truncates


The most principled way to approach this is to either *always* 
require a cast for possibly-truncating operations, or to *never* 
require one. As it stands, `-preview=intpromote` is an 
unsatisfying half-measure that both requires casts when they are 
not necessary, and fails to require them when they may be 
necessary.


More information about the Digitalmars-d mailing list