Conversation
```
g++ -o pybind11/tests/test_modules.os -c -std=c++20 -fPIC -fvisibility=hidden -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wundef -Wnon-virtual-dtor -Wunused-result -Werror -funsigned-char -Wpedantic -isystem /wrk/cpython_installs/v3.14.2_df793163d58_default/include/python3.14 -isystem /usr/include/eigen3 -DPYBIND11_SMART_HOLDER_PADDING_ON -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -DPYBIND11_TEST_BOOST -Ipybind11/include -I/wrk/forked/pybind11/include -I/wrk/clone/pybind11/include /wrk/forked/pybind11/tests/test_modules.cpp
In file included from /wrk/forked/pybind11/include/pybind11/eval.h:14,
from /wrk/forked/pybind11/tests/pybind11_tests.h:3,
from /wrk/forked/pybind11/tests/constructor_stats.h:68,
from /wrk/forked/pybind11/tests/test_modules.cpp:11:
/wrk/forked/pybind11/include/pybind11/pybind11.h: In instantiation of ‘pybind11::module_& pybind11::module_::def(const std::string&, Func&&, const Extra& ...) [with Func = test_submodule_modules(pybind11::module_&)::<lambda(int)>; Extra = {pybind11::arg}; std::string = std::__cxx11::basic_string<char>]’:
/wrk/forked/pybind11/tests/test_modules.cpp:129:21: required from here
/wrk/forked/pybind11/include/pybind11/pybind11.h:1549:57: error: binding reference of type ‘std::remove_reference<pybind11::arg>::type&’ {aka ‘pybind11::arg&’} to ‘const pybind11::arg’ discards qualifiers
1549 | return def(name_.c_str(), f, std::forward<Extra>(extra)...);
| ~~~~~~~~~~~~~~~~~~~^~~~~~~
In file included from /usr/include/c++/13/bits/stl_pair.h:61,
from /usr/include/c++/13/bits/stl_algobase.h:64,
from /usr/include/c++/13/bits/specfun.h:43,
from /usr/include/c++/13/cmath:3699,
from /usr/include/c++/13/math.h:36,
from /wrk/cpython_installs/v3.14.2_df793163d58_default/include/python3.14/Python.h:23,
from /wrk/forked/pybind11/include/pybind11/conduit/wrap_include_python_h.h:44,
from /wrk/forked/pybind11/include/pybind11/detail/common.h:12,
from /wrk/forked/pybind11/include/pybind11/attr.h:13,
from /wrk/forked/pybind11/include/pybind11/detail/class.h:12,
from /wrk/forked/pybind11/include/pybind11/pybind11.h:12:
/usr/include/c++/13/bits/move.h:70:56: note: initializing argument 1 of ‘constexpr _Tp&& std::forward(typename remove_reference<_Functor>::type&) [with _Tp = pybind11::arg; typename remove_reference<_Functor>::type = pybind11::arg]’
70 | forward(typename std::remove_reference<_Tp>::type& __t) noexcept
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
```
|
I started looking at this on the weekend but didn't get very far. I pushed a new tests (generated by Cursor) that I believe will make the builds here fail (but should work with master; although I haven't validated that). I probably won't have time to come back here this week. Wild idea on my mind: maybe we should drop C++11 and C++14 first (that's overdue now IMO), then use |
|
Leaving this here, JIC there is something useful in it: Your first promptCould you please review this PR (current branch): /wrk/logs/gh_pr_info_pybind_pybind11_5995_2026-02-28+214859.md Did the PR author add the overloads systematically? Do you see any obvious omissions? Is the test coverage complete? Cursor GPT-5.3 Codex (Extra High) responseFindings (ordered by severity)
template <typename Func, typename... Extra>
module_ &def(const std::string &name_, Func &&f, const Extra &...extra) {
return def(name_.c_str(), f, std::forward<Extra>(extra)...);
}I confirmed with a compile-only snippet using
Obvious omissions
Test coverage assessment
|
Thank you @rwgk for looking at this issue adding the tests. I'm also a bit busy this week but I will try to get to fixing the issue(s) ASAP. (I also thought about |
|
The Engineering away the need to write My thinking from there:
|
|
If pybind11 is moving to C++17, having just |
I've added some
std::stringoverloads for various functions related to modules.The motivation is the following. My project has a lot of code like
With the current
pybind11, I have to writem.def(("func1_" + suffix).c_str(), ...), but it would be nicer to be able to do justm.def("func1_" + suffix, ...).