Skip to content

Commit

Permalink
Workaround NVCC parse failure in cast_op (google#4893)
Browse files Browse the repository at this point in the history
* 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 google#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>
  • Loading branch information
Flamefire and pre-commit-ci[bot] authored Oct 21, 2023
1 parent 7969049 commit 3414c56
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ using make_caster = type_caster<intrinsic_t<type>>;
// Shortcut for calling a caster's `cast_op_type` cast operator for casting a type_caster to a T
template <typename T>
typename make_caster<T>::template cast_op_type<T> cast_op(make_caster<T> &caster) {
return caster.operator typename make_caster<T>::template cast_op_type<T>();
using result_t = typename make_caster<T>::template cast_op_type<T>; // See PR #4893
return caster.operator result_t();
}
template <typename T>
typename make_caster<T>::template cast_op_type<typename std::add_rvalue_reference<T>::type>
cast_op(make_caster<T> &&caster) {
return std::move(caster).operator typename make_caster<T>::
template cast_op_type<typename std::add_rvalue_reference<T>::type>();
using result_t = typename make_caster<T>::template cast_op_type<
typename std::add_rvalue_reference<T>::type>; // See PR #4893
return std::move(caster).operator result_t();
}

template <typename type>
Expand Down

0 comments on commit 3414c56

Please sign in to comment.