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