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