Reverting commit 63495313 by un-commenting…

Reverting commit 63495313 by un-commenting `const` in `def_buffer(...)`. To make this possible, `operator T const&` and `operator T const*` in `smart_holder_type_caster` need to be marked as `const` member functions.
parent ceb0ea7c
......@@ -1384,12 +1384,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
return cast(const_cast<T const *>(src), policy, parent); // Mutbl2Const
}
// clang-format off
#if defined(_MSC_VER) && _MSC_VER < 1910
// Working around MSVC 2015 bug. `const` sensitivity is lost.
// Working around MSVC 2015 bug. const-correctness is lost.
// SMART_HOLDER_WIP: IMPROVABLE: make common code work with MSVC 2015.
template <typename T_> using cast_op_type = detail::cast_op_type<T_>;
template <typename T_>
using cast_op_type = detail::cast_op_type<T_>;
#else
template <typename T_>
using cast_op_type = conditional_t<
......@@ -1397,17 +1396,20 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
T const *,
conditional_t<std::is_same<remove_reference_t<T_>, T *>::value,
T *,
conditional_t<std::is_same<T_, T const &>::value,
T const &,
T &>>>;
conditional_t<std::is_same<T_, T const &>::value, T const &, T &>>>;
#endif
operator T const&() { return this->loaded_as_lvalue_ref(); }
operator T&() { return this->loaded_as_lvalue_ref(); }
operator T const*() { return this->loaded_as_raw_ptr_unowned(); }
operator T*() { return this->loaded_as_raw_ptr_unowned(); }
// clang-format on
// The const operators here prove that the existing type_caster mechanism already supports
// const-correctness. However, fully implementing const-correctness inside this type_caster
// is still a major project.
operator T const &() const {
return const_cast<smart_holder_type_caster *>(this)->loaded_as_lvalue_ref();
}
operator T const *() const {
return const_cast<smart_holder_type_caster *>(this)->loaded_as_raw_ptr_unowned();
}
operator T &() { return this->loaded_as_lvalue_ref(); }
operator T *() { return this->loaded_as_raw_ptr_unowned(); }
// Originally type_caster_generic::cast.
PYBIND11_NOINLINE static handle cast_const_raw_ptr(const void *_src,
......
......@@ -1430,8 +1430,7 @@ public:
template <typename Return, typename Class, typename... Args>
class_ &def_buffer(Return (Class::*func)(Args...) const) {
// NEEDED: Explanation why the const needs to be removed, or fix elsewhere.
return def_buffer([func] (/*const*/ type &obj) { return (obj.*func)(); });
return def_buffer([func] (const type &obj) { return (obj.*func)(); });
}
template <typename C, typename D, typename... Extra>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment