Skip to content

Commit 8cade94

Browse files
authored
Merge pull request #4283 from ntrel/index-fmt
[spec] Tweak array indexing expression docs & mention array bounds checks
2 parents 58263cd + 63ac525 commit 8cade94

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
@@ -1871,22 +1871,22 @@ $(GNAME IndexOperation):
18711871
$(I ArgumentList) and `$` appears in that scope only.
18721872
)
18731873

1874-
$(P If the $(I PostfixExpression) is an expression of static or
1874+
* If the $(I PostfixExpression) is an expression of static or
18751875
dynamic array type, the result of the indexing is an lvalue
18761876
of the *i*th element in the array, where `i` is an integer
18771877
evaluated from $(I ArgumentList).
1878-
If $(I PostfixExpression) is a pointer `p`, the result is
1878+
See $(DDSUBLINK spec/arrays, indexing, array indexing).
1879+
1880+
* If $(I PostfixExpression) is a $(DDSUBLINK spec/type, pointers, pointer) `p`, the result is
18791881
`*(p + i)` (see $(RELATIVE_LINK2 pointer_arithmetic, Pointer Arithmetic)).
1880-
)
18811882

1882-
$(P If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
1883+
* If the base $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
18831884
then the $(I ArgumentList) must consist of only one argument,
18841885
and that must be statically evaluatable to an integral constant.
18851886
That integral constant $(I n) then selects the $(I n)th
18861887
expression in the $(I ValueSeq), which is the result
18871888
of the $(I IndexOperation).
18881889
It is an error if $(I n) is out of bounds of the $(I ValueSeq).
1889-
)
18901890

18911891
$(P The index operator can be $(DDSUBLINK spec/operatoroverloading, array, overloaded).
18921892
Using multiple indices in *ArgumentList* is only supported for operator
@@ -1920,6 +1920,7 @@ $(GNAME Slice):
19201920
referencing elements `a[i]` to `a[j-1]` inclusive, where `i`
19211921
and `j` are integers evaluated from the first and second $(I
19221922
AssignExpression) respectively.
1923+
See $(DDSUBLINK spec/arrays, slicing, array slicing).
19231924

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

0 commit comments

Comments
 (0)