[basic.stc.dynamic.general] (original) (raw)

A C++ implementation provides access to, and management of, dynamic storage via the globalallocation functions operator new and operator new[] and the global deallocation functions operator delete and operator delete[].

[Note 1:

The non-allocating forms described in [new.delete.placement]do not perform allocation or deallocation.

— _end note_]

The library provides default definitions for the global allocation and deallocation functions.

Some global allocation and deallocation functions are replaceable ([new.delete]).

A C++ program shall provide at most one definition of a replaceable allocation or deallocation function.

Any such function definition replaces the default version provided in the library ([replacement.functions]).

The following allocation and deallocation functions ([support.dynamic]) are implicitly declared in global scope in each translation unit of a program.

[[nodiscard]] void* operator new(std::size_t);[[nodiscard]] void* operator new(std::size_t, std::align_val_t);void operator delete(void*) noexcept;void operator delete(void*, std::size_t) noexcept;void operator delete(void*, std::align_val_t) noexcept;void operator delete(void*, std::size_t, std::align_val_t) noexcept;[[nodiscard]] void* operator new[](std::size_t);[[nodiscard]] void* operator new[](std::size_t, std::align_val_t);void operator delete[](void*) noexcept;void operator delete[](void*, std::size_t) noexcept;void operator delete[](void*, std::align_val_t) noexcept;void operator delete[](void*, std::size_t, std::align_val_t) noexcept;

These implicit declarations introduce only the function namesoperator new, operator new[],operator delete, and operator delete[].

[Note 2:

The implicit declarations do not introduce the names std,std​::​size_­t,std​::​align_­val_­t, or any other names that the library uses to declare these names.

Thus, a new-expression,delete-expression, or function call that refers to one of these functions without importing or including the header is well-formed.

However, referring to stdor std​::​size_­tor std​::​align_­val_­tis ill-formed unless the name has been declared by importing or including the appropriate header.

— _end note_]

Allocation and/or deallocation functions may also be declared and defined for any class ([class.free]).