[Issue 19683] New: casting int[] array literal or enum to ubyte[] does element-wise cast
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 17 20:54:11 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19683
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 at puremagic.com
Reporter: dkorpel at 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
data.
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
--
More information about the Digitalmars-d-bugs
mailing list