Skip to content

Commit 8d2d49d

Browse files
committed
[libc++] Support more GCC 15 type_traits builtins
GCC 15 has added builtins for various C++ type traits that Clang already had. Since __has_builtin(...) now finds these, the #if branches previously only used for Clang are now used for GCC 15. However, GCC 15 requires that these builtins only be used in type aliases, not in template aliases. These changes follow the model of llvm#81386 where a previous GCC version added builtins for __remove_cv and __remove_cvref. Fixed: llvm#137704 Fixed: llvm#117319
1 parent c88b537 commit 8d2d49d

File tree

6 files changed

+52
-0
lines changed

6 files changed

+52
-0
lines changed

libcxx/include/__type_traits/add_lvalue_reference.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020

2121
#if __has_builtin(__add_lvalue_reference)
2222

23+
# if defined(_LIBCPP_COMPILER_GCC)
24+
template <class _Tp>
25+
struct __add_lvalue_reference_gcc {
26+
using type = __add_lvalue_reference(_Tp);
27+
};
28+
29+
template <class _Tp>
30+
using __add_lvalue_reference_t _LIBCPP_NODEBUG = typename __add_lvalue_reference_gcc<_Tp>::type;
31+
# else
2332
template <class _Tp>
2433
using __add_lvalue_reference_t _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
34+
# endif // defined(_LIBCPP_COMPILER_GCC)
2535

2636
#else
2737

libcxx/include/__type_traits/add_pointer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222

2323
#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && __has_builtin(__add_pointer)
2424

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

2838
#else
2939
template <class _Tp, bool = __is_referenceable_v<_Tp> || is_void<_Tp>::value>

libcxx/include/__type_traits/add_rvalue_reference.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2020

2121
#if __has_builtin(__add_rvalue_reference)
2222

23+
# if defined(_LIBCPP_COMPILER_GCC)
24+
template <class _Tp>
25+
struct __add_rvalue_reference_gcc {
26+
using type = __add_rvalue_reference(_Tp);
27+
};
28+
29+
template <class _Tp>
30+
using __add_rvalue_reference_t _LIBCPP_NODEBUG = typename __add_rvalue_reference_gcc<_Tp>::type;
31+
# else
2332
template <class _Tp>
2433
using __add_rvalue_reference_t _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
34+
# endif // defined(_LIBCPP_COMPILER_GCC)
2535

2636
#else
2737

libcxx/include/__type_traits/decay.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@
2626
_LIBCPP_BEGIN_NAMESPACE_STD
2727

2828
#if __has_builtin(__decay)
29+
# if defined(_LIBCPP_COMPILER_GCC)
30+
template <class _Tp>
31+
struct __decay_gcc {
32+
using type = __decay(_Tp);
33+
};
34+
35+
template <class _Tp>
36+
using __decay_t _LIBCPP_NODEBUG = typename __decay_gcc<_Tp>::type;
37+
# else
2938
template <class _Tp>
3039
using __decay_t _LIBCPP_NODEBUG = __decay(_Tp);
40+
# endif // defined(_LIBCPP_COMPILER_GCC)
3141

3242
template <class _Tp>
3343
struct _LIBCPP_NO_SPECIALIZATIONS decay {

libcxx/include/__type_traits/remove_all_extents.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ struct _LIBCPP_NO_SPECIALIZATIONS remove_all_extents {
2424
using type _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
2525
};
2626

27+
# if defined(_LIBCPP_COMPILER_GCC)
28+
template <class _Tp>
29+
using __remove_all_extents_t = typename remove_all_extents<_Tp>::type;
30+
# else
2731
template <class _Tp>
2832
using __remove_all_extents_t _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
33+
# endif // defined(_LIBCPP_COMPILER_GCC)
34+
2935
#else
3036
template <class _Tp>
3137
struct remove_all_extents {

libcxx/include/__type_traits/remove_extent.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ struct _LIBCPP_NO_SPECIALIZATIONS remove_extent {
2424
using type _LIBCPP_NODEBUG = __remove_extent(_Tp);
2525
};
2626

27+
# if defined(_LIBCPP_COMPILER_GCC)
28+
template <class _Tp>
29+
using __remove_extent_t = typename remove_extent<_Tp>::type;
30+
# else
2731
template <class _Tp>
2832
using __remove_extent_t _LIBCPP_NODEBUG = __remove_extent(_Tp);
33+
# endif // defined(_LIBCPP_COMPILER_GCC)
34+
2935
#else
3036
template <class _Tp>
3137
struct remove_extent {

0 commit comments

Comments
 (0)