Skip to content

virtual inheritance problem #2071

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

Closed
jcpryan opened this issue Jan 15, 2020 · 2 comments
Closed

virtual inheritance problem #2071

jcpryan opened this issue Jan 15, 2020 · 2 comments

Comments

@jcpryan
Copy link

jcpryan commented Jan 15, 2020

When moving from version 2.0.1 to 2.2.1, compiled using both visual studio 2015 and 2019, I encountered an error

Run-Time Check Failure #0 - The value of ESP was not properly 
saved across a function call.  This is usually a result of 
calling a function declared with one calling convention with 
a function pointer declared with a different calling convention.

in code that had virtual inheritance. Here is a simplified example that illustrates the issue:

struct A0 {
virtual int size() const = 0;
int non_virtual() const { return 2; }
};
struct A1 : public virtual A0 {
int size() const { return 1; }
};
inline void A_test(const A0& a) {
std::cout << a.non_virtual() << std::endl;
std::cout << a.size() << std::endl;
}

PYBIND11_PLUGIN(virtual_test) {
pybind11::module m("virtual_test", "virtual test extension module");
pybind11::class_(m, "A0")
.def("size", &A0::size)
.def("non_virtual", &A0::non_virtual);
pybind11::class_<A1, A0>(m, "A1")
.def(py::init<>());
m.def("A_test", A_test);
}

and in the python script

a1 = A1()
A_test(a1)
print 'done'

With virtual inheritance, thd code only prints
2
then crashes, but correctly prints
2
1
done
when the virtual keyword is removed.

Thanks,
jcr

@jcpryan
Copy link
Author

jcpryan commented Jan 16, 2020

It seems I just need to change
class_<A1, A0>(m, "A1")
to
class_<A1, A0>(m, "A1", multiple_inheritance())
even though the eventual class that uses multiple inheritance is not wrapped.
I'm not sure why it worked in 2.0.1.
Regards,
jcr

@bstaletic
Copy link
Collaborator

Seems like this issue is resolved. @jcpryan Thanks for providing the answer.

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

No branches or pull requests

2 participants