diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index 913515c17b..aa993f495d 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -37,7 +37,7 @@ class type_caster { PYBIND11_NAMESPACE_BEGIN(initimpl) -inline void no_nullptr(const void *ptr) { +inline void no_nullptr(void *ptr) { if (!ptr) { throw type_error("pybind11::init(): factory function returned nullptr"); } @@ -61,7 +61,7 @@ bool is_alias(Cpp *ptr) { } // Failing fallback version of the above for a no-alias class (always returns false) template -constexpr bool is_alias(const void *) { +constexpr bool is_alias(void *) { return false; } @@ -167,12 +167,7 @@ void construct(value_and_holder &v_h, Holder holder, bool need_alias) { "is not an alias instance"); } - // Cast away constness to store in void* storage. - // The value_and_holder storage is fundamentally untyped (void**), so we lose - // const-correctness here by design. The const qualifier will be restored - // when the pointer is later retrieved and cast back to the original type. - // This explicit const_cast makes the const-removal clearly visible. - v_h.value_ptr() = const_cast(static_cast(ptr)); + v_h.value_ptr() = ptr; v_h.type->init_instance(v_h.inst, &holder); }