Skip to content

Commit 857e017

Browse files
Document changing view indices after construction as undefined behavior. (#59591)
Refs: https://discourse.julialang.org/t/is-it-defined-behavior-to-modify-iter-while-for-looping-over-it/132477/11?u=gunnarfarneback ``` julia> v = collect(1:7); julia> i = collect(1:7); julia> w = view(v, i); julia> i[end] = 0; julia> w[end] 128974949945120 # random value or segfault possible ```
1 parent 0c8768f commit 857e017

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

base/subarray.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ Calling [`getindex`](@ref) or [`setindex!`](@ref) on the returned value
173173
(often a [`SubArray`](@ref)) computes the indices to access or modify the
174174
parent array on the fly. The behavior is undefined if the shape of the parent array is
175175
changed after `view` is called because there is no bound check for the parent array; e.g.,
176-
it may cause a segmentation fault.
176+
it may cause a segmentation fault. It is likewise undefined behavior to modify the `inds`
177+
array(s) after construction of the view.
177178
178179
Some immutable parent arrays (like ranges) may choose to simply
179180
recompute a new array in some circumstances instead of returning

0 commit comments

Comments
 (0)