wg21.cmeerw.net

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:

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:00adminsetstatus: drwp -> cd4 2015-05-25 00:00:00adminsetstatus: dr -> drwp 2015-04-13 00:00:00adminsetmessages: + msg5347 2014-11-24 00:00:00adminsetstatus: tentatively ready -> dr 2014-10-13 00:00:00adminsetmessages: + msg5132 2014-10-13 00:00:00adminsetstatus: drafting -> tentatively ready 2014-07-07 00:00:00adminsetstatus: open -> drafting 2014-02-15 00:00:00admincreate

Read the original on wg21.cmeerw.net ↗