[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 8 17:39:03 PST 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 9cc2122bf5a81f7063c2a32b2cb78c8d615578a1 6c74eb263dd889858f3f7be328d85fe354f71835 -- clang/test/SemaCXX/type-traits-invocable.cpp clang/include/clang/AST/Type.h clang/lib/Sema/SemaExprCXX.cpp libcxx/include/__type_traits/invoke.h
``````````

</details>

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

``````````diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 4f4b6492e5..d033113805 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5520,7 +5520,8 @@ static bool IsBaseOf(Sema &Self, QualType LhsT, QualType RhsT,
       ->isDerivedFrom(cast<CXXRecordDecl>(lhsRecord->getDecl()));
 }
 
-static bool IsConvertible(Sema& Self, QualType LhsT, QualType RhsT, SourceLocation KeyLoc, bool CheckNothrow) {
+static bool IsConvertible(Sema &Self, QualType LhsT, QualType RhsT,
+                          SourceLocation KeyLoc, bool CheckNothrow) {
   // C++0x [meta.rel]p4:
   //   Given the following function prototype:
   //
@@ -5667,7 +5668,7 @@ static bool IsInvocable(Sema &S, SourceLocation KWLoc,
     if (Object->isPointerType())
       Object = Object->getPointeeType();
     // bullets 2, 5 - ignore reference_wrapper
-    else if (auto* RD = Object->getAsCXXRecordDecl()) {
+    else if (auto *RD = Object->getAsCXXRecordDecl()) {
       if (auto *TS = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
         if (TS->isInStdNamespace() && TS->getName() == "reference_wrapper")
           Object = TS->getTemplateArgs().get(0).getAsType();
@@ -5865,7 +5866,8 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
     return IsInvocable(S, KWLoc, Args, RParenLoc,
                        Kind == TT_IsNothrowInvocableR);
 
-  default: llvm_unreachable("not a TT");
+  default:
+    llvm_unreachable("not a TT");
   }
 
   return false;
diff --git a/libcxx/include/__type_traits/invoke.h b/libcxx/include/__type_traits/invoke.h
index 5286d78bf6..0920539c71 100644
--- a/libcxx/include/__type_traits/invoke.h
+++ b/libcxx/include/__type_traits/invoke.h
@@ -424,7 +424,7 @@ struct __invoke_void_return_wrapper<_Ret, true> {
 
 // is_invocable
 
-#if __has_builtin(__is_invocable_r)
+#  if __has_builtin(__is_invocable_r)
 
 template <class _Fn, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_invocable : bool_constant<__is_invocable_r(void, _Fn, _Args...)> {};
@@ -438,7 +438,7 @@ inline constexpr bool is_invocable_v = __is_invocable_r(void, _Fn, _Args...);
 template <class _Ret, class _Fn, class... _Args>
 inline constexpr bool is_invocable_r_v = __is_invocable_r(_Ret, _Fn, _Args...);
 
-#else
+#  else
 
 template <class _Fn, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_invocable : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
@@ -452,11 +452,11 @@ inline constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value;
 template <class _Ret, class _Fn, class... _Args>
 inline constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value;
 
-#endif // __has_builtin(__is_invocable_r)
+#  endif // __has_builtin(__is_invocable_r)
 
 // is_nothrow_invocable
 
-#if __has_builtin(__is_nothrow_invocable_r)
+#  if __has_builtin(__is_nothrow_invocable_r)
 
 template <class _Fn, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : bool_constant<__is_nothrow_invocable_r(void, _Fn, _Args...)> {};
@@ -470,7 +470,7 @@ inline constexpr bool is_nothrow_invocable_v = __is_nothrow_invocable_r(void, _F
 template <class _Ret, class _Fn, class... _Args>
 inline constexpr bool is_nothrow_invocable_r_v = __is_nothrow_invocable_r(_Ret, _Fn, _Args...);
 
-#else
+#  else
 
 template <class _Fn, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {
@@ -486,7 +486,7 @@ inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args..
 template <class _Ret, class _Fn, class... _Args>
 inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
 
-#endif // __has_builtin(__is_nothrow_invocable_r)
+#  endif // __has_builtin(__is_nothrow_invocable_r)
 
 template <class _Fn, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_of<_Fn, _Args...> {};

``````````

</details>


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


More information about the cfe-commits mailing list