Title
Non-array objects as array[1]
Status
cd4
Section
7.6.9 [expr.rel]
Submitter
Daniel Krügler

Created on 2012-12-20.00:00:00 last changed 94 months ago

Messages

Date: 2014-11-15.00:00:00

[Moved to DR at the November, 2014 meeting.]

Date: 2013-08-15.00:00:00

Proposed resolution (August, 2013):

  1. Change 7.6.2.2 [expr.unary.op] paragraph 3 as follows:

  2. ...Otherwise, if the type of the expression is T, the result has type “pointer to T” and is a prvalue that is the address of the designated object (6.7.1 [intro.memory]) or a pointer to the designated function. [Note: In particular, the address of an object of type “cv T” is “pointer to cv T”, with the same cv-qualification. —end note] For purposes of pointer arithmetic (7.6.6 [expr.add]) and comparison (7.6.9 [expr.rel], 7.6.10 [expr.eq]), an object that is not an array element whose address is taken in this way is considered to belong to an array with one element of type T. [Example:

      struct A { int i; };
      struct B : A { };
      ... &B::i ...        // has type int A::*
      int a;
      int* p1 = &a;
      int* p2 = p1 + 1;    // Defined behavior
      bool b = p2 > p1;    // Defined behavior, with value true
    

    end example] [Note: a pointer to member...

  3. Delete 7.6.6 [expr.add] paragraph 4:

  4. For the purposes of these operators, a pointer to a nonarray object behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.
  5. Change 7.6.6 [expr.add] paragraph 5 as follows:

  6. When an expression that has integral type is added to or subtracted from a pointer, the result has the type of the pointer operand. If the pointer operand points to an element of an array object [Footnote: An object that is not an array element is considered to belong to a single-element array for this purpose; see 7.6.2.2 [expr.unary.op] —end footnote], and the array is large enough, the result points to an element...
  7. Change 7.6.9 [expr.rel] paragraph 3 as follows:

  8. Comparing pointers to objects [Footnote: An object that is not an array element is considered to belong to a single-element array for this purpose; see 7.6.2.2 [expr.unary.op] —end footnote] is defined as follows:...

[Drafting note: No change is proposed for 7.6.10 [expr.eq], since the comparison is phrased in terms of “same address”, not in terms of array elements, so the handling of one-past-the-end addresses falls out of the specification of pointer arithmetic.]

Date: 2012-12-20.00:00:00

The provision to treat non-array objects as if they were array objects with a bound of 1 is given only for pointer arithmetic in C++ (7.6.6 [expr.add] paragraph 4). C99 supplies similar wording for the relational and equality operators, explicitly allowing pointers resulting from such implicit-array treatment to be compared. C++ should follow suit.

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: + msg5348
2014-11-24 00:00:00adminsetstatus: ready -> dr
2014-03-03 00:00:00adminsetstatus: review -> ready
2013-09-03 00:00:00adminsetmessages: + msg4469
2013-09-03 00:00:00adminsetstatus: drafting -> review
2012-12-20 00:00:00admincreate