www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd Regression(?): bigEndianToNative buffer slice allows only literals

reply "Lucas Burson" <ljdelight+dlang gmail.com> writes:
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]
May 13 2015
parent "Lucas Burson" <ljdelight+dlang gmail.com> writes:
I reported this as a regression 
https://issues.dlang.org/show_bug.cgi?id=14582
May 13 2015