[libcxx-commits] [libcxx] 1b9c5f6 - [libc++] Remove redundant __invoke_constexpr functions

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 7 04:56:24 PDT 2022


Author: Nikolas Klauser
Date: 2022-04-07T13:56:11+02:00
New Revision: 1b9c5f60aabdfd59096fb66b2bff55b7e71e1c5f

URL: https://github.com/llvm/llvm-project/commit/1b9c5f60aabdfd59096fb66b2bff55b7e71e1c5f
DIFF: https://github.com/llvm/llvm-project/commit/1b9c5f60aabdfd59096fb66b2bff55b7e71e1c5f.diff

LOG: [libc++] Remove redundant __invoke_constexpr functions

There are `constexpr` versions for the different `__invoke` functions, which seem to be identical other than begin `constexpr` since C++11 instead of being `constexpr` since C++20.

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D123003

Added: 
    

Modified: 
    libcxx/include/tuple
    libcxx/include/type_traits
    libcxx/include/variant
    libcxx/test/libcxx/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp
    libcxx/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
    libcxx/test/libcxx/utilities/function.objects/func.require/invoke_helpers.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/tuple b/libcxx/include/tuple
index 0a62578eadbbd..76297dd76e5b2 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1609,7 +1609,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
                                             __tuple_indices<_Id...>)
 _LIBCPP_NOEXCEPT_RETURN(
-    _VSTD::__invoke_constexpr(
+    _VSTD::__invoke(
         _VSTD::forward<_Fn>(__f),
         _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
 )

diff  --git a/libcxx/include/type_traits b/libcxx/include/type_traits
index 968229e119dbe..2ea883fdbec03 100644
--- a/libcxx/include/type_traits
+++ b/libcxx/include/type_traits
@@ -3460,139 +3460,74 @@ using __enable_if_bullet6 = typename enable_if
 template <class ..._Args>
 auto __invoke(__any, _Args&& ...__args) -> __nat;
 
-template <class ..._Args>
-auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
-
 // bullets 1, 2 and 3
 
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet1<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
     noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
     -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
     { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
 
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet1<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-    noexcept(noexcept((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...)))
-    -> decltype(      (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
-    { return          (static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...); }
-
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet2<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
     noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
     -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
     { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
 
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet2<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-    noexcept(noexcept((__a0.get().*__f)(static_cast<_Args&&>(__args)...)))
-    -> decltype(      (__a0.get().*__f)(static_cast<_Args&&>(__args)...))
-    { return          (__a0.get().*__f)(static_cast<_Args&&>(__args)...); }
-
 template <class _Fp, class _A0, class ..._Args,
           class = __enable_if_bullet3<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
     noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
     -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
     { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
 
-template <class _Fp, class _A0, class ..._Args,
-          class = __enable_if_bullet3<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
-    noexcept(noexcept(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...)))
-    -> decltype(      ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
-    { return          ((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...); }
-
 // bullets 4, 5 and 6
 
 template <class _Fp, class _A0,
           class = __enable_if_bullet4<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0)
     noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
     -> decltype(      static_cast<_A0&&>(__a0).*__f)
     { return          static_cast<_A0&&>(__a0).*__f; }
 
-template <class _Fp, class _A0,
-          class = __enable_if_bullet4<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-    noexcept(noexcept(static_cast<_A0&&>(__a0).*__f))
-    -> decltype(      static_cast<_A0&&>(__a0).*__f)
-    { return          static_cast<_A0&&>(__a0).*__f; }
-
 template <class _Fp, class _A0,
           class = __enable_if_bullet5<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0)
     noexcept(noexcept(__a0.get().*__f))
     -> decltype(      __a0.get().*__f)
     { return          __a0.get().*__f; }
 
-template <class _Fp, class _A0,
-          class = __enable_if_bullet5<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-    noexcept(noexcept(__a0.get().*__f))
-    -> decltype(      __a0.get().*__f)
-    { return          __a0.get().*__f; }
-
 template <class _Fp, class _A0,
           class = __enable_if_bullet6<_Fp, _A0>>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _A0&& __a0)
     noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
     -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
     { return          (*static_cast<_A0&&>(__a0)).*__f; }
 
-template <class _Fp, class _A0,
-          class = __enable_if_bullet6<_Fp, _A0>>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _A0&& __a0)
-    noexcept(noexcept((*static_cast<_A0&&>(__a0)).*__f))
-    -> decltype(      (*static_cast<_A0&&>(__a0)).*__f)
-    { return          (*static_cast<_A0&&>(__a0)).*__f; }
-
 // bullet 7
 
 template <class _Fp, class ..._Args>
 inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
+constexpr auto
 __invoke(_Fp&& __f, _Args&& ...__args)
     noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
     -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
     { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
 
-template <class _Fp, class ..._Args>
-inline _LIBCPP_INLINE_VISIBILITY
-_LIBCPP_CONSTEXPR auto
-__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
-    noexcept(noexcept(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...)))
-    -> decltype(      static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
-    { return          static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...); }
-
 // __invokable
 template <class _Ret, class _Fp, class ..._Args>
 struct __invokable_r

diff  --git a/libcxx/include/variant b/libcxx/include/variant
index 6012aaad1f297..b1800ed63b965 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -547,7 +547,7 @@ private:
     template <class _Fp, class... _Vs>
     inline _LIBCPP_INLINE_VISIBILITY
     static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
-        return _VSTD::__invoke_constexpr(
+        return _VSTD::__invoke(
             static_cast<_Fp>(__f),
             __access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
     }
@@ -667,8 +667,8 @@ private:
       __std_visit_exhaustive_visitor_check<
           _Visitor,
           decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
-      return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
-                                _VSTD::forward<_Alts>(__alts).__value...);
+      return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
+                             _VSTD::forward<_Alts>(__alts).__value...);
     }
     _Visitor&& __visitor;
   };
@@ -683,12 +683,12 @@ private:
           _Visitor,
           decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
       if constexpr (is_void_v<_Rp>) {
-        _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
-                                  _VSTD::forward<_Alts>(__alts).__value...);
+        _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
+                        _VSTD::forward<_Alts>(__alts).__value...);
       }
       else {
-        return _VSTD::__invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
-                                         _VSTD::forward<_Alts>(__alts).__value...);
+        return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor),
+                               _VSTD::forward<_Alts>(__alts).__value...);
       }
     }
 

diff  --git a/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp b/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp
index 28ee3a39afeec..6d3a9f3856411 100644
--- a/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp
+++ b/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp
@@ -244,30 +244,55 @@ struct TestCase : public TestCaseImp<MemFun03, Sig, Arity, CV> {};
 #if TEST_STD_VER >= 11
 template <class Sig, int Arity, class CV, bool RValue = false>
 struct TestCase11 : public TestCaseImp<MemFun11, Sig, Arity, CV, RValue, true> {};
-#endif
+
+template <class Type>
+struct ReferenceWrapper {
+    using type = Type;
+    Type* ptr;
+
+    static void fun(Type&) noexcept;
+    static void fun(Type&&) = delete;
+
+    template <class Type2,
+              class = typename std::enable_if<!std::__is_same_uncvref<Type2, ReferenceWrapper>::value>::type>
+    constexpr ReferenceWrapper(Type2&& t) noexcept : ptr(&t) {}
+
+    constexpr Type& get() const noexcept { return *ptr; }
+    constexpr operator Type&() const noexcept { return *ptr; }
+
+    template <class... _ArgTypes>
+    constexpr typename std::__invoke_of<Type&, _ArgTypes...>::type operator() (_ArgTypes&&... __args) const {
+        return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
+    }
+};
 
 template <class Tp>
-struct DerivedFromRefWrap : public std::reference_wrapper<Tp> {
-  DerivedFromRefWrap(Tp& tp) : std::reference_wrapper<Tp>(tp) {}
+struct DerivedFromRefWrap : public ReferenceWrapper<Tp> {
+  constexpr DerivedFromRefWrap(Tp& tp) : ReferenceWrapper<Tp>(tp) {}
 };
 
-#if TEST_STD_VER >= 11
-void test_derived_from_ref_wrap() {
+TEST_CONSTEXPR_CXX14 bool test_derived_from_ref_wrap() {
     int x = 42;
-    std::reference_wrapper<int> r(x);
-    std::reference_wrapper<std::reference_wrapper<int>> r2(r);
+    ReferenceWrapper<int> r(x);
     DerivedFromRefWrap<int> d(x);
-    auto get_fn = &std::reference_wrapper<int>::get;
+    auto get_fn = &ReferenceWrapper<int>::get;
     auto& ret = std::__invoke(get_fn, r);
-    auto& cret = std::__invoke_constexpr(get_fn, r);
     assert(&ret == &x);
-    assert(&cret == &x);
     auto& ret2 = std::__invoke(get_fn, d);
-    auto& cret2 = std::__invoke_constexpr(get_fn, d);
     assert(&ret2 == &x);
-    assert(&cret2 == &x);
+
+    return true;
+}
+
+TEST_CONSTEXPR_CXX20 bool test_reference_wrapper_reference_wrapper() {
+    int x = 42;
+    auto get_fn = &std::reference_wrapper<int>::get;
+    std::reference_wrapper<int> r(x);
+    std::reference_wrapper<std::reference_wrapper<int>> r2(r);
     auto& ret3 = std::__invoke(get_fn, r2);
     assert(&ret3 == &x);
+
+    return true;
 }
 #endif
 
@@ -366,7 +391,14 @@ int main(int, char**) {
     TestCase11<R(A&&, A&&, A&&, ...)  const volatile &&,  3, Q_CV, /* RValue */ true>::run();
 
     test_derived_from_ref_wrap();
+    test_reference_wrapper_reference_wrapper();
+#if TEST_STD_VER > 11
+    static_assert(test_derived_from_ref_wrap(), "");
 #endif
+#if TEST_STD_VER > 17
+    static_assert(test_reference_wrapper_reference_wrapper(), "");
+#endif
+#endif // TEST_STD_VER >= 11
 
   return 0;
 }

diff  --git a/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp b/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
index 082e11d3d94eb..44b706cdfda35 100644
--- a/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
+++ b/libcxx/test/libcxx/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp
@@ -195,21 +195,9 @@ struct TestCase {
             Expect e = std::__invoke(M, std::forward<T>(obj));
             assert(&e == expect);
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(M, std::forward<T>(obj))), Expect
-              >::value), "");
-            Expect e = std::__invoke_constexpr(M, std::forward<T>(obj));
-            assert(&e == expect);
-        }
-#endif
     }
 };
 
-
-
-
 int main(int, char**) {
     TestCase<ArgType>::run();
     TestCase<ArgType const>::run();

diff  --git a/libcxx/test/libcxx/utilities/function.objects/func.require/invoke_helpers.h b/libcxx/test/libcxx/utilities/function.objects/func.require/invoke_helpers.h
index 7660269133c60..f6f418b51c489 100644
--- a/libcxx/test/libcxx/utilities/function.objects/func.require/invoke_helpers.h
+++ b/libcxx/test/libcxx/utilities/function.objects/func.require/invoke_helpers.h
@@ -282,16 +282,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(ptr, object_cast(object));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(ptr, object_cast(object)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(ptr, object_cast(object));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class MethodPtr, class ObjectT>
@@ -304,16 +294,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class MethodPtr, class ObjectT>
@@ -326,16 +306,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class MethodPtr, class ObjectT>
@@ -348,16 +318,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(ptr, object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     //==========================================================================
@@ -373,16 +333,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(object_cast(object));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(object_cast(object)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(object_cast(object));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class ObjectT>
@@ -395,16 +345,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(object_cast(object), arg_cast(a0));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class ObjectT>
@@ -417,16 +357,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 
     template <class ObjectT>
@@ -439,16 +369,6 @@ struct BasicTest {
             CallRet ret = std::__invoke(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
             assert(ID::checkCalled(ret));
         }
-#if TEST_STD_VER >= 11
-        {
-            static_assert((std::is_same<
-                decltype(std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2)))
-              , CallRet>::value), "");
-            assert(ID::unchecked_call == false);
-            CallRet ret = std::__invoke_constexpr(object_cast(object), arg_cast(a0), arg_cast(a1), arg_cast(a2));
-            assert(ID::checkCalled(ret));
-        }
-#endif
     }
 };
 


        


More information about the libcxx-commits mailing list