Skip to content

[BUG]: Using smart_holder in virtual inheritance relationship error #5786

@MannixYang

Description

@MannixYang

Required prerequisites

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

3.0.0

Problem description

The following code about virtual inheritance relationship , i use smart_holder instead of std::shared_ptr.

class Animal {
public:
  virtual std::shared_ptr<Animal> clone() const = 0;
  virtual ~Animal() = default;
};

class Cat : virtual public Animal {
public:
  virtual ~Cat() override = default;
};

class Tiger : virtual public Cat {
public:
  Tiger() = default;
  Tiger(const Tiger &) = default;
  ~Tiger() override = default;
  std::shared_ptr<Animal> clone() const override {
    return std::make_shared<Tiger>(*this);
  }
};

void bind_animals(pybind11::module_ &module) {

  pybind11::class_<Animal, pybind11::smart_holder>(module, "Animal");

  pybind11::class_<Cat, Animal, pybind11::smart_holder>(module, "Cat");

  pybind11::class_<Tiger, Cat, pybind11::smart_holder>(
      module, "Tiger", pybind11::multiple_inheritance())
      .def(pybind11::init<>())
      .def("clone", &Tiger::clone);
}

In python code:

tiger = Tiger()
tiger.clone()

An error occurred:

due to a fatal error condition:
  SIGSEGV - Segmentation violation signal

But it is ok to use std::shared_ptr as py::class_ holder. Are there problems with my usage of the smart_holder.
Can anyone help me with this? It's urgent. Thank you very much!

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

Not a regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions