annotate gcc/testsuite/g++.dg/cpp1y/sized-dealloc1.C @ 131:84e7813d76e9

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