From 4cddfb24bf507980703b76a2446e0ab9338e9852 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Fri, 20 Nov 2026 21:48:26 +0800 Subject: [PATCH] Work around an MSVC 19.52 bug in the generated invocation functions - Moved the generated function of each signature from a lambda variable template inside signature_traits_impl to a namespace-scope variable template, because MSVC 19.52 fails to convert the lambda to a function pointer from the second specialization of a member variable template on when its parameters expand the enclosing class template's pack (C2440). The member variable template now copies the closure, so each specialization keeps its own closure type and the call sites are unchanged. - Replaced signature_traits_impl::pointer_type with erased_ptr_t so the namespace-scope variable template can name the erased pointer type. --- include/proxy/v5/detail/core.h | 62 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/include/proxy/v5/detail/core.h b/include/proxy/v5/detail/core.h index 59fcd3cd..29ef3ea7 100644 --- a/include/proxy/v5/detail/core.h +++ b/include/proxy/v5/detail/core.h @@ -362,42 +362,48 @@ struct destroying_guard { struct relocate_dispatch; +template +using erased_ptr_t = std::conditional_t; +template +constexpr auto invocation_function = + [](erased_ptr_t ptr, Args... args) noexcept(NE) -> R { + auto* self = std::launder( + static_cast>*>(ptr)); + if constexpr (std::is_same_v) { + [self](void* rhs) { + if constexpr (is_bitwise_trivially_relocatable_v

) { + if constexpr (!std::is_empty_v

) { + std::uninitialized_copy_n(reinterpret_cast(self), + sizeof(P), static_cast(rhs)); + } + } else { + destroying_guard

guard{self}; + std::construct_at(static_cast(rhs), std::move(*self)); + } + }(args...); + } else if constexpr (Q == qualifier_type::rv) { + destroying_guard

guard{self}; + return invoke_dispatch(get_operand(self), + std::forward(args)...); + } else { + return invoke_dispatch(get_operand(self), + std::forward(args)...); + } +}; + template struct signature_traits : inapplicable_traits {}; template struct signature_traits_impl : applicable_traits { using return_type = R; - using pointer_type = std::conditional_t; - using function_type = R(pointer_type, Args...) noexcept(NE); + using function_type = R(erased_ptr_t, Args...) noexcept(NE); template static constexpr auto invoke = - [](pointer_type ptr, Args... args) noexcept(NE) -> R { - auto* self = std::launder( - static_cast>*>(ptr)); - if constexpr (std::is_same_v) { - [self](void* rhs) { - if constexpr (is_bitwise_trivially_relocatable_v

) { - if constexpr (!std::is_empty_v

) { - std::uninitialized_copy_n(reinterpret_cast(self), - sizeof(P), static_cast(rhs)); - } - } else { - destroying_guard

guard{self}; - std::construct_at(static_cast(rhs), std::move(*self)); - } - }(args...); - } else if constexpr (Q == qualifier_type::rv) { - destroying_guard

guard{self}; - return invoke_dispatch(get_operand(self), - std::forward(args)...); - } else { - return invoke_dispatch(get_operand(self), - std::forward(args)...); - } - }; + invocation_function; static constexpr qualifier_type this_qualifier = Q; template