This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-10-26
[Moved to DR at the November, 2014 meeting.]
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.
Proposed resolution (August, 2013):
Change 7.6.2.2 [expr.unary.op] paragraph 3 as follows:
...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...
Delete 7.6.6 [expr.add] paragraph 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.
Change 7.6.6 [expr.add] paragraph 5 as follows:
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...
Change 7.6.9 [expr.rel] paragraph 3 as follows:
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.]