@@ -20,8 +20,8 @@ class C1 {
2020 void *ptr) noexcept ; // NON_COMPLIANT: class-specific declaration
2121 void *operator new (
2222 std::size_t size,
23- const std::nothrow_t &) noexcept ; // NON_COMPLIANT: class-specific
24- // nothrow declaration
23+ const std::nothrow_t
24+ &) noexcept ; // NON_COMPLIANT: class-specific nothrow declaration
2525 void *operator new (std::size_t size,
2626 void *ptr) noexcept ; // NON_COMPLIANT: class-specific
2727 // placement declaration
@@ -34,6 +34,15 @@ class C1 {
3434 void *
3535 operator new (std::size_t size, double alignment,
3636 int pool); // NON_COMPLIANT: class-specific custom declaration
37+ void operator delete (void *ptr,
38+ void *) noexcept ; // NON_COMPLIANT: class-specific
39+ // placement delete declaration
40+ void operator delete[] (void *ptr,
41+ void *) noexcept ; // NON_COMPLIANT: class-specific
42+ // placement delete[] declaration
43+ void operator delete (void *ptr,
44+ int hint) noexcept ; // NON_COMPLIANT: class-specific
45+ // custom delete declaration
3746};
3847
3948/* *
@@ -105,41 +114,40 @@ class C2 {
105114};
106115
107116/* *
108- * Global replaceable forms - COMPLIANT
109- * These are the "blessed" signatures that can be replaced globally.
117+ * Re-declared allocation / deallocations functions - NON_COMPLIANT
110118 */
111- void *
112- operator new ( std::size_t size); // COMPLIANT : re-declaring global replaceable
119+ void *operator new (
120+ std::size_t size); // NON_COMPLIANT : re-declaring global replaceable
113121void *operator new (std::size_t size) {
114122 return std::malloc (size);
115- } // COMPLIANT : implementing global replaceable
123+ } // NON_COMPLIANT : implementing global replaceable
116124void operator delete (void *ptr) noexcept {
117125 std::free (ptr);
118- } // COMPLIANT : implementing global replaceable
126+ } // NON_COMPLIANT : implementing global replaceable
119127void *operator new [](std::size_t size) {
120128 return std::malloc (size);
121- } // COMPLIANT : implementing global replaceable
129+ } // NON_COMPLIANT : implementing global replaceable
122130void operator delete[] (void *ptr) noexcept {
123131 std::free (ptr);
124- } // COMPLIANT : implementing global replaceable
132+ } // NON_COMPLIANT : implementing global replaceable
125133void *operator new (std::size_t size, const std::nothrow_t &) noexcept {
126134 return std::malloc (size);
127- } // COMPLIANT : implementing global replaceable nothrow
135+ } // NON_COMPLIANT : implementing global replaceable nothrow
128136void *operator new [](std::size_t size, const std::nothrow_t &) noexcept {
129137 return std::malloc (size);
130- } // COMPLIANT : implementing global replaceable nothrow
138+ } // NON_COMPLIANT : implementing global replaceable nothrow
131139void operator delete (void *ptr, std::size_t ) noexcept {
132140 std::free (ptr);
133- } // COMPLIANT : implementing global replaceable sized
141+ } // NON_COMPLIANT : implementing global replaceable sized
134142void operator delete[] (void *ptr, std::size_t ) noexcept {
135143 std::free (ptr);
136- } // COMPLIANT : implementing global replaceable sized
144+ } // NON_COMPLIANT : implementing global replaceable sized
137145void operator delete (void *ptr, const std::nothrow_t &) noexcept {
138146 std::free (ptr);
139- } // COMPLIANT : implementing global replaceable placement deallocation
147+ } // NON_COMPLIANT : implementing global replaceable placement deallocation
140148void operator delete[] (void *ptr, const std::nothrow_t &) noexcept {
141149 std::free (ptr);
142- } // COMPLIANT : implementing global replaceable placement deallocation
150+ } // NON_COMPLIANT : implementing global replaceable placement deallocation
143151
144152/* *
145153 * Global non-standard forms - NON_COMPLIANT
@@ -198,6 +206,20 @@ void use_custom_new_expressions() {
198206 * Test taking address of global placement new.
199207 */
200208void take_address_of_placement_new () {
209+ void *(*c1)(std::size_t ) =
210+ &::operator new ; // COMPLIANT: address of replaceable new
211+ void *(*c2)(std::size_t ) =
212+ ::operator new ; // COMPLIANT: implicit address of replaceable new
213+ void *(*c3)(std::size_t ) =
214+ &::operator new []; // COMPLIANT: address of replaceable new[]
215+ void *(*c4)(std::size_t ) =
216+ ::operator new []; // COMPLIANT: implicit address of replaceable new[]
217+ void *(*c5)(std::size_t , const std::nothrow_t &) =
218+ &::operator new ; // COMPLIANT: address of nothrow new
219+ void *(*c6)(std::size_t , const std::nothrow_t &) =
220+ &::operator new []; // COMPLIANT: address of nothrow new[]
221+
222+ // Non-compliant: taking address of non-replaceable allocation functions
201223 void *(*p1)(std::size_t , void *) =
202224 &::operator new ; // NON_COMPLIANT: address of placement new
203225 void *(*p2)(std::size_t , void *) =
@@ -212,6 +234,25 @@ void take_address_of_placement_new() {
212234 * Test taking address of global placement delete.
213235 */
214236void take_address_of_placement_delete () {
237+ // Compliant: taking address of replaceable deallocation functions
238+ void (*c1)(void *) =
239+ &::operator delete ; // COMPLIANT: address of replaceable delete
240+ void (*c2)(void *) =
241+ ::operator delete ; // COMPLIANT: implicit address of replaceable delete
242+ void (*c3)(void *) =
243+ &::operator delete[] ; // COMPLIANT: address of replaceable delete[]
244+ void (*c4)(void *) = ::operator delete[] ; // COMPLIANT: implicit address of
245+ // replaceable delete[]
246+ void (*c5)(void *, std::size_t ) =
247+ &::operator delete ; // COMPLIANT: address of sized delete
248+ void (*c6)(void *, std::size_t ) =
249+ &::operator delete[] ; // COMPLIANT: address of sized delete[]
250+ void (*c7)(void *, const std::nothrow_t &) =
251+ &::operator delete ; // COMPLIANT: address of nothrow delete
252+ void (*c8)(void *, const std::nothrow_t &) =
253+ &::operator delete[] ; // COMPLIANT: address of nothrow delete[]
254+
255+ // Non-compliant: taking address of non-replaceable deallocation functions
215256 void (*p1)(void *, void *) =
216257 &::operator delete ; // NON_COMPLIANT: address of placement delete
217258 void (*p2)(void *, void *) =
@@ -228,11 +269,14 @@ void take_address_of_placement_delete() {
228269 */
229270void take_address_of_class_specific_new () {
230271 void *(*p1)(std::size_t ) =
231- &C1::operator new ; // NON_COMPLIANT: address of class-specific new
272+ &C1::operator new ; // COMPLIANT: address of class-specific replaceable
273+ // allocation function
232274 void *(*p2)(std::size_t ) =
233- &C1::operator new []; // NON_COMPLIANT: address of class-specific new[]
275+ &C1::operator new []; // COMPLIANT: address of class-specific replaceable
276+ // allocation function
234277 void *(*p3)(std::size_t , const std::nothrow_t &) =
235- &C1::operator new ; // NON_COMPLIANT: address of class-specific nothrow new
278+ &C1::operator new ; // COMPLIANT: address of class-specific replaceable
279+ // non-throwing allocation function
236280 void *(*p4)(std::size_t , void *) =
237281 &C1::operator new ; // NON_COMPLIANT: address of class-specific placement
238282 // new
@@ -245,9 +289,20 @@ void take_address_of_class_specific_new() {
245289 */
246290void take_address_of_class_specific_delete () {
247291 void (*p1)(void *) =
248- &C1::operator delete ; // NON_COMPLIANT: address of class-specific delete
249- void (*p2)(void *) = &C1::operator delete[] ; // NON_COMPLIANT: address of
250- // class-specific delete[]
292+ &C1::operator delete ; // COMPLIANT: address of class-specific
293+ // replaceable deallocation function
294+ void (*p2)(void *) =
295+ &C1::operator delete[] ; // COMPLIANT: address of class-specific
296+ // replaceable deallocation function
297+ void (*p3)(void *, void *) =
298+ &C1::operator delete ; // NON_COMPLIANT: address of class-specific
299+ // placement delete
300+ void (*p4)(void *, void *) =
301+ &C1::operator delete[] ; // NON_COMPLIANT: address of class-specific
302+ // placement delete[]
303+ void (*p5)(void *, int ) =
304+ &C1::operator delete ; // NON_COMPLIANT: address of class-specific custom
305+ // delete
251306}
252307
253308/* *
0 commit comments