From c4e3b1fcdc3d425ac21669823031c080bb1c7b92 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Mon, 24 Apr 2017 14:30:19 -0400 Subject: [PATCH] default zero-initialize RefValues of numeric types --- base/refpointer.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/refpointer.jl b/base/refpointer.jl index a63b5b7c468ce..def9e1750980c 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -38,8 +38,10 @@ unsafe_convert(::Type{Ref{T}}, x) where {T} = unsafe_convert(Ptr{T}, x) mutable struct RefValue{T} <: Ref{T} x::T - RefValue{T}() where {T} = new() RefValue{T}(x) where {T} = new(x) + RefValue{T}() where {T} = new() + RefValue{T}() where {T<:Ptr} = new(C_NULL) + RefValue{T}() where {T<:Number} = isbits(T) ? new(zero(T)) : new() end RefValue{T}(x::T) = RefValue{T}(x) isassigned(x::RefValue) = isdefined(x, :x)