[Issue 19907] New: passing slice to fixed array not working with variable offset

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 28 06:12:19 UTC 2019


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

          Issue ID: 19907
           Summary: passing slice to fixed array not working with variable
                    offset
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: turkeyman at gmail.com

Consider this function:

  void fun(ref char[4]);

You can call it like this:

  char[20] buffer;

  // pass a slice of buffer as the static array
  fun(buffer[10 .. 10 + 4]);

That works as expected, but this doesn't work:

  // pass a slice of buffer as the static array with variable offset
  int x = 10;
  fun(buffer[x .. x + 4]);

This is pretty annoying... only workaround some hideous casting:

  fun(*cast(char[4]*)(buffer.ptr + x));

Would be nice for the prior expression to work in @safe code.

--


More information about the Digitalmars-d-bugs mailing list