[BUG] Factory functions declared noexcept do not work with py::init() when compiling with C++17/C++20
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
A modified example from the docs with noexcept factory function will not compile.
error C2027: use of undefined type 'pybind11::detail::initimpl::factory<Func,pybind11::detail::void_type (__cdecl *)(void),init::Example (int) noexcept,pybind11::detail::void_type (void)>'
with
[
Func=init::Example (__cdecl *)(int) noexcept
]
Reproducible example code
class Example {
private:
Example(int) noexcept; // private constructor
public:
// Factory function:
static Example create(int a) noexcept { return Example(a); }
};
py::class_<Example>(m, "Example")
.def(py::init(&Example::create));
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 using py::init(&Example::create) and the reported C++17/C++20 compiler error. Trace the py::init factory handling for noexcept function types; done means the example compiles and works with the supported C++17 and C++20 configurations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100