[Issue 15041] Pointer slice with one negative index throws 'Range violation'
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 28 02:01:28 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15041
Vladimir Panteleev <thecybershadow at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |thecybershadow at gmail.com
--- Comment #1 from Vladimir Panteleev <thecybershadow at gmail.com> ---
> assert(p[-1 .. 1] == "aa"); // 'Range violation'
What happens here is that -1 gets implicitly casted to size_t, which is
unsigned, so this becomes p[size_t.max .. 1]. Slicing p[a..b] when a>b is
nonsense, hence the RangeError.
The check is removed when -release is present.
I'm not sure this is a bug.
--
More information about the Digitalmars-d-bugs
mailing list