Created on 2014-02-15.00:00:00 last changed 95 months ago
[Moved to DR at the November, 2014 meeting.]
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 Tis different from the cv-unqualifiedand 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:
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.
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:
void f() { int i = 0; int* arr[3] = {&i, &i, &i}; int const * const * aptr = arr; assert(aptr[2] == &i); }
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.
History | |||
---|---|---|---|
Date | User | Action | Args |
2017-02-06 00:00:00 | admin | set | status: drwp -> cd4 |
2015-05-25 00:00:00 | admin | set | status: dr -> drwp |
2015-04-13 00:00:00 | admin | set | messages: + msg5347 |
2014-11-24 00:00:00 | admin | set | status: tentatively ready -> dr |
2014-10-13 00:00:00 | admin | set | messages: + msg5132 |
2014-10-13 00:00:00 | admin | set | status: drafting -> tentatively ready |
2014-07-07 00:00:00 | admin | set | status: open -> drafting |
2014-02-15 00:00:00 | admin | create |