diff --git a/base/broadcast.jl b/base/broadcast.jl index 48bc79868dec8..da0ce8bd0c733 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -140,7 +140,8 @@ end # extract array values @nexprs $nargs i->(@inbounds val_i = _broadcast_getindex(A_i, I_i)) # call the function and store the result - @inbounds B[I] = @ncall $nargs f val + result = @ncall $nargs f val + @inbounds B[I] = result end end end diff --git a/test/boundscheck_exec.jl b/test/boundscheck_exec.jl index daf602c91c06e..95509cff93eaf 100644 --- a/test/boundscheck_exec.jl +++ b/test/boundscheck_exec.jl @@ -174,4 +174,11 @@ if bc_opt != bc_off @test_throws BoundsError k1(Int[]) end +# Ensure that broadcast doesn't use @inbounds when calling the function +if bc_opt != bc_off + let A = zeros(3,3) + @test_throws BoundsError broadcast(getindex, A, 1:3, 1:3) + end +end + end