If I write operators new and delete for a class, do I have to write all of their overloads?

Viewed 1303

The C++ Reference page lists 8 class specific overloads for global new operators. Four of those were added for 2017 version of C++.

Class-specific allocation functions

void* T::operator new  ( std::size_t count );   
void* T::operator new[]( std::size_t count );
void* T::operator new  ( std::size_t count, std::align_val_t al ); // (since C++17)
void* T::operator new[]( std::size_t count, std::align_val_t al ); // (since C++17)

Class-specific placement allocation functions

void* T::operator new  ( std::size_t count, user-defined-args... );
void* T::operator new[]( std::size_t count, user-defined-args... );
void* T::operator new  ( std::size_t count,
    std::align_val_t al, user-defined-args... ); // (since C++17)
void* T::operator new[]( std::size_t count,
     std::align_val_t al, user-defined-args... ); // (since C++17)

That website also lists 10 class specific versions of global delete operators, of which 4 were introduced for 2017.

Class-specific usual deallocation functions

void T::operator delete  ( void* ptr );
void T::operator delete[]( void* ptr );
void T::operator delete  ( void* ptr, std::align_val_t al ); // (since C++17)
void T::operator delete[]( void* ptr, std::align_val_t al ); // (since C++17)
void T::operator delete  ( void* ptr, std::size_t sz );
void T::operator delete[]( void* ptr, std::size_t sz );
void T::operator delete  ( void* ptr, std::size_t sz, std::align_val_t al ); // (since C++17)
void T::operator delete[]( void* ptr, std::size_t sz, std::align_val_t al ); // (since C++17)

Class-specific placement deallocation functions

void T::operator delete  ( void* ptr, args... );
void T::operator delete[]( void* ptr, args... );

If I write a C++ class with new and delete operators, do I need to overload all of those? I am ignoring the replaceable global operators since I am only writing class specific operators.

This other question provides info on writing ISO compliant new and delete operators, but does not say if I should overload all of them, or just some.

The answer to this question about class specific new and delete operators does not say whether to replace all or just some of them.

If you can provide citations from the C++ Standard or comments by C++ memory experts, that would help.

3 Answers
Related