Skip to content

Commit ece86ff

Browse files
committed
[CUDA] add wrapper header for libc++'s __utlility/declval.h
Since llvm#116709 more libc++ code relies on std::declval() and it broke some CUDA compilations. The new wrapper adds GPU-side overloads for the declval() helper functions which allows it to continue working when used from CUDA sources.
1 parent 09f7cab commit ece86ff

File tree

1 file changed

+31
-0
lines changed
  • clang/lib/Headers/cuda_wrappers/__utility

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef __CUDA_WRAPPERS_UTILITY_DECLVAL_H__
2+
#define __CUDA_WRAPPERS_UTILITY_DECLVAL_H__
3+
4+
#include_next <__utility/declval.h>
5+
6+
// The stuff below is the exact copy of the <__utility/declval.h>,
7+
// but with __device__ attribute applied to the functions, so it works on a GPU.
8+
9+
_LIBCPP_BEGIN_NAMESPACE_STD
10+
11+
// Suppress deprecation notice for volatile-qualified return type resulting
12+
// from volatile-qualified types _Tp.
13+
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14+
template <class _Tp>
15+
__attribute__((device))
16+
_Tp&& __declval(int);
17+
template <class _Tp>
18+
__attribute__((device))
19+
_Tp __declval(long);
20+
_LIBCPP_SUPPRESS_DEPRECATED_POP
21+
22+
template <class _Tp>
23+
__attribute__((device))
24+
_LIBCPP_HIDE_FROM_ABI decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT {
25+
static_assert(!__is_same(_Tp, _Tp),
26+
"std::declval can only be used in an unevaluated context. "
27+
"It's likely that your current usage is trying to extract a value from the function.");
28+
}
29+
30+
_LIBCPP_END_NAMESPACE_STD
31+
#endif // __CUDA_WRAPPERS_UTILITY_DECLVAL_H__

0 commit comments

Comments
 (0)