Skip to content

Commit

Permalink
Add assertion for proxy_invoke() and proxy_reflect() (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa authored Oct 14, 2024
1 parent 7f35556 commit 52ab85b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef _MSFT_PROXY_
#define _MSFT_PROXY_

#include <cassert>
#include <cstddef>
#include <bit>
#include <concepts>
Expand Down Expand Up @@ -565,12 +566,14 @@ struct meta_ptr_reset_guard {

template <class F>
struct proxy_helper {
static inline const auto& get_meta(const proxy<F>& p) noexcept
{ return *p.meta_.operator->(); }
static inline const auto& get_meta(const proxy<F>& p) noexcept {
assert(p.has_value());
return *p.meta_.operator->();
}
template <class C, class O, qualifier_type Q, class... Args>
static decltype(auto) invoke(add_qualifier_t<proxy<F>, Q> p, Args&&... args) {
auto dispatcher = p.meta_
->template dispatcher_meta<typename overload_traits<O>
auto dispatcher = get_meta(p)
.template dispatcher_meta<typename overload_traits<O>
::template meta_provider<C::is_direct, typename C::dispatch_type>>
::dispatcher;
if constexpr (C::is_direct &&
Expand Down Expand Up @@ -788,9 +791,12 @@ class proxy : public details::facade_traits<F>::direct_accessor {
private:
template <class P, class... Args>
P& initialize(Args&&... args) {
std::construct_at(reinterpret_cast<P*>(ptr_), std::forward<Args>(args)...);
P& result = *std::construct_at(
reinterpret_cast<P*>(ptr_), std::forward<Args>(args)...);
if constexpr (requires { (bool)result; })
{ assert((bool)result); }
meta_ = details::meta_ptr<typename _Traits::meta>{std::in_place_type<P>};
return *std::launder(reinterpret_cast<P*>(ptr_));
return result;
}

[[___PRO_NO_UNIQUE_ADDRESS_ATTRIBUTE]]
Expand Down

0 comments on commit 52ab85b

Please sign in to comment.