From 701e40421f83a28bb179c99d440f5c4037313fe7 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 13:12:51 -0300 Subject: [PATCH] trystero: handler's operation tables hold static member functions, not lambdas, since MSVC 14.52 converts no lambda whose parameters expand Args to a function pointer once a signature has a second target type MSVC 14.52.37025, which the CI's windows-2025-vs2026 image brought in place of 14.51.36231, refuses a handler of a signature with parameters as soon as operations_of is instantiated for a second target type of that signature (C2440, "no user-defined-conversion operator available" from the invoke lambda to R (*)(unsigned char*, Args&&...)), which every unit of trystero's detail does. The two tables are now inline_operations and allocated_operations, whose static member functions do what the lambdas did; an inline target's rehome is its move. --- doc/changelog.adoc | 4 +- include/webcpp/trystero/handler.hpp | 139 +++++++++++++++------------- 2 files changed, 78 insertions(+), 65 deletions(-) diff --git a/doc/changelog.adoc b/doc/changelog.adoc index 49c3753..0221c2d 100644 --- a/doc/changelog.adoc +++ b/doc/changelog.adoc @@ -37,8 +37,8 @@ removing `json::parse` and `make_id`; `append_string` returns its error, and `webcpp-secp256k1-tables` for its tables and no `-sSECP256K1_ROOT`, and `app::join` to `+[[nodiscard]]+`. * Fixed relays hiding a genuine Nostr event, slowing rooms with colliding ids -or making them read an 8 MiB refusal, and rooms dropping or piling up -simultaneous offers. +or making them read 8 MiB refusals, rooms dropping or piling up simultaneous +offers, and MSVC 14.52 builds. * Added `room_options::max_json_document_bytes` for a received JSON payload; every JSON text is read in the room's resource within bounds, and a self id not UTF-8 is replaced by a random one. diff --git a/include/webcpp/trystero/handler.hpp b/include/webcpp/trystero/handler.hpp index 329c25f..39c7ea4 100644 --- a/include/webcpp/trystero/handler.hpp +++ b/include/webcpp/trystero/handler.hpp @@ -269,71 +269,84 @@ class handler { return *std::launder(reinterpret_cast(storage)); } - // A target is destroyed with std::destroy_at: MSVC 14.3 and 14.5 refuse `p->~T()` in these - // functions when T is a closure type (C2300, "class does not have a destructor called '~T'"). + // The functions of the two tables below are static member functions, never lambdas: once a + // handler of one signature has a second target type, MSVC 14.52 converts to a function pointer + // no lambda of the table whose parameters expand Args (C2440, "no user-defined-conversion + // operator available"). A target is destroyed with std::destroy_at: MSVC 14.3 and 14.5 refuse + // `p->~T()` in these functions when T is a closure type (C2300, "class does not have a + // destructor called '~T'"). + + /** What a target of type `T` held inline in the handler's storage does. */ template - static constexpr operations operations_of = [] { - if constexpr (fits_inline) { - return operations{ - .invoke = [](unsigned char* storage, Args&&... args) -> R { - return static_cast( - (*inline_target(storage))(std::forward(args)...)); - }, - // Each of these functions constructs a target in to's storage with placement new, - // which readability-non-const-parameter does not count as a write, from the - // source, which it moves: misc-const-correctness, seeing a target that a move - // copies (a function pointer), would make the source const and every move a copy. - .move = - [](unsigned char* from, - unsigned char* to) noexcept { // NOLINT(readability-non-const-parameter) - T* const source = inline_target(from); // NOLINT(misc-const-correctness) - ::new (static_cast(to)) T(std::move(*source)); - std::destroy_at(source); - }, - .rehome = - [](unsigned char* from, std::pmr::memory_resource& /*from_resource*/, - unsigned char* to, // NOLINT(readability-non-const-parameter) - std::pmr::memory_resource& /*to_resource*/) { - T* const source = inline_target(from); // NOLINT(misc-const-correctness) - ::new (static_cast(to)) T(std::move(*source)); - std::destroy_at(source); - }, - .destroy = - [](unsigned char* storage, std::pmr::memory_resource& /*resource*/) noexcept { - std::destroy_at(inline_target(storage)); - }, - }; - } else { - return operations{ - .invoke = [](unsigned char* storage, Args&&... args) -> R { - return static_cast( - (*allocated_target(storage))(std::forward(args)...)); - }, - // As above, each constructs in to's storage with placement new. - .move = - [](unsigned char* from, - unsigned char* to) noexcept { // NOLINT(readability-non-const-parameter) - ::new (static_cast(to)) T*(allocated_target(from)); - }, - .rehome = - [](unsigned char* from, std::pmr::memory_resource& from_resource, - unsigned char* to, // NOLINT(readability-non-const-parameter) - std::pmr::memory_resource& to_resource) { - T* const source = allocated_target(from); - ::new (static_cast(to)) - T*(make(allocator_type(&to_resource), std::move(*source))); - std::destroy_at(source); - allocator_type(&from_resource).deallocate_object(source); - }, - .destroy = - [](unsigned char* storage, std::pmr::memory_resource& resource) noexcept { - T* const target = allocated_target(storage); - std::destroy_at(target); - allocator_type(&resource).deallocate_object(target); - }, - }; + struct inline_operations { + static R invoke(unsigned char* storage, Args&&... args) { + return static_cast((*inline_target(storage))(std::forward(args)...)); + } + + // Each of these functions constructs a target in to's storage with placement new, which + // readability-non-const-parameter does not count as a write, from the source, which it + // moves: misc-const-correctness, seeing a target that a move copies (a function pointer), + // would make the source const and every move a copy. + static void move(unsigned char* from, + unsigned char* to) noexcept { // NOLINT(readability-non-const-parameter) + T* const source = inline_target(from); // NOLINT(misc-const-correctness) + ::new (static_cast(to)) T(std::move(*source)); + std::destroy_at(source); + } + + // A target held inline is in no resource: it moves as it does between equal resources. + static void rehome(unsigned char* from, std::pmr::memory_resource& /*from_resource*/, + unsigned char* to, std::pmr::memory_resource& /*to_resource*/) { + move(from, to); + } + + static void destroy(unsigned char* storage, + std::pmr::memory_resource& /*resource*/) noexcept { + std::destroy_at(inline_target(storage)); + } + }; + + /** What a target of type `T` allocated from the handler's resource does. */ + template + struct allocated_operations { + static R invoke(unsigned char* storage, Args&&... args) { + return static_cast((*allocated_target(storage))(std::forward(args)...)); } - }(); + + // As in inline_operations, each constructs in to's storage with placement new. + static void move(unsigned char* from, + unsigned char* to) noexcept { // NOLINT(readability-non-const-parameter) + ::new (static_cast(to)) T*(allocated_target(from)); + } + + static void rehome(unsigned char* from, std::pmr::memory_resource& from_resource, + unsigned char* to, // NOLINT(readability-non-const-parameter) + std::pmr::memory_resource& to_resource) { + T* const source = allocated_target(from); + ::new (static_cast(to)) + T*(make(allocator_type(&to_resource), std::move(*source))); + std::destroy_at(source); + allocator_type(&from_resource).deallocate_object(source); + } + + static void destroy(unsigned char* storage, std::pmr::memory_resource& resource) noexcept { + T* const target = allocated_target(storage); + std::destroy_at(target); + allocator_type(&resource).deallocate_object(target); + } + }; + + template + using operations_for = + std::conditional_t, inline_operations, allocated_operations>; + + template + static constexpr operations operations_of{ + .invoke = &operations_for::invoke, + .move = &operations_for::move, + .rehome = &operations_for::rehome, + .destroy = &operations_for::destroy, + }; void reset() noexcept { if (operations_ != nullptr) {