June 05, 2020 [Issue 15685] &slice[$] should be allowed | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=15685 Mathias LANG <pro.mathias.lang@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |pro.mathias.lang@gmail.com Resolution|--- |INVALID --- Comment #1 from Mathias LANG <pro.mathias.lang@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`. -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply