Skip to content

Commit ef51e61

Browse files
authored
[libc++] Handle _LIBCPP_HAS_NO_{THREADS,LOCALIZATION} consistently with other carve-outs (#98319)
Previously, we would issue an #error when using a header that requires threading support or localization support in a configuration where that is disabled. This is unlike what we do for all the other carve outs like no-filesystem, no-wide-characters or no-random-device. Instead of issuing an #error, we normally just remove the problematic parts of the header. This patch makes the handling of no-localization and no-threads consistent with the other carve-outs. I dislike the fact that users won't get an explicit error message when trying to use e.g. ios in a build that doesn't support localization, but I think it is better to handle things consistently. Note that besides the consistency argument, the #error approach doesn't really work anyways since it would break down if we moved towards assuming the C locale only in the no-localization mode.
1 parent 97ebc97 commit ef51e61

File tree

11 files changed

+387
-379
lines changed

11 files changed

+387
-379
lines changed

libcxx/docs/ReleaseNotes/19.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ Deprecations and Removals
134134
`std-allocator-const <https://clang.llvm.org/extra/clang-tidy/checks/portability/std-allocator-const.html>`
135135
enabled.
136136

137+
- When configuring libc++ with localization or threads disabled, the library no longer emits an error when
138+
trying to ``#include <locale>`` and other such headers. Instead, those headers have no content. This is
139+
consistent with the behavior for all other libc++ carve-outs like filesystem, wide characters, a source
140+
of randomness, and others. Users that were checking whether including a header would fail (e.g. via a script
141+
or CMake's ``try_compile`` will experience a change in behavior).
142+
137143

138144
Upcoming Deprecations and Removals
139145
----------------------------------

libcxx/include/barrier

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,36 @@ namespace std
4747

4848
#include <__config>
4949

50-
#ifdef _LIBCPP_HAS_NO_THREADS
51-
# error "<barrier> is not supported since libc++ has been configured without support for threads."
52-
#endif
53-
54-
#include <__assert>
55-
#include <__atomic/atomic_base.h>
56-
#include <__atomic/memory_order.h>
57-
#include <__memory/unique_ptr.h>
58-
#include <__thread/poll_with_backoff.h>
59-
#include <__thread/timed_backoff_policy.h>
60-
#include <__utility/move.h>
61-
#include <cstddef>
62-
#include <cstdint>
63-
#include <limits>
64-
#include <version>
65-
66-
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
67-
# pragma GCC system_header
68-
#endif
50+
#if !defined(_LIBCPP_HAS_NO_THREADS)
51+
52+
# include <__assert>
53+
# include <__atomic/atomic_base.h>
54+
# include <__atomic/memory_order.h>
55+
# include <__memory/unique_ptr.h>
56+
# include <__thread/poll_with_backoff.h>
57+
# include <__thread/timed_backoff_policy.h>
58+
# include <__utility/move.h>
59+
# include <cstddef>
60+
# include <cstdint>
61+
# include <limits>
62+
# include <version>
63+
64+
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
65+
# pragma GCC system_header
66+
# endif
6967

7068
_LIBCPP_PUSH_MACROS
71-
#include <__undef_macros>
69+
# include <__undef_macros>
7270

73-
#if _LIBCPP_STD_VER >= 14
71+
# if _LIBCPP_STD_VER >= 14
7472

7573
_LIBCPP_BEGIN_NAMESPACE_STD
7674

7775
struct __empty_completion {
7876
inline _LIBCPP_HIDE_FROM_ABI void operator()() noexcept {}
7977
};
8078

81-
# ifndef _LIBCPP_HAS_NO_TREE_BARRIER
79+
# ifndef _LIBCPP_HAS_NO_TREE_BARRIER
8280

8381
/*
8482
@@ -152,7 +150,7 @@ public:
152150
}
153151
};
154152

155-
# else
153+
# else
156154

157155
/*
158156
@@ -253,7 +251,7 @@ public:
253251
}
254252
};
255253

256-
# endif // !_LIBCPP_HAS_NO_TREE_BARRIER
254+
# endif // !_LIBCPP_HAS_NO_TREE_BARRIER
257255

258256
template <class _CompletionF = __empty_completion>
259257
class _LIBCPP_DEPRECATED_ATOMIC_SYNC barrier {
@@ -265,7 +263,7 @@ public:
265263
static _LIBCPP_HIDE_FROM_ABI constexpr ptrdiff_t max() noexcept { return __barrier_base<_CompletionF>::max(); }
266264

267265
_LIBCPP_AVAILABILITY_SYNC
268-
_LIBCPP_HIDE_FROM_ABI explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
266+
_LIBCPP_HIDE_FROM_ABI explicit barrier(ptrdiff_t __count, _CompletionF __completion = _CompletionF())
269267
: __b_(__count, std::move(__completion)) {
270268
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
271269
__count >= 0,
@@ -292,10 +290,12 @@ public:
292290

293291
_LIBCPP_END_NAMESPACE_STD
294292

295-
#endif // _LIBCPP_STD_VER >= 14
293+
# endif // _LIBCPP_STD_VER >= 14
296294

297295
_LIBCPP_POP_MACROS
298296

297+
#endif // !defined(_LIBCPP_HAS_NO_THREADS)
298+
299299
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
300300
# include <atomic>
301301
# include <concepts>

0 commit comments

Comments
 (0)