dmd Regression(?): bigEndianToNative buffer slice allows only literals

Lucas Burson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 13 19:58:24 PDT 2015


The std.batmanip bigEndianToNative has a regression where the 
slice range doesn't work with variables (only literals).
Is the syntax incorrect or is this a regression in dmd?

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-learn mailing list