[libcxx-commits] [clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 18 04:47:55 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 7e2b5e233a49f1c99cf9a3696ca4322ff989a386 f9b9431a97952909190c69e1dee188ef234addb2 --extensions cpp,h -- clang/test/SemaCXX/type-trait-common-type.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/AST/DeclID.h clang/include/clang/Basic/Builtins.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/DeclTemplate.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaTemplate.cpp clang/test/AST/Interp/crash-GH49103-2.cpp clang/test/SemaCXX/crash-GH49103-2.cpp clang/test/SemaCXX/type-traits.cpp libcxx/include/__type_traits/common_type.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4000c2c2d6..355b809da9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1170,8 +1170,7 @@ ASTContext::getTypePackElementDecl() const {
   return TypePackElementDecl;
 }
 
-BuiltinTemplateDecl *
-ASTContext::getCommonTypeDecl() const {
+BuiltinTemplateDecl *ASTContext::getCommonTypeDecl() const {
   if (!CommonTypeDecl)
     CommonTypeDecl =
         buildBuiltinTemplateDecl(BTK__common_type, getCommonTypeName());
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3f862d06af..e520df617e 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3058,9 +3058,10 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
-static std::optional<QualType>
-commonTypeImpl(Sema &S, TemplateName BaseTemplate,
-               SourceLocation TemplateLoc, ArrayRef<TemplateArgument> Ts) {
+static std::optional<QualType> commonTypeImpl(Sema &S,
+                                              TemplateName BaseTemplate,
+                                              SourceLocation TemplateLoc,
+                                              ArrayRef<TemplateArgument> Ts) {
   auto lookUpCommonType = [&](TemplateArgument T1,
                               TemplateArgument T2) -> std::optional<QualType> {
     // Don't bother looking for other specializations if both types are
@@ -3130,8 +3131,8 @@ commonTypeImpl(Sema &S, TemplateName BaseTemplate,
         ExprResult Cond = &CondExpr;
 
         // declval<D1>()
-        auto EVK = ConstRefQual ? ExprValueKind::VK_LValue
-                                     : ExprValueKind::VK_PRValue;
+        auto EVK =
+            ConstRefQual ? ExprValueKind::VK_LValue : ExprValueKind::VK_PRValue;
         if (ConstRefQual) {
           D1.addConst();
           D2.addConst();
diff --git a/libcxx/include/__type_traits/common_type.h b/libcxx/include/__type_traits/common_type.h
index 8240250742..103b58e42a 100644
--- a/libcxx/include/__type_traits/common_type.h
+++ b/libcxx/include/__type_traits/common_type.h
@@ -31,7 +31,7 @@ template <class... _Args>
 struct common_type : __common_type<common_type, __type_identity, __empty, _Args...> {};
 
 #else
-#if _LIBCPP_STD_VER >= 20
+#  if _LIBCPP_STD_VER >= 20
 // Let COND_RES(X, Y) be:
 template <class _Tp, class _Up>
 using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>());
@@ -47,10 +47,10 @@ struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>> {
 
 template <class _Tp, class _Up, class = void>
 struct __common_type2_imp : __common_type3<_Tp, _Up> {};
-#else
+#  else
 template <class _Tp, class _Up, class = void>
 struct __common_type2_imp {};
-#endif
+#  endif
 
 // sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
 template <class _Tp, class _Up>

``````````

</details>


https://github.com/llvm/llvm-project/pull/99473


More information about the libcxx-commits mailing list