Array subscripting and xvalues
8.2.1 [expr.sub]
Jason Merrill

Created on 2010-10-24.00:00:00 last changed 75 months ago


Date: 2013-04-15.00:00:00

[Moved to DR status at the April, 2013 meeting.]

Date: 2013-01-15.00:00:00

Additional note (January, 2013):

The preceding resolution differs from that discussed in the December, 2012 drafting review teleconference by the deletion of the words “an lvalue” in the second sentence. The issue has consequently been moved to "review" status instead of "tentatively ready."

Date: 2012-12-15.00:00:00

Proposed resolution (December, 2012):

Change 8.2.1 [expr.sub] paragraph 1 as follows:

A postfix expression followed by an expression in square brackets is a postfix expression. One of the expressions shall have the type “array of T” or “pointer to T” and the other shall have unscoped enumeration or integral type. The result is an lvalue of type “T.” The type “T” shall be a completely-defined object type.62 The expression E1[E2] is identical (by definition) to *((E1)+(E2)) [Note: see 8.3 [expr.unary] and 8.7 [expr.add] for details of * and + and 11.3.4 [dcl.array] for details of arrays. —end note], except that in the case of an array operand, the result is an lvalue if that operand is an lvalue and an xvalue otherwise.

(See also issue 616.)

Date: 2010-10-24.00:00:00

Because the subscripting operation is defined as indirection through a pointer value, the result of a subscript operator applied to an xvalue array is an lvalue, not an xvalue. This could be surprising to some.

Date User Action Args
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-10-14 00:00:00adminsetstatus: dr -> drwp
2013-05-03 00:00:00adminsetmessages: + msg4381
2013-05-03 00:00:00adminsetstatus: review -> dr
2013-01-14 00:00:00adminsetmessages: + msg4199
2013-01-14 00:00:00adminsetmessages: + msg4198
2013-01-14 00:00:00adminsetstatus: drafting -> review
2012-11-03 00:00:00adminsetstatus: open -> drafting
2010-10-24 00:00:00admincreate