Bug 22055 – [The D Bug Tracker] Casting slices in CTFE yields the wrong result

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-06-21T07:28:48Z
Last change time
2021-06-21T08:52:59Z
Assigned to
No Owner
Creator
Eyal

Comments

Comment #0 by eyal — 2021-06-21T07:28:48Z
unittest { int[] runtimeInts = [1,2]; enum int[] compiletimeInts = [1,2]; pragma(msg, "pragma(msg): ", cast(ubyte[])compiletimeInts); writefln("CT: %s", cast(ubyte[])compiletimeInts); writefln("RT: %s", cast(ubyte[])runtimeInts); } Outputs: pragma(msg): [cast(ubyte)1u, cast(ubyte)2u] CT: [1, 2] RT: [1, 0, 0, 0, 2, 0, 0, 0] This is a problematic semantic discrepancy between compile-time and runtime, and even between 2 runtime values if they're casts of compile-time vs. runtime values. I suppose the runtime value is the correct one.
Comment #1 by ag0aep6g — 2021-06-21T08:52:59Z
*** This issue has been marked as a duplicate of issue 16357 ***