Skip to content

Incorrect binding when the derived class is polymorphic and the base is not #1080

@Phobosmir

Description

@Phobosmir

The issue from Gitter

Reproducible example code

#include "pybind11/pybind11.h"
namespace py = pybind11;

struct BaseNonPolymorphic {
	unsigned int a;
	unsigned int b;
	unsigned int c;
	unsigned int d;
};
struct Derived : BaseNonPolymorphic {
	Derived() {
		a = 1;
		b = 2;
		c = 3;
		d = 4;
	};
	virtual ~Derived() {};
};
PYBIND11_MODULE(test_inheritance, m) {
	py::class_<BaseNonPolymorphic > base_class(m, "Base");
	base_class
		.def_readwrite("d", &BaseNonPolymorphic::d)
	;

	py::class_<Derived> derived_class(m, "Derived", base_class);
	derived_class
		.def(py::init<>())
	;
}
import test_inheritance
derived_instance = test_inheritance.Derived()
assert derived_instance.d == 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions