[Issue 10763] (&x)[0 .. 1] doesn't work in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 12 19:01:51 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10763



--- Comment #4 from timon.gehr at gmx.ch 2013-08-12 19:01:50 PDT ---
(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.

> 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. Furthermore, I don't see what the restriction buys in
terms of implementation effort. Every program can be rewritten to only contain
arrays.

> And there's annoying things like:
> 
> // global scope
> int x;
> int *p = &x + 1; // points to junk! - must not compile
> 

Agreed, but I think this is not closely related. DMD already allows creating
invalid addresses in CTFE by other means.

> 
> Is there really a use case for this unsafe behaviour?

Make more code CTFE-able.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list