diff --git a/source/compatibility.tex b/source/compatibility.tex index f62d7182fe..eab16c0e68 100644 --- a/source/compatibility.tex +++ b/source/compatibility.tex @@ -40,6 +40,21 @@ \end{codeblock} \end{example} +\rSec2[diff.cpp20.expr]{\ref{expr}: expressions} + +\diffref{expr.sub} +\change +Change the meaning of comma in subscript expressions. +\rationale +Enable repurposing a deprecated syntax to support multidimensional indexing. +\effect +Valid \CppXX{} code that uses a comma expression within a +subscript expression may fail to compile. For example: +\begin{codeblock} +arr[1, 2] // was equivalent to \tcode{arr[(1, 2)]}, + // now equivalent to \tcode{arr.operator[](1, 2)} or ill-formed +\end{codeblock} + \rSec2[diff.cpp20.utilities]{\ref{utilities}: general utilities library} \diffref{format} diff --git a/source/expressions.tex b/source/expressions.tex index 8e94a9c0de..4dfce6de52 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -2982,7 +2982,7 @@ \begin{bnf} \nontermdef{postfix-expression}\br primary-expression\br - postfix-expression \terminal{[} expr-or-braced-init-list \terminal{]}\br + postfix-expression \terminal{[} \opt{expression-list} \terminal{]}\br postfix-expression \terminal{(} \opt{expression-list} \terminal{)}\br simple-type-specifier \terminal{(} \opt{expression-list} \terminal{)}\br typename-specifier \terminal{(} \opt{expression-list} \terminal{)}\br @@ -3020,8 +3020,18 @@ \pnum \indextext{operator!subscripting}% \indextext{\idxcode{[]}|see{operator, subscripting}}% -A postfix expression followed by an expression in square brackets is a -postfix expression. One of the expressions shall be a glvalue of type ``array of +A \defnadj{subscript}{expression} is a postfix expression +followed by square brackets containing +a possibly empty, comma-separated list of \grammarterm{initializer-clause}s +which constitute the arguments to the subscript operator. +The \grammarterm{postfix-expression} is sequenced before +each expression in the \grammarterm{expression-list}. + +\pnum +With the built-in subscript operator, +an \grammarterm{expression-list} shall be present, +consisting of a single \grammarterm{assignment-expression}. +One of the expressions shall be a glvalue of type ``array of \tcode{T}'' or a prvalue of type ``pointer to \tcode{T}'' and the other shall be a prvalue of unscoped enumeration or integral type. The result is of type ``\tcode{T}''. @@ -3036,13 +3046,6 @@ \tcode{*((E1)+(E2))}, except that in the case of an array operand, the result is an lvalue if that operand is an lvalue and an xvalue otherwise. -The expression \tcode{E1} is sequenced before the expression \tcode{E2}. - -\pnum -A comma expression\iref{expr.comma} -appearing as the \grammarterm{expr-or-braced-init-list} -of a subscripting expression is deprecated; -see \ref{depr.comma.subscript}. \pnum \begin{note} @@ -3052,9 +3055,6 @@ \tcode{+} and~\ref{dcl.array} for details of array types. \end{note} -\pnum -A \grammarterm{braced-init-list} shall not be used with the built-in subscript operator. - \rSec3[expr.call]{Function call} \pnum @@ -7067,7 +7067,9 @@ \pnum \begin{note} In contexts where the comma token is given special meaning -(e.g. function calls\iref{expr.call}, lists of initializers\iref{dcl.init}, +(e.g. function calls\iref{expr.call}, +subscript expressions\iref{expr.sub}, +lists of initializers\iref{dcl.init}, or \grammarterm{template-argument-list}{s}\iref{temp.names}), the comma operator as described in this subclause can appear only in parentheses. \begin{example} @@ -7079,14 +7081,6 @@ \end{example} \end{note} -\pnum -\begin{note} -A comma expression -appearing as the \grammarterm{expr-or-braced-init-list} -of a subscripting expression\iref{expr.sub} is deprecated; -see \ref{depr.comma.subscript}. -\end{note} - \rSec1[expr.const]{Constant expressions}% \indextext{expression!constant} diff --git a/source/future.tex b/source/future.tex index 4a49f9986b..52de1a6d20 100644 --- a/source/future.tex +++ b/source/future.tex @@ -58,24 +58,6 @@ \end{codeblock} \end{example} -\rSec1[depr.comma.subscript]{Comma operator in subscript expressions} - -\pnum -A comma expression\iref{expr.comma} -appearing as the \grammarterm{expr-or-braced-init-list} -of a subscripting expression\iref{expr.sub} is deprecated. -\begin{note} -A parenthesized comma expression is not deprecated. -\end{note} -\begin{example} -\begin{codeblock} -void f(int *a, int b, int c) { - a[b,c]; // deprecated - a[(b,c)]; // OK -} -\end{codeblock} -\end{example} - \rSec1[depr.array.comp]{Array comparisons} \pnum diff --git a/source/overloading.tex b/source/overloading.tex index e5a980808e..9628d1d6aa 100644 --- a/source/overloading.tex +++ b/source/overloading.tex @@ -3297,17 +3297,17 @@ \pnum A \defnadj{subscripting}{operator function} is a function named \tcode{\keyword{operator}[]} -that is a non-static member function with exactly one non-object parameter. +that is a non-static member function. For an expression of the form \begin{ncsimplebnf} -postfix-expression \terminal{[} expr-or-braced-init-list \terminal{]} +postfix-expression \terminal{[} \opt{expression-list} \terminal{]} \end{ncsimplebnf} the operator function is selected by overload resolution\iref{over.match.oper}. If a member function is selected, the expression is interpreted as \begin{ncsimplebnf} -postfix-expression . \keyword{operator} \terminal{[}\terminal{]} \terminal{(} expr-or-braced-init-list \terminal{)} +postfix-expression . \keyword{operator} \terminal{[}\terminal{]} \terminal{(} \opt{expression-list} \terminal{)} \end{ncsimplebnf} \pnum @@ -3315,11 +3315,14 @@ \begin{codeblock} struct X { Z operator[](std::initializer_list); + Z oeprator[](auto...); }; X x; -x[{1,2,3}] = 7; // OK: meaning \tcode{x.\keyword{operator}[](\{1,2,3\})} +x[{1,2,3}] = 7; // OK, meaning \tcode{x.\keyword{operator}[](\{1,2,3\})} +x[1,2,3] = 7; // OK, meaning \tcode{x.\keyword{operator}[](1,2,3)} int a[10]; a[{1,2,3}] = 7; // error: built-in subscript operator +a[1,2,3] = 7; // error: built-in subscript operator \end{codeblock} \end{example} diff --git a/source/preprocessor.tex b/source/preprocessor.tex index ba19bded34..e87ba67cae 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -1777,6 +1777,7 @@ \defnxname{cpp_inline_variables} & \tcode{201606L} \\ \rowsep \defnxname{cpp_lambdas} & \tcode{200907L} \\ \rowsep \defnxname{cpp_modules} & \tcode{201907L} \\ \rowsep +\defnxname{cpp_multidimensional_subscript} & \tcode{202110L} \\ \rowsep \defnxname{cpp_namespace_attributes} & \tcode{201411L} \\ \rowsep \defnxname{cpp_noexcept_function_type} & \tcode{201510L} \\ \rowsep \defnxname{cpp_nontype_template_args} & \tcode{201911L} \\ \rowsep diff --git a/source/xrefdelta.tex b/source/xrefdelta.tex index f36e221fa7..42363268d8 100644 --- a/source/xrefdelta.tex +++ b/source/xrefdelta.tex @@ -69,5 +69,8 @@ \movedxref{range.split.outer.value}{range.lazy.split.outer.value} \movedxref{range.split.inner}{range.lazy.split.inner} +% P2128R6 Multidimensional subscript operator +\removedxref{depr.comma.subscript} + % Deprecated features. %\deprxref{old.label} (if moved to depr.old.label, otherwise use \movedxref)