Modifying view index results in silent out-of-bound access

It’s undefined behavior. view does a bounds check on the indices when the view (SubArray) is constructed, but thereafter it assumes that the indices don’t change and hence it assumes @inbounds is correct — apparently it reads past the end of the array in this example.

Probably the documentation should have a warning about mutating the indices after a view is constructed. Or possibly the @inbounds should be removed here (to be replaced with @propagate_inbounds so that the caller can still eliminate the bounds check).

2 Likes