Issue 114048
Summary Error when compiling CUDA code with libc++ and C++ standard 26
Labels libc++
Assignees
Reporter OgnianM
    The error:
```
/usr/local/lib/clang/20/include/cuda_wrappers/new:94:25: error: __device__ function 'operator new' cannot overload __host__ __device__ function 'operator new'
   94 | __device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
      | ^
/usr/local/bin/../include/c++/v1/new:252:1: note: previous declaration is here
  252 | operator new(std::size_t, void* __p) _NOEXCEPT {
      | ^
```

Looks like it's caused by the `_LIBCPP_CONSTEXPR_SINCE_CXX26` macro making `operator new(std::size_t, void* __p)` implicitly a __host__ __device__ function when CXX >= 26.

The simplest fix would be wrapping the device overrides for placement new in `cuda_wrappers/new` in an `#if` like so

```
// Device overrides for placement new and delete.
#if _LIBCPP_STD_VER < 26
__device__ inline void *operator new(__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
  return __ptr;
}
__device__ inline void *operator new[](__SIZE_TYPE__, void *__ptr) CUDA_NOEXCEPT {
  return __ptr;
}
#endif
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to