diff --git a/base/reinterpretarray.jl b/base/reinterpretarray.jl index d8f786a515d98..06d93d27f7377 100644 --- a/base/reinterpretarray.jl +++ b/base/reinterpretarray.jl @@ -79,6 +79,7 @@ IndexStyle(a::ReinterpretArray) = IndexStyle(a.parent) parent(a::ReinterpretArray) = a.parent dataids(a::ReinterpretArray) = dataids(a.parent) +unaliascopy(a::ReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent)) function size(a::ReinterpretArray{T,N,S} where {N}) where {T,S} psize = size(a.parent) diff --git a/test/reinterpretarray.jl b/test/reinterpretarray.jl index 70899c8b6ee53..d712a8ffa3b47 100644 --- a/test/reinterpretarray.jl +++ b/test/reinterpretarray.jl @@ -161,6 +161,16 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2) @test r == OffsetArray(reshape(1:8, 2, 2, 2), (0, offsetvt...)) end +@testset "potentially aliased copies" begin + buffer = UInt8[1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0] + mid = length(buffer) รท 2 + x1 = reinterpret(Int64, @view buffer[1:mid]) + x2 = reinterpret(Int64, @view buffer[mid+1:end]) + x1 .= x2 + @test x1 == x2 == [2] + @test x1[] === x2[] === Int64(2) +end + # Test 0-dimensional Arrays A = zeros(UInt32) B = reinterpret(Int32,A)