aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/InitPreprocessor.cpp
diff options
context:
space:
mode:
authorOliver Hunt <oliver@apple.com>2025-04-10 17:13:10 -0700
committerGitHub <noreply@github.com>2025-04-10 17:13:10 -0700
commit1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e (patch)
tree211f37abb77edad44b740df8a5f01bcba0a92b62 /clang/lib/Frontend/InitPreprocessor.cpp
parent2f298294759307e532dcce50549534cbe8ba6561 (diff)
downloadllvm-1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e.zip
llvm-1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e.tar.gz
llvm-1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e.tar.bz2
[RFC] Initial implementation of P2719 (#113510)
This is a basic implementation of P2719: "Type-aware allocation and deallocation functions" described at http://wg21.link/P2719 The proposal includes some more details but the basic change in functionality is the addition of support for an additional implicit parameter in operators `new` and `delete` to act as a type tag. Tag is of type `std::type_identity<T>` where T is the concrete type being allocated. So for example, a custom type specific allocator for `int` say can be provided by the declaration of void *operator new(std::type_identity<int>, size_t, std::align_val_t); void operator delete(std::type_identity<int>, void*, size_t, std::align_val_t); However this becomes more powerful by specifying templated declarations, for example template <typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t); template <typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t);); Where the operators being resolved will be the concrete type being operated over (NB. A completely unconstrained global definition as above is not recommended as it triggers many problems similar to a general override of the global operators). These type aware operators can be declared as either free functions or in class, and can be specified with or without the other implicit parameters, with overload resolution performed according to the existing standard parameter prioritisation, only with type parameterised operators having higher precedence than non-type aware operators. The only exception is destroying_delete which for reasons discussed in the paper we do not support type-aware variants by default.
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 90d0f5c..659af42 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -776,6 +776,9 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
if (LangOpts.Char8)
Builder.defineMacro("__cpp_char8_t", "202207L");
Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
+
+ // TODO: Final number?
+ Builder.defineMacro("__cpp_type_aware_allocators", "202500L");
}
/// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target