diff --git a/include/proxy/v4/detail/skills.h b/include/proxy/v4/detail/skills.h index adee855..0c64e58 100644 --- a/include/proxy/v4/detail/skills.h +++ b/include/proxy/v4/detail/skills.h @@ -205,7 +205,8 @@ struct proxy_cast_dispatch { if (typeid(T) == *ctx.type_ptr) [[likely]] { if (ctx.is_ref) { if constexpr (std::is_lvalue_reference_v) { - if (ctx.is_const || !std::is_const_v) [[likely]] { + if (ctx.is_const || !std::is_const_v>) + [[likely]] { *static_cast(ctx.result_ptr) = (void*)std::addressof(self); } } diff --git a/tests/proxy_rtti_tests.cpp b/tests/proxy_rtti_tests.cpp index fbfbb95..91d5da7 100644 --- a/tests/proxy_rtti_tests.cpp +++ b/tests/proxy_rtti_tests.cpp @@ -131,6 +131,26 @@ TEST(ProxyRttiTests, TestIndirectCast_ConstPtr_Fail) { ASSERT_EQ(v, 123); } +TEST(ProxyRttiTests, TestIndirectCast_Ref_ConstTarget) { + const auto p = pro::make_proxy(123); + bool exception_thrown = false; + try { + proxy_cast(*p); + } catch (const pro::bad_proxy_cast&) { + exception_thrown = true; + } + ASSERT_TRUE(exception_thrown); + ASSERT_EQ(proxy_cast(*p), 123); +} + +TEST(ProxyRttiTests, TestIndirectCast_Ptr_ConstTarget) { + const auto p = pro::make_proxy(123); + ASSERT_EQ(proxy_cast(&*p), nullptr); + auto ptr = proxy_cast(&*p); + static_assert(std::is_same_v); + ASSERT_EQ(*ptr, 123); +} + TEST(ProxyRttiTests, TestIndirectTypeid) { int a = 123; pro::proxy p = &a;