[Issue 15685] &slice[$] should be allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 5 10:35:59 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=15685
Mathias LANG <pro.mathias.lang at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |pro.mathias.lang at gmail.com
Resolution|--- |INVALID
--- Comment #1 from Mathias LANG <pro.mathias.lang at gmail.com> ---
In order to get this address, you should do `slice.ptr + slice.length`.
`&slice[$]` would give you an element *after* the array, so it's potentially
pointing to unallocated / invalid / protected memory. It's a pointer you should
*never* access.
When writing C-style code, it's common to do `while (p++ < pend)` where `pend`
is this pointer, but the type system can't guarantee you'll use it correctly.
Also, that would break `@safe` code. So marking as `INVALID` since we don't
want to allow it, and there's an easy workaround: use `ptr + length`.
--
More information about the Digitalmars-d-bugs
mailing list