Skip to content

Commit 78af2e2

Browse files
jensmaurerzygoloid
authored andcommitted
[dcl.array,expr.sub] Consolidate notes on symmetry of array subscripting.
1 parent c9d19d1 commit 78af2e2

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

source/declarators.tex

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,31 +1183,8 @@
11831183

11841184
\pnum
11851185
\begin{note}
1186-
Except where it has been declared for a class\iref{over.sub},
1187-
the subscript operator
1188-
\tcode{[]}
1189-
is interpreted
1190-
in such a way that
1191-
\tcode{E1[E2]}
1192-
is identical to
1193-
\tcode{*((E1)+(E2))}\iref{expr.sub}.
1194-
Because of the conversion rules
1195-
that apply to
1196-
\tcode{+},
1197-
if
1198-
\tcode{E1}
1199-
is an array and
1200-
\tcode{E2}
1201-
an integer,
1202-
then
1203-
\tcode{E1[E2]}
1204-
refers to the
1205-
\tcode{E2}-th
1206-
member of
1207-
\tcode{E1}.
1208-
Therefore,
1209-
despite its asymmetric
1210-
appearance, subscripting is a commutative operation.
1186+
The subscript operator can be overloaded for a class\iref{over.sub}.
1187+
For the operator's built-in meaning, see \ref{expr.sub}.
12111188
\end{note}
12121189

12131190
\rSec2[dcl.fct]{Functions}%

source/expressions.tex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,14 +2145,19 @@
21452145
is true even if the subscript operator is used in the following common idiom:
21462146
\tcode{\&x[0]}.}
21472147
The expression \tcode{E1[E2]} is identical (by definition) to
2148-
\tcode{*((E1)+(E2))}
2149-
\begin{note}
2150-
see~\ref{expr.unary} and~\ref{expr.add} for details of \tcode{*} and
2151-
\tcode{+} and~\ref{dcl.array} for details of arrays.
2152-
\end{note}, except that in the case of an array operand, the result is an lvalue
2148+
\tcode{*((E1)+(E2))},
2149+
except that in the case of an array operand, the result is an lvalue
21532150
if that operand is an lvalue and an xvalue otherwise.
21542151
The expression \tcode{E1} is sequenced before the expression \tcode{E2}.
21552152

2153+
\pnum
2154+
\begin{note}
2155+
Despite its asymmetric appearance, subscripting is a commutative
2156+
operation except for sequencing.
2157+
See~\ref{expr.unary} and~\ref{expr.add} for details of \tcode{*} and
2158+
\tcode{+} and~\ref{dcl.array} for details of array types.
2159+
\end{note}
2160+
21562161
\pnum
21572162
A \grammarterm{braced-init-list} shall not be used with the built-in subscript operator.
21582163

0 commit comments

Comments
 (0)