Skip to content

Commit 5bd0611

Browse files
committed
Update documentation for __builtin_operator_new and
__builtin_operator_delete to match r328134.
1 parent 987f153 commit 5bd0611

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,21 +2129,32 @@ object that overloads ``operator&``.
21292129
``__builtin_operator_new`` and ``__builtin_operator_delete``
21302130
------------------------------------------------------------
21312131
2132-
``__builtin_operator_new`` allocates memory just like a non-placement non-class
2133-
*new-expression*. This is exactly like directly calling the normal
2134-
non-placement ``::operator new``, except that it allows certain optimizations
2132+
A call to ``__builtin_operator_new(args)`` is exactly the same as a call to
2133+
``::operator new(args)``, except that it allows certain optimizations
21352134
that the C++ standard does not permit for a direct function call to
21362135
``::operator new`` (in particular, removing ``new`` / ``delete`` pairs and
2137-
merging allocations).
2136+
merging allocations), and that the call is required to resolve to a
2137+
`replaceable global allocation function
2138+
<https://en.cppreference.com/w/cpp/memory/new/operator_new>`_.
21382139
2139-
Likewise, ``__builtin_operator_delete`` deallocates memory just like a
2140-
non-class *delete-expression*, and is exactly like directly calling the normal
2141-
``::operator delete``, except that it permits optimizations. Only the unsized
2142-
form of ``__builtin_operator_delete`` is currently available.
2140+
Likewise, ``__builtin_operator_delete`` is exactly the same as a call to
2141+
``::operator delete(args)``, except that it permits optimizations
2142+
and that the call is required to resolve to a
2143+
`replaceable global deallocation function
2144+
<https://en.cppreference.com/w/cpp/memory/new/operator_delete>`_.
21432145
21442146
These builtins are intended for use in the implementation of ``std::allocator``
21452147
and other similar allocation libraries, and are only available in C++.
21462148
2149+
Query for this feature with ``__has_builtin(__builtin_operator_new)`` or
2150+
``__has_builtin(__builtin_operator_delete)``:
2151+
2152+
* If the value is at least ``201802L``, the builtins behave as described above.
2153+
2154+
* If the value is non-zero, the builtins may not support calling arbitrary
2155+
replaceable global (de)allocation functions, but do support calling at least
2156+
``::operator new(size_t)`` and ``::operator delete(void*)``.
2157+
21472158
``__builtin_preserve_access_index``
21482159
-----------------------------------
21492160

0 commit comments

Comments
 (0)