From 66f4a9930865cd3b6343e1fde07bb90c3ed0a7a3 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Wed, 29 Nov 2023 13:36:04 +0100 Subject: [PATCH 1/4] Call concat with proper namespace in cast.h --- include/pybind11/cast.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 8b5beb0ef6..95074f8aa8 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -662,8 +662,9 @@ class tuple_caster { return cast(*src, policy, parent); } - static constexpr auto name - = const_name("tuple[") + concat(make_caster::name...) + const_name("]"); + static constexpr auto name = const_name("tuple[") + + pybind11::detail::concat(make_caster::name...) + + const_name("]"); template using cast_op_type = type; @@ -1464,7 +1465,8 @@ class argument_loader { static_assert(args_pos == -1 || args_pos == constexpr_first(), "py::args cannot be specified more than once"); - static constexpr auto arg_names = concat(type_descr(make_caster::name)...); + static constexpr auto arg_names + = pybind11::detail::concat(type_descr(make_caster::name)...); bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); } From 5a489d53f2477a754471f68e0a27e291b1e5858f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 21 Mar 2024 03:25:22 -0400 Subject: [PATCH 2/4] Apply suggestions from code review --- include/pybind11/cast.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 95074f8aa8..dd2e094edb 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -663,7 +663,7 @@ class tuple_caster { } static constexpr auto name = const_name("tuple[") - + pybind11::detail::concat(make_caster::name...) + + ::pybind11::detail::concat(make_caster::name...) + const_name("]"); template @@ -1466,7 +1466,7 @@ class argument_loader { "py::args cannot be specified more than once"); static constexpr auto arg_names - = pybind11::detail::concat(type_descr(make_caster::name)...); + = ::pybind11::detail::concat(type_descr(make_caster::name)...); bool load_args(function_call &call) { return load_impl_sequence(call, indices{}); } From bade99c119928e14032adca0be6af867d69017e5 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 27 Mar 2024 00:57:22 -0400 Subject: [PATCH 3/4] tests: add test for ADL on concat Signed-off-by: Henry Schreiner --- tests/test_custom_type_casters.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_custom_type_casters.cpp b/tests/test_custom_type_casters.cpp index b4af02a452..3cbb8687fb 100644 --- a/tests/test_custom_type_casters.cpp +++ b/tests/test_custom_type_casters.cpp @@ -134,6 +134,16 @@ struct type_caster : public other_lib::my_caster {}; } // namespace detail } // namespace PYBIND11_NAMESPACE +// This simply is required to compile +namespace ADL_issue { +template +OutStringType concat(Args &&...) { + return OutStringType(); +} + +struct test {}; +} // namespace ADL_issue + TEST_SUBMODULE(custom_type_casters, m) { // test_custom_type_casters @@ -206,4 +216,6 @@ TEST_SUBMODULE(custom_type_casters, m) { py::return_value_policy::reference); m.def("other_lib_type", [](other_lib::MyType x) { return x; }); + + m.def("_adl_issue", [](const ADL_issue::test &) {}); } From 64157f2ca100a82b1d011beb68171ebfbbabd261 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 27 Mar 2024 15:57:20 -0400 Subject: [PATCH 4/4] fix: fully qualify all usages of concat Signed-off-by: Henry Schreiner --- include/pybind11/eigen/tensor.h | 5 +++-- include/pybind11/functional.h | 3 ++- include/pybind11/numpy.h | 2 +- include/pybind11/stl.h | 3 ++- include/pybind11/typing.h | 11 ++++++----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/pybind11/eigen/tensor.h b/include/pybind11/eigen/tensor.h index 25d12baca1..d4ed6c0ca8 100644 --- a/include/pybind11/eigen/tensor.h +++ b/include/pybind11/eigen/tensor.h @@ -70,7 +70,7 @@ struct eigen_tensor_helper struct helper> { - static constexpr auto value = concat(const_name(((void) Is, "?"))...); + static constexpr auto value = ::pybind11::detail::concat(const_name(((void) Is, "?"))...); }; static constexpr auto dimensions_descriptor @@ -104,7 +104,8 @@ struct eigen_tensor_helper< return get_shape() == shape; } - static constexpr auto dimensions_descriptor = concat(const_name()...); + static constexpr auto dimensions_descriptor + = ::pybind11::detail::concat(const_name()...); template static Type *alloc(Args &&...args) { diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 87ec4d10cb..6856119cde 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -128,7 +128,8 @@ struct type_caster> { } PYBIND11_TYPE_CASTER(type, - const_name("Callable[[") + concat(make_caster::name...) + const_name("Callable[[") + + ::pybind11::detail::concat(make_caster::name...) + const_name("], ") + make_caster::name + const_name("]")); }; diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 8551aa2648..3d373be112 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -371,7 +371,7 @@ struct array_info> { } static constexpr auto extents = const_name::is_array>( - concat(const_name(), array_info::extents), const_name()); + ::pybind11::detail::concat(const_name(), array_info::extents), const_name()); }; // For numpy we have special handling for arrays of characters, so we don't include // the size in the array extents. diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 6eb4859917..ea7d35c889 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -421,7 +421,8 @@ struct variant_caster> { using Type = V; PYBIND11_TYPE_CASTER(Type, - const_name("Union[") + detail::concat(make_caster::name...) + const_name("Union[") + + ::pybind11::detail::concat(make_caster::name...) + const_name("]")); }; diff --git a/include/pybind11/typing.h b/include/pybind11/typing.h index b7b1a4e54a..506f9c77bd 100644 --- a/include/pybind11/typing.h +++ b/include/pybind11/typing.h @@ -69,8 +69,9 @@ PYBIND11_NAMESPACE_BEGIN(detail) template struct handle_type_name> { - static constexpr auto name - = const_name("tuple[") + concat(make_caster::name...) + const_name("]"); + static constexpr auto name = const_name("tuple[") + + ::pybind11::detail::concat(make_caster::name...) + + const_name("]"); }; template <> @@ -108,9 +109,9 @@ struct handle_type_name> { template struct handle_type_name> { using retval_type = conditional_t::value, void_type, Return>; - static constexpr auto name = const_name("Callable[[") + concat(make_caster::name...) - + const_name("], ") + make_caster::name - + const_name("]"); + static constexpr auto name + = const_name("Callable[[") + ::pybind11::detail::concat(make_caster::name...) + + const_name("], ") + make_caster::name + const_name("]"); }; PYBIND11_NAMESPACE_END(detail)