From f5be5cdaad7edf52e39ad439cf5d608c930efca2 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Sun, 22 Sep 2024 09:25:52 +0200 Subject: [PATCH] [Clang] Add __builtin_common_type (#99473) This implements the logic of the `common_type` base template as a builtin alias. If there should be no `type` member, an empty class is returned. Otherwise a specialization of a `type_identity`-like class is returned. The base template (i.e. `std::common_type`) as well as the empty class and `type_identity`-like struct are given as arguments to the builtin. --- clang/docs/LanguageExtensions.rst | 40 ++++ clang/docs/ReleaseNotes.rst | 3 + clang/include/clang/AST/ASTContext.h | 11 + clang/include/clang/AST/DeclID.h | 3 + clang/include/clang/Basic/Builtins.h | 5 +- clang/lib/AST/ASTContext.cpp | 7 + clang/lib/AST/ASTImporter.cpp | 3 + clang/lib/AST/DeclTemplate.cpp | 56 +++++ clang/lib/Lex/PPMacroExpansion.cpp | 1 + clang/lib/Sema/SemaLookup.cpp | 7 +- clang/lib/Sema/SemaTemplate.cpp | 159 ++++++++++++- clang/lib/Serialization/ASTReader.cpp | 7 + clang/lib/Serialization/ASTWriter.cpp | 1 + clang/test/SemaCXX/type-trait-common-type.cpp | 210 ++++++++++++++++++ libcxx/include/__type_traits/common_type.h | 22 +- libcxx/include/module.modulemap | 2 + 16 files changed, 531 insertions(+), 6 deletions(-) create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index f62f90fb9650a9..0c6b9b1b8f9ce4 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1516,6 +1516,46 @@ Attributes (N2335) C2 ``#embed`` (N3017) C23 C89, C++ ============================================ ================================ ============= ============= +Builtin type aliases +==================== + +Clang provides a few builtin aliases to improve the throughput of certain metaprogramming facilities. + +__builtin_common_type +--------------------- + +.. code-block:: c++ + + template