Bug 19907 – passing slice to fixed array not working with variable offset

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-28T06:12:19Z
Last change time
2024-12-13T19:03:33Z
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#19571 →

Comments

Comment #0 by turkeyman — 2019-05-28T06:12:19Z
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.
Comment #1 by dfj1esp02 — 2019-05-28T06:55:51Z
Workaround: buffer[x..$][0..4]
Comment #2 by turkeyman — 2019-05-28T07:45:33Z
Nice.
Comment #3 by iamthewilsonator — 2019-06-10T04:53:29Z
Is the workaround sufficient to close this?
Comment #4 by turkeyman — 2019-06-10T05:04:51Z
I don't think it should be closed, seems like a legit issue to me... Workaround is workable though, so it's not a priority.
Comment #5 by robert.schadek — 2024-12-13T19:03:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19571 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB