Skip to content

Commit ae9990e

Browse files
authored
[libc++] Remove dead code from <type_traits> (#143854)
Since we've upgraded to GCC 15 now, we can remove a bunch of dead code from `<type_traits>`.
1 parent 3ee0f97 commit ae9990e

File tree

11 files changed

+48
-217
lines changed

11 files changed

+48
-217
lines changed

libcxx/include/__type_traits/add_lvalue_reference.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,25 @@
1010
#define _LIBCPP___TYPE_TRAITS_ADD_LVALUE_REFERENCE_H
1111

1212
#include <__config>
13-
#include <__type_traits/is_referenceable.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
1716
#endif
1817

1918
_LIBCPP_BEGIN_NAMESPACE_STD
2019

21-
#if __has_builtin(__add_lvalue_reference) && !defined(_LIBCPP_COMPILER_GCC)
22-
2320
template <class _Tp>
24-
using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
25-
26-
#else
27-
28-
template <class _Tp, bool = __is_referenceable_v<_Tp>>
29-
struct __add_lvalue_reference_impl {
30-
using type _LIBCPP_NODEBUG = _Tp;
31-
};
32-
template <class _Tp >
33-
struct __add_lvalue_reference_impl<_Tp, true> {
34-
using type _LIBCPP_NODEBUG = _Tp&;
21+
struct _LIBCPP_NO_SPECIALIZATIONS add_lvalue_reference {
22+
using type _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
3523
};
3624

25+
#ifdef _LIBCPP_COMPILER_GCC
3726
template <class _Tp>
38-
using __add_lvalue_reference_t = typename __add_lvalue_reference_impl<_Tp>::type;
39-
40-
#endif // __has_builtin(__add_lvalue_reference)
41-
27+
using __add_lvalue_reference_t _LIBCPP_NODEBUG = typename add_lvalue_reference<_Tp>::type;
28+
#else
4229
template <class _Tp>
43-
struct _LIBCPP_NO_SPECIALIZATIONS add_lvalue_reference {
44-
using type _LIBCPP_NODEBUG = __add_lvalue_reference_t<_Tp>;
45-
};
30+
using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
31+
#endif
4632

4733
#if _LIBCPP_STD_VER >= 14
4834
template <class _Tp>

libcxx/include/__type_traits/add_pointer.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020

2121
_LIBCPP_BEGIN_NAMESPACE_STD
2222

23-
#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer) && !defined(_LIBCPP_COMPILER_GCC)
23+
#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
2424

25+
template <class _Tp>
26+
struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
27+
using type _LIBCPP_NODEBUG = __add_pointer(_Tp);
28+
};
29+
30+
# ifdef _LIBCPP_COMPILER_GCC
31+
template <class _Tp>
32+
using __add_pointer_t _LIBCPP_NODEBUG = typename add_pointer<_Tp>::type;
33+
# else
2534
template <class _Tp>
2635
using __add_pointer_t _LIBCPP_NODEBUG = __add_pointer(_Tp);
36+
# endif
2737

2838
#else
2939
template <class _Tp, bool = __is_referenceable_v<_Tp> || is_void<_Tp>::value>
@@ -38,13 +48,13 @@ struct __add_pointer_impl<_Tp, false> {
3848
template <class _Tp>
3949
using __add_pointer_t = typename __add_pointer_impl<_Tp>::type;
4050

41-
#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
42-
4351
template <class _Tp>
4452
struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
4553
using type _LIBCPP_NODEBUG = __add_pointer_t<_Tp>;
4654
};
4755

56+
#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
57+
4858
#if _LIBCPP_STD_VER >= 14
4959
template <class _Tp>
5060
using add_pointer_t = __add_pointer_t<_Tp>;

libcxx/include/__type_traits/add_rvalue_reference.h

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,25 @@
1010
#define _LIBCPP___TYPE_TRAITS_ADD_RVALUE_REFERENCE_H
1111

1212
#include <__config>
13-
#include <__type_traits/is_referenceable.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
1716
#endif
1817

1918
_LIBCPP_BEGIN_NAMESPACE_STD
2019

21-
#if __has_builtin(__add_rvalue_reference) && !defined(_LIBCPP_COMPILER_GCC)
22-
2320
template <class _Tp>
24-
using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
25-
26-
#else
27-
28-
template <class _Tp, bool = __is_referenceable_v<_Tp> >
29-
struct __add_rvalue_reference_impl {
30-
using type _LIBCPP_NODEBUG = _Tp;
31-
};
32-
template <class _Tp >
33-
struct __add_rvalue_reference_impl<_Tp, true> {
34-
using type _LIBCPP_NODEBUG = _Tp&&;
21+
struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
22+
using type _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
3523
};
3624

25+
#ifdef _LIBCPP_COMPILER_GCC
3726
template <class _Tp>
38-
using __add_rvalue_reference_t = typename __add_rvalue_reference_impl<_Tp>::type;
39-
40-
#endif // __has_builtin(__add_rvalue_reference)
41-
27+
using __add_rvalue_reference_t _LIBCPP_NODEBUG = typename add_rvalue_reference<_Tp>::type;
28+
#else
4229
template <class _Tp>
43-
struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
44-
using type _LIBCPP_NODEBUG = __add_rvalue_reference_t<_Tp>;
45-
};
30+
using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
31+
#endif
4632

4733
#if _LIBCPP_STD_VER >= 14
4834
template <class _Tp>

libcxx/include/__type_traits/decay.h

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,25 @@
1010
#define _LIBCPP___TYPE_TRAITS_DECAY_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_pointer.h>
14-
#include <__type_traits/conditional.h>
15-
#include <__type_traits/is_array.h>
16-
#include <__type_traits/is_function.h>
17-
#include <__type_traits/is_referenceable.h>
18-
#include <__type_traits/remove_cv.h>
19-
#include <__type_traits/remove_extent.h>
20-
#include <__type_traits/remove_reference.h>
2113

2214
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2315
# pragma GCC system_header
2416
#endif
2517

2618
_LIBCPP_BEGIN_NAMESPACE_STD
2719

28-
#if __has_builtin(__decay) && !defined(_LIBCPP_COMPILER_GCC)
29-
template <class _Tp>
30-
using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
31-
3220
template <class _Tp>
3321
struct _LIBCPP_NO_SPECIALIZATIONS decay {
34-
using type _LIBCPP_NODEBUG = __decay_t<_Tp>;
35-
};
36-
37-
#else
38-
template <class _Up, bool>
39-
struct __decay {
40-
using type _LIBCPP_NODEBUG = __remove_cv_t<_Up>;
41-
};
42-
43-
template <class _Up>
44-
struct __decay<_Up, true> {
45-
public:
46-
using type _LIBCPP_NODEBUG =
47-
__conditional_t<is_array<_Up>::value,
48-
__add_pointer_t<__remove_extent_t<_Up> >,
49-
__conditional_t<is_function<_Up>::value, typename add_pointer<_Up>::type, __remove_cv_t<_Up> > >;
22+
using type _LIBCPP_NODEBUG = __decay(_Tp);
5023
};
5124

25+
#ifdef _LIBCPP_COMPILER_GCC
5226
template <class _Tp>
53-
struct decay {
54-
private:
55-
using _Up _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tp>;
56-
57-
public:
58-
using type _LIBCPP_NODEBUG = typename __decay<_Up, __is_referenceable_v<_Up> >::type;
59-
};
60-
27+
using __decay_t _LIBCPP_NODEBUG = typename decay<_Tp>::type;
28+
#else
6129
template <class _Tp>
62-
using __decay_t = typename decay<_Tp>::type;
63-
#endif // __has_builtin(__decay)
30+
using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
31+
#endif
6432

6533
#if _LIBCPP_STD_VER >= 14
6634
template <class _Tp>

libcxx/include/__type_traits/has_unique_object_representation.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/remove_all_extents.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716
# pragma GCC system_header
@@ -23,12 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2322

2423
template <class _Tp>
2524
struct _LIBCPP_NO_SPECIALIZATIONS has_unique_object_representations
26-
// TODO: We work around a Clang and GCC bug in __has_unique_object_representations by using remove_all_extents
27-
// even though it should not be necessary. This was reported to the compilers:
28-
// - Clang: https://github.com/llvm/llvm-project/issues/95311
29-
// - GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115476
30-
// remove_all_extents_t can be removed once all the compilers we support have fixed this bug.
31-
: public integral_constant<bool, __has_unique_object_representations(remove_all_extents_t<_Tp>)> {};
25+
: integral_constant<bool, __has_unique_object_representations(_Tp)> {};
3226

3327
template <class _Tp>
3428
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool has_unique_object_representations_v =

libcxx/include/__type_traits/is_array.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_ARRAY_H
1111

1212
#include <__config>
13-
#include <__cstddef/size_t.h>
1413
#include <__type_traits/integral_constant.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -19,32 +18,13 @@
1918

2019
_LIBCPP_BEGIN_NAMESPACE_STD
2120

22-
#if __has_builtin(__is_array) && \
23-
(!defined(_LIBCPP_COMPILER_CLANG_BASED) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1900))
24-
2521
template <class _Tp>
2622
struct _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> {};
2723

28-
# if _LIBCPP_STD_VER >= 17
24+
#if _LIBCPP_STD_VER >= 17
2925
template <class _Tp>
3026
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_array_v = __is_array(_Tp);
31-
# endif
32-
33-
#else
34-
35-
template <class _Tp>
36-
struct is_array : public false_type {};
37-
template <class _Tp>
38-
struct is_array<_Tp[]> : public true_type {};
39-
template <class _Tp, size_t _Np>
40-
struct is_array<_Tp[_Np]> : public true_type {};
41-
42-
# if _LIBCPP_STD_VER >= 17
43-
template <class _Tp>
44-
inline constexpr bool is_array_v = is_array<_Tp>::value;
45-
# endif
46-
47-
#endif // __has_builtin(__is_array)
27+
#endif
4828

4929
_LIBCPP_END_NAMESPACE_STD
5030

libcxx/include/__type_traits/is_const.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,13 @@
1818

1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

21-
#if __has_builtin(__is_const)
22-
2321
template <class _Tp>
2422
struct _LIBCPP_NO_SPECIALIZATIONS is_const : _BoolConstant<__is_const(_Tp)> {};
2523

26-
# if _LIBCPP_STD_VER >= 17
24+
#if _LIBCPP_STD_VER >= 17
2725
template <class _Tp>
2826
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_const_v = __is_const(_Tp);
29-
# endif
30-
31-
#else
32-
33-
template <class _Tp>
34-
struct is_const : public false_type {};
35-
template <class _Tp>
36-
struct is_const<_Tp const> : public true_type {};
37-
38-
# if _LIBCPP_STD_VER >= 17
39-
template <class _Tp>
40-
inline constexpr bool is_const_v = is_const<_Tp>::value;
41-
# endif
42-
43-
#endif // __has_builtin(__is_const)
27+
#endif
4428

4529
_LIBCPP_END_NAMESPACE_STD
4630

libcxx/include/__type_traits/is_pointer.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111

1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
14-
#include <__type_traits/remove_cv.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716
# pragma GCC system_header
1817
#endif
1918

2019
_LIBCPP_BEGIN_NAMESPACE_STD
2120

22-
#if __has_builtin(__is_pointer)
23-
2421
template <class _Tp>
2522
struct _LIBCPP_NO_SPECIALIZATIONS is_pointer : _BoolConstant<__is_pointer(_Tp)> {};
2623

@@ -29,36 +26,6 @@ template <class _Tp>
2926
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pointer_v = __is_pointer(_Tp);
3027
# endif
3128

32-
#else // __has_builtin(__is_pointer)
33-
34-
template <class _Tp>
35-
struct __libcpp_is_pointer : false_type {};
36-
template <class _Tp>
37-
struct __libcpp_is_pointer<_Tp*> : true_type {};
38-
39-
template <class _Tp>
40-
struct __libcpp_remove_objc_qualifiers {
41-
typedef _Tp type;
42-
};
43-
# if __has_feature(objc_arc)
44-
// clang-format off
45-
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
46-
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
47-
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
48-
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
49-
// clang-format on
50-
# endif
51-
52-
template <class _Tp>
53-
struct is_pointer : __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<__remove_cv_t<_Tp> >::type> {};
54-
55-
# if _LIBCPP_STD_VER >= 17
56-
template <class _Tp>
57-
inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
58-
# endif
59-
60-
#endif // __has_builtin(__is_pointer)
61-
6229
_LIBCPP_END_NAMESPACE_STD
6330

6431
#endif // _LIBCPP___TYPE_TRAITS_IS_POINTER_H

libcxx/include/__type_traits/is_volatile.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,13 @@
1818

1919
_LIBCPP_BEGIN_NAMESPACE_STD
2020

21-
#if __has_builtin(__is_volatile)
22-
2321
template <class _Tp>
2422
struct _LIBCPP_NO_SPECIALIZATIONS is_volatile : _BoolConstant<__is_volatile(_Tp)> {};
2523

26-
# if _LIBCPP_STD_VER >= 17
24+
#if _LIBCPP_STD_VER >= 17
2725
template <class _Tp>
2826
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_volatile_v = __is_volatile(_Tp);
29-
# endif
30-
31-
#else
32-
33-
template <class _Tp>
34-
struct is_volatile : public false_type {};
35-
template <class _Tp>
36-
struct is_volatile<_Tp volatile> : public true_type {};
37-
38-
# if _LIBCPP_STD_VER >= 17
39-
template <class _Tp>
40-
inline constexpr bool is_volatile_v = is_volatile<_Tp>::value;
41-
# endif
42-
43-
#endif // __has_builtin(__is_volatile)
27+
#endif
4428

4529
_LIBCPP_END_NAMESPACE_STD
4630

0 commit comments

Comments
 (0)