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 ace0f2bc
...@@ -1377,12 +1377,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>, ...@@ -1377,12 +1377,11 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
return cast(const_cast<T const *>(src), policy, parent); // Mutbl2Const return cast(const_cast<T const *>(src), policy, parent); // Mutbl2Const
} }
// clang-format off
#if defined(_MSC_VER) && _MSC_VER < 1910 #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. // 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 #else
template <typename T_> template <typename T_>
using cast_op_type = conditional_t< using cast_op_type = conditional_t<
...@@ -1390,17 +1389,20 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>, ...@@ -1390,17 +1389,20 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
T const *, T const *,
conditional_t<std::is_same<remove_reference_t<T_>, T *>::value, conditional_t<std::is_same<remove_reference_t<T_>, T *>::value,
T *, T *,
conditional_t<std::is_same<T_, T const &>::value, conditional_t<std::is_same<T_, T const &>::value, T const &, T &>>>;
T const &,
T &>>>;
#endif #endif
operator T const&() { return this->loaded_as_lvalue_ref(); } // The const operators here prove that the existing type_caster mechanism already supports
operator T&() { return this->loaded_as_lvalue_ref(); } // const-correctness. However, fully implementing const-correctness inside this type_caster
operator T const*() { return this->loaded_as_raw_ptr_unowned(); } // is still a major project.
operator T*() { return this->loaded_as_raw_ptr_unowned(); } operator T const &() const {
return const_cast<smart_holder_type_caster *>(this)->loaded_as_lvalue_ref();
// clang-format on }
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. // Originally type_caster_generic::cast.
PYBIND11_NOINLINE static handle cast_const_raw_ptr(const void *_src, PYBIND11_NOINLINE static handle cast_const_raw_ptr(const void *_src,
......
...@@ -1429,8 +1429,7 @@ public: ...@@ -1429,8 +1429,7 @@ public:
template <typename Return, typename Class, typename... Args> template <typename Return, typename Class, typename... Args>
class_ &def_buffer(Return (Class::*func)(Args...) const) { 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> 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