111
|
1 // Test for C++14 sized deallocation. The operators delete defined below
|
|
2 // should be called only in C++14 mode and above.
|
|
3 // { dg-do run }
|
|
4
|
|
5 extern "C" void abort();
|
|
6 typedef __SIZE_TYPE__ size_t;
|
|
7 #include <new>
|
|
8
|
|
9 bool called;
|
|
10 void operator delete[] (void *p, size_t s) throw()
|
|
11 {
|
|
12 called = true;
|
|
13 operator delete[] (p);
|
|
14 }
|
|
15
|
|
16 void operator delete (void *p, size_t s) throw()
|
|
17 {
|
|
18 called = true;
|
|
19 operator delete (p);
|
|
20 }
|
|
21
|
|
22 void operator delete[] (void *p, size_t s, const std::nothrow_t &) throw()
|
|
23 {
|
|
24 called = true;
|
|
25 operator delete[] (p);
|
|
26 }
|
|
27
|
|
28 void operator delete (void *p, size_t s, const std::nothrow_t &) throw()
|
|
29 {
|
|
30 called = true;
|
|
31 operator delete (p);
|
|
32 }
|
|
33
|
|
34 struct A { ~A(){} };
|
|
35
|
|
36 struct B { };
|
|
37
|
|
38 struct C;
|
|
39
|
|
40 struct D { ~D(){}; D() { throw 1; } };
|
|
41
|
|
42 int main()
|
|
43 {
|
|
44 /* * If the type is complete and if, for the second alternative (delete
|
|
45 array) only, the operand is a pointer to a class type with a
|
|
46 non-trivial destructor or a (possibly multi-dimensional) array
|
|
47 thereof, the function with two parameters is selected.
|
|
48
|
|
49 * Otherwise, it is unspecified which of the two deallocation functions
|
|
50 is selected. */
|
|
51 delete new int;
|
|
52 if (called != (__cplusplus >= 201402L)) abort(); called = false;
|
|
53
|
|
54 delete new A;
|
|
55 if (called != (__cplusplus >= 201402L)) abort(); called = false;
|
|
56
|
|
57 delete[] new A[2];
|
|
58 if (called != (__cplusplus >= 201402L)) abort(); called = false;
|
|
59
|
|
60 delete new B;
|
|
61 if (called != (__cplusplus >= 201402L)) abort(); called = false;
|
|
62
|
|
63 /* N3778 added the sized placement deallocation functions, but the core
|
|
64 language rules don't provide any way they would be called. */
|
|
65 try { new (std::nothrow) D; } catch (int) {}
|
|
66 if (called) abort();
|
|
67
|
|
68 try { new (std::nothrow) D[2]; } catch (int) {}
|
|
69 if (called) abort();
|
|
70
|
|
71 /* Make sure we don't try to use the size of an array that doesn't have a
|
|
72 cookie. */
|
|
73 delete[] new B[2];
|
|
74 if (called) abort();
|
|
75 }
|