blob: 1727a74ff36955f92b2bbd30aab89e5c32203517 (
plain)
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
90
91
92
93
|
// { dg-do run }
// { dg-xfail-run-if "AIX operator delete" { powerpc-ibm-aix* } }
// pr 55635, the delete operator must be called, regardless of whether
// the dtor throws
static int deleted;
void operator delete (void *) throw ()
{
deleted = 1;
}
struct Foo {
~Foo()
#if __cplusplus <= 201402L
throw(int) // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } }
#else
noexcept(false)
#endif
{throw 1;}
};
struct Baz {
void operator delete (void *) throw ()
{
deleted = 2;
}
virtual ~Baz()
#if __cplusplus <= 201402L
throw(int) // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } }
#else
noexcept(false)
#endif
{throw 1;}
};
int non_virt ()
{
deleted = 0;
Foo *p = new Foo;
try { delete p; }
catch (...) { return deleted != 1;}
return 1;
}
int virt_glob ()
{
deleted = 0;
Baz *p = ::new Baz;
try { ::delete p; }
catch (...) { return deleted != 1;}
return 1;
}
int virt_del ()
{
deleted = 0;
Baz *p = new Baz;
try { delete p; }
catch (...) { return deleted != 2;}
return 1;
}
int ary ()
{
deleted = 0;
Baz *p = new Baz[5];
try { delete[] p; }
catch (...) { return deleted != 1;}
return 1;
}
int main ()
{
if (non_virt ())
return 1;
if (virt_glob ())
return 2;
if (virt_del ())
return 3;
if (ary ())
return 4;
return 0;
}
|