[libcxx-commits] [libcxx] [libc++][modules] Remove a dependency of __type_traits/invoke.h on __utility (PR #106795)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 30 13:57:51 PDT 2024


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/106795

We can use static_cast<T&&> instead of std::forward to break up a cyclic dependency between __type_traits and __utility. While we normally favour using std::forward instead of static_cast, in this case using std::forward kinda breaks the layering of __type_traits being a dependency-free "submodule" of the codebase.

>From 4da62dd4cca2504056fb3b4365d835c8c8b4e02c Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 30 Aug 2024 12:26:49 -0400
Subject: [PATCH] [libc++][modules] Remove a dependency of
 __type_traits/invoke.h on __utility

We can use static_cast<T&&> instead of std::forward to break up a
cyclic dependency between __type_traits and __utility. While we
normally favour using std::forward instead of static_cast, in this
case using std::forward kinda breaks the layering of __type_traits
being a dependency-free "submodule" of the codebase.
---
 libcxx/include/__type_traits/invoke.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__type_traits/invoke.h b/libcxx/include/__type_traits/invoke.h
index 71db32ae6a3cef..f17da7669c4512 100644
--- a/libcxx/include/__type_traits/invoke.h
+++ b/libcxx/include/__type_traits/invoke.h
@@ -23,7 +23,6 @@
 #include <__type_traits/is_void.h>
 #include <__type_traits/nat.h>
 #include <__utility/declval.h>
-#include <__utility/forward.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -213,7 +212,7 @@ template <class _Ret, bool = is_void<_Ret>::value>
 struct __invoke_void_return_wrapper {
   template <class... _Args>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static _Ret __call(_Args&&... __args) {
-    return std::__invoke(std::forward<_Args>(__args)...);
+    return std::__invoke(static_cast<_Args&&>(__args)...);
   }
 };
 
@@ -221,7 +220,7 @@ template <class _Ret>
 struct __invoke_void_return_wrapper<_Ret, true> {
   template <class... _Args>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void __call(_Args&&... __args) {
-    std::__invoke(std::forward<_Args>(__args)...);
+    std::__invoke(static_cast<_Args&&>(__args)...);
   }
 };
 



More information about the libcxx-commits mailing list