Description
There are a couple of regressions in current master
versus 2.1 with the following:
#include <iostream>
#include <pybind11/pybind11.h>
namespace py = pybind11;
struct Foo {
protected:
int foo() { return 42; }
public:
// virtual ~Foo() = default;
};
struct PyFoo : Foo {
public:
int foo() { return Foo::foo(); }
};
PYBIND11_PLUGIN(expose) {
py::module m("expose");
py::class_<Foo, PyFoo>(m, "Foo")
.def(py::init<>())
.def("foo", &PyFoo::foo)
;
return m.ptr();
}
which was a nice trick to allow exposing protected base class methods to Python.
The first regression is that the above fails a static assertion because Foo
isn't polymorphic. But I think that if using py::init_alias<>()
for constructors, or for aliases that have just simply inherited constructors and no member variables, a non-polymorphic class is actually okay.
The second problem is that the above fails because of the method_adapter
changes added in #855: the cast from the deduced PyFoo
member function pointer isn't castable to the base Foo
member function pointer type.
Admittedly this is a bit fragile; we could also solve them by providing a nicer way to binding protected methods, if someone can think of one.