================ @@ -0,0 +1,219 @@ +========================= +C++ Type Aware Allocators +========================= + +.. contents:: + :local: + +Introduction +============ + +Clang includes an experimental implementation of P2719 "Type-aware allocation +and deallocation functions". + +This is a feature that extends the semantics of ``new``, ``new[]``, ``delete`` and +``delete[]`` operators to expose the type being allocated to the operator. This +can be used to customize allocation of types without needing to modify the +type declaration, or via template definitions fully generic type aware +allocators. + +A major use case of this feature is to support hardened or secure allocators +by supporting anything from simple type property based hardening through to +complete type isolating allocators and beyond, and as such there are no +restrictions on the types or locations that it can be used - anywhere +an allocation or deallocation operator can be declared today can be extended +or replaced with an equivalent type aware declaration. + +Beyond security this feature also allows developers to make rules around +how types may be allocated more explicit by controlling the use and +availability of ``new`` and ``delete`` for types without needing to directly +modify the type. This can be useful where allocation is expected to be +performed through specific interfaces, or explicitly via global ``new`` and +``delete`` operators. + +P2719 introduces a type-identity tag as valid parameter type for all allocation +operators. This tag is a default initialized value of type +``std::type_identity<T>`` where T is the type being allocated or deallocated. +Unlike the other placement arguments this tag is passed as the first parameter +to the operator. + +Usage +===== + +Type aware allocation is currently disabled by default, to enable it use the +``-fexperimental-cxx-type-aware-allocators`` argument to clang. + +The most basic usage is as follows + +.. code-block:: c++ + + #include <new> + #include <type_identity> ---------------- zmodem wrote:
I think this should be `<type_traits>`? https://github.com/llvm/llvm-project/pull/113510 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits