Skip to content

Commit 63ac525

Browse files
committed
[spec/expression] Improve array indexing docs
Make array.dd indexing/slicing sections mention bounds checks. Similar to #4282, use list for kinds of base expression to index. Link to array indexing/slicing.
1 parent d8e6268 commit 63ac525

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spec/arrays.dd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ assert(b[1] == 2);
237237
---------
238238
)
239239

240+
$(P Dynamic and static array indexing is $(RELATIVE_LINK2 bounds, bounds checked)
241+
by default.)
242+
240243
$(P See also $(GLINK2 expression, IndexOperation).)
241244

242245
$(H3 $(LNAME2 pointer-arithmetic, Pointer Arithmetic))
@@ -293,6 +296,9 @@ assert(b == [3]);
293296
---------
294297
)
295298

299+
$(P Each index in the slice expression is $(RELATIVE_LINK2 bounds, bounds checked)
300+
by default.)
301+
296302
$(P $(I Expression)`[]` is shorthand for a slice of the entire array.
297303
)
298304

spec/expression.dd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,22 +1858,22 @@ $(GNAME IndexOperation):
18581858
$(I ArgumentList) and `$` appears in that scope only.
18591859
)
18601860

1861-
$(P If the $(I PostfixExpression) is an expression of static or
1861+
* If the $(I PostfixExpression) is an expression of static or
18621862
dynamic array type, the result of the indexing is an lvalue
18631863
of the *i*th element in the array, where `i` is an integer
18641864
evaluated from $(I ArgumentList).
1865-
If $(I PostfixExpression) is a pointer `p`, the result is
1865+
See $(DDSUBLINK spec/arrays, indexing, array indexing).
1866+
1867+
* If $(I PostfixExpression) is a $(DDSUBLINK spec/type, pointers, pointer) `p`, the result is
18661868
`*(p + i)` (see $(RELATIVE_LINK2 pointer_arithmetic, Pointer Arithmetic)).
1867-
)
18681869

1869-
$(P If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
1870+
* If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
18701871
then the $(I ArgumentList) must consist of only one argument,
18711872
and that must be statically evaluatable to an integral constant.
18721873
That integral constant $(I n) then selects the $(I n)th
18731874
expression in the $(I ValueSeq), which is the result
18741875
of the $(I IndexOperation).
18751876
It is an error if $(I n) is out of bounds of the $(I ValueSeq).
1876-
)
18771877

18781878
$(P The index operator can be $(DDSUBLINK spec/operatoroverloading, array, overloaded).
18791879
Using multiple indices in *ArgumentList* is only supported for operator
@@ -1907,6 +1907,7 @@ $(GNAME Slice):
19071907
referencing elements `a[i]` to `a[j-1]` inclusive, where `i`
19081908
and `j` are integers evaluated from the first and second $(I
19091909
AssignExpression) respectively.
1910+
See $(DDSUBLINK spec/arrays, slicing, array slicing).
19101911

19111912
* If the base $(I PostfixExpression) is a $(DDSUBLINK spec/type, pointers, pointer) `p`, the result
19121913
will be a dynamic array referencing elements from `p[i]` to `p[j-1]`

0 commit comments

Comments
 (0)