phobos's circle CI runs a busted version of DMD

Salih Dincer salihdb at hotmail.com
Thu Jan 12 16:31:32 UTC 2023


On Thursday, 12 January 2023 at 04:01:13 UTC, Ali Çehreli wrote:
> On 1/11/23 15:54, Salih Dincer wrote:
>
> > The problem is that it shift via int first.
>
> Yes but it shouldn't because one of the operands is uint and 
> the 'int' operand should be converted to uint and the operation 
> should have uint semantics.

Deadalnix is RIGHT!

Interestingly, triple shifting (>>>) does not work correctly on 
any type, except long!

```d
struct TestType(T)
{
   import std.traits : Unsigned;
   alias U = Unsigned!T;

   T t = T.min;       // sample: -128 for byte
   U u = U.max/2 + 1; // sample: 128 for ubyte
}

void main()
{
   alias T = long; // int, short, byte

   TestType!T v1, v2;
   enum bits = T.sizeof * 8 - 1;

   v1.t >>= bits;
   assert(v1.t == -1); // okay, because signed type

   v1.u >>= bits;
   assert(v1.u == 1); // okay, because unsigned type

   v2.t >>>= bits;
   assert(v2.t == 1); /* okay, no sign extension
                         but  -1 for byte, short, int */
   v2.u >>>= bits;
   assert(v2.u == 1); // okay, no sign extension
}
```

SDB at 79


More information about the Digitalmars-d mailing list