Skip to content

virtual inheritance problem #2071

Closed
Closed

Description

@jcpryan

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

Activity

  1. jcpryan commented on Jan 16, 2020

    @jcpryan
    Author

    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

  2. bstaletic commented on Jul 12, 2020

    @bstaletic
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions