xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
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___CONFIG
11#define _LIBCPP___CONFIG
12
13#include <__config_site>
14
15#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16#  pragma GCC system_header
17#endif
18
19#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
20#  pragma clang deprecated(                                                                                            \
21      _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES,                                                                           \
22      "_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES is deprecated in LLVM 18 and will be removed in LLVM 19")
23#endif
24#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
25#  pragma clang deprecated(                                                                                            \
26      _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES,                                                                           \
27      "_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES is deprecated in LLVM 18 and will be removed in LLVM 19")
28#endif
29
30#if defined(__apple_build_version__)
31// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
32#  define _LIBCPP_COMPILER_CLANG_BASED
33#  define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
34#elif defined(__clang__)
35#  define _LIBCPP_COMPILER_CLANG_BASED
36#  define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
37#elif defined(__GNUC__)
38#  define _LIBCPP_COMPILER_GCC
39#  define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
40#endif
41
42#ifdef __cplusplus
43
44// Warn if a compiler version is used that is not supported anymore
45// LLVM RELEASE Update the minimum compiler versions
46#if defined(_LIBCPP_ENABLE_COMPILER_VERSION_CHECKS) // FreeBSD customization
47#  if defined(_LIBCPP_CLANG_VER)
48#    if _LIBCPP_CLANG_VER < 1600
49#      warning "Libc++ only supports Clang 16 and later"
50#    endif
51#  elif defined(_LIBCPP_APPLE_CLANG_VER)
52#    if _LIBCPP_APPLE_CLANG_VER < 1500
53#      warning "Libc++ only supports AppleClang 15 and later"
54#    endif
55#  elif defined(_LIBCPP_GCC_VER)
56#    if _LIBCPP_GCC_VER < 1300
57#      warning "Libc++ only supports GCC 13 and later"
58#    endif
59#  endif
60#endif // _LIBCPP_ENABLE_COMPILER_VERSION_CHECKS
61
62// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
63
64// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
65// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
66// defined to XXYYZZ.
67#  define _LIBCPP_VERSION 180100
68
69#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
70#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
71
72#  if __STDC_HOSTED__ == 0
73#    define _LIBCPP_FREESTANDING
74#  endif
75
76// NOLINTBEGIN(libcpp-cpp-version-check)
77#  ifndef _LIBCPP_STD_VER
78#    if __cplusplus <= 201103L
79#      define _LIBCPP_STD_VER 11
80#    elif __cplusplus <= 201402L
81#      define _LIBCPP_STD_VER 14
82#    elif __cplusplus <= 201703L
83#      define _LIBCPP_STD_VER 17
84#    elif __cplusplus <= 202002L
85#      define _LIBCPP_STD_VER 20
86#    elif __cplusplus <= 202302L
87#      define _LIBCPP_STD_VER 23
88#    else
89// Expected release year of the next C++ standard
90#      define _LIBCPP_STD_VER 26
91#    endif
92#  endif // _LIBCPP_STD_VER
93// NOLINTEND(libcpp-cpp-version-check)
94
95#  if defined(__ELF__)
96#    define _LIBCPP_OBJECT_FORMAT_ELF 1
97#  elif defined(__MACH__)
98#    define _LIBCPP_OBJECT_FORMAT_MACHO 1
99#  elif defined(_WIN32)
100#    define _LIBCPP_OBJECT_FORMAT_COFF 1
101#  elif defined(__wasm__)
102#    define _LIBCPP_OBJECT_FORMAT_WASM 1
103#  elif defined(_AIX)
104#    define _LIBCPP_OBJECT_FORMAT_XCOFF 1
105#  else
106// ... add new file formats here ...
107#  endif
108
109// ABI {
110
111#  if _LIBCPP_ABI_VERSION >= 2
112// Change short string representation so that string data starts at offset 0,
113// improving its alignment in some cases.
114#    define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
115// Fix deque iterator type in order to support incomplete types.
116#    define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
117// Fix undefined behavior in how std::list stores its linked nodes.
118#    define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
119// Fix undefined behavior in  how __tree stores its end and parent nodes.
120#    define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
121// Fix undefined behavior in how __hash_table stores its pointer types.
122#    define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
123#    define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
124#    define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
125// Define a key function for `bad_function_call` in the library, to centralize
126// its vtable and typeinfo to libc++ rather than having all other libraries
127// using that class define their own copies.
128#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
129// Override the default return value of exception::what() for
130// bad_function_call::what() with a string that is specific to
131// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
132// because it changes the vtable layout of bad_function_call.
133#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
134// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
135#    define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
136// Give reverse_iterator<T> one data member of type T, not two.
137// Also, in C++17 and later, don't derive iterator types from std::iterator.
138#    define _LIBCPP_ABI_NO_ITERATOR_BASES
139// Use the smallest possible integer type to represent the index of the variant.
140// Previously libc++ used "unsigned int" exclusively.
141#    define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
142// Unstable attempt to provide a more optimized std::function
143#    define _LIBCPP_ABI_OPTIMIZED_FUNCTION
144// All the regex constants must be distinct and nonzero.
145#    define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
146// Re-worked external template instantiations for std::string with a focus on
147// performance and fast-path inlining.
148#    define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
149// Enable clang::trivial_abi on std::unique_ptr.
150#    define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
151// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
152#    define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
153// std::random_device holds some state when it uses an implementation that gets
154// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
155// implementation to another one on a platform that has already shipped
156// std::random_device, one needs to retain the same object layout to remain ABI
157// compatible. This switch removes these workarounds for platforms that don't care
158// about ABI compatibility.
159#    define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
160// Don't export the legacy __basic_string_common class and its methods from the built library.
161#    define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
162// Don't export the legacy __vector_base_common class and its methods from the built library.
163#    define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
164// According to the Standard, `bitset::operator[] const` returns bool
165#    define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
166// Fix the implementation of CityHash used for std::hash<fundamental-type>.
167// This is an ABI break because `std::hash` will return a different result,
168// which means that hashing the same object in translation units built against
169// different versions of libc++ can return inconsistent results. This is especially
170// tricky since std::hash is used in the implementation of unordered containers.
171//
172// The incorrect implementation of CityHash has the problem that it drops some
173// bits on the floor.
174#    define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
175// Remove the base 10 implementation of std::to_chars from the dylib.
176// The implementation moved to the header, but we still export the symbols from
177// the dylib for backwards compatibility.
178#    define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
179#  elif _LIBCPP_ABI_VERSION == 1
180#    if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
181// Enable compiling copies of now inline methods into the dylib to support
182// applications compiled against older libraries. This is unnecessary with
183// COFF dllexport semantics, since dllexport forces a non-inline definition
184// of inline functions to be emitted anyway. Our own non-inline copy would
185// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
186// the linker will take issue with the symbols in the shared object if the
187// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
188// so disable it.
189#      define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
190#    endif
191// Feature macros for disabling pre ABI v1 features. All of these options
192// are deprecated.
193#    if defined(__FreeBSD__)
194#      define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
195#    endif
196// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol
197// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def
198// in the library, so we need to always rely on the library version.
199#    if defined(_AIX)
200#      define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
201#    endif
202#  endif
203
204#  if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
205// Define a key function for `bad_function_call` in the library, to centralize
206// its vtable and typeinfo to libc++ rather than having all other libraries
207// using that class define their own copies.
208#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
209#  endif
210
211// We had some bugs where we use [[no_unique_address]] together with construct_at,
212// which causes UB as the call on construct_at could write to overlapping subobjects
213//
214// https://github.com/llvm/llvm-project/issues/70506
215// https://github.com/llvm/llvm-project/issues/70494
216//
217// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions.
218// The macro below is used for all classes whose ABI have changed as part of fixing these bugs.
219#  define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua")))
220
221// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
222// within the bounds of the original container and asserts it on every dereference.
223//
224// ABI impact: changes the iterator type of the relevant containers.
225//
226// Supported containers:
227// - `span`;
228// - `string_view`;
229// - `array`.
230// #define _LIBCPP_ABI_BOUNDED_ITERATORS
231
232// } ABI
233
234// HARDENING {
235
236// TODO(hardening): deprecate this in LLVM 19.
237// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
238// equivalent to setting the extensive mode.
239#  ifdef _LIBCPP_ENABLE_ASSERTIONS
240#    if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
241#      error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
242#    endif
243#    if _LIBCPP_ENABLE_ASSERTIONS
244#      define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
245#    endif
246#  endif
247
248// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
249//
250// - `_LIBCPP_HARDENING_MODE_NONE`;
251// - `_LIBCPP_HARDENING_MODE_FAST`;
252// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
253// - `_LIBCPP_HARDENING_MODE_DEBUG`.
254//
255// These values have the following effects:
256//
257// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
258//
259// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
260//   that can be done with relatively little runtime overhead in constant time;
261//
262// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
263//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
264//   but are not necessarily security-critical;
265//
266// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
267//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
268//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
269
270// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
271// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
272//
273// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
274//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
275//   - the sentinel is reachable from the begin iterator;
276//   - TODO(hardening): both iterators refer to the same container.
277//
278// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
279//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
280//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
281//   `optional` and `function` are considered one-element containers for the purposes of this check.
282//
283// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
284//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
285//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
286//   compiler optimizations).
287//
288// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
289//   given ranges do not overlap.
290//
291// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
292//   was allocated by the given allocator). Violating this category typically results in a memory leak.
293//
294// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
295//   an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
296//   attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
297//   (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
298//   otherwise create an immediate security issue.
299//
300// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
301//   the containers have compatible allocators.
302//
303// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
304//   for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
305//   original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
306//   a string view where only a subset of elements is possible to access). This category is for assertions violating
307//   which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
308//   user code.
309//
310// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
311//   be benign in our implementation.
312//
313// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
314//   by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
315//   thus, this would often be a heuristic check and it might be quite expensive.
316//
317// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
318//   user input.
319//
320// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
321
322// clang-format off
323#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
324#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
325#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
326#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
327// clang-format on
328
329#  ifndef _LIBCPP_HARDENING_MODE
330#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
331#  endif
332
333#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
334      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
335      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
336      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
337#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
338_LIBCPP_HARDENING_MODE_NONE, \
339_LIBCPP_HARDENING_MODE_FAST, \
340_LIBCPP_HARDENING_MODE_EXTENSIVE, \
341_LIBCPP_HARDENING_MODE_DEBUG
342#  endif
343
344// clang-format off
345// Fast hardening mode checks.
346
347#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
348
349// Enabled checks.
350#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
351#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
352// Disabled checks.
353// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access.
354#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSUME(expression)
355// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
356// vulnerability.
357#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSUME(expression)
358#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)       _LIBCPP_ASSUME(expression)
359#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)  _LIBCPP_ASSUME(expression)
360#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSUME(expression)
361#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)   _LIBCPP_ASSUME(expression)
362#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                 _LIBCPP_ASSUME(expression)
363#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)     _LIBCPP_ASSUME(expression)
364#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
365#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSUME(expression)
366
367// Extensive hardening mode checks.
368
369#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
370
371// Enabled checks.
372#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
373#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
374#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSERT(expression, message)
375#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSERT(expression, message)
376#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)       _LIBCPP_ASSERT(expression, message)
377#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)  _LIBCPP_ASSERT(expression, message)
378#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSERT(expression, message)
379#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)   _LIBCPP_ASSERT(expression, message)
380#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                 _LIBCPP_ASSERT(expression, message)
381#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSERT(expression, message)
382// Disabled checks.
383#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)     _LIBCPP_ASSUME(expression)
384#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
385
386// Debug hardening mode checks.
387
388#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
389
390// All checks enabled.
391#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSERT(expression, message)
392#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSERT(expression, message)
393#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSERT(expression, message)
394#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSERT(expression, message)
395#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)        _LIBCPP_ASSERT(expression, message)
396#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)   _LIBCPP_ASSERT(expression, message)
397#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSERT(expression, message)
398#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)    _LIBCPP_ASSERT(expression, message)
399#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                  _LIBCPP_ASSERT(expression, message)
400#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)      _LIBCPP_ASSERT(expression, message)
401#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSERT(expression, message)
402#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSERT(expression, message)
403
404// Disable all checks if hardening is not enabled.
405
406#  else
407
408// All checks disabled.
409#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSUME(expression)
410#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSUME(expression)
411#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSUME(expression)
412#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSUME(expression)
413#    define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message)        _LIBCPP_ASSUME(expression)
414#    define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message)   _LIBCPP_ASSUME(expression)
415#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSUME(expression)
416#    define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message)    _LIBCPP_ASSUME(expression)
417#    define _LIBCPP_ASSERT_PEDANTIC(expression, message)                  _LIBCPP_ASSUME(expression)
418#    define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message)      _LIBCPP_ASSUME(expression)
419#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSUME(expression)
420#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSUME(expression)
421
422#  endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
423// clang-format on
424
425// } HARDENING
426
427#  define _LIBCPP_TOSTRING2(x) #x
428#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
429
430// NOLINTNEXTLINE(libcpp-cpp-version-check)
431#  if __cplusplus < 201103L
432#    define _LIBCPP_CXX03_LANG
433#  endif
434
435#  ifndef __has_attribute
436#    define __has_attribute(__x) 0
437#  endif
438
439#  ifndef __has_builtin
440#    define __has_builtin(__x) 0
441#  endif
442
443#  ifndef __has_extension
444#    define __has_extension(__x) 0
445#  endif
446
447#  ifndef __has_feature
448#    define __has_feature(__x) 0
449#  endif
450
451#  ifndef __has_cpp_attribute
452#    define __has_cpp_attribute(__x) 0
453#  endif
454
455#  ifndef __has_constexpr_builtin
456#    define __has_constexpr_builtin(x) 0
457#  endif
458
459// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
460// the compiler and '1' otherwise.
461#  ifndef __is_identifier
462#    define __is_identifier(__x) 1
463#  endif
464
465#  ifndef __has_declspec_attribute
466#    define __has_declspec_attribute(__x) 0
467#  endif
468
469#  define __has_keyword(__x) !(__is_identifier(__x))
470
471#  ifndef __has_include
472#    define __has_include(...) 0
473#  endif
474
475#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
476#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
477#  endif
478
479// FIXME: ABI detection should be done via compiler builtin macros. This
480// is just a placeholder until Clang implements such macros. For now assume
481// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
482// and allow the user to explicitly specify the ABI to handle cases where this
483// heuristic falls short.
484#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
485#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
486#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
487#    define _LIBCPP_ABI_ITANIUM
488#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
489#    define _LIBCPP_ABI_MICROSOFT
490#  else
491#    if defined(_WIN32) && defined(_MSC_VER)
492#      define _LIBCPP_ABI_MICROSOFT
493#    else
494#      define _LIBCPP_ABI_ITANIUM
495#    endif
496#  endif
497
498#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
499#    define _LIBCPP_ABI_VCRUNTIME
500#  endif
501
502#  if __has_feature(experimental_library)
503#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
504#      define _LIBCPP_ENABLE_EXPERIMENTAL
505#    endif
506#  endif
507
508// Incomplete features get their own specific disabling flags. This makes it
509// easier to grep for target specific flags once the feature is complete.
510#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
511#    define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
512#    define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
513#    define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
514#    define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
515#  endif
516
517// Need to detect which libc we're using if we're on Linux.
518#  if defined(__linux__)
519#    include <features.h>
520#    if defined(__GLIBC_PREREQ)
521#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
522#    else
523#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
524#    endif // defined(__GLIBC_PREREQ)
525#  endif   // defined(__linux__)
526
527#  if defined(__MVS__)
528#    include <features.h> // for __NATIVE_ASCII_F
529#  endif
530
531#  ifndef __BYTE_ORDER__
532#    error                                                                                                             \
533        "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
534#  endif
535
536#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
537#    define _LIBCPP_LITTLE_ENDIAN
538#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
539#    define _LIBCPP_BIG_ENDIAN
540#  endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
541
542#  if defined(_WIN32)
543#    define _LIBCPP_WIN32API
544#    define _LIBCPP_SHORT_WCHAR 1
545// Both MinGW and native MSVC provide a "MSVC"-like environment
546#    define _LIBCPP_MSVCRT_LIKE
547// If mingw not explicitly detected, assume using MS C runtime only if
548// a MS compatibility version is specified.
549#    if defined(_MSC_VER) && !defined(__MINGW32__)
550#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
551#    endif
552#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
553#      define _LIBCPP_HAS_BITSCAN64
554#    endif
555#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
556#  endif // defined(_WIN32)
557
558#  if defined(_AIX) && !defined(__64BIT__)
559// The size of wchar is 2 byte on 32-bit mode on AIX.
560#    define _LIBCPP_SHORT_WCHAR 1
561#  endif
562
563// Libc++ supports various implementations of std::random_device.
564//
565// _LIBCPP_USING_DEV_RANDOM
566//      Read entropy from the given file, by default `/dev/urandom`.
567//      If a token is provided, it is assumed to be the path to a file
568//      to read entropy from. This is the default behavior if nothing
569//      else is specified. This implementation requires storing state
570//      inside `std::random_device`.
571//
572// _LIBCPP_USING_ARC4_RANDOM
573//      Use arc4random(). This allows obtaining random data even when
574//      using sandboxing mechanisms. On some platforms like Apple, this
575//      is the recommended source of entropy for user-space programs.
576//      When this option is used, the token passed to `std::random_device`'s
577//      constructor *must* be "/dev/urandom" -- anything else is an error.
578//
579// _LIBCPP_USING_GETENTROPY
580//      Use getentropy().
581//      When this option is used, the token passed to `std::random_device`'s
582//      constructor *must* be "/dev/urandom" -- anything else is an error.
583//
584// _LIBCPP_USING_FUCHSIA_CPRNG
585//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
586//      deliver high-quality entropy and cannot fail.
587//      When this option is used, the token passed to `std::random_device`'s
588//      constructor *must* be "/dev/urandom" -- anything else is an error.
589//
590// _LIBCPP_USING_NACL_RANDOM
591//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
592//      including accesses to the special files under `/dev`. This implementation
593//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
594//      When this option is used, the token passed to `std::random_device`'s
595//      constructor *must* be "/dev/urandom" -- anything else is an error.
596//
597// _LIBCPP_USING_WIN32_RANDOM
598//      Use rand_s(), for use on Windows.
599//      When this option is used, the token passed to `std::random_device`'s
600//      constructor *must* be "/dev/urandom" -- anything else is an error.
601#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
602      defined(__DragonFly__)
603#    define _LIBCPP_USING_ARC4_RANDOM
604#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
605#    define _LIBCPP_USING_GETENTROPY
606#  elif defined(__Fuchsia__)
607#    define _LIBCPP_USING_FUCHSIA_CPRNG
608#  elif defined(__native_client__)
609#    define _LIBCPP_USING_NACL_RANDOM
610#  elif defined(_LIBCPP_WIN32API)
611#    define _LIBCPP_USING_WIN32_RANDOM
612#  else
613#    define _LIBCPP_USING_DEV_RANDOM
614#  endif
615
616#  ifndef _LIBCPP_CXX03_LANG
617
618#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
619#    define _ALIGNAS_TYPE(x) alignas(x)
620#    define _ALIGNAS(x) alignas(x)
621#    define _LIBCPP_NORETURN [[noreturn]]
622#    define _NOEXCEPT noexcept
623#    define _NOEXCEPT_(x) noexcept(x)
624#    define _LIBCPP_CONSTEXPR constexpr
625
626#  else
627
628#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
629#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
630#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
631#    define _LIBCPP_NORETURN __attribute__((__noreturn__))
632#    define _LIBCPP_HAS_NO_NOEXCEPT
633#    define nullptr __nullptr
634#    define _NOEXCEPT throw()
635#    define _NOEXCEPT_(x)
636#    define static_assert(...) _Static_assert(__VA_ARGS__)
637#    define decltype(...) __decltype(__VA_ARGS__)
638#    define _LIBCPP_CONSTEXPR
639
640typedef __char16_t char16_t;
641typedef __char32_t char32_t;
642
643#  endif
644
645#  if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
646#    define _LIBCPP_HAS_NO_EXCEPTIONS
647#  endif
648
649#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
650
651#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
652
653#    if defined(__APPLE__)
654#      if defined(__i386__) || defined(__x86_64__)
655// use old string layout on x86_64 and i386
656#      elif defined(__arm__)
657// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
658#        if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
659#          define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
660#        endif
661#      else
662#        define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
663#      endif
664#    endif
665
666// Objective-C++ features (opt-in)
667#    if __has_feature(objc_arc)
668#      define _LIBCPP_HAS_OBJC_ARC
669#    endif
670
671#    if __has_feature(objc_arc_weak)
672#      define _LIBCPP_HAS_OBJC_ARC_WEAK
673#    endif
674
675#    if __has_extension(blocks)
676#      define _LIBCPP_HAS_EXTENSION_BLOCKS
677#    endif
678
679#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
680#      define _LIBCPP_HAS_BLOCKS_RUNTIME
681#    endif
682
683#    if !__has_feature(address_sanitizer)
684#      define _LIBCPP_HAS_NO_ASAN
685#    endif
686
687#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
688
689#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
690
691#  elif defined(_LIBCPP_COMPILER_GCC)
692
693#    if !defined(__SANITIZE_ADDRESS__)
694#      define _LIBCPP_HAS_NO_ASAN
695#    endif
696
697#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
698
699#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
700
701#  endif // _LIBCPP_COMPILER_[CLANG|GCC]
702
703#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
704
705#    ifdef _DLL
706#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
707#    else
708#      define _LIBCPP_CRT_FUNC
709#    endif
710
711#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
712#      define _LIBCPP_DLL_VIS
713#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
714#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
715#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
716#      define _LIBCPP_EXPORTED_FROM_ABI
717#    elif defined(_LIBCPP_BUILDING_LIBRARY)
718#      define _LIBCPP_DLL_VIS __declspec(dllexport)
719#      if defined(__MINGW32__)
720#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
721#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
722#      else
723#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
724#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
725#      endif
726#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
727#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
728#    else
729#      define _LIBCPP_DLL_VIS __declspec(dllimport)
730#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
731#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
732#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
733#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
734#    endif
735
736#    define _LIBCPP_HIDDEN
737#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
738#    define _LIBCPP_TEMPLATE_VIS
739#    define _LIBCPP_TEMPLATE_DATA_VIS
740#    define _LIBCPP_TYPE_VISIBILITY_DEFAULT
741
742#  else
743
744#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
745#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
746#    else
747#      define _LIBCPP_VISIBILITY(vis)
748#    endif
749
750#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
751#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
752#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
753#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
754#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
755
756// TODO: Make this a proper customization point or remove the option to override it.
757#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
758#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
759#    endif
760
761#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
762// The inline should be removed once PR32114 is resolved
763#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
764#    else
765#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
766#    endif
767
768// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
769#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
770#      define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
771#    else
772#      define _LIBCPP_TEMPLATE_VIS
773#    endif
774
775#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \
776        _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization
777#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
778#    else
779#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT
780#    endif
781
782#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
783
784#  if __has_attribute(exclude_from_explicit_instantiation)
785#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
786#  else
787// Try to approximate the effect of exclude_from_explicit_instantiation
788// (which is that entities are not assumed to be provided by explicit
789// template instantiations in the dylib) by always inlining those entities.
790#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
791#  endif
792
793#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
794#    define _LIBCPP_HARDENING_SIG f
795#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
796#    define _LIBCPP_HARDENING_SIG s
797#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
798#    define _LIBCPP_HARDENING_SIG d
799#  else
800#    define _LIBCPP_HARDENING_SIG n // "none"
801#  endif
802
803#  ifdef _LIBCPP_HAS_NO_EXCEPTIONS
804#    define _LIBCPP_EXCEPTIONS_SIG n
805#  else
806#    define _LIBCPP_EXCEPTIONS_SIG e
807#  endif
808
809#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
810    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
811
812// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
813// on two levels:
814// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
815//    symbols from their dynamic library by means of using the libc++ headers. This ensures
816//    that those symbols stay private to the dynamic library in which it is defined.
817//
818// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
819//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
820//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
821//    program contains two definitions of a function, the ODR requires them to be token-by-token
822//    equivalent, and the linker is allowed to pick either definition and discard the other one.
823//
824//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
825//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
826//    compiled with different settings), the two definitions are both visible by the linker and they
827//    have the same name, but they have a meaningfully different implementation (one throws an exception
828//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
829//    practice what will happen is that the linker will pick one of the definitions at random and will
830//    discard the other one. This can quite clearly lead to incorrect program behavior.
831//
832//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
833//    property that causes the code of a function to differ from the code in another configuration
834//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
835//    tag, but we encode the ones that we think are most important: library version, exceptions, and
836//    hardening mode.
837//
838//    Note that historically, solving this problem has been achieved in various ways, including
839//    force-inlining all functions or giving internal linkage to all functions. Both these previous
840//    solutions suffer from drawbacks that lead notably to code bloat.
841//
842// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
843// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
844//
845// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
846// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
847// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
848// the virtual function pointer in the vtable based on the mangled name of the function. Since
849// we use an ABI tag that changes with each released version, the mangled name of the virtual
850// function would change, which is incorrect. Note that it doesn't make much sense to change
851// the implementation of a virtual function in an ABI-incompatible way in the first place,
852// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
853//
854// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
855//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
856//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
857#  ifndef _LIBCPP_NO_ABI_TAG
858#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
859      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
860          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
861#  else
862#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
863#  endif
864#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
865
866// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
867// "C" function, as those lack mangling.
868#  define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
869
870#  ifdef _LIBCPP_BUILDING_LIBRARY
871#    if _LIBCPP_ABI_VERSION > 1
872#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
873#    else
874#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
875#    endif
876#  else
877#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
878#  endif
879
880// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around
881//                only to ease the renaming for downstreams.
882#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
883#  define _VSTD std
884
885// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
886// clang-format off
887#  define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {                                  \
888                               inline namespace _LIBCPP_ABI_NAMESPACE {
889#  define _LIBCPP_END_NAMESPACE_STD }}
890
891#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
892                                             inline namespace __fs { namespace filesystem {
893
894#  define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
895// clang-format on
896
897#  if __has_attribute(__enable_if__)
898#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
899#  endif
900
901#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
902#    define _LIBCPP_HAS_NO_INT128
903#  endif
904
905#  ifdef _LIBCPP_CXX03_LANG
906#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
907      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
908        enum __lx
909// clang-format off
910#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
911      __lx __v_;                                                                                                       \
912      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
913      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
914      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
915      };
916// clang-format on
917
918#  else // _LIBCPP_CXX03_LANG
919#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
920#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
921#  endif // _LIBCPP_CXX03_LANG
922
923#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
924#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
925#  endif
926
927#  ifdef __FreeBSD__
928#    define _DECLARE_C99_LDBL_MATH 1
929#  endif
930
931// If we are getting operator new from the MSVC CRT, then allocation overloads
932// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
933#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
934#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
935#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
936// We're deferring to Microsoft's STL to provide aligned new et al. We don't
937// have it unless the language feature test macro is defined.
938#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
939#  elif defined(__MVS__)
940#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
941#  endif
942
943#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
944#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
945#  endif
946
947// It is not yet possible to use aligned_alloc() on all Apple platforms since
948// 10.15 was the first version to ship an implementation of aligned_alloc().
949#  if defined(__APPLE__)
950#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
951         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
952#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
953#    endif
954#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
955// Android only provides aligned_alloc when targeting API 28 or higher.
956#    define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
957#  endif
958
959#  if defined(__APPLE__) || defined(__FreeBSD__)
960#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
961#  endif
962
963#  if defined(__APPLE__) || defined(__FreeBSD__)
964#    define _LIBCPP_WCTYPE_IS_MASK
965#  endif
966
967#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
968#    define _LIBCPP_HAS_NO_CHAR8_T
969#  endif
970
971// Deprecation macros.
972//
973// Deprecations warnings are always enabled, except when users explicitly opt-out
974// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
975#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
976#    if __has_attribute(__deprecated__)
977#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
978#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
979#    elif _LIBCPP_STD_VER >= 14
980#      define _LIBCPP_DEPRECATED [[deprecated]]
981#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
982#    else
983#      define _LIBCPP_DEPRECATED
984#      define _LIBCPP_DEPRECATED_(m)
985#    endif
986#  else
987#    define _LIBCPP_DEPRECATED
988#    define _LIBCPP_DEPRECATED_(m)
989#  endif
990
991#  if !defined(_LIBCPP_CXX03_LANG)
992#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
993#  else
994#    define _LIBCPP_DEPRECATED_IN_CXX11
995#  endif
996
997#  if _LIBCPP_STD_VER >= 14
998#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
999#  else
1000#    define _LIBCPP_DEPRECATED_IN_CXX14
1001#  endif
1002
1003#  if _LIBCPP_STD_VER >= 17
1004#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
1005#  else
1006#    define _LIBCPP_DEPRECATED_IN_CXX17
1007#  endif
1008
1009#  if _LIBCPP_STD_VER >= 20
1010#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1011#  else
1012#    define _LIBCPP_DEPRECATED_IN_CXX20
1013#  endif
1014
1015#  if _LIBCPP_STD_VER >= 23
1016#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
1017#  else
1018#    define _LIBCPP_DEPRECATED_IN_CXX23
1019#  endif
1020
1021#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
1022#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1023#  else
1024#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1025#  endif
1026
1027// Macros to enter and leave a state where deprecation warnings are suppressed.
1028#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1029#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
1030      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
1031          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1032#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
1033#  else
1034#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1035#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
1036#  endif
1037
1038#  if _LIBCPP_STD_VER <= 11
1039#    define _LIBCPP_EXPLICIT_SINCE_CXX14
1040#  else
1041#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
1042#  endif
1043
1044#  if _LIBCPP_STD_VER >= 23
1045#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
1046#  else
1047#    define _LIBCPP_EXPLICIT_SINCE_CXX23
1048#  endif
1049
1050#  if _LIBCPP_STD_VER >= 14
1051#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
1052#  else
1053#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
1054#  endif
1055
1056#  if _LIBCPP_STD_VER >= 17
1057#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
1058#  else
1059#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
1060#  endif
1061
1062#  if _LIBCPP_STD_VER >= 20
1063#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
1064#  else
1065#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
1066#  endif
1067
1068#  if _LIBCPP_STD_VER >= 23
1069#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
1070#  else
1071#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
1072#  endif
1073
1074#  ifndef _LIBCPP_HAS_NO_ASAN
1075extern "C" _LIBCPP_EXPORTED_FROM_ABI void
1076__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
1077extern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
1078    const void*, const void*, const void*, const void*, const void*, const void*);
1079extern "C" _LIBCPP_EXPORTED_FROM_ABI int
1080__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
1081#  endif
1082
1083// Try to find out if RTTI is disabled.
1084#  if !defined(__cpp_rtti) || __cpp_rtti < 199711L
1085#    define _LIBCPP_HAS_NO_RTTI
1086#  endif
1087
1088#  ifndef _LIBCPP_WEAK
1089#    define _LIBCPP_WEAK __attribute__((__weak__))
1090#  endif
1091
1092// Thread API
1093// clang-format off
1094#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
1095      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
1096      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
1097      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1098
1099#    if defined(__FreeBSD__) ||                                                                                        \
1100        defined(__wasi__) ||                                                                                           \
1101        defined(__NetBSD__) ||                                                                                         \
1102        defined(__OpenBSD__) ||                                                                                        \
1103        defined(__NuttX__) ||                                                                                          \
1104        defined(__linux__) ||                                                                                          \
1105        defined(__GNU__) ||                                                                                            \
1106        defined(__APPLE__) ||                                                                                          \
1107        defined(__MVS__) ||                                                                                            \
1108        defined(_AIX) ||                                                                                               \
1109        defined(__EMSCRIPTEN__)
1110// clang-format on
1111#      define _LIBCPP_HAS_THREAD_API_PTHREAD
1112#    elif defined(__Fuchsia__)
1113// TODO(44575): Switch to C11 thread API when possible.
1114#      define _LIBCPP_HAS_THREAD_API_PTHREAD
1115#    elif defined(_LIBCPP_WIN32API)
1116#      define _LIBCPP_HAS_THREAD_API_WIN32
1117#    else
1118#      error "No thread API"
1119#    endif // _LIBCPP_HAS_THREAD_API
1120#  endif   // _LIBCPP_HAS_NO_THREADS
1121
1122#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1123#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
1124#      define _LIBCPP_HAS_COND_CLOCKWAIT
1125#    elif defined(_LIBCPP_GLIBC_PREREQ)
1126#      if _LIBCPP_GLIBC_PREREQ(2, 30)
1127#        define _LIBCPP_HAS_COND_CLOCKWAIT
1128#      endif
1129#    endif
1130#  endif
1131
1132#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1133#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1134       _LIBCPP_HAS_NO_THREADS is not defined.
1135#  endif
1136
1137#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1138#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1139       _LIBCPP_HAS_NO_THREADS is defined.
1140#  endif
1141
1142#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
1143#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1144       _LIBCPP_HAS_NO_THREADS is defined.
1145#  endif
1146
1147#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1148#    define __STDCPP_THREADS__ 1
1149#  endif
1150
1151// The glibc and Bionic implementation of pthreads implements
1152// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1153// mutexes have no destroy mechanism.
1154//
1155// This optimization can't be performed on Apple platforms, where
1156// pthread_mutex_destroy can allow the kernel to release resources.
1157// See https://llvm.org/D64298 for details.
1158//
1159// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1160//               respective stakeholders.
1161// clang-format off
1162#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
1163      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
1164       defined(_LIBCPP_HAS_THREAD_API_WIN32)
1165// clang-format on
1166#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1167#  endif
1168
1169// Destroying a condvar is a nop on Windows.
1170//
1171// This optimization can't be performed on Apple platforms, where
1172// pthread_cond_destroy can allow the kernel to release resources.
1173// See https://llvm.org/D64298 for details.
1174//
1175// TODO(EricWF): This is potentially true for some pthread implementations
1176// as well.
1177#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1178#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1179#  endif
1180
1181#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
1182      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1183#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1184#  endif
1185
1186#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1187#    define _LIBCPP_HAS_C_ATOMIC_IMP
1188#  elif defined(_LIBCPP_COMPILER_GCC)
1189#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
1190#  endif
1191
1192#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
1193      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1194#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
1195#  else
1196#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1197#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
1198#    endif
1199#    ifdef _LIBCPP_FREESTANDING
1200#      define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1201#    endif
1202#  endif
1203
1204#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
1205#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
1206#  else
1207#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
1208#  endif
1209
1210#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1211#    if defined(__clang__) && __has_attribute(acquire_capability)
1212// Work around the attribute handling in clang.  When both __declspec and
1213// __attribute__ are present, the processing goes awry preventing the definition
1214// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1215// combining the two does work.
1216#      if !defined(_MSC_VER)
1217#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1218#      endif
1219#    endif
1220#  endif
1221
1222#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1223#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1224#  else
1225#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1226#  endif
1227
1228#  if _LIBCPP_STD_VER >= 20
1229#    define _LIBCPP_CONSTINIT constinit
1230#  elif __has_attribute(__require_constant_initialization__)
1231#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1232#  else
1233#    define _LIBCPP_CONSTINIT
1234#  endif
1235
1236#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
1237// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
1238// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
1239// when compiling for CUDA we use the non-underscored version of the noinline
1240// attribute.
1241//
1242// This is a temporary workaround and we still expect the CUDA SDK team to solve
1243// this issue properly in the SDK headers.
1244//
1245// See https://github.com/llvm/llvm-project/pull/73838 for more details.
1246#    define _LIBCPP_NOINLINE __attribute__((noinline))
1247#  elif __has_attribute(__noinline__)
1248#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
1249#  else
1250#    define _LIBCPP_NOINLINE
1251#  endif
1252
1253// We often repeat things just for handling wide characters in the library.
1254// When wide characters are disabled, it can be useful to have a quick way of
1255// disabling it without having to resort to #if-#endif, which has a larger
1256// impact on readability.
1257#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1258#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
1259#  else
1260#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1261#  endif
1262
1263#  if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1264#    define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1265#    define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1266#    define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1267#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1268#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1269#  endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1270
1271#  if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1272#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1273#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1274#    define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1275#    define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1276#    define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1277#    define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1278#  endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1279
1280// clang-format off
1281#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
1282#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
1283// clang-format on
1284
1285#  ifndef _LIBCPP_NO_AUTO_LINK
1286#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1287#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1288#        pragma comment(lib, "c++.lib")
1289#      else
1290#        pragma comment(lib, "libc++.lib")
1291#      endif
1292#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1293#  endif   // _LIBCPP_NO_AUTO_LINK
1294
1295// Configures the fopen close-on-exec mode character, if any. This string will
1296// be appended to any mode string used by fstream for fopen/fdopen.
1297//
1298// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1299// do.
1300#  if defined(__BIONIC__)
1301#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1302#  else
1303#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1304#  endif
1305
1306#  if __has_cpp_attribute(msvc::no_unique_address)
1307// MSVC implements [[no_unique_address]] as a silent no-op currently.
1308// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1309// However, MSVC implements [[msvc::no_unique_address]] which does what
1310// [[no_unique_address]] is supposed to do, in general.
1311
1312// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1313// [[msvc::no_unique_address]] though. If/when it does implement
1314// [[msvc::no_unique_address]], this should be preferred though.
1315#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1316#  elif __has_cpp_attribute(no_unique_address)
1317#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1318#  else
1319#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1320// Note that this can be replaced by #error as soon as clang-cl
1321// implements msvc::no_unique_address, since there should be no C++20
1322// compiler that doesn't support one of the two attributes at that point.
1323// We generally don't want to use this macro outside of C++20-only code,
1324// because using it conditionally in one language version only would make
1325// the ABI inconsistent.
1326#  endif
1327
1328#  ifdef _LIBCPP_COMPILER_CLANG_BASED
1329#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1330#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1331#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1332#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1333#  elif defined(_LIBCPP_COMPILER_GCC)
1334#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1335#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1336#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1337#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1338#  else
1339#    define _LIBCPP_DIAGNOSTIC_PUSH
1340#    define _LIBCPP_DIAGNOSTIC_POP
1341#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1342#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1343#  endif
1344
1345// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1346// functions is gradually being added to existing C libraries. The conditions
1347// below check for known C library versions and conditions under which these
1348// functions are declared by the C library.
1349#  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1350// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1351// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1352// the latter depends on internal GNU libc details that are not appropriate
1353// to depend on here, so any declarations present when __cpp_char8_t is not
1354// defined are ignored.
1355#  if defined(_LIBCPP_GLIBC_PREREQ)
1356#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1357#      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1358#    endif
1359#  endif
1360
1361// There are a handful of public standard library types that are intended to
1362// support CTAD but don't need any explicit deduction guides to do so. This
1363// macro is used to mark them as such, which suppresses the
1364// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1365// with these classes.
1366#  if _LIBCPP_STD_VER >= 17
1367#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1368#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1369        template <class... _Tag>                                                                                       \
1370        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1371#    else
1372#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
1373        template <class... _Tag>                                                                                       \
1374        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1375#    endif
1376#  else
1377#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1378#  endif
1379
1380// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1381// compiler intrinsics in the Objective-C++ mode.
1382#  ifdef __OBJC__
1383#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1384#  endif
1385
1386#  define _PSTL_PRAGMA(x) _Pragma(#x)
1387
1388// Enable SIMD for compilers that support OpenMP 4.0
1389#  if (defined(_OPENMP) && _OPENMP >= 201307)
1390
1391#    define _PSTL_UDR_PRESENT
1392#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1393#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1394#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1395#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1396#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1397#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1398
1399// Declaration of reduction functor, where
1400// NAME - the name of the functor
1401// OP - type of the callable object with the reduction operation
1402// omp_in - refers to the local partial result
1403// omp_out - refers to the final value of the combiner operator
1404// omp_priv - refers to the private copy of the initial value
1405// omp_orig - refers to the original variable to be reduced
1406#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
1407      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1408
1409#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1410
1411#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1412#    define _PSTL_PRAGMA_DECLARE_SIMD
1413#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1414#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1415#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1416#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1417#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1418
1419#  else // (defined(_OPENMP) && _OPENMP >= 201307)
1420
1421#    define _PSTL_PRAGMA_SIMD
1422#    define _PSTL_PRAGMA_DECLARE_SIMD
1423#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1424#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1425#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1426#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1427#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1428
1429#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
1430
1431#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1432
1433// Optional attributes - these are useful for a better QoI, but not required to be available
1434
1435#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1436#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1437#  else
1438#    define _LIBCPP_NO_CFI
1439#  endif
1440
1441#  if __has_attribute(__malloc__)
1442#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
1443#  else
1444#    define _LIBCPP_NOALIAS
1445#  endif
1446
1447#  if __has_attribute(__using_if_exists__)
1448#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1449#  else
1450#    define _LIBCPP_USING_IF_EXISTS
1451#  endif
1452
1453#  if __has_cpp_attribute(nodiscard)
1454#    define _LIBCPP_NODISCARD [[__nodiscard__]]
1455#  else
1456// We can't use GCC's [[gnu::warn_unused_result]] and
1457// __attribute__((warn_unused_result)), because GCC does not silence them via
1458// (void) cast.
1459#    define _LIBCPP_NODISCARD
1460#  endif
1461
1462// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1463// specified as such as an extension.
1464#  if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1465#    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
1466#  else
1467#    define _LIBCPP_NODISCARD_EXT
1468#  endif
1469
1470#  if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1471#    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
1472#  else
1473#    define _LIBCPP_NODISCARD_AFTER_CXX17
1474#  endif
1475
1476#  if __has_attribute(__no_destroy__)
1477#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1478#  else
1479#    define _LIBCPP_NO_DESTROY
1480#  endif
1481
1482#  if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1483#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1484#  else
1485#    define _LIBCPP_DIAGNOSE_WARNING(...)
1486#  endif
1487
1488// Use a function like macro to imply that it must be followed by a semicolon
1489#  if __has_cpp_attribute(fallthrough)
1490#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1491#  elif __has_attribute(__fallthrough__)
1492#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1493#  else
1494#    define _LIBCPP_FALLTHROUGH() ((void)0)
1495#  endif
1496
1497#  if __has_cpp_attribute(_Clang::__lifetimebound__)
1498#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1499#  else
1500#    define _LIBCPP_LIFETIMEBOUND
1501#  endif
1502
1503#  if __has_attribute(__nodebug__)
1504#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1505#  else
1506#    define _LIBCPP_NODEBUG
1507#  endif
1508
1509#  if __has_attribute(__standalone_debug__)
1510#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1511#  else
1512#    define _LIBCPP_STANDALONE_DEBUG
1513#  endif
1514
1515#  if __has_attribute(__preferred_name__)
1516#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1517#  else
1518#    define _LIBCPP_PREFERRED_NAME(x)
1519#  endif
1520
1521#  if __has_attribute(__no_sanitize__)
1522#    define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1523#  else
1524#    define _LIBCPP_NO_SANITIZE(...)
1525#  endif
1526
1527#  if __has_attribute(__init_priority__)
1528#    define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1529#  else
1530#    define _LIBCPP_INIT_PRIORITY_MAX
1531#  endif
1532
1533#  if __has_attribute(__format__)
1534// The attribute uses 1-based indices for ordinary and static member functions.
1535// The attribute uses 2-based indices for non-static member functions.
1536#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
1537      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1538#  else
1539#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1540#  endif
1541
1542#  if __has_attribute(__packed__)
1543#    define _LIBCPP_PACKED __attribute__((__packed__))
1544#  else
1545#    define _LIBCPP_PACKED
1546#  endif
1547
1548#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1549#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1550#  else
1551#    define _LIBCPP_DECLSPEC_EMPTY_BASES
1552#  endif
1553
1554// Allow for build-time disabling of unsigned integer sanitization
1555#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1556#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1557#  else
1558#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1559#  endif
1560
1561// Clang-18 has support for deducing this, but it does not set the FTM.
1562#  if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1563#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
1564#  endif
1565
1566#endif // __cplusplus
1567
1568#endif // _LIBCPP___CONFIG
1569