From 26949b35731f3cbf351ce2a1b8c37d0550aae26b Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Fri, 20 Oct 2023 11:05:08 +0200 Subject: [PATCH 1/3] Workaround NVCC parse failure in `cast_op` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a bug in some CUDA versions (observed in CUDA 12.1 and 11.7 w/ GCC 12.2), that makes `cast_op` fail to compile: `cast.h:45:120: error: expected template-name before ‘<’ token` Defining the nested type as an alias and using it allows this to work without any change in semantics. Fixes #4606 --- include/pybind11/cast.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 3c9b7c9273..d63aeee6c0 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -42,13 +42,14 @@ using make_caster = type_caster>; // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T template typename make_caster::template cast_op_type cast_op(make_caster &caster) { - return caster.operator typename make_caster::template cast_op_type(); + using result_t = typename make_caster::template cast_op_type; + return caster.operator result_t(); } template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { - return std::move(caster).operator typename make_caster:: - template cast_op_type::type>(); + using result_t = typename make_caster::template cast_op_type::type>; + return std::move(caster).operator result_t(); } template From 352b04dd9535ede8593d7681d35adf9f5c4f44ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 10:13:11 +0000 Subject: [PATCH 2/3] style: pre-commit fixes --- include/pybind11/cast.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d63aeee6c0..e72e9ae492 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -48,7 +48,8 @@ typename make_caster::template cast_op_type cast_op(make_caster &caster template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { - using result_t = typename make_caster::template cast_op_type::type>; + using result_t = typename make_caster::template cast_op_type< + typename std::add_rvalue_reference::type>; return std::move(caster).operator result_t(); } From 6a23a534588acdc57148116f27bf5798257d14fc Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sat, 21 Oct 2023 17:43:15 +0200 Subject: [PATCH 3/3] Add comments to result_t referencing PR --- 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 e72e9ae492..8b5beb0ef6 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -42,14 +42,14 @@ using make_caster = type_caster>; // Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T template typename make_caster::template cast_op_type cast_op(make_caster &caster) { - using result_t = typename make_caster::template cast_op_type; + using result_t = typename make_caster::template cast_op_type; // See PR #4893 return caster.operator result_t(); } template typename make_caster::template cast_op_type::type> cast_op(make_caster &&caster) { using result_t = typename make_caster::template cast_op_type< - typename std::add_rvalue_reference::type>; + typename std::add_rvalue_reference::type>; // See PR #4893 return std::move(caster).operator result_t(); }