[Issue 22055] New: [The D Bug Tracker] Casting slices in CTFE yields the wrong result

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 21 07:28:48 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=22055

          Issue ID: 22055
           Summary: [The D Bug Tracker] Casting slices in CTFE yields the
                    wrong result
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

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.

--


More information about the Digitalmars-d-bugs mailing list