New integer promotion rules

rumbu rumbu at rumbu.ro
Wed Jan 17 19:40:46 UTC 2018


This started in the last DMD version (2.078):

byte b = -10;
ulong u = b < 0 ? -b : b;

//Deprecation: integral promotion not done for `-b`, use 
'-transition=intpromote' switch or `-cast(int)(b)

Why do I need a to promote a byte to int to obtain an ulong? Even 
in the extreme case where b is byte.min, -byte.min as unsigned is 
exactly what i need: 128;

This leads to more cases:

ubyte u = cast(ubyte)-b;
//Deprecation: integral promotion not done for `-b`, use 
'-transition=intpromote' switch or `-cast(int)(b)`

Last time I checked, casting is somehow synonym with "I know what 
I'm doing", why do I need another cast to prove my sanity: ubyte 
u = cast(ubyte)-cast(int)b;






		




More information about the Digitalmars-d-learn mailing list