[cfe-dev] (Request for comments) Implicit cast kind for initialization of references.
abramo.bagnara at gmail.com
Mon Oct 24 15:20:17 PDT 2011
Il 24/10/2011 23:50, Johannes Schaub ha scritto:
> Abramo Bagnara wrote:
>> Il 24/10/2011 19:47, Ahmed Charles ha scritto:
>>> a[i] becomes *(a+i), which dereferences the address, i.e. undefined
>>> behavior, in your case.
>> Not without an lvalue to rvalue conversion.
> That may be the ultimate goal of the C++ committee to word into the Standard
> some time in the future, but the current C++11 does not incorporate that
> understanding yet. It leaves undefined the effects of evaluating an lvalue
> referring to nothing. So evaluating *(a+i) is UB *if* there is no object at
> address a+i. Since whether there is an object in this case is unspecified,
> the Standard does not require anything from the implementation - in other
> words, the behavior is undefined.
Note that from C99 times &*E is considered equivalent to E, so starting
from the original
int *p = &a;
we have the following equivalent transformations:
&a => &*(a+5) => a + 5
IMHO following a different line of thought we'd soon come to nonsense.
More information about the cfe-dev