1// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=clc++ -pedantic -verify -fsyntax-only 2 3class A { 4 public: 5 A() : x(21) {} 6 int x; 7}; 8 9typedef __SIZE_TYPE__ size_t; 10 11class B { 12 public: 13 B() : bx(42) {} 14 void *operator new(size_t); 15 void operator delete(void *ptr); 16 int bx; 17}; 18 19// There are no global user-defined new operators at this point. Test that clang 20// rejects these gracefully. 21void test_default_new_delete(void *buffer, A **pa) { 22 A *a = new A; // expected-error {{'default new' is not supported in C++ for OpenCL}} 23 delete a; // expected-error {{'default delete' is not supported in C++ for OpenCL}} 24 *pa = new (buffer) A; // expected-error {{use of placement new requires explicit declaration}} 25} 26 27// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}} 28void *operator new(size_t _s, void *ptr) noexcept { 29 return ptr; 30} 31 32// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}} 33void *operator new[](size_t _s, void *ptr) noexcept { 34 return ptr; 35} 36 37void test_new_delete(void *buffer, A **a, B **b) { 38 *a = new A; // expected-error {{no matching function for call to 'operator new'}} 39 delete a; // expected-error {{'default delete' is not supported in C++ for OpenCL}} 40 41 *a = new A[20]; // expected-error {{no matching function for call to 'operator new[]'}} 42 delete[] *a; // expected-error {{'default delete' is not supported in C++ for OpenCL}} 43 44 // User-defined placement new is supported. 45 *a = new (buffer) A; 46 47 // User-defined placement new[] is supported. 48 *a = new (buffer) A[30]; 49 50 // User-defined new is supported. 51 *b = new B; 52 53 // User-defined delete is supported. 54 delete *b; 55} 56