Open Holt59 opened 2 years ago
The solution I found was to have an intermediate class AB
that inherits both A
and B
, and then have PyB
inherits AB
instead of A
and B
, this seems to fix the issue.
@Holt59 Could you add a PR adding this test to our test suite? That would make debugging a solution easier. The static_cast is probably to ensure consistent behavior and fix some other edge case. Does replacing it with a dynamic_cast also solve the problem?
@Skylion007 I will see if I can add a PR. Replacing with dynamic_cast
does not solve the issue, I think the problem is that the py::object
is not retrieved properly from the this
when this
is a B*
(and not a PyB*
).
@Skylion007 PR with test case added here: https://github.com/pybind/pybind11/pull/3915
Required prerequisites
Problem description
When using
PYBIND11_OVERRIDE_PURE
inside of class with multiple inheritance, e.g.This functions throws a "Tried to call pure virtual function ..." exception when constructing a new
B
in Python.Removing this
static_cast
:...solves the issue.
Is there any reason to have this
static_cast
here? Is there something I'm missing?Reproducible example code