Skip to content

Commit

Permalink
Workaround NVCC parse failure in cast_op
Browse files Browse the repository at this point in the history
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 pybind#4606
  • Loading branch information
Flamefire committed Oct 20, 2023
1 parent 7969049 commit 26949b3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ 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>;
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>;
return std::move(caster).operator result_t();
}

template <typename type>
Expand Down

0 comments on commit 26949b3

Please sign in to comment.