www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19683] New: casting int[] array literal or enum to ubyte[]


          Issue ID: 19683
           Summary: casting int[] array literal or enum to ubyte[] does
                    element-wise cast
           Product: D
           Version: D2
          Hardware: x86
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

When an array literal of type int[] is casted to a ubyte[] the result has the
same length and all integers are truncated to ubytes, while normally it would
result in an array 4 times the length of the int[] with the same underlying

See: https://forum.dlang.org/post/koajkwkvkrajrwszgwua forum.dlang.org

void main ()
   enum A = [0x10203040, 0x50607080];
   auto B = [0x10203040, 0x50607080];
   assert (A == B);
   auto p = cast (ubyte []) A;
   auto q = cast (ubyte []) B;
   assert (p == q); // fails

Relevant spec: https://dlang.org/spec/expression.html#cast_expressions

Feb 17 2019