Protected operator delete
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
I'm trying to wrap a complicated library (that I have no control over). For one reason or another some (base)classes have a protected operator delete. Trying to wrap a class like that results in a compilation error (cf. code below).
What is the canonical way of handling such a situation? NB: I don't want to instantiate the protected operator class I just want to register it as a part of the type system.
BTW: I found the following PR that might be related: #264
Reproducible example code
#include <pybind11/pybind11.h>
namespace py = pybind11;
class A{
protected:
void operator delete(void* ptr){};
};
class B: public A{
public:
using A::operator delete;
};
void dummy(A a){};
PYBIND11_MODULE(example, m) {
py::class_<A>(m,"A");
py::class_<B>(m,"B");
py::implicitly_convertible<B, A>();
m.def("dummy",&dummy);
};
For the record this is the error I get
/home/adam/anaconda2/envs/cpp-py-bindgen/include/python3.6m/pybind11/pybind11.h: In instantiation of ‘struct pybind11::detail::has_operator_delete<A, void>’:
/home/adam/anaconda2/envs/cpp-py-bindgen/include/python3.6m/pybind11/pybind11.h:1002:35: required by substitution of ‘template<class T, typename std::enable_if<((! pybind11::detail::has_operator_delete<T>::value) && pybind11::detail::has_operator_delete_size<T>::value), int>::type <anonymous> > void pybind11::detail::call_operator_delete(T*, pybind11::size_t, pybind11::size_t) [with T = A; typename std::enable_if<((! pybind11::detail::has_operator_delete<T>::value) && pybind11::detail::has_operator_delete_size<T>::value), int>::type <anonymous> = <missing>]’
/home/adam/anaconda2/envs/cpp-py-bindgen/include/python3.6m/pybind11/pybind11.h:1356:41: required from ‘static void pybind11::class_<type_, options>::dealloc(pybind11::detail::value_and_holder&) [with type_ = A; options = {}]’
/home/adam/anaconda2/envs/cpp-py-bindgen/include/python3.6m/pybind11/pybind11.h:1081:24: required from ‘pybind11::class_<type_, options>::class_(pybind11::handle, const char*, const Extra& ...) [with Extra = {}; type_ = A; options = {}]’
example.cpp:27:24: required from here
/home/adam/anaconda2/envs/cpp-py-bindgen/include/python3.6m/pybind11/pybind11.h:994:69: error: ‘static void A::operator delete(void*)’ is protected within this context
template <typename T> struct has_operator_delete<T, void_t<decltype(static_cast<void (*)(void *)>(T::operator delete))>>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example.cpp:10:9: note: declared protected here
void operator delete(void* ptr){};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the has_operator_delete and call_operator_delete code in pybind11.h, then reproduce the protected-delete case from example.cpp. Determine the supported behavior for registering A and B without instantiation, and document or test the resulting handling once the intended behavior is established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100