Title
Evaluation order for subscripting
Status
cd6
Section
7.6.1.2 [expr.sub]
Submitter
Corentin Jabot

Created on 2022-04-21.00:00:00 last changed 27 months ago

Messages

Date: 2022-07-15.19:32:32

Proposed resolution (2022-06-24, amended 2022-07-15, approved by CWG 2022-07-15):

Change in 7.6.1.2 [expr.sub] paragraph 1 as follows:

A subscript expression is a postfix expression followed by square brackets containing a possibly empty, comma-separated list of initializer-clauses which that constitute the arguments to the subscript operator. The postfix-expression and the initialization of the object parameter of any applicable subscript operator function is sequenced before each expression in the expression-list and also before any default argument. The initialization of a non-object parameter of a subscript operator function S (12.4.5 [over.sub]), including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other non-object parameter of S.
Date: 2022-06-24.21:34:44

Notes from the 2022-06-03 CWG telecon:

Repeating the function call rules for the subscript operator in 7.6.1.2 [expr.sub] instead would be preferred, to avoid any impression of a special case.

Date: 2022-06-05.09:03:57

Notes from the 2022-05-20 CWG telecon:

A wording approach amending 12.2.2.3 [over.match.oper] paragraph 2 instead would be preferred.

Possible resolution (2022-05-21): [SUPERSEDED]

Change in 12.2.2.3 [over.match.oper] paragraph 2 as follows:

Therefore, the operator notation is first transformed to the equivalent function-call notation as summarized in Table 17 (where @ denotes one of the operators covered in the specified subclause). However, except for the subscript operator (7.6.1.2 [expr.sub]), the operands are sequenced in the order prescribed for the built-in operator (7.6 [expr.compound]).
Date: 2022-06-05.09:03:57

Suggested resolution: [SUPERSEDED]

Add a new paragraph 4 at the end of 7.6.1.2 [expr.sub]:

If the subscript operator invokes an operator function, the sequencing restrictions of the corresponding function call expression apply (12.4.5 [over.sub], 7.6.1.3 [expr.call]).
Date: 2022-07-15.00:00:00

[Accepted at the July, 2022 meeting.]

The specification about the relative sequencing of multiple parameters of the subscripting operator is missing. Also, issue 2507 adds support for default arguments for user-defined subscripting operators, but the sequencing of these is unspecified, too.

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: ready -> cd6
2022-07-15 19:32:32adminsetstatus: open -> ready
2022-06-24 21:34:44adminsetmessages: + msg6869
2022-06-05 09:03:57adminsetmessages: + msg6843
2022-06-05 09:03:57adminsetmessages: + msg6842
2022-04-21 13:41:07adminsetmessages: + msg6806
2022-04-21 00:00:00admincreate