diff --git a/src/CxxWrap.jl b/src/CxxWrap.jl index 1463d4b..d550029 100644 --- a/src/CxxWrap.jl +++ b/src/CxxWrap.jl @@ -498,12 +498,12 @@ function ptrunion(::Type{T}) where {T} return result end -valuetype(t::Type) = valuetype(cpp_trait_type(t), t) +valuetype(t::Type) = valuetype(Base.invokelatest(cpp_trait_type,t), t) valuetype(::Type{IsNormalType}, ::Type{T}) where {T} = T function valuetype(::Type{IsCxxType}, ::Type{T}) where {T} ST = supertype(T) - if T == allocated_type(ST) - return ST + if T == Base.invokelatest(allocated_type,ST) # Case of a C++ by-value argument + return Union{ST, CxxRef{ST}, ConstCxxRef{ST}} end return T end @@ -512,7 +512,7 @@ function valuetype(::Type{<:SmartPointer{T}}) where {T} return result end -map_julia_arg_type(t::Type) = Union{Base.invokelatest(valuetype,t),argument_overloads(t)...} +map_julia_arg_type(t::Type) = Union{valuetype(t), argument_overloads(t)...} map_julia_arg_type(a::Type{StrictlyTypedNumber{T}}) where {T} = T map_julia_arg_type(a::Type{StrictlyTypedNumber{CxxBool}}) = Union{Bool,CxxBool} map_julia_arg_type(x::Type{CxxBool}) = Union{Bool,CxxBool} @@ -684,7 +684,7 @@ function wrap_reference_converters(julia_mod) Core.eval(julia_mod, :($(@__MODULE__).dereferenced_type(::Type{$st}) = $reftype)) Core.eval(julia_mod, :(Base.convert(::Type{$st}, x::$bt) = x)) Core.eval(julia_mod, :(Base.convert(::Type{$st}, x::$reftype) = x)) - Core.eval(julia_mod, :(Base.cconvert(::Type{$reftype}, x::$bt) = $reftype(x.cpp_object))) + Core.eval(julia_mod, :(Base.cconvert(::Type{$reftype}, x::Union{CxxRef{<:$st},ConstCxxRef{<:$st},$bt}) = $reftype(x.cpp_object))) Core.eval(julia_mod, :(Base.unsafe_convert(::Type{$reftype}, x::$st) = $reftype(x.cpp_object))) Core.eval(julia_mod, :(Base.:(==)(a::Union{CxxRef{<:$st},ConstCxxRef{<:$st},$bt}, b::$reftype) = (a.cpp_object == b.cpp_object))) Core.eval(julia_mod, :(Base.:(==)(a::$reftype, b::Union{CxxRef{<:$st},ConstCxxRef{<:$st},$bt}) = (b == a))) diff --git a/test/types.jl b/test/types.jl index 52261bc..3464b8c 100644 --- a/test/types.jl +++ b/test/types.jl @@ -135,16 +135,17 @@ if CxxWrap.libcxxwrapversion() > v"0.9.4" wp = CxxPtr(w) wcp = ConstCxxPtr(w) @test CppTypes.greet_byvalue(w) == "hello" - @test CppTypes.greet_byvalue(wr[]) == "hello" - @test CppTypes.greet_overload(w) == "hello_byval" + @test CppTypes.greet_byvalue(wr) == "hello" + @test CppTypes.greet_byvalue(wcr) == "hello" + @test CppTypes.greet_overload(w) == "hello_byref" @test CppTypes.greet_overload(wr) == "hello_byref" - @test CppTypes.greet_overload(wr[]) == "hello_byval" + @test CppTypes.greet_overload(wr[]) == "hello_byref" @test CppTypes.greet_overload(wcr) == "hello_byconstref" - @test CppTypes.greet_overload(wcr[]) == "hello_byval" + @test CppTypes.greet_overload(wcr[]) == "hello_byref" @test CppTypes.greet_overload(wp) == "hello_bypointer" - @test CppTypes.greet_overload(wp[]) == "hello_byval" + @test CppTypes.greet_overload(wp[]) == "hello_byref" @test CppTypes.greet_overload(wcp) == "hello_byconstpointer" - @test CppTypes.greet_overload(wcp[]) == "hello_byval" + @test CppTypes.greet_overload(wcp[]) == "hello_byref" @test CppTypes.greet_overload(swf) == "shared factory hello_bysharedptr" end