xref: /aosp_15_r20/external/clang/test/SemaCXX/address-space-newdelete.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li void* operator new (__SIZE_TYPE__ size, void* ptr);
4*67e74705SXin Li void* operator new[](__SIZE_TYPE__ size, void* ptr);
5*67e74705SXin Li 
6*67e74705SXin Li typedef int __attribute__((address_space(1))) int_1;
7*67e74705SXin Li 
test_new(void * p)8*67e74705SXin Li void test_new(void *p) {
9*67e74705SXin Li   (void)new int_1; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
10*67e74705SXin Li   (void)new __attribute__((address_space(1))) int; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
11*67e74705SXin Li   (void)new int_1 [5]; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
12*67e74705SXin Li   (void)new __attribute__((address_space(1))) int [5]; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
13*67e74705SXin Li 
14*67e74705SXin Li   // Placement new
15*67e74705SXin Li   (void)new (p) int_1; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
16*67e74705SXin Li   (void)new (p) __attribute__((address_space(1))) int; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
17*67e74705SXin Li   (void)new (p) int_1 [5]; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
18*67e74705SXin Li   (void)new (p) __attribute__((address_space(1))) int [5]; // expected-error{{'new' cannot allocate objects of type 'int' in address space '1'}}
19*67e74705SXin Li }
20*67e74705SXin Li 
test_delete(int_1 * ip1)21*67e74705SXin Li void test_delete(int_1 *ip1) {
22*67e74705SXin Li   delete ip1; // expected-error{{'delete' cannot delete objects of type 'int' in address space '1'}}
23*67e74705SXin Li   delete [] ip1; // expected-error{{'delete' cannot delete objects of type 'int' in address space '1'}}
24*67e74705SXin Li }
25