http://d.puremagic.com/issues/show_bug.cgi?id=10763
--- Comment #5 from Don <[email protected]> 2013-08-19 02:37:33 PDT --- (In reply to comment #4) > (In reply to comment #3) > > It's basically the same as issue 10266. > > Issue 10266 additionally requests allowing reinterpret-casts between T* and > T[1]* (my implementation currently rejects this, but allowing it would be > easy.) > > > The corner cases arise if you still disallow &x + 1. My guess is that you're > > allowing it in your implementation? > > ... > > Yes, but dereferencing it is an error. Subtracting one results in the address > of x. That is not the issue. The problem is that in C, simply creating the pointer is undefined behaviour. No dereferencing is involved. Note that is undefined behaviour, it's not even implementation-specific behaviour! Simply storing an invalid pointer into a pointer register may generate a hardware exception on some systems. In C, you are not permitted to do pointer arithmetic unless the pointer points to an array, or one-past-the-end-of-an-array. > > The problem with allowing it is that we're departing from C. > > Does C actually disallow adding 0 to a pointer to a local variable? That's > what > the example is doing. I'm not sure if that's legal or not. I suspect not, though I think it would always work in practice. But adding 1 to a pointer to a local variable is definitely illegal, and there are systems where it will not work. So the end of the slice is problematic. > > Is there really a use case for this unsafe behaviour? > > Make more code CTFE-able. But it's undefined behaviour. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
