Skip to content

Commit de4a57c

Browse files
committed
[libc++] Re-add transitive includes that had been removed since LLVM 14
This commit re-adds transitive includes that had been removed by 4cd04d1, c36870c, a83f4b9, 1458458, 2e2f315, and 489637e. This should cover almost all the includes that had been removed since LLVM 14 and that would contribute to breaking user code when releasing LLVM 15. It is possible to disable the inclusion of these headers by defining _LIBCPP_REMOVE_TRANSITIVE_INCLUDES. The intent is that vendors will enable that macro and start fixing downstream issues immediately. We can then remove the macro (and the transitive includes) by default in a future release. That way, we will break users only once by removing transitive includes in bulk instead of doing it bit by bit a every release, which is more disruptive for users. Note 1: The set of headers to re-add was found by re-generating the transitive include test on a checkout of release/14.x, which provided the list of all transitive includes we used to provide. Note 2: Several includes of <vector>, <optional>, <array> and <unordered_map> have been added in this commit. These transitive inclusions were added when we implemented boyer_moore_searcher in <functional>. Note 3: This is a best effort patch to try and resolve downstream breakage caused since branching LLVM 14. I wasn't able to perfectly mirror transitive includes in LLVM 14 for a few headers, so I added a release note explaining it. To summarize, adding boyer_moore_searcher created a bunch of circular dependencies, so we have to break backwards compatibility in a few cases. Differential Revision: https://reviews.llvm.org/D128661
1 parent ea1b861 commit de4a57c

File tree

126 files changed

+955
-14
lines changed

Some content is hidden

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

126 files changed

+955
-14
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set(LIBCXX_TEST_PARAMS "enable_transitive_includes=False" CACHE STRING "")
2+
set(LIBCXXABI_TEST_PARAMS "${LIBCXX_TEST_PARAMS}" CACHE STRING "")

libcxx/docs/ReleaseNotes.rst

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,15 @@ API Changes
9797
``<filesystem>`` header. The associated macro
9898
``_LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM`` has also been removed.
9999

100-
- Some libc++ headers no longer transitively include all of:
101-
- ``<algorithm>``
102-
- ``<chrono>``
103-
- ``<exception>``
104-
- ``<functional>``
105-
- ``<iterator>``
106-
- ``<new>``
107-
- ``<typeinfo>``
108-
- ``<utility>``
109-
110-
If, after updating libc++, you see compiler errors related to missing declarations
111-
in namespace ``std``, it might be because one of your source files now needs to
112-
include one or more of the headers listed above.
100+
- Libc++ is getting ready to remove unnecessary transitive inclusions. This may
101+
break your code in the future. To future-proof your code to these removals,
102+
please compile your code with ``_LIBCPP_REMOVE_TRANSITIVE_INCLUDES`` defined
103+
and fix any compilation error resulting from missing includes.
104+
105+
- The ``<algorithm>``, ``<array>``, ``<optional>``, ``<unordered_map>`` and ``<vector>``
106+
headers no longer transitively include the ``<functional>`` header. If you see compiler
107+
errors related to missing declarations in namespace ``std``, make sure you have the
108+
necessary includes.
113109

114110
- The integer distributions ``binomial_distribution``, ``discrete_distribution``,
115111
``geometric_distribution``, ``negative_binomial_distribution``, ``poisson_distribution``,

libcxx/include/algorithm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,12 @@ template <class BidirectionalIterator, class Compare>
12601260
#include <__algorithm/unwrap_iter.h>
12611261
#include <__algorithm/upper_bound.h>
12621262

1263+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
1264+
# include <chrono>
1265+
# include <iterator>
1266+
# include <utility>
1267+
#endif
1268+
12631269
// standard-mandated includes
12641270
#include <initializer_list>
12651271

libcxx/include/any

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ namespace std {
9494
#include <typeinfo>
9595
#include <version>
9696

97+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
98+
# include <chrono>
99+
#endif
100+
97101
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
98102
# pragma GCC system_header
99103
#endif

libcxx/include/array

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce
123123
#include <type_traits>
124124
#include <version>
125125

126+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
127+
# include <algorithm>
128+
# include <iterator>
129+
# include <utility>
130+
#endif
131+
126132
// standard-mandated includes
127133

128134
// [iterator.range]

libcxx/include/atomic

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ template <class T>
534534
# include <__threading_support>
535535
#endif
536536

537+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
538+
# include <chrono>
539+
#endif
540+
537541
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
538542
# pragma GCC system_header
539543
#endif

libcxx/include/bit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace std {
7171
#include <type_traits>
7272
#include <version>
7373

74+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
75+
# include <iosfwd>
76+
#endif
77+
7478
#if defined(__IBMCPP__)
7579
# include "__support/ibm/support.h"
7680
#endif

libcxx/include/charconv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ namespace std {
9696
#include <limits>
9797
#include <type_traits>
9898

99+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
100+
# include <iosfwd>
101+
#endif
102+
99103
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
100104
# pragma GCC system_header
101105
#endif

libcxx/include/coroutine

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ struct suspend_always;
4646
#include <__coroutine/trivial_awaitables.h>
4747
#include <version>
4848

49+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
50+
# include <iosfwd>
51+
#endif
52+
4953
// standard-mandated includes
5054
#include <compare>
5155

libcxx/include/deque

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ template <class T, class Allocator, class Predicate>
185185
#include <type_traits>
186186
#include <version>
187187

188+
#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
189+
# include <algorithm>
190+
# include <functional>
191+
# include <iterator>
192+
#endif
193+
188194
// standard-mandated includes
189195

190196
// [iterator.range]

0 commit comments

Comments
 (0)