Bug with inheritance, shared_ptr holder and enable_shared_from_this
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
error C2683: 'dynamic_cast': 'base' is not a polymorphic type
If base derives from std::enable_shared_from_this, pybind11 uses dynamic_cast, even if type is not polymorphic.
Reproducible example code
#include <memory>
#include <pybind11/pybind11.h>
struct base : public std::enable_shared_from_this<base>
{
};
struct derived : base
{
};
void python_export(pybind11::module& m)
{
pybind11::class_<base, std::shared_ptr<base>>(m, "Base")
.def(pybind11::init<>())
;
pybind11::class_<derived, base, std::shared_ptr<derived>>(m, "Derived")
.def(pybind11::init<>())
;
}
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 by compiling and running the reproducible C++ example with pybind11, focusing on the shared_ptr holder and inheritance path for base and derived. Trace where enable_shared_from_this causes dynamic_cast to be used and verify the behavior for a non-polymorphic base. Done means the example compiles without C2683 while preserving the shared_ptr inheritance behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100