Skip to content

Issue with method returning std::unique_ptr combined with trampoline class #1962

Open
@bpatzak

Description

@bpatzak

Hello,
I encountered the problem with method returning std::unique_ptr. When exposed without trampoline class, everything works, however when trampoline class is involved, the code does not compile and compiler complains for missing type_caster. The behavior is illustrated on attached minimal example.

#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
namespace py = pybind11;

class Status {
public:
  Status() {}
};

class Factory {
public:
  Factory() {}
  virtual std::unique_ptr<Status> GetStatus() const {
    return std::unique_ptr<Status> (new Status);
  }
};

template <class FactoryBase = Factory> class PyFactory: public FactoryBase {
public:
  using FactoryBase::FactoryBase;
  std::unique_ptr<Status> GetStatus() const override {
    PYBIND11_OVERLOAD(std::unique_ptr<Status> , FactoryBase, GetStatus, );
  }
};


PYBIND11_MODULE(demo2, m) {

  py::class_<Status>(m, "Status")
    .def(py::init<>())
    ;

  py::class_<Factory, PyFactory<>>(m, "Factory")
    .def(py::init<>())
    .def("GetStatus", &Factory::GetStatus)
    ;
}

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