D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14582 - bigEndianToNative buffer slice allows only literals
Summary: bigEndianToNative buffer slice allows only literals
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-14 05:44 UTC by Lucas Burson
Modified: 2015-05-16 07:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lucas Burson 2015-05-14 05:44:33 UTC
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 Vladimir Panteleev 2015-05-14 16:37:06 UTC
Broken by https://github.com/D-Programming-Language/dmd/pull/4193.

I believe this change is intentional.
Comment 2 Kenji Hara 2015-05-16 07:40:45 UTC
(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.