[BUG]: Cannot wrap class with virtual inheritance and shared_ptr holder?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
The code below throws an error
pybind11.h(1792,1): error C2664: 'std::shared_ptr::shared_ptr(std::nullptr_t) noexcept': cannot convert argument 1 from 'V *' to 'std::nullptr_t
This does not seem expected... This only does it for the bindings of B, not A.
This is different from the other issues I found since in this case the class is actually polymorphic and does inherit from enable_shared_from_this.
Reproducible example code
#include <memory>
#include <pybind11/pybind11.h>
namespace py = pybind11;
class A : public std::enable_shared_from_this<A> {
public:
virtual ~A() {}
};
class B : public virtual A {
protected:
~B() {}
};
PYBIND11_MODULE(module, m) {
py::class_<A, std::shared_ptr<A>>(m, "A");
py::class_<B, std::shared_ptr<B>, A>(m, "B");
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible C++ example and inspect pybind11.h around line 1792, where the shared_ptr conversion error is reported. Confirm the failure when binding B with virtual inheritance and its shared_ptr holder; done means the example binds successfully without the reported compiler error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100