Skip to content

[libc++] Simplify the implementation of remove_reference #85207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

philnik777
Copy link
Contributor

GCC 13 introduced the type trait __remove_reference. We can simplify the implementation of remove_reference a bit by using it.

@philnik777 philnik777 requested a review from a team as a code owner March 14, 2024 11:30
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

GCC 13 introduced the type trait __remove_reference. We can simplify the implementation of remove_reference a bit by using it.


Full diff: https://github.com/llvm/llvm-project/pull/85207.diff

1 Files Affected:

  • (modified) libcxx/include/__type_traits/remove_reference.h (+7-7)
diff --git a/libcxx/include/__type_traits/remove_reference.h b/libcxx/include/__type_traits/remove_reference.h
index fd66417bd84fed..ba67891758adce 100644
--- a/libcxx/include/__type_traits/remove_reference.h
+++ b/libcxx/include/__type_traits/remove_reference.h
@@ -10,7 +10,6 @@
 #define _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
 
 #include <__config>
-#include <cstddef>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -26,15 +25,16 @@ struct remove_reference {
 
 template <class _Tp>
 using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
-#else
-// clang-format off
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _LIBCPP_NODEBUG _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&>  {typedef _LIBCPP_NODEBUG _Tp type;};
-template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
-// clang-format on
+#elif __has_builtin(__remove_reference)
+template <class _Tp>
+struct remove_reference {
+  using type _LIBCPP_NODEBUG = __remove_reference(_Tp);
+};
 
 template <class _Tp>
 using __libcpp_remove_reference_t = typename remove_reference<_Tp>::type;
+#else
+#  error "remove_reference not implemented!"
 #endif // __has_builtin(__remove_reference_t)
 
 #if _LIBCPP_STD_VER >= 14

@ldionne ldionne self-assigned this Mar 18, 2024
@philnik777 philnik777 force-pushed the simplify_remove_reference branch from 4ada903 to af0e1c7 Compare March 18, 2024 07:57
@philnik777 philnik777 merged commit a10aa44 into llvm:main Mar 18, 2024
@philnik777 philnik777 deleted the simplify_remove_reference branch March 18, 2024 12:57
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
GCC 13 introduced the type trait `__remove_reference`. We can simplify
the implementation of `remove_reference` a bit by using it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants