Skip to content

Commit a10aa44

Browse files
authored
[libc++] Simplify the implementation of remove_reference (llvm#85207)
GCC 13 introduced the type trait `__remove_reference`. We can simplify the implementation of `remove_reference` a bit by using it.
1 parent 27d5049 commit a10aa44

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

libcxx/include/__type_traits/remove_reference.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_REMOVE_REFERENCE_H
1111

1212
#include <__config>
13-
#include <cstddef>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
@@ -26,15 +25,16 @@ struct remove_reference {
2625

2726
template <class _Tp>
2827
using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
29-
#else
30-
// clang-format off
31-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG _Tp type;};
32-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG _Tp type;};
33-
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG _Tp type;};
34-
// clang-format on
28+
#elif __has_builtin(__remove_reference)
29+
template <class _Tp>
30+
struct remove_reference {
31+
using type _LIBCPP_NODEBUG = __remove_reference(_Tp);
32+
};
3533

3634
template <class _Tp>
3735
using __libcpp_remove_reference_t = typename remove_reference<_Tp>::type;
36+
#else
37+
# error "remove_reference not implemented!"
3838
#endif // __has_builtin(__remove_reference_t)
3939

4040
#if _LIBCPP_STD_VER >= 14

libcxx/include/cwchar

+4
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp
254254

255255
_LIBCPP_END_NAMESPACE_STD
256256

257+
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
258+
# include <cstddef>
259+
#endif
260+
257261
#endif // _LIBCPP_CWCHAR

libcxx/include/execution

+4
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,8 @@ _LIBCPP_END_NAMESPACE_STD
142142

143143
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
144144

145+
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
146+
# include <cstddef>
147+
#endif
148+
145149
#endif // _LIBCPP_EXECUTION

libcxx/test/libcxx/transitive_includes/cxx23.csv

-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ coroutine version
142142
cstddef version
143143
ctgmath ccomplex
144144
ctgmath cmath
145-
cwchar cstddef
146145
cwchar cwctype
147146
cwctype cctype
148147
deque compare
@@ -161,7 +160,6 @@ exception cstdlib
161160
exception new
162161
exception typeinfo
163162
exception version
164-
execution cstddef
165163
execution version
166164
expected cstddef
167165
expected initializer_list

libcxx/test/libcxx/transitive_includes/cxx26.csv

-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ coroutine version
142142
cstddef version
143143
ctgmath ccomplex
144144
ctgmath cmath
145-
cwchar cstddef
146145
cwchar cwctype
147146
cwctype cctype
148147
deque compare
@@ -161,7 +160,6 @@ exception cstdlib
161160
exception new
162161
exception typeinfo
163162
exception version
164-
execution cstddef
165163
execution version
166164
expected cstddef
167165
expected initializer_list

0 commit comments

Comments
 (0)