From 52ab85be9ec91ee9dbe46161fa8cb987d1702cb6 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Mon, 14 Oct 2024 13:58:20 +0800 Subject: [PATCH] Add assertion for `proxy_invoke()` and `proxy_reflect()` (#175) --- proxy.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/proxy.h b/proxy.h index 92b3556..f54b139 100644 --- a/proxy.h +++ b/proxy.h @@ -4,6 +4,7 @@ #ifndef _MSFT_PROXY_ #define _MSFT_PROXY_ +#include #include #include #include @@ -565,12 +566,14 @@ struct meta_ptr_reset_guard { template struct proxy_helper { - static inline const auto& get_meta(const proxy& p) noexcept - { return *p.meta_.operator->(); } + static inline const auto& get_meta(const proxy& p) noexcept { + assert(p.has_value()); + return *p.meta_.operator->(); + } template static decltype(auto) invoke(add_qualifier_t, Q> p, Args&&... args) { - auto dispatcher = p.meta_ - ->template dispatcher_meta + auto dispatcher = get_meta(p) + .template dispatcher_meta ::template meta_provider> ::dispatcher; if constexpr (C::is_direct && @@ -788,9 +791,12 @@ class proxy : public details::facade_traits::direct_accessor { private: template P& initialize(Args&&... args) { - std::construct_at(reinterpret_cast(ptr_), std::forward(args)...); + P& result = *std::construct_at( + reinterpret_cast(ptr_), std::forward(args)...); + if constexpr (requires { (bool)result; }) + { assert((bool)result); } meta_ = details::meta_ptr{std::in_place_type

}; - return *std::launder(reinterpret_cast(ptr_)); + return result; } [[___PRO_NO_UNIQUE_ADDRESS_ATTRIBUTE]]