Proposed Resolution (July, 2014): Change 7.6.6 [expr.add] paragraph 7 as follows:
For addition or subtraction, if the expressions P
or Q have type “pointer
to cv T ”, where T
is
different from the cv-unqualified and the
array element type are not similar
(7.3.6 [conv.qual]), the behavior is
undefined. [Note: In particular, a pointer to a base
class cannot be used for pointer arithmetic when the array
contains objects of a derived class type. —end
note]
The resolution of issue 1504 added
7.6.6 [expr.add] paragraph 7: This wording was intended to address derived-base conversion in pointer
arithmetic, but it inadvertently categorized as undefined behavior
previously well-defined pointer arithmetic on pointers that are the result
of multi-level qualification conversions. For example: This now has undefined behavior because the type of *aptr is
“pointer to const int ,” which is different from the
cv-unqualified array element type, “pointer
to int .” See also
issue 330.
For addition or subtraction, if the expressions P or Q
have type “pointer to cv T ”, where T
is different from the cv-unqualified array element type, the behavior is
undefined.
void f() {
int i = 0;
int* arr[3] = {&i, &i, &i};
int const * const * aptr = arr;
assert(aptr[2] == &i);
}