From 3414c56b6c7c521d868c9a137ca2ace2e26b5b2e Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sat, 21 Oct 2023 19:50:14 +0200 Subject: [PATCH] Workaround NVCC parse failure in `cast_op` (#4893) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Workaround NVCC parse failure in `cast_op` 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 * style: pre-commit fixes * Add comments to result_t referencing PR --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- 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 3c9b7c927..8b5beb0ef 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -42,13 +42,15 @@ 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; // See PR #4893 + 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< + typename std::add_rvalue_reference::type>; // See PR #4893 + return std::move(caster).operator result_t(); } template