2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CONFIG
11 #define _LIBCPP___CONFIG
13 #include <__config_site>
15 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16 # pragma GCC system_header
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
32 // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
34 // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
35 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
37 # define _LIBCPP_VERSION 180000
39 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
40 # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
42 // Valid C++ identifier that revs with every libc++ version. This can be used to
43 // generate identifiers that must be unique for every released libc++ version.
44 # define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION)
46 # if __STDC_HOSTED__ == 0
47 # define _LIBCPP_FREESTANDING
50 // NOLINTBEGIN(libcpp-cpp-version-check)
51 # ifndef _LIBCPP_STD_VER
52 # if __cplusplus <= 201103L
53 # define _LIBCPP_STD_VER 11
54 # elif __cplusplus <= 201402L
55 # define _LIBCPP_STD_VER 14
56 # elif __cplusplus <= 201703L
57 # define _LIBCPP_STD_VER 17
58 # elif __cplusplus <= 202002L
59 # define _LIBCPP_STD_VER 20
60 # elif __cplusplus <= 202302L
61 # define _LIBCPP_STD_VER 23
63 // Expected release year of the next C++ standard
64 # define _LIBCPP_STD_VER 26
66 # endif // _LIBCPP_STD_VER
67 // NOLINTEND(libcpp-cpp-version-check)
70 # define _LIBCPP_OBJECT_FORMAT_ELF 1
71 # elif defined(__MACH__)
72 # define _LIBCPP_OBJECT_FORMAT_MACHO 1
73 # elif defined(_WIN32)
74 # define _LIBCPP_OBJECT_FORMAT_COFF 1
75 # elif defined(__wasm__)
76 # define _LIBCPP_OBJECT_FORMAT_WASM 1
78 # define _LIBCPP_OBJECT_FORMAT_XCOFF 1
80 // ... add new file formats here ...
85 # if _LIBCPP_ABI_VERSION >= 2
86 // Change short string representation so that string data starts at offset 0,
87 // improving its alignment in some cases.
88 # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
89 // Fix deque iterator type in order to support incomplete types.
90 # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
91 // Fix undefined behavior in how std::list stores its linked nodes.
92 # define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
93 // Fix undefined behavior in how __tree stores its end and parent nodes.
94 # define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
95 // Fix undefined behavior in how __hash_table stores its pointer types.
96 # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
97 # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
98 # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
99 // Define a key function for `bad_function_call` in the library, to centralize
100 // its vtable and typeinfo to libc++ rather than having all other libraries
101 // using that class define their own copies.
102 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
103 // Override the default return value of exception::what() for
104 // bad_function_call::what() with a string that is specific to
105 // bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
106 // because it changes the vtable layout of bad_function_call.
107 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
108 // Enable optimized version of __do_get_(un)signed which avoids redundant copies.
109 # define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
110 // Give reverse_iterator<T> one data member of type T, not two.
111 // Also, in C++17 and later, don't derive iterator types from std::iterator.
112 # define _LIBCPP_ABI_NO_ITERATOR_BASES
113 // Use the smallest possible integer type to represent the index of the variant.
114 // Previously libc++ used "unsigned int" exclusively.
115 # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
116 // Unstable attempt to provide a more optimized std::function
117 # define _LIBCPP_ABI_OPTIMIZED_FUNCTION
118 // All the regex constants must be distinct and nonzero.
119 # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
120 // Re-worked external template instantiations for std::string with a focus on
121 // performance and fast-path inlining.
122 # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
123 // Enable clang::trivial_abi on std::unique_ptr.
124 # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
125 // Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
126 # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
127 // std::random_device holds some state when it uses an implementation that gets
128 // entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
129 // implementation to another one on a platform that has already shipped
130 // std::random_device, one needs to retain the same object layout to remain ABI
131 // compatible. This switch removes these workarounds for platforms that don't care
132 // about ABI compatibility.
133 # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
134 // Don't export the legacy __basic_string_common class and its methods from the built library.
135 # define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
136 // Don't export the legacy __vector_base_common class and its methods from the built library.
137 # define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
138 // According to the Standard, `bitset::operator[] const` returns bool
139 # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
140 // Fix the implementation of CityHash used for std::hash<fundamental-type>.
141 // This is an ABI break because `std::hash` will return a different result,
142 // which means that hashing the same object in translation units built against
143 // different versions of libc++ can return inconsistent results. This is especially
144 // tricky since std::hash is used in the implementation of unordered containers.
146 // The incorrect implementation of CityHash has the problem that it drops some
147 // bits on the floor.
148 # define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
149 // Remove the base 10 implementation of std::to_chars from the dylib.
150 // The implementation moved to the header, but we still export the symbols from
151 // the dylib for backwards compatibility.
152 # define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
153 # elif _LIBCPP_ABI_VERSION == 1
154 # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
155 // Enable compiling copies of now inline methods into the dylib to support
156 // applications compiled against older libraries. This is unnecessary with
157 // COFF dllexport semantics, since dllexport forces a non-inline definition
158 // of inline functions to be emitted anyway. Our own non-inline copy would
159 // conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
160 // the linker will take issue with the symbols in the shared object if the
161 // weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
163 # define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
165 // Feature macros for disabling pre ABI v1 features. All of these options
167 # if defined(__FreeBSD__) && __FreeBSD__ < 14
168 # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
170 // For XCOFF linkers, we have problems if we see a weak hidden version of a symbol
171 // in user code (like you get with -fvisibility-inlines-hidden) and then a strong def
172 // in the library, so we need to always rely on the library version.
174 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
178 # if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
179 // Enable additional explicit instantiations of iostreams components. This
180 // reduces the number of weak definitions generated in programs that use
181 // iostreams by providing a single strong definition in the shared library.
182 # define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
184 // Define a key function for `bad_function_call` in the library, to centralize
185 // its vtable and typeinfo to libc++ rather than having all other libraries
186 // using that class define their own copies.
187 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
190 // Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
191 // within the bounds of the original container and asserts it on every dereference.
193 // ABI impact: changes the iterator type of the relevant containers.
195 // Supported containers:
199 // #define _LIBCPP_ABI_BOUNDED_ITERATORS
205 // TODO(hardening): remove this in LLVM 19.
206 // This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
207 // equivalent to setting the hardened mode.
208 # ifdef _LIBCPP_ENABLE_ASSERTIONS
209 # warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_HARDENED_MODE instead."
210 # if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
211 # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
213 # if _LIBCPP_ENABLE_ASSERTIONS
214 # define _LIBCPP_ENABLE_HARDENED_MODE 1
218 // Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes
219 // security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with
220 // `_LIBCPP_ENABLE_DEBUG_MODE`.
222 // #define _LIBCPP_ENABLE_HARDENED_MODE 1
224 // Enables the debug mode which contains all the checks from the hardened mode and additionally more expensive checks
225 // that may affect the complexity of algorithms. The debug mode is intended to be used for testing, not in production.
226 // Mutually exclusive with `_LIBCPP_ENABLE_HARDENED_MODE`.
228 // #define _LIBCPP_ENABLE_DEBUG_MODE 1
230 // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
231 // macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
233 // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
234 // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
235 // - the sentinel is reachable from the begin iterator;
236 // - TODO(hardening): both iterators refer to the same container.
238 // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
239 // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
240 // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
241 // `optional` and `function` are considered one-element containers for the purposes of this check.
243 // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
244 // given ranges do not overlap.
246 // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
247 // the containers have compatible allocators.
249 // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
252 // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
254 # ifndef _LIBCPP_ENABLE_HARDENED_MODE
255 # define _LIBCPP_ENABLE_HARDENED_MODE _LIBCPP_ENABLE_HARDENED_MODE_DEFAULT
257 # if _LIBCPP_ENABLE_HARDENED_MODE != 0 && _LIBCPP_ENABLE_HARDENED_MODE != 1
258 # error "_LIBCPP_ENABLE_HARDENED_MODE must be set to 0 or 1."
261 # ifndef _LIBCPP_ENABLE_DEBUG_MODE
262 # define _LIBCPP_ENABLE_DEBUG_MODE _LIBCPP_ENABLE_DEBUG_MODE_DEFAULT
264 # if _LIBCPP_ENABLE_DEBUG_MODE != 0 && _LIBCPP_ENABLE_DEBUG_MODE != 1
265 # error "_LIBCPP_ENABLE_DEBUG_MODE must be set to 0 or 1."
268 # if _LIBCPP_ENABLE_HARDENED_MODE && _LIBCPP_ENABLE_DEBUG_MODE
269 # error "Only one of _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled."
272 // Hardened mode checks.
275 # if _LIBCPP_ENABLE_HARDENED_MODE
278 # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message)
279 # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
281 // Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
283 # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
284 # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
285 # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
286 # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
288 // Debug mode checks.
290 # elif _LIBCPP_ENABLE_DEBUG_MODE
292 // All checks enabled.
293 # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message)
294 # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
295 # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message)
296 # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message)
297 # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message)
298 # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message)
300 // Disable all checks if hardening is not enabled.
304 // All checks disabled.
305 # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression)
306 # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression)
307 # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
308 # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
309 # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
310 # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
312 # endif // _LIBCPP_ENABLE_HARDENED_MODE
317 # define _LIBCPP_TOSTRING2(x) #x
318 # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
320 // NOLINTNEXTLINE(libcpp-cpp-version-check)
321 # if __cplusplus < 201103L
322 # define _LIBCPP_CXX03_LANG
325 # ifndef __has_attribute
326 # define __has_attribute(__x) 0
329 # ifndef __has_builtin
330 # define __has_builtin(__x) 0
333 # ifndef __has_extension
334 # define __has_extension(__x) 0
337 # ifndef __has_feature
338 # define __has_feature(__x) 0
341 # ifndef __has_cpp_attribute
342 # define __has_cpp_attribute(__x) 0
345 # ifndef __has_constexpr_builtin
346 # define __has_constexpr_builtin(x) 0
349 // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
350 // the compiler and '1' otherwise.
351 # ifndef __is_identifier
352 # define __is_identifier(__x) 1
355 # ifndef __has_declspec_attribute
356 # define __has_declspec_attribute(__x) 0
359 # define __has_keyword(__x) !(__is_identifier(__x))
361 # ifndef __has_include
362 # define __has_include(...) 0
365 # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
366 # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
369 // FIXME: ABI detection should be done via compiler builtin macros. This
370 // is just a placeholder until Clang implements such macros. For now assume
371 // that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
372 // and allow the user to explicitly specify the ABI to handle cases where this
373 // heuristic falls short.
374 # if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
375 # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
376 # elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
377 # define _LIBCPP_ABI_ITANIUM
378 # elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
379 # define _LIBCPP_ABI_MICROSOFT
381 # if defined(_WIN32) && defined(_MSC_VER)
382 # define _LIBCPP_ABI_MICROSOFT
384 # define _LIBCPP_ABI_ITANIUM
388 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
389 # define _LIBCPP_ABI_VCRUNTIME
392 # if __has_feature(experimental_library)
393 # ifndef _LIBCPP_ENABLE_EXPERIMENTAL
394 # define _LIBCPP_ENABLE_EXPERIMENTAL
398 // Incomplete features get their own specific disabling flags. This makes it
399 // easier to grep for target specific flags once the feature is complete.
400 # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
401 # define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
402 # define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
403 # define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
406 // Need to detect which libc we're using if we're on Linux.
407 # if defined(__linux__)
408 # include <features.h>
409 # if defined(__GLIBC_PREREQ)
410 # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
412 # define _LIBCPP_GLIBC_PREREQ(a, b) 0
413 # endif // defined(__GLIBC_PREREQ)
414 # endif // defined(__linux__)
416 # if defined(__MVS__)
417 # include <features.h> // for __NATIVE_ASCII_F
420 # ifndef __BYTE_ORDER__
422 "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
425 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
426 # define _LIBCPP_LITTLE_ENDIAN
427 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
428 # define _LIBCPP_BIG_ENDIAN
429 # endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
432 # define _LIBCPP_WIN32API
433 # define _LIBCPP_SHORT_WCHAR 1
434 // Both MinGW and native MSVC provide a "MSVC"-like environment
435 # define _LIBCPP_MSVCRT_LIKE
436 // If mingw not explicitly detected, assume using MS C runtime only if
437 // a MS compatibility version is specified.
438 # if defined(_MSC_VER) && !defined(__MINGW32__)
439 # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
441 # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
442 # define _LIBCPP_HAS_BITSCAN64
444 # define _LIBCPP_HAS_OPEN_WITH_WCHAR
445 # endif // defined(_WIN32)
447 # if defined(_AIX) && !defined(__64BIT__)
448 // The size of wchar is 2 byte on 32-bit mode on AIX.
449 # define _LIBCPP_SHORT_WCHAR 1
452 // Libc++ supports various implementations of std::random_device.
454 // _LIBCPP_USING_DEV_RANDOM
455 // Read entropy from the given file, by default `/dev/urandom`.
456 // If a token is provided, it is assumed to be the path to a file
457 // to read entropy from. This is the default behavior if nothing
458 // else is specified. This implementation requires storing state
459 // inside `std::random_device`.
461 // _LIBCPP_USING_ARC4_RANDOM
462 // Use arc4random(). This allows obtaining random data even when
463 // using sandboxing mechanisms. On some platforms like Apple, this
464 // is the recommended source of entropy for user-space programs.
465 // When this option is used, the token passed to `std::random_device`'s
466 // constructor *must* be "/dev/urandom" -- anything else is an error.
468 // _LIBCPP_USING_GETENTROPY
470 // When this option is used, the token passed to `std::random_device`'s
471 // constructor *must* be "/dev/urandom" -- anything else is an error.
473 // _LIBCPP_USING_FUCHSIA_CPRNG
474 // Use Fuchsia's zx_cprng_draw() system call, which is specified to
475 // deliver high-quality entropy and cannot fail.
476 // When this option is used, the token passed to `std::random_device`'s
477 // constructor *must* be "/dev/urandom" -- anything else is an error.
479 // _LIBCPP_USING_NACL_RANDOM
480 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
481 // including accesses to the special files under `/dev`. This implementation
482 // uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
483 // When this option is used, the token passed to `std::random_device`'s
484 // constructor *must* be "/dev/urandom" -- anything else is an error.
486 // _LIBCPP_USING_WIN32_RANDOM
487 // Use rand_s(), for use on Windows.
488 // When this option is used, the token passed to `std::random_device`'s
489 // constructor *must* be "/dev/urandom" -- anything else is an error.
490 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
491 defined(__DragonFly__)
492 # define _LIBCPP_USING_ARC4_RANDOM
493 # elif defined(__wasi__) || defined(__EMSCRIPTEN__)
494 # define _LIBCPP_USING_GETENTROPY
495 # elif defined(__Fuchsia__)
496 # define _LIBCPP_USING_FUCHSIA_CPRNG
497 # elif defined(__native_client__)
498 # define _LIBCPP_USING_NACL_RANDOM
499 # elif defined(_LIBCPP_WIN32API)
500 # define _LIBCPP_USING_WIN32_RANDOM
502 # define _LIBCPP_USING_DEV_RANDOM
505 # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
506 # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
508 # define _LIBCPP_NO_CFI
511 # ifndef _LIBCPP_CXX03_LANG
513 # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
514 # define _ALIGNAS_TYPE(x) alignas(x)
515 # define _ALIGNAS(x) alignas(x)
516 # define _LIBCPP_NORETURN [[noreturn]]
517 # define _NOEXCEPT noexcept
518 # define _NOEXCEPT_(x) noexcept(x)
519 # define _LIBCPP_CONSTEXPR constexpr
523 # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
524 # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
525 # define _ALIGNAS(x) __attribute__((__aligned__(x)))
526 # define _LIBCPP_NORETURN __attribute__((__noreturn__))
527 # define _LIBCPP_HAS_NO_NOEXCEPT
528 # define nullptr __nullptr
529 # define _NOEXCEPT throw()
530 # define _NOEXCEPT_(x)
531 # define static_assert(...) _Static_assert(__VA_ARGS__)
532 # define decltype(...) __decltype(__VA_ARGS__)
533 # define _LIBCPP_CONSTEXPR
535 typedef __char16_t char16_t;
536 typedef __char32_t char32_t;
540 # if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
541 # define _LIBCPP_HAS_NO_EXCEPTIONS
544 # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
546 # if defined(_LIBCPP_COMPILER_CLANG_BASED)
548 # if defined(__APPLE__)
549 # if defined(__i386__) || defined(__x86_64__)
550 // use old string layout on x86_64 and i386
551 # elif defined(__arm__)
552 // use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
553 # if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
554 # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
557 # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
561 // Objective-C++ features (opt-in)
562 # if __has_feature(objc_arc)
563 # define _LIBCPP_HAS_OBJC_ARC
566 # if __has_feature(objc_arc_weak)
567 # define _LIBCPP_HAS_OBJC_ARC_WEAK
570 # if __has_extension(blocks)
571 # define _LIBCPP_HAS_EXTENSION_BLOCKS
574 # if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
575 # define _LIBCPP_HAS_BLOCKS_RUNTIME
578 # if !__has_feature(address_sanitizer)
579 # define _LIBCPP_HAS_NO_ASAN
582 // Allow for build-time disabling of unsigned integer sanitization
583 # if __has_attribute(no_sanitize)
584 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
587 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
589 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
591 # elif defined(_LIBCPP_COMPILER_GCC)
593 # if !defined(__SANITIZE_ADDRESS__)
594 # define _LIBCPP_HAS_NO_ASAN
597 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
599 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
601 # endif // _LIBCPP_COMPILER_[CLANG|GCC]
603 # if defined(_LIBCPP_OBJECT_FORMAT_COFF)
606 # define _LIBCPP_CRT_FUNC __declspec(dllimport)
608 # define _LIBCPP_CRT_FUNC
611 # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
612 # define _LIBCPP_DLL_VIS
613 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
614 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
615 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
616 # define _LIBCPP_EXPORTED_FROM_ABI
617 # elif defined(_LIBCPP_BUILDING_LIBRARY)
618 # define _LIBCPP_DLL_VIS __declspec(dllexport)
619 # if defined(__MINGW32__)
620 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
621 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
623 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
624 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
626 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
627 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
629 # define _LIBCPP_DLL_VIS __declspec(dllimport)
630 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
631 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
632 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
633 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
636 # define _LIBCPP_HIDDEN
637 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
638 # define _LIBCPP_TEMPLATE_VIS
639 # define _LIBCPP_TEMPLATE_DATA_VIS
640 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
644 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
645 # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
647 # define _LIBCPP_VISIBILITY(vis)
650 # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
651 # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
652 # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
653 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
654 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
656 // TODO: Make this a proper customization point or remove the option to override it.
657 # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
658 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
661 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
662 // The inline should be removed once PR32114 is resolved
663 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
665 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
668 // GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
669 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
670 # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
672 # define _LIBCPP_TEMPLATE_VIS
675 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
676 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
678 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
681 # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
683 # if __has_attribute(exclude_from_explicit_instantiation)
684 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
686 // Try to approximate the effect of exclude_from_explicit_instantiation
687 // (which is that entities are not assumed to be provided by explicit
688 // template instantiations in the dylib) by always inlining those entities.
689 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
692 // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
694 // 1. The symbol is given hidden visibility, which ensures that users won't start exporting
695 // symbols from their dynamic library by means of using the libc++ headers. This ensures
696 // that those symbols stay private to the dynamic library in which it is defined.
698 // 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures
699 // that no ODR violation can arise from mixing two TUs compiled with different versions
700 // of libc++ where we would have changed the definition of a symbol. If the symbols shared
701 // the same name, the ODR would require that their definitions be token-by-token equivalent,
702 // which basically prevents us from being able to make any change to any function in our
703 // headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at
704 // each release, which lets us change the definition of these symbols at our leisure.
705 // Note that historically, this has been achieved in various ways, including force-inlining
706 // all functions or giving internal linkage to all functions. Both these (previous) solutions
707 // suffer from drawbacks that lead notably to code bloat.
709 // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
710 // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
712 // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
713 // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
714 // name of a virtual function is part of its ABI, since some architectures like arm64e can sign
715 // the virtual function pointer in the vtable based on the mangled name of the function. Since
716 // we use an ABI tag that changes with each released version, the mangled name of the virtual
717 // function would change, which is incorrect. Note that it doesn't make much sense to change
718 // the implementation of a virtual function in an ABI-incompatible way in the first place,
719 // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
721 // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
722 // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
723 // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
724 # ifndef _LIBCPP_NO_ABI_TAG
725 # define _LIBCPP_HIDE_FROM_ABI \
726 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
727 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
729 # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
731 # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
733 // This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
734 // "C" function, as those lack mangling.
735 # define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
737 # ifdef _LIBCPP_BUILDING_LIBRARY
738 # if _LIBCPP_ABI_VERSION > 1
739 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
741 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
744 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
747 // Just so we can migrate to the new macros gradually.
748 # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
750 // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
752 # define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
753 inline namespace _LIBCPP_ABI_NAMESPACE {
754 # define _LIBCPP_END_NAMESPACE_STD }}
757 _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
759 # if _LIBCPP_STD_VER >= 17
760 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
761 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
763 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
764 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
767 # define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
770 # define _VSTD_FS std::__fs::filesystem
772 # if __has_attribute(__enable_if__)
773 # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
776 # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
777 # define _LIBCPP_HAS_NO_INT128
780 # if __has_attribute(__malloc__)
781 # define _LIBCPP_NOALIAS __attribute__((__malloc__))
783 # define _LIBCPP_NOALIAS
786 # if __has_attribute(__using_if_exists__)
787 # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
789 # define _LIBCPP_USING_IF_EXISTS
792 # ifdef _LIBCPP_CXX03_LANG
793 # define _LIBCPP_DECLARE_STRONG_ENUM(x) \
794 struct _LIBCPP_EXPORTED_FROM_ABI x { \
797 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
799 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
800 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
801 _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \
805 # else // _LIBCPP_CXX03_LANG
806 # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
807 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
808 # endif // _LIBCPP_CXX03_LANG
810 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
811 # define _LIBCPP_LOCALE__L_EXTENSIONS 1
815 # define _DECLARE_C99_LDBL_MATH 1
818 // If we are getting operator new from the MSVC CRT, then allocation overloads
819 // for align_val_t were added in 19.12, aka VS 2017 version 15.3.
820 # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
821 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
822 # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
823 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
824 // have it unless the language feature test macro is defined.
825 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
826 # elif defined(__MVS__)
827 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
830 # if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
831 # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
834 // It is not yet possible to use aligned_alloc() on all Apple platforms since
835 // 10.15 was the first version to ship an implementation of aligned_alloc().
836 # if defined(__APPLE__)
837 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
838 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
839 # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
841 # elif defined(__ANDROID__) && __ANDROID_API__ < 28
842 // Android only provides aligned_alloc when targeting API 28 or higher.
843 # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
846 # if defined(__APPLE__) || defined(__FreeBSD__)
847 # define _LIBCPP_HAS_DEFAULTRUNELOCALE
850 # if defined(__APPLE__) || defined(__FreeBSD__)
851 # define _LIBCPP_WCTYPE_IS_MASK
854 # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
855 # define _LIBCPP_HAS_NO_CHAR8_T
858 // Deprecation macros.
860 // Deprecations warnings are always enabled, except when users explicitly opt-out
861 // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
862 # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
863 # if __has_attribute(__deprecated__)
864 # define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
865 # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
866 # elif _LIBCPP_STD_VER >= 14
867 # define _LIBCPP_DEPRECATED [[deprecated]]
868 # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
870 # define _LIBCPP_DEPRECATED
871 # define _LIBCPP_DEPRECATED_(m)
874 # define _LIBCPP_DEPRECATED
875 # define _LIBCPP_DEPRECATED_(m)
878 # if !defined(_LIBCPP_CXX03_LANG)
879 # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
881 # define _LIBCPP_DEPRECATED_IN_CXX11
884 # if _LIBCPP_STD_VER >= 14
885 # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
887 # define _LIBCPP_DEPRECATED_IN_CXX14
890 # if _LIBCPP_STD_VER >= 17
891 # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
893 # define _LIBCPP_DEPRECATED_IN_CXX17
896 # if _LIBCPP_STD_VER >= 20
897 # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
899 # define _LIBCPP_DEPRECATED_IN_CXX20
902 # if _LIBCPP_STD_VER >= 23
903 # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
905 # define _LIBCPP_DEPRECATED_IN_CXX23
908 # if !defined(_LIBCPP_HAS_NO_CHAR8_T)
909 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
911 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T
914 // Macros to enter and leave a state where deprecation warnings are suppressed.
915 # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
916 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
917 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
918 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
919 # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
921 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
922 # define _LIBCPP_SUPPRESS_DEPRECATED_POP
925 # if _LIBCPP_STD_VER <= 11
926 # define _LIBCPP_EXPLICIT_SINCE_CXX14
928 # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
931 # if _LIBCPP_STD_VER >= 23
932 # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
934 # define _LIBCPP_EXPLICIT_SINCE_CXX23
937 # if _LIBCPP_STD_VER >= 14
938 # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
940 # define _LIBCPP_CONSTEXPR_SINCE_CXX14
943 # if _LIBCPP_STD_VER >= 17
944 # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
946 # define _LIBCPP_CONSTEXPR_SINCE_CXX17
949 # if _LIBCPP_STD_VER >= 20
950 # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
952 # define _LIBCPP_CONSTEXPR_SINCE_CXX20
955 # if _LIBCPP_STD_VER >= 23
956 # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
958 # define _LIBCPP_CONSTEXPR_SINCE_CXX23
961 # if __has_cpp_attribute(nodiscard)
962 # define _LIBCPP_NODISCARD [[__nodiscard__]]
964 // We can't use GCC's [[gnu::warn_unused_result]] and
965 // __attribute__((warn_unused_result)), because GCC does not silence them via
967 # define _LIBCPP_NODISCARD
970 // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
971 // specified as such as an extension.
972 # if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
973 # define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
975 # define _LIBCPP_NODISCARD_EXT
978 # if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
979 # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
981 # define _LIBCPP_NODISCARD_AFTER_CXX17
984 # if __has_attribute(__no_destroy__)
985 # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
987 # define _LIBCPP_NO_DESTROY
990 # ifndef _LIBCPP_HAS_NO_ASAN
991 extern "C" _LIBCPP_EXPORTED_FROM_ABI void
992 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
993 # if _LIBCPP_CLANG_VER >= 1600
994 extern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
995 const void*, const void*, const void*, const void*, const void*, const void*);
996 extern "C" _LIBCPP_EXPORTED_FROM_ABI int
997 __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
1001 // Try to find out if RTTI is disabled.
1002 # if !defined(__cpp_rtti) || __cpp_rtti < 199711L
1003 # define _LIBCPP_HAS_NO_RTTI
1006 # ifndef _LIBCPP_WEAK
1007 # define _LIBCPP_WEAK __attribute__((__weak__))
1012 # if !defined(_LIBCPP_HAS_NO_THREADS) && \
1013 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
1014 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
1015 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1017 # if defined(__FreeBSD__) || \
1018 defined(__wasi__) || \
1019 defined(__NetBSD__) || \
1020 defined(__OpenBSD__) || \
1021 defined(__NuttX__) || \
1022 defined(__linux__) || \
1023 defined(__GNU__) || \
1024 defined(__APPLE__) || \
1025 defined(__MVS__) || \
1027 defined(__EMSCRIPTEN__)
1029 # define _LIBCPP_HAS_THREAD_API_PTHREAD
1030 # elif defined(__Fuchsia__)
1031 // TODO(44575): Switch to C11 thread API when possible.
1032 # define _LIBCPP_HAS_THREAD_API_PTHREAD
1033 # elif defined(_LIBCPP_WIN32API)
1034 # define _LIBCPP_HAS_THREAD_API_WIN32
1036 # error "No thread API"
1037 # endif // _LIBCPP_HAS_THREAD_API
1038 # endif // _LIBCPP_HAS_NO_THREADS
1040 # if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1041 # if defined(__ANDROID__) && __ANDROID_API__ >= 30
1042 # define _LIBCPP_HAS_COND_CLOCKWAIT
1043 # elif defined(_LIBCPP_GLIBC_PREREQ)
1044 # if _LIBCPP_GLIBC_PREREQ(2, 30)
1045 # define _LIBCPP_HAS_COND_CLOCKWAIT
1050 # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1051 # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1052 _LIBCPP_HAS_NO_THREADS is not defined.
1055 # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1056 # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1057 _LIBCPP_HAS_NO_THREADS is defined.
1060 # if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
1061 # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1062 _LIBCPP_HAS_NO_THREADS is defined.
1065 # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1066 # define __STDCPP_THREADS__ 1
1069 // The glibc and Bionic implementation of pthreads implements
1070 // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1071 // mutexes have no destroy mechanism.
1073 // This optimization can't be performed on Apple platforms, where
1074 // pthread_mutex_destroy can allow the kernel to release resources.
1075 // See https://llvm.org/D64298 for details.
1077 // TODO(EricWF): Enable this optimization on Bionic after speaking to their
1078 // respective stakeholders.
1080 # if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
1081 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1082 defined(_LIBCPP_HAS_THREAD_API_WIN32)
1084 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1087 // Destroying a condvar is a nop on Windows.
1089 // This optimization can't be performed on Apple platforms, where
1090 // pthread_cond_destroy can allow the kernel to release resources.
1091 // See https://llvm.org/D64298 for details.
1093 // TODO(EricWF): This is potentially true for some pthread implementations
1095 # if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1096 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1099 // Some systems do not provide gets() in their C library, for security reasons.
1100 # if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
1101 # define _LIBCPP_C_HAS_NO_GETS
1104 # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
1105 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1106 # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1109 # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1110 # define _LIBCPP_HAS_C_ATOMIC_IMP
1111 # elif defined(_LIBCPP_COMPILER_GCC)
1112 # define _LIBCPP_HAS_GCC_ATOMIC_IMP
1115 # if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1116 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1117 # define _LIBCPP_HAS_NO_ATOMIC_HEADER
1119 # ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1120 # define _LIBCPP_ATOMIC_FLAG_TYPE bool
1122 # ifdef _LIBCPP_FREESTANDING
1123 # define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1127 # ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1128 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1131 # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
1132 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
1134 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
1137 # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1138 # if defined(__clang__) && __has_attribute(acquire_capability)
1139 // Work around the attribute handling in clang. When both __declspec and
1140 // __attribute__ are present, the processing goes awry preventing the definition
1141 // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1142 // combining the two does work.
1143 # if !defined(_MSC_VER)
1144 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1149 # ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1150 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1152 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1155 # if _LIBCPP_STD_VER >= 20
1156 # define _LIBCPP_CONSTINIT constinit
1157 # elif __has_attribute(__require_constant_initialization__)
1158 # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1160 # define _LIBCPP_CONSTINIT
1163 # if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1164 # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1166 # define _LIBCPP_DIAGNOSE_WARNING(...)
1169 // Use a function like macro to imply that it must be followed by a semicolon
1170 # if __has_cpp_attribute(fallthrough)
1171 # define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1172 # elif __has_attribute(__fallthrough__)
1173 # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1175 # define _LIBCPP_FALLTHROUGH() ((void)0)
1178 # if __has_cpp_attribute(_Clang::__lifetimebound__)
1179 # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1181 # define _LIBCPP_LIFETIMEBOUND
1184 # if __has_attribute(__nodebug__)
1185 # define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1187 # define _LIBCPP_NODEBUG
1190 # if __has_attribute(__standalone_debug__)
1191 # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1193 # define _LIBCPP_STANDALONE_DEBUG
1196 # if __has_attribute(__preferred_name__)
1197 # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1199 # define _LIBCPP_PREFERRED_NAME(x)
1202 # if __has_attribute(__no_sanitize__)
1203 # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1205 # define _LIBCPP_NO_SANITIZE(...)
1208 // We often repeat things just for handling wide characters in the library.
1209 // When wide characters are disabled, it can be useful to have a quick way of
1210 // disabling it without having to resort to #if-#endif, which has a larger
1211 // impact on readability.
1212 # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1213 # define _LIBCPP_IF_WIDE_CHARACTERS(...)
1215 # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1218 # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1219 # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1221 # define _LIBCPP_DECLSPEC_EMPTY_BASES
1224 # if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1225 # define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1226 # define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1227 # define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1228 # define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1229 # define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1230 # endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1232 # if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1233 # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1234 # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1235 # define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1236 # define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1237 # define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1238 # define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1239 # endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1242 # 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()\")")
1243 # 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()\")")
1246 # ifndef _LIBCPP_NO_AUTO_LINK
1247 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1248 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1249 # pragma comment(lib, "c++.lib")
1251 # pragma comment(lib, "libc++.lib")
1253 # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1254 # endif // _LIBCPP_NO_AUTO_LINK
1256 // Configures the fopen close-on-exec mode character, if any. This string will
1257 // be appended to any mode string used by fstream for fopen/fdopen.
1259 // Not all platforms support this, but it helps avoid fd-leaks on platforms that
1261 # if defined(__BIONIC__)
1262 # define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1264 # define _LIBCPP_FOPEN_CLOEXEC_MODE
1267 // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1268 // of functions used in cstdio may not be available for low API levels when
1269 // using 64-bit file offsets on LP32.
1270 # if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1271 # define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1274 # if __has_attribute(__init_priority__)
1275 # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1277 # define _LIBCPP_INIT_PRIORITY_MAX
1280 # if __has_attribute(__format__)
1281 // The attribute uses 1-based indices for ordinary and static member functions.
1282 // The attribute uses 2-based indices for non-static member functions.
1283 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1284 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1286 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1289 # if __has_cpp_attribute(msvc::no_unique_address)
1290 // MSVC implements [[no_unique_address]] as a silent no-op currently.
1291 // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1292 // However, MSVC implements [[msvc::no_unique_address]] which does what
1293 // [[no_unique_address]] is supposed to do, in general.
1295 // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1296 // [[msvc::no_unique_address]] though. If/when it does implement
1297 // [[msvc::no_unique_address]], this should be preferred though.
1298 # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1299 # elif __has_cpp_attribute(no_unique_address)
1300 # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1302 # define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1303 // Note that this can be replaced by #error as soon as clang-cl
1304 // implements msvc::no_unique_address, since there should be no C++20
1305 // compiler that doesn't support one of the two attributes at that point.
1306 // We generally don't want to use this macro outside of C++20-only code,
1307 // because using it conditionally in one language version only would make
1308 // the ABI inconsistent.
1311 # ifdef _LIBCPP_COMPILER_CLANG_BASED
1312 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1313 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1314 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1315 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1316 # elif defined(_LIBCPP_COMPILER_GCC)
1317 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1318 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1319 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1320 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1322 # define _LIBCPP_DIAGNOSTIC_PUSH
1323 # define _LIBCPP_DIAGNOSTIC_POP
1324 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1325 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1328 # if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
1329 # define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
1330 # define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
1332 # define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */
1333 # define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
1336 # if __has_attribute(__packed__)
1337 # define _LIBCPP_PACKED __attribute__((__packed__))
1339 # define _LIBCPP_PACKED
1342 // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1343 // functions is gradually being added to existing C libraries. The conditions
1344 // below check for known C library versions and conditions under which these
1345 // functions are declared by the C library.
1346 # define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1347 // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1348 // __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1349 // the latter depends on internal GNU libc details that are not appropriate
1350 // to depend on here, so any declarations present when __cpp_char8_t is not
1351 // defined are ignored.
1352 # if defined(_LIBCPP_GLIBC_PREREQ)
1353 # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1354 # undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1358 // There are a handful of public standard library types that are intended to
1359 // support CTAD but don't need any explicit deduction guides to do so. This
1360 // macro is used to mark them as such, which suppresses the
1361 // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1362 // with these classes.
1363 # if _LIBCPP_STD_VER >= 17
1364 # ifdef _LIBCPP_COMPILER_CLANG_BASED
1365 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1366 template <class... _Tag> \
1367 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1369 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
1370 template <class... _Tag> \
1371 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1374 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1377 // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1378 // compiler intrinsics in the Objective-C++ mode.
1380 # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1383 # define _PSTL_PRAGMA(x) _Pragma(#x)
1385 // Enable SIMD for compilers that support OpenMP 4.0
1386 # if (defined(_OPENMP) && _OPENMP >= 201307)
1388 # define _PSTL_UDR_PRESENT
1389 # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1390 # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1391 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1392 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1393 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1394 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1396 // Declaration of reduction functor, where
1397 // NAME - the name of the functor
1398 // OP - type of the callable object with the reduction operation
1399 // omp_in - refers to the local partial result
1400 // omp_out - refers to the final value of the combiner operator
1401 // omp_priv - refers to the private copy of the initial value
1402 // omp_orig - refers to the original variable to be reduced
1403 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
1404 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1406 # elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1408 # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1409 # define _PSTL_PRAGMA_DECLARE_SIMD
1410 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1411 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1412 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1413 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1414 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1416 # else // (defined(_OPENMP) && _OPENMP >= 201307)
1418 # define _PSTL_PRAGMA_SIMD
1419 # define _PSTL_PRAGMA_DECLARE_SIMD
1420 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1421 # define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1422 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1423 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1424 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1426 # endif // (defined(_OPENMP) && _OPENMP >= 201307)
1428 # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1430 #endif // __cplusplus
1432 #endif // _LIBCPP___CONFIG