[Issue 14582] New: bigEndianToNative buffer slice allows only literals

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed May 13 22:44:33 PDT 2015


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

          Issue ID: 14582
           Summary: bigEndianToNative buffer slice allows only literals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: ljdelight at gmail.com

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]

--


More information about the Digitalmars-d-bugs mailing list