short s, t; t = -s: no (longer) works: Deprecation: integral promotion not done for -s, use
kdevel
kdevel at vogtner.de
Sat Feb 24 21:42:59 UTC 2018
On Saturday, 24 February 2018 at 20:17:12 UTC, Steven
Schveighoffer wrote:
> On 2/24/18 3:07 PM, kdevel wrote:
>> I don't get the point of the deprecation message:
>>
>> --- intprom.d
>> import std.stdio;
>>
>> void main ()
>> {
>> short s, t;
>> t = -s;
>> }
>> ---
>
> https://dlang.org/changelog/2.078.0.html#fix16997
My goodness! So there is currently no negation operator defined
on short and some other types?
>> $ dmd intprom.d
>> intprom.d(6): Deprecation: integral promotion not done for -s,
>> use '-transition=intpromote' switch or -cast(int)(s)
>>
>> What shall I do in order to get my template code
>>
>> void mymain (T) ()
>> {
>> :
>> b[i] = -b [i];
>> :
>> }
>>
>> compiled for any type for which negation is defined?
>
> b[i] = cast(typeof(b[i]))-b[i];
>
> And then use -transition=intpromote.
>
> Note, your function wasn't real code, so maybe if you have the
> type of b[i] somewhere it might look better than what I wrote
> (like maybe cast(T)-b[i]).
Any objections against leaving out the compiler switch and using
b[i] = cast (T) (0 - b[i]);
instead?
More information about the Digitalmars-d-learn
mailing list