Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/proxy/v4/detail/skills.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>) {
if (ctx.is_const || !std::is_const_v<T>) [[likely]] {
if (ctx.is_const || !std::is_const_v<std::remove_reference_t<T>>)
[[likely]] {
*static_cast<void**>(ctx.result_ptr) = (void*)std::addressof(self);
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/proxy_rtti_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ TEST(ProxyRttiTests, TestIndirectCast_ConstPtr_Fail) {
ASSERT_EQ(v, 123);
}

TEST(ProxyRttiTests, TestIndirectCast_Ref_ConstTarget) {
const auto p = pro::make_proxy<detail::TestFacade, int>(123);
bool exception_thrown = false;
try {
proxy_cast<int&>(*p);
} catch (const pro::bad_proxy_cast&) {
exception_thrown = true;
}
ASSERT_TRUE(exception_thrown);
ASSERT_EQ(proxy_cast<const int&>(*p), 123);
}

TEST(ProxyRttiTests, TestIndirectCast_Ptr_ConstTarget) {
const auto p = pro::make_proxy<detail::TestFacade, int>(123);
ASSERT_EQ(proxy_cast<int>(&*p), nullptr);
auto ptr = proxy_cast<const int>(&*p);
static_assert(std::is_same_v<decltype(ptr), const int*>);
ASSERT_EQ(*ptr, 123);
}

TEST(ProxyRttiTests, TestIndirectTypeid) {
int a = 123;
pro::proxy<detail::TestFacade> p = &a;
Expand Down
Loading