Negating a short?

2024-11-05 Thread Andy Valencia via Digitalmars-d-learn
I have a template which has a bit where it negates a value. This works well until it encountered a short, where ldc2 complained: integral promotion not done for -val I ended up with this, but is negating a short really this problematic, or did I miss something? static if (!__traits(isUn

Re: Negating a short?

2024-11-05 Thread Dennis via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia wrote: I ended up with this, but is negating a short really this problematic, or did I miss something? This is a relic from when integer promotion was added to unary operators to match the behavior of C compilers. You can add the `-pr

Re: Negating a short?

2024-11-05 Thread Lance Bachmeier via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia wrote: I have a template which has a bit where it negates a value. This works well until it encountered a short, where ldc2 complained: integral promotion not done for -val My reading of the spec is that this should be legal: https

Re: Negating a short?

2024-11-05 Thread Andy Valencia via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 19:37:32 UTC, Dennis wrote: On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia wrote: I ended up with this, but is negating a short really this problematic, or did I miss something? This is a relic from when integer promotion was added to unary operators

Re: Negating a short?

2024-11-05 Thread Dennis via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 20:29:08 UTC, Andy Valencia wrote: I still see: tst15.d(6): Error: cannot implicitly convert expression `-cast(int)s` of type `int` to `short` That's right, it only removes the deprecation that requires a double cast to fix, but you still need an explicit cast

Re: Negating a short?

2024-11-05 Thread Andy Valencia via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 00:00:48 UTC, Dennis wrote: That's right, it only removes the deprecation that requires a double cast to fix, but you still need an explicit cast to truncate the result of `-s` (which got promoted to `int`) back to a `short`, unless the compiler can prove at co