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