Files
cppdraft_translate/cppdraft/expr/sub.md
2025-10-25 03:02:53 +03:00

67 lines
3.3 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[expr.sub]
# 7 Expressions [[expr]](./#expr)
## 7.6 Compound expressions [[expr.compound]](expr.compound#expr.sub)
### 7.6.1 Postfix expressions [[expr.post]](expr.post#expr.sub)
#### 7.6.1.2 Subscripting [expr.sub]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L3701)
A [*subscript expression*](#def:expression,subscript "7.6.1.2Subscripting[expr.sub]") is a postfix expression
followed by square brackets containing
a possibly empty, comma-separated list of [*initializer-clause*](dcl.init.general#nt:initializer-clause "9.5.1General[dcl.init.general]")*s* that constitute the arguments to the subscript operator[.](#1.sentence-1)
The [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1General[expr.post.general]") and
the initialization of the object parameter ([[dcl.fct]](dcl.fct "9.3.4.6Functions")) of
any applicable subscript operator function ([[over.sub]](over.sub "12.4.5Subscripting")) is sequenced before
each expression in the [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1General[expr.post.general]") and also before
any default argument ([[dcl.fct.default]](dcl.fct.default "9.3.4.7Default arguments"))[.](#1.sentence-2)
The initialization of a non-object parameter of
a subscript operator function S,
including every associated value computation and side effect,
is indeterminately sequenced with respect to that of
any other non-object parameter of S[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L3719)
With the built-in subscript operator,
an [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1General[expr.post.general]") shall be present,
consisting of a single [*assignment-expression*](expr.assign#nt:assignment-expression "7.6.19Assignment and compound assignment operators[expr.assign]")[.](#2.sentence-1)
One of the expressions shall be a glvalue of type “array ofT” or a prvalue of type “pointer
to T” and the other shall be a prvalue of unscoped enumeration or integral type[.](#2.sentence-2)
The result is of type “€[.](#2.sentence-3)
The type “€ shall be a completely-defined object type[.](#2.sentence-4)[48](#footnote-48 "This is true even if the subscript operator is used in the following common idiom: &x[0].")
The expression E1[E2] is identical (by definition) to*((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[.](#2.sentence-5)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L3739)
[*Note [1](#note-1)*:
Despite its asymmetric appearance, subscripting is a commutative
operation except for sequencing[.](#3.sentence-1)
See [[expr.unary]](expr.unary "7.6.2Unary expressions") and [[expr.add]](expr.add "7.6.6Additive operators") for details of * and+ and [[dcl.array]](dcl.array "9.3.4.5Arrays") for details of array types[.](#3.sentence-2)
— *end note*]
[48)](#footnote-48)[48)](#footnoteref-48)
This
is true even if the subscript operator is used in the following common idiom:&x[0][.](#footnote-48.sentence-1)