From be3bafe9df489c90534391207903249d8ca621e5 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 25 Aug 2024 10:02:41 -0700 Subject: [PATCH] Add `static_assert()` following a suggestion by @iwanders under PR #5334 --- include/pybind11/detail/struct_smart_holder.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/pybind11/detail/struct_smart_holder.h b/include/pybind11/detail/struct_smart_holder.h index a6faf06e5e..b1e24d7bb3 100644 --- a/include/pybind11/detail/struct_smart_holder.h +++ b/include/pybind11/detail/struct_smart_holder.h @@ -242,7 +242,9 @@ struct smart_holder { std::string("smart_holder::extract_deleter() precondition failure (") + context + ")."); } - return std::unique_ptr(new D(custom_deleter_ptr->deleter)); // D must be copyable. + static_assert(std::is_copy_constructible::value, + "Required for compatibility with smart_holder functionality."); + return std::unique_ptr(new D(custom_deleter_ptr->deleter)); } return nullptr; }