-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sized_dealloc.cpp
89 lines (67 loc) · 1.75 KB
/
test_sized_dealloc.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// $HOME/bin/bin/g++ -g -std=c++14 -DCHECK=true -o test_sized_dealloc test_sized_dealloc.cpp
// $HOME/bin/bin/g++ -g -std=c++14 -DCHECK=false -fno-sized-deallocation -o test_sized_dealloc test_sized_dealloc.cpp
// $HOME/bin/bin/g++ -g -std=c++11 -DCHECK=false -o test_sized_dealloc test_sized_dealloc.cpp
// $HOME/bin/bin/g++ -g -std=c++11 -DCHECK=true -fsized-deallocation -o test_sized_dealloc test_sized_dealloc.cpp
extern "C" void abort();
typedef __SIZE_TYPE__ size_t;
#include <new>
bool called = false;
void
operator delete[] (void *p, size_t s) throw()
{
called = true;
operator delete[] (p);
}
void
operator delete (void *p, size_t s) throw()
{
called = true;
operator delete (p);
}
void
operator delete[] (void *p, size_t s, const std::nothrow_t &) throw()
{
called = true;
operator delete[] (p);
}
void
operator delete (void *p, size_t s, const std::nothrow_t &) throw()
{
called = true;
operator delete (p);
}
struct A { ~A(){} };
struct B { };
struct C;
struct D { ~D(){}; D() { throw 1; } };
int
main()
{
bool check = CHECK;
delete new int;
if (called != check)
abort();
called = false;
delete new A;
if (called != check)
abort();
called = false;
delete[] new A[2];
if (called != check)
abort();
called = false;
delete new B;
if (called != check)
abort();
called = false;
/* N3778 added the sized placement deallocation functions, but the core
language rules don't provide any way they would be called. */
try { new (std::nothrow) D; } catch (int) {}
if (called) abort();
try { new (std::nothrow) D[2]; } catch (int) {}
if (called) abort();
/* Make sure we don't try to use the size of an array that doesn't have a
cookie. */
delete[] new B[2];
if (called) abort();
}