[FEA]: Improve compilation error message of cuda::std::apply with wrong arguments
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
### Is this a duplicate?
- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this request and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)
### Area
libcu++
### Is your feature request related to a problem? Please describe.
Error message when `cuda::std::apply` gets a function that is not possible to be called with the supplied tuple is not helpful with finding out what went wrong. This is especially problematic with function templates because apply needs instantiated functions and it's easy to make a mistake.
Consider the following example with a bug, where a function was meant to be called with a tuple of two integers: https://godbolt.org/z/76vbcsMWM
When std::apply/tuple is used, the error message is immediately clear:
```
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/tuple(1723): error: no instance of function template "std::__invoke" matches the argument list
argument types are: (void (int &&, int &&), const int, const int)
return std::__invoke(std::forward<_Fn>(__f),
```
I tried to call `void (int &&, int &&)` with `const int, const int`, so my template instantiation is wrong.
With cuda::std::apply/tuple, the error message seems completely not related to the problem:
```
/opt/compiler-explorer/cuda/12.6.1/bin/../targets/x86_64-linux/include/cuda/std/detail/libcxx/include/tuple(1297): error: function "cuda::std::__4::__nat::~__nat() noexcept" (declared at line 30 of /opt/compiler-explorer/cuda/12.6.1/bin/../targets/x86_64-linux/include/cuda/std/__type_traits/nat.h) cannot be referenced -- it is a deleted function
__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, __tuple_indices<_Id...>) noexcept(noexcept(::cuda::std::__4::__invoke(::cuda::std::__4::forward<_Fn>(__f), ::cuda::std::__4::get<_Id>(::cuda::std::__4::forward<_Tuple>(__t))...))) { return ::cuda::std::__4::__invoke(::cuda::std::__4::forward<_Fn>(__f), ::cuda::std::__4::get<_Id>(::cuda::std::__4::forward<_Tuple>(__t))...); }
^
detected during:
instantiation of "decltype(auto) cuda::std::__4::__apply_tuple_impl(_Fn &&, _Tuple &&, cuda::std::__4::__tuple_indices<_Id...>) [with _Fn=void (&)(int &&, int &&), _Tuple=const cuda::std::__4::tuple &, _Id=<0UL, 1UL>]" at line 1302
instantiation of "decltype(auto) cuda::std::__4::apply(_Fn &&, _Tuple &&) [with _Fn=void (&)(int &&, int &&), _Tuple=const cuda::std::__4::tuple &]" at line 15 of
instantiation of "void bar(const cuda::std::__4::tuple &) [with Ts=]" at line 20 of
/opt/compiler-explorer/cuda/12.6.1/bin/../targets/x86_64-linux/include/cuda/std/detail/libcxx/include/tuple(1297): error: "cuda::std::__4::__nat::~__nat() noexcept" (declared at line 30 of /opt/compiler-explorer/cuda/12.6.1/bin/../targets/x86_64-linux/include/cuda/std/__type_traits/nat.h), required for copy that was eliminated, cannot be referenced -- it is a deleted function
__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, __tuple_indices<_Id...>) noexcept(noexcept(::cuda::std::__4::__invoke(::cuda::std::__4::forward<_Fn>(__f), ::cuda::std::__4::get<_Id>(::cuda::std::__4::forward<_Tuple>(__t))...))) { return ::cuda::std::__4::__invoke(::cuda::std::__4::forward<_Fn>(__f), ::cuda::std::__4::get<_Id>(::cuda::std::__4::forward<_Tuple>(__t))...); }
```
### Describe the solution you'd like
It would be great to generate a more helpful error message in this case, one that references the function and argument types, not just the still packed tuple type and complaining about some deleted destructor.
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.