xref: /aosp_15_r20/external/clang/test/SemaCUDA/overloaded-delete.cu (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // expected-no-diagnostics
2*67e74705SXin Li 
3*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s
4*67e74705SXin Li // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s
5*67e74705SXin Li 
6*67e74705SXin Li #include "Inputs/cuda.h"
7*67e74705SXin Li 
8*67e74705SXin Li struct S {
operator deleteS9*67e74705SXin Li   __host__ static void operator delete(void*, size_t) {}
operator deleteS10*67e74705SXin Li   __device__ static void operator delete(void*, size_t) {}
11*67e74705SXin Li };
12*67e74705SXin Li 
test(S * s)13*67e74705SXin Li __host__ __device__ void test(S* s) {
14*67e74705SXin Li   // This shouldn't be ambiguous -- we call the host overload in host mode and
15*67e74705SXin Li   // the device overload in device mode.
16*67e74705SXin Li   delete s;
17*67e74705SXin Li }
18*67e74705SXin Li 
operator delete(void * ptr)19*67e74705SXin Li __host__ void operator delete(void *ptr) {}
operator delete(void * ptr)20*67e74705SXin Li __device__ void operator delete(void *ptr) {}
21*67e74705SXin Li 
test_global_delete(int * ptr)22*67e74705SXin Li __host__ __device__ void test_global_delete(int *ptr) {
23*67e74705SXin Li   // Again, there should be no ambiguity between which operator delete we call.
24*67e74705SXin Li   ::delete ptr;
25*67e74705SXin Li }
26