Range violation instead of empty slice on a[3 .. 2]
SimonN via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Nov 21 21:04:42 PST 2015
On Sunday, 22 November 2015 at 00:24:43 UTC, Jonathan M Davis
wrote:
>> this is only an error if bounds checking is not turned on.
> It's a logic error regardless.
> you're going to have to create a wrapper.
Right, I am using a wrapper, and I'm not relying on any behavior
of a[3..2] during -boundscheck=off.
> How does the runtime know that you're not just
> providing it garbage values?
The runtime flags an empty slice as an error here, seemingly
without reason, because the slice can't access any element
outside of bounds.
However, considering (2U - 3U) > 0, I understand that there is no
way to catch this problem without comparing the two bounds. And
the comparison is designed to be skippable for speed. Therefore,
3..2 is reasonably flagged as an error.
So, thanks for pointing it it out again!
-- Simon
More information about the Digitalmars-d-learn
mailing list