~shimon/dismaltc

ref: 461e0617cb03f1d5027af4fbb3da0722791022e9 dismaltc/clang/disable-test/SemaOpenCLCXX/newdelete.cl -rw-r--r-- 1.7 KiB
461e0617Itoh Shimon re-enable tests. 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only

class A {
  public:
  A() : x(21) {}
  int x;
};

typedef __SIZE_TYPE__ size_t;

class B {
  public:
  B() : bx(42) {}
  void *operator new(size_t);
  void operator delete(void *ptr);
  int bx;
};

// There are no global user-defined new operators at this point. Test that clang
// rejects these gracefully.
void test_default_new_delete(void *buffer, A **pa) {
  A *a = new A;         // expected-error {{'default new' is not supported in OpenCL C++}}
  delete a;             // expected-error {{'default delete' is not supported in OpenCL C++}}
  *pa = new (buffer) A; // expected-error {{'default new' is not supported in OpenCL C++}}
}

// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
void *operator new(size_t _s, void *ptr) noexcept {
  return ptr;
}

// expected-note@+1 {{candidate function not viable: requires 2 arguments, but 1 was provided}}
void *operator new[](size_t _s, void *ptr) noexcept {
  return ptr;
}

void test_new_delete(void *buffer, A **a, B **b) {
  *a = new A; // expected-error {{no matching function for call to 'operator new'}}
  delete a;   // expected-error {{'default delete' is not supported in OpenCL C++}}

  *a = new A[20]; // expected-error {{no matching function for call to 'operator new[]'}}
  delete[] *a;    // expected-error {{'default delete' is not supported in OpenCL C++}}

  // User-defined placement new is supported.
  *a = new (buffer) A;

  // User-defined placement new[] is supported.
  *a = new (buffer) A[30];

  // User-defined new is supported.
  *b = new B;

  // User-defined delete is supported.
  delete *b;
}