Bug 14582 – bigEndianToNative buffer slice allows only literals

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-14T05:44:00Z
Last change time
2015-05-16T07:40:45Z
Assigned to
nobody
Creator
ljdelight

Comments

Comment #0 by ljdelight — 2015-05-14T05:44:33Z
The std.batmanip bigEndianToNative has a regression where the slice range doesn't work with variables (only literals). Using this main.d: import std.bitmanip; int main(string args[]) { auto datain = new ubyte[16]; // this syntax works ushort descriptorLength = bigEndianToNative!ushort(datain[2..4]); // this syntax fails (worked in previous version) int offset = 2; descriptorLength = bigEndianToNative!ushort(cast(ubyte[2]) datain[offset..offset+2]); return 0; } I get this error on the command line: main.d(14): Error: cannot cast expression datain[cast(uint)offset..cast(uint)(offset + 2)] of type ubyte[] to ubyte[2]
Comment #1 by dlang-bugzilla — 2015-05-14T16:37:06Z
Broken by https://github.com/D-Programming-Language/dmd/pull/4193. I believe this change is intentional.
Comment #2 by k.hara.pg — 2015-05-16T07:40:45Z
(In reply to Vladimir Panteleev from comment #1) > Broken by https://github.com/D-Programming-Language/dmd/pull/4193. > > I believe this change is intentional. Yes, this is intentional change, so it's not a regression. To support such the cast operation (from a dynamic array slice with offset + compile-time known length to static array reference), I'm proposing enhancement issue 13700, but my compiler change for that is not yet merged.