On Thursday, 5 June 2014 at 20:37:51 UTC, Steven Schveighoffer
wrote:
On Thu, 05 Jun 2014 16:32:24 -0400, monarch_dodra
<[email protected]> wrote:
On Thursday, 5 June 2014 at 19:57:08 UTC, Steven Schveighoffer
wrote:
A possible fix could be to reject the call to ptr at runtime
if the slice is empty.
I don't know why you'd ever do "arr.ptr" in the first place,
other than to avoid the bounds check. So I think the call
should just be unsafe, and we call it a day. Or maybe to
interface with a function that want a pointer?
That's true. You can always get a pointer to any valid element
with &arr[x]. Then at least you have bounds checking to save
you.
In fact, in safe code, arr.ptr could be replaced with &arr[0].
&arr[0] does bound checking. That is different ;)