[all-commits] [llvm/llvm-project] 1cd592: [RFC] Initial implementation of P2719 (#113510)

Oliver Hunt via All-commits all-commits at lists.llvm.org
Thu Apr 10 17:13:31 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e
      https://github.com/llvm/llvm-project/commit/1cd59264aa2fb4b0ba70ff03c1298b1b5c21271e
  Author: Oliver Hunt <oliver at apple.com>
  Date:   2025-04-10 (Thu, 10 Apr 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/AST/ASTContext.h
    M clang/include/clang/AST/Decl.h
    M clang/include/clang/AST/DeclarationName.h
    M clang/include/clang/AST/ExprCXX.h
    M clang/include/clang/AST/Stmt.h
    M clang/include/clang/Basic/DiagnosticGroups.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/include/clang/Driver/Options.td
    M clang/include/clang/Sema/Sema.h
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/ASTImporter.cpp
    M clang/lib/AST/ByteCode/Compiler.cpp
    M clang/lib/AST/ByteCode/Interp.cpp
    M clang/lib/AST/Decl.cpp
    M clang/lib/AST/DeclCXX.cpp
    M clang/lib/AST/ExprCXX.cpp
    M clang/lib/AST/ExprConstant.cpp
    M clang/lib/CodeGen/CGExprCXX.cpp
    M clang/lib/Frontend/InitPreprocessor.cpp
    M clang/lib/Sema/Sema.cpp
    M clang/lib/Sema/SemaCoroutine.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaDeclCXX.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/lib/Serialization/ASTReaderStmt.cpp
    M clang/lib/Serialization/ASTWriterStmt.cpp
    M clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.allocation/p1.cpp
    A clang/test/CodeGenCXX/Inputs/std-coroutine.h
    A clang/test/CodeGenCXX/type-aware-allocators.cpp
    A clang/test/CodeGenCXX/type-aware-coroutines.cpp
    A clang/test/CodeGenCXX/type-aware-new-constexpr.cpp
    A clang/test/CodeGenCXX/type-aware-placement-operators.cpp
    M clang/test/CodeGenCoroutines/coro-alloc-2.cpp
    M clang/test/Modules/new-delete.cpp
    M clang/test/SemaCXX/cxx2a-destroying-delete.cpp
    M clang/test/SemaCXX/delete.cpp
    M clang/test/SemaCXX/new-delete.cpp
    A clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
    A clang/test/SemaCXX/type-aware-coroutines.cpp
    A clang/test/SemaCXX/type-aware-new-constexpr.cpp
    A clang/test/SemaCXX/type-aware-new-delete-arrays.cpp
    A clang/test/SemaCXX/type-aware-new-delete-basic-free-declarations.cpp
    A clang/test/SemaCXX/type-aware-new-delete-basic-in-class-declarations.cpp
    A clang/test/SemaCXX/type-aware-new-delete-basic-resolution.cpp
    A clang/test/SemaCXX/type-aware-new-delete-qualifiers.cpp
    A clang/test/SemaCXX/type-aware-new-invalid-type-identity.cpp
    A clang/test/SemaCXX/type-aware-placement-operators.cpp

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list