Skip to content

Commit e78f53d

Browse files
authored
Reapply "[libc++][C++03] Copy the LLVM 19 headers (#108999)" (#112127)
This reverts commit 68c04b0. This disables the IWYU mapping that caused the failure, since the headers aren't reachable for now. This is the first part of the "Freezing C++03 headers" proposal explained in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc/77319/58. This patch mechanically copies the headers as of the LLVM 19.1 release into a subdirectory of libc++ so that we can start using these headers when building in C++03 mode. We are going to be backporting important changes to that copy of the headers until the LLVM 21 release. After the LLVM 21 release, only critical bugfixes will be fixed in the C++03 copy of the headers. This patch only performs a copy of the headers -- these headers are still unused by the rest of the codebase.
1 parent c919970 commit e78f53d

File tree

1,020 files changed

+199790
-0
lines changed

Some content is hidden

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

1,020 files changed

+199790
-0
lines changed

libcxx/include/__cxx03/CMakeLists.txt

Lines changed: 1092 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___ALGORITHM_ADJACENT_FIND_H
11+
#define _LIBCPP___ALGORITHM_ADJACENT_FIND_H
12+
13+
#include <__algorithm/comp.h>
14+
#include <__algorithm/iterator_operations.h>
15+
#include <__config>
16+
#include <__iterator/iterator_traits.h>
17+
#include <__utility/move.h>
18+
19+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20+
# pragma GCC system_header
21+
#endif
22+
23+
_LIBCPP_PUSH_MACROS
24+
#include <__undef_macros>
25+
26+
_LIBCPP_BEGIN_NAMESPACE_STD
27+
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) {
31+
if (__first == __last)
32+
return __first;
33+
_Iter __i = __first;
34+
while (++__i != __last) {
35+
if (__pred(*__first, *__i))
36+
return __first;
37+
__first = __i;
38+
}
39+
return __i;
40+
}
41+
42+
template <class _ForwardIterator, class _BinaryPredicate>
43+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
44+
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
45+
return std::__adjacent_find(std::move(__first), std::move(__last), __pred);
46+
}
47+
48+
template <class _ForwardIterator>
49+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
50+
adjacent_find(_ForwardIterator __first, _ForwardIterator __last) {
51+
return std::adjacent_find(std::move(__first), std::move(__last), __equal_to());
52+
}
53+
54+
_LIBCPP_END_NAMESPACE_STD
55+
56+
_LIBCPP_POP_MACROS
57+
58+
#endif // _LIBCPP___ALGORITHM_ADJACENT_FIND_H
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___ALGORITHM_ALL_OF_H
11+
#define _LIBCPP___ALGORITHM_ALL_OF_H
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
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))
26+
return false;
27+
return true;
28+
}
29+
30+
_LIBCPP_END_NAMESPACE_STD
31+
32+
#endif // _LIBCPP___ALGORITHM_ALL_OF_H
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___ALGORITHM_ANY_OF_H
11+
#define _LIBCPP___ALGORITHM_ANY_OF_H
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
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))
26+
return true;
27+
return false;
28+
}
29+
30+
_LIBCPP_END_NAMESPACE_STD
31+
32+
#endif // _LIBCPP___ALGORITHM_ANY_OF_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_BINARY_SEARCH_H
10+
#define _LIBCPP___ALGORITHM_BINARY_SEARCH_H
11+
12+
#include <__algorithm/comp.h>
13+
#include <__algorithm/comp_ref_type.h>
14+
#include <__algorithm/lower_bound.h>
15+
#include <__config>
16+
#include <__iterator/iterator_traits.h>
17+
18+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19+
# pragma GCC system_header
20+
#endif
21+
22+
_LIBCPP_BEGIN_NAMESPACE_STD
23+
24+
template <class _ForwardIterator, class _Tp, class _Compare>
25+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
26+
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {
27+
__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);
28+
return __first != __last && !__comp(__value, *__first);
29+
}
30+
31+
template <class _ForwardIterator, class _Tp>
32+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
33+
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
34+
return std::binary_search(__first, __last, __value, __less<>());
35+
}
36+
37+
_LIBCPP_END_NAMESPACE_STD
38+
39+
#endif // _LIBCPP___ALGORITHM_BINARY_SEARCH_H
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_CLAMP_H
10+
#define _LIBCPP___ALGORITHM_CLAMP_H
11+
12+
#include <__algorithm/comp.h>
13+
#include <__assert>
14+
#include <__config>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
# pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
#if _LIBCPP_STD_VER >= 17
23+
template <class _Tp, class _Compare>
24+
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
25+
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
26+
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
27+
_LIBCPP_LIFETIMEBOUND const _Tp& __hi,
28+
_Compare __comp) {
29+
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
30+
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
31+
}
32+
33+
template <class _Tp>
34+
[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&
35+
clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
36+
_LIBCPP_LIFETIMEBOUND const _Tp& __lo,
37+
_LIBCPP_LIFETIMEBOUND const _Tp& __hi) {
38+
return std::clamp(__v, __lo, __hi, __less<>());
39+
}
40+
#endif
41+
42+
_LIBCPP_END_NAMESPACE_STD
43+
44+
#endif // _LIBCPP___ALGORITHM_CLAMP_H
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_COMP_H
10+
#define _LIBCPP___ALGORITHM_COMP_H
11+
12+
#include <__config>
13+
#include <__type_traits/desugars_to.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
struct __equal_to {
22+
template <class _T1, class _T2>
23+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _T1& __x, const _T2& __y) const {
24+
return __x == __y;
25+
}
26+
};
27+
28+
template <class _Tp, class _Up>
29+
inline const bool __desugars_to_v<__equal_tag, __equal_to, _Tp, _Up> = true;
30+
31+
// The definition is required because __less is part of the ABI, but it's empty
32+
// because all comparisons should be transparent.
33+
template <class _T1 = void, class _T2 = _T1>
34+
struct __less {};
35+
36+
template <>
37+
struct __less<void, void> {
38+
template <class _Tp, class _Up>
39+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __lhs, const _Up& __rhs) const {
40+
return __lhs < __rhs;
41+
}
42+
};
43+
44+
template <class _Tp>
45+
inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true;
46+
47+
_LIBCPP_END_NAMESPACE_STD
48+
49+
#endif // _LIBCPP___ALGORITHM_COMP_H
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
10+
#define _LIBCPP___ALGORITHM_COMP_REF_TYPE_H
11+
12+
#include <__assert>
13+
#include <__config>
14+
#include <__utility/declval.h>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
# pragma GCC system_header
18+
#endif
19+
20+
_LIBCPP_BEGIN_NAMESPACE_STD
21+
22+
template <class _Compare>
23+
struct __debug_less {
24+
_Compare& __comp_;
25+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI __debug_less(_Compare& __c) : __comp_(__c) {}
26+
27+
template <class _Tp, class _Up>
28+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __x, const _Up& __y) {
29+
bool __r = __comp_(__x, __y);
30+
if (__r)
31+
__do_compare_assert(0, __y, __x);
32+
return __r;
33+
}
34+
35+
template <class _Tp, class _Up>
36+
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool operator()(_Tp& __x, _Up& __y) {
37+
bool __r = __comp_(__x, __y);
38+
if (__r)
39+
__do_compare_assert(0, __y, __x);
40+
return __r;
41+
}
42+
43+
template <class _LHS, class _RHS>
44+
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline
45+
_LIBCPP_HIDE_FROM_ABI decltype((void)std::declval<_Compare&>()(std::declval<_LHS&>(), std::declval<_RHS&>()))
46+
__do_compare_assert(int, _LHS& __l, _RHS& __r) {
47+
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering");
48+
(void)__l;
49+
(void)__r;
50+
}
51+
52+
template <class _LHS, class _RHS>
53+
_LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void __do_compare_assert(long, _LHS&, _RHS&) {}
54+
};
55+
56+
// Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference.
57+
#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
58+
template <class _Comp>
59+
using __comp_ref_type = __debug_less<_Comp>;
60+
#else
61+
template <class _Comp>
62+
using __comp_ref_type = _Comp&;
63+
#endif
64+
65+
_LIBCPP_END_NAMESPACE_STD
66+
67+
#endif // _LIBCPP___ALGORITHM_COMP_REF_TYPE_H

0 commit comments

Comments
 (0)