Skip to content

Commit b7eec36

Browse files
committed
libcxx: Update to Clang 20.
See: * https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319 * https://discourse.llvm.org/t/rfc-project-hand-in-hand-llvm-libc-libc-code-sharing/77701 We're dropping support for C++03 for Zig due to the first change; it would be insane to ship 1018 duplicate header files just for this outdated use case. As a result of the second change, I had to bring in a subset of the headers from llvm-libc since libc++ now depends on these. Hopefully we can continue to get away with not copying the entirety of llvm-libc.
1 parent a058ed0 commit b7eec36

File tree

993 files changed

+36339
-19468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

993 files changed

+36339
-19468
lines changed

lib/libcxx/include/__algorithm/adjacent_find.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
1212

1313
#include <__algorithm/comp.h>
14-
#include <__algorithm/iterator_operations.h>
1514
#include <__config>
16-
#include <__iterator/iterator_traits.h>
15+
#include <__functional/identity.h>
16+
#include <__type_traits/invoke.h>
1717
#include <__utility/move.h>
1818

1919
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -25,28 +25,30 @@ _LIBCPP_PUSH_MACROS
2525

2626
_LIBCPP_BEGIN_NAMESPACE_STD
2727

28-
template <class _Iter, class _Sent, class _BinaryPredicate>
29-
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
30-
__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
28+
template <class _Iter, class _Sent, class _Pred, class _Proj>
29+
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
30+
__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
3131
if (__first == __last)
3232
return __first;
33+
3334
_Iter __i = __first;
3435
while (++__i != __last) {
35-
if (__pred(*__first, *__i))
36+
if (std::__invoke(__pred, std::__invoke(__proj, *__first), std::__invoke(__proj, *__i)))
3637
return __first;
3738
__first = __i;
3839
}
3940
return __i;
4041
}
4142

4243
template <class _ForwardIterator, class _BinaryPredicate>
43-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
44+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
4445
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
45-
return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
46+
__identity __proj;
47+
return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj);
4648
}
4749

4850
template <class _ForwardIterator>
49-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
51+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
5052
adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
5153
return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());
5254
}

lib/libcxx/include/__algorithm/all_of.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@
1111
#define _LIBCPP___ALGORITHM_ALL_OF_H
1212

1313
#include <__config>
14+
#include <__functional/identity.h>
15+
#include <__type_traits/invoke.h>
1416

1517
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618
# pragma GCC system_header
1719
#endif
1820

1921
_LIBCPP_BEGIN_NAMESPACE_STD
2022

21-
template <class _InputIterator, class _Predicate>
22-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
23-
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24-
for (; __first != __last; ++__first)
25-
if (!__pred(*__first))
23+
template <class _Iter, class _Sent, class _Proj, class _Pred>
24+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25+
__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
26+
for (; __first != __last; ++__first) {
27+
if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
2628
return false;
29+
}
2730
return true;
2831
}
2932

33+
template <class _InputIterator, class _Predicate>
34+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
35+
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
36+
__identity __proj;
37+
return std::__all_of(__first, __last, __pred, __proj);
38+
}
39+
3040
_LIBCPP_END_NAMESPACE_STD
3141

3242
#endif // _LIBCPP___ALGORITHM_ALL_OF_H

lib/libcxx/include/__algorithm/any_of.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@
1111
#define _LIBCPP___ALGORITHM_ANY_OF_H
1212

1313
#include <__config>
14+
#include <__functional/identity.h>
15+
#include <__type_traits/invoke.h>
1416

1517
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618
# pragma GCC system_header
1719
#endif
1820

1921
_LIBCPP_BEGIN_NAMESPACE_STD
2022

21-
template <class _InputIterator, class _Predicate>
22-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
23-
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24-
for (; __first != __last; ++__first)
25-
if (__pred(*__first))
23+
template <class _Iter, class _Sent, class _Proj, class _Pred>
24+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25+
__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
26+
for (; __first != __last; ++__first) {
27+
if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
2628
return true;
29+
}
2730
return false;
2831
}
2932

33+
template <class _InputIterator, class _Predicate>
34+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
35+
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
36+
__identity __proj;
37+
return std::__any_of(__first, __last, __pred, __proj);
38+
}
39+
3040
_LIBCPP_END_NAMESPACE_STD
3141

3242
#endif // _LIBCPP___ALGORITHM_ANY_OF_H

lib/libcxx/include/__algorithm/binary_search.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__algorithm/comp_ref_type.h>
1414
#include <__algorithm/lower_bound.h>
1515
#include <__config>
16-
#include <__iterator/iterator_traits.h>
1716

1817
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918
# pragma GCC system_header
@@ -22,14 +21,14 @@
2221
_LIBCPP_BEGIN_NAMESPACE_STD
2322

2423
template <class _ForwardIterator, class _Tp, class _Compare>
25-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
24+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2625
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
2726
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
2827
return __first != __last && !__comp(__value, *__first);
2928
}
3029

3130
template <class _ForwardIterator, class _Tp>
32-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
31+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
3332
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
3433
return std::binary_search(__first, __last, __value, __less<>());
3534
}

lib/libcxx/include/__algorithm/comp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__config>
1313
#include <__type_traits/desugars_to.h>
14+
#include <__type_traits/is_integral.h>
1415

1516
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1617
# pragma GCC system_header
@@ -44,6 +45,9 @@ struct __less<void, void> {
4445
template <class _Tp>
4546
inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
4647

48+
template <class _Tp>
49+
inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value;
50+
4751
_LIBCPP_END_NAMESPACE_STD
4852

4953
#endif // _LIBCPP___ALGORITHM_COMP_H

lib/libcxx/include/__algorithm/comp_ref_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ struct __debug_less {
5656
// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
5757
#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
5858
template <class _Comp>
59-
using __comp_ref_type = __debug_less<_Comp>;
59+
using __comp_ref_type _LIBCPP_NODEBUG = __debug_less<_Comp>;
6060
#else
6161
template <class _Comp>
62-
using __comp_ref_type = _Comp&;
62+
using __comp_ref_type _LIBCPP_NODEBUG = _Comp&;
6363
#endif
6464

6565
_LIBCPP_END_NAMESPACE_STD

lib/libcxx/include/__algorithm/copy.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
#include <__algorithm/copy_move_common.h>
1313
#include <__algorithm/for_each_segment.h>
14-
#include <__algorithm/iterator_operations.h>
1514
#include <__algorithm/min.h>
1615
#include <__config>
16+
#include <__iterator/iterator_traits.h>
1717
#include <__iterator/segmented_iterator.h>
1818
#include <__type_traits/common_type.h>
19+
#include <__type_traits/enable_if.h>
1920
#include <__utility/move.h>
2021
#include <__utility/pair.h>
2122

@@ -28,10 +29,9 @@ _LIBCPP_PUSH_MACROS
2829

2930
_LIBCPP_BEGIN_NAMESPACE_STD
3031

31-
template <class, class _InIter, class _Sent, class _OutIter>
32+
template <class _InIter, class _Sent, class _OutIter>
3233
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter);
3334

34-
template <class _AlgPolicy>
3535
struct __copy_impl {
3636
template <class _InIter, class _Sent, class _OutIter>
3737
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
@@ -47,7 +47,7 @@ struct __copy_impl {
4747

4848
template <class _InIter, class _OutIter>
4949
struct _CopySegment {
50-
using _Traits = __segmented_iterator_traits<_InIter>;
50+
using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_InIter>;
5151

5252
_OutIter& __result_;
5353

@@ -56,7 +56,7 @@ struct __copy_impl {
5656

5757
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
5858
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
59-
__result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second;
59+
__result_ = std::__copy(__lfirst, __llast, std::move(__result_)).second;
6060
}
6161
};
6262

@@ -85,7 +85,7 @@ struct __copy_impl {
8585
while (true) {
8686
auto __local_last = _Traits::__end(__segment_iterator);
8787
auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first);
88-
auto __iters = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first);
88+
auto __iters = std::__copy(__first, __first + __size, __local_first);
8989
__first = std::move(__iters.first);
9090

9191
if (__first == __last)
@@ -103,17 +103,16 @@ struct __copy_impl {
103103
}
104104
};
105105

106-
template <class _AlgPolicy, class _InIter, class _Sent, class _OutIter>
106+
template <class _InIter, class _Sent, class _OutIter>
107107
pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
108108
__copy(_InIter __first, _Sent __last, _OutIter __result) {
109-
return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >(
110-
std::move(__first), std::move(__last), std::move(__result));
109+
return std::__copy_move_unwrap_iters<__copy_impl>(std::move(__first), std::move(__last), std::move(__result));
111110
}
112111

113112
template <class _InputIterator, class _OutputIterator>
114113
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
115114
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) {
116-
return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second;
115+
return std::__copy(__first, __last, __result).second;
117116
}
118117

119118
_LIBCPP_END_NAMESPACE_STD

lib/libcxx/include/__algorithm/copy_backward.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#include <__algorithm/iterator_operations.h>
1414
#include <__algorithm/min.h>
1515
#include <__config>
16+
#include <__iterator/iterator_traits.h>
1617
#include <__iterator/segmented_iterator.h>
1718
#include <__type_traits/common_type.h>
19+
#include <__type_traits/enable_if.h>
1820
#include <__type_traits/is_constructible.h>
1921
#include <__utility/move.h>
2022
#include <__utility/pair.h>

lib/libcxx/include/__algorithm/copy_if.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,41 @@
1010
#define _LIBCPP___ALGORITHM_COPY_IF_H
1111

1212
#include <__config>
13+
#include <__functional/identity.h>
14+
#include <__type_traits/invoke.h>
15+
#include <__utility/move.h>
16+
#include <__utility/pair.h>
1317

1418
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1519
# pragma GCC system_header
1620
#endif
1721

22+
_LIBCPP_PUSH_MACROS
23+
#include <__undef_macros>
24+
1825
_LIBCPP_BEGIN_NAMESPACE_STD
1926

20-
template <class _InputIterator, class _OutputIterator, class _Predicate>
21-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
22-
copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
27+
template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
28+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
29+
__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
2330
for (; __first != __last; ++__first) {
24-
if (__pred(*__first)) {
31+
if (std::__invoke(__pred, std::__invoke(__proj, *__first))) {
2532
*__result = *__first;
2633
++__result;
2734
}
2835
}
29-
return __result;
36+
return std::make_pair(std::move(__first), std::move(__result));
37+
}
38+
39+
template <class _InputIterator, class _OutputIterator, class _Predicate>
40+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
41+
copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) {
42+
__identity __proj;
43+
return std::__copy_if(__first, __last, __result, __pred, __proj).second;
3044
}
3145

3246
_LIBCPP_END_NAMESPACE_STD
3347

48+
_LIBCPP_POP_MACROS
49+
3450
#endif // _LIBCPP___ALGORITHM_COPY_IF_H

lib/libcxx/include/__algorithm/copy_move_common.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#ifndef _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
1010
#define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H
1111

12-
#include <__algorithm/iterator_operations.h>
1312
#include <__algorithm/unwrap_iter.h>
1413
#include <__algorithm/unwrap_range.h>
1514
#include <__config>
15+
#include <__cstddef/size_t.h>
1616
#include <__iterator/iterator_traits.h>
1717
#include <__memory/pointer_traits.h>
1818
#include <__string/constexpr_c_functions.h>
@@ -24,7 +24,6 @@
2424
#include <__type_traits/is_volatile.h>
2525
#include <__utility/move.h>
2626
#include <__utility/pair.h>
27-
#include <cstddef>
2827

2928
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3029
# pragma GCC system_header

lib/libcxx/include/__algorithm/count.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#include <__bit/popcount.h>
1717
#include <__config>
1818
#include <__functional/identity.h>
19-
#include <__functional/invoke.h>
2019
#include <__fwd/bit_reference.h>
2120
#include <__iterator/iterator_traits.h>
21+
#include <__type_traits/enable_if.h>
22+
#include <__type_traits/invoke.h>
2223

2324
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2425
# pragma GCC system_header
@@ -43,7 +44,7 @@ __count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
4344
// __bit_iterator implementation
4445
template <bool _ToCount, class _Cp, bool _IsConst>
4546
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type
46-
__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) {
47+
__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) {
4748
using _It = __bit_iterator<_Cp, _IsConst>;
4849
using __storage_type = typename _It::__storage_type;
4950
using difference_type = typename _It::difference_type;
@@ -74,12 +75,14 @@ template <class, class _Cp, bool _IsConst, class _Tp, class _Proj, __enable_if_t
7475
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<__bit_iterator<_Cp, _IsConst> >
7576
__count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) {
7677
if (__value)
77-
return std::__count_bool<true>(__first, static_cast<typename _Cp::size_type>(__last - __first));
78-
return std::__count_bool<false>(__first, static_cast<typename _Cp::size_type>(__last - __first));
78+
return std::__count_bool<true>(
79+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
80+
return std::__count_bool<false>(
81+
__first, static_cast<typename __size_difference_type_traits<_Cp>::size_type>(__last - __first));
7982
}
8083

8184
template <class _InputIterator, class _Tp>
82-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
85+
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator>
8386
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
8487
__identity __proj;
8588
return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj);

0 commit comments

Comments
 (0)