Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Pure virtual method overriding using mixin class gives: Tried to call pure virtual function … #5405

Open
3 tasks done
ManuelSchneid3r opened this issue Oct 10, 2024 · 1 comment
Labels
triage New bug, unverified

Comments

@ManuelSchneid3r
Copy link
Contributor

ManuelSchneid3r commented Oct 10, 2024

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.5

Problem description

I cant override pure virtual functions using mixin classes. Pybind does not realize that the function in question does exist but is provided by the mixin class.

Reproducible example code

struct M {
    int f() { return 1; }
};

struct A {
    virtual int f() = 0;
};

// Imagine a trampoline class AT for A here

PYBIND11_MODULE(example, m) {
    pybind11::class_<M>(m, "Mixin")
        .def("f", &M::f);
    pybind11::class_<A, AT>(m, "Abstract")
        .def("f", &A::f);
}
class Derived(M, A):
    ...

d = D()
d.foo()

The last statement throws "Tried to call pure virtual function". For example in plain Python this works as expected:

class A():
    def f(self):
        pass

class M:
    def f(self):
        return "mixed in"

class D(M, A):
     pass

d = D()
print(d.f())

Is this a regression? Put the last known working version here if it is.

Not a regression

@ManuelSchneid3r ManuelSchneid3r added the triage New bug, unverified label Oct 10, 2024
@ManuelSchneid3r
Copy link
Contributor Author

Added an example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant