1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___CONFIG
11#define _LIBCPP___CONFIG
12
13#include <__config_site>
14
15#if defined(_MSC_VER) && !defined(__clang__)
16#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#    define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
18#  endif
19#endif
20
21#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
22#  pragma GCC system_header
23#endif
24
25#ifdef __cplusplus
26
27#  define _LIBCPP_VERSION 15000
28
29#  if __STDC_HOSTED__ == 0
30#    define _LIBCPP_FREESTANDING
31#  endif
32
33#  ifndef _LIBCPP_STD_VER
34#    if __cplusplus <= 201103L
35#      define _LIBCPP_STD_VER 11
36#    elif __cplusplus <= 201402L
37#      define _LIBCPP_STD_VER 14
38#    elif __cplusplus <= 201703L
39#      define _LIBCPP_STD_VER 17
40#    elif __cplusplus <= 202002L
41#      define _LIBCPP_STD_VER 20
42#    else
43#      define _LIBCPP_STD_VER 22 // current year, or date of c++2b ratification
44#    endif
45#  endif // _LIBCPP_STD_VER
46
47#  if defined(__ELF__)
48#    define _LIBCPP_OBJECT_FORMAT_ELF 1
49#  elif defined(__MACH__)
50#    define _LIBCPP_OBJECT_FORMAT_MACHO 1
51#  elif defined(_WIN32)
52#    define _LIBCPP_OBJECT_FORMAT_COFF 1
53#  elif defined(__wasm__)
54#    define _LIBCPP_OBJECT_FORMAT_WASM 1
55#  elif defined(_AIX)
56#    define _LIBCPP_OBJECT_FORMAT_XCOFF 1
57#  else
58// ... add new file formats here ...
59#  endif
60
61#  if _LIBCPP_ABI_VERSION >= 2
62// Change short string representation so that string data starts at offset 0,
63// improving its alignment in some cases.
64#    define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
65// Fix deque iterator type in order to support incomplete types.
66#    define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
67// Fix undefined behavior in how std::list stores its linked nodes.
68#    define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
69// Fix undefined behavior in  how __tree stores its end and parent nodes.
70#    define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
71// Fix undefined behavior in how __hash_table stores its pointer types.
72#    define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
73#    define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
74#    define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
75// Define a key function for `bad_function_call` in the library, to centralize
76// its vtable and typeinfo to libc++ rather than having all other libraries
77// using that class define their own copies.
78#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
79// Override the default return value of exception::what() for
80// bad_function_call::what() with a string that is specific to
81// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
82// because it changes the vtable layout of bad_function_call.
83#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
84// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
85#    define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
86// In C++20 and later, don't derive std::plus from std::binary_function,
87// nor std::negate from std::unary_function.
88#    define _LIBCPP_ABI_NO_BINDER_BASES
89// Give reverse_iterator<T> one data member of type T, not two.
90// Also, in C++17 and later, don't derive iterator types from std::iterator.
91#    define _LIBCPP_ABI_NO_ITERATOR_BASES
92// Use the smallest possible integer type to represent the index of the variant.
93// Previously libc++ used "unsigned int" exclusively.
94#    define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
95// Unstable attempt to provide a more optimized std::function
96#    define _LIBCPP_ABI_OPTIMIZED_FUNCTION
97// All the regex constants must be distinct and nonzero.
98#    define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
99// Use raw pointers, not wrapped ones, for std::span's iterator type.
100#    define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
101// Re-worked external template instantiations for std::string with a focus on
102// performance and fast-path inlining.
103#    define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
104// Enable clang::trivial_abi on std::unique_ptr.
105#    define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
106// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
107#    define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
108// std::random_device holds some state when it uses an implementation that gets
109// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
110// implementation to another one on a platform that has already shipped
111// std::random_device, one needs to retain the same object layout to remain ABI
112// compatible. This switch removes these workarounds for platforms that don't care
113// about ABI compatibility.
114#    define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
115// Don't export the legacy __basic_string_common class and its methods from the built library.
116#    define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
117// Don't export the legacy __vector_base_common class and its methods from the built library.
118#    define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
119// According to the Standard, `bitset::operator[] const` returns bool
120#    define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
121// Remove the base 10 implementation of std::to_chars from the dylib.
122// The implementation moved to the header, but we still export the symbols from
123// the dylib for backwards compatibility.
124#    define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
125#  elif _LIBCPP_ABI_VERSION == 1
126#    if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
127// Enable compiling copies of now inline methods into the dylib to support
128// applications compiled against older libraries. This is unnecessary with
129// COFF dllexport semantics, since dllexport forces a non-inline definition
130// of inline functions to be emitted anyway. Our own non-inline copy would
131// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
132// the linker will take issue with the symbols in the shared object if the
133// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
134// so disable it.
135#      define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
136#    endif
137// Feature macros for disabling pre ABI v1 features. All of these options
138// are deprecated.
139#    if defined(__FreeBSD__)
140#      define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
141#    endif
142#  endif
143
144#  if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
145// Enable additional explicit instantiations of iostreams components. This
146// reduces the number of weak definitions generated in programs that use
147// iostreams by providing a single strong definition in the shared library.
148#    define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
149
150// Define a key function for `bad_function_call` in the library, to centralize
151// its vtable and typeinfo to libc++ rather than having all other libraries
152// using that class define their own copies.
153#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
154#  endif
155
156#  define _LIBCPP_TOSTRING2(x) #  x
157#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
158
159#  if __cplusplus < 201103L
160#    define _LIBCPP_CXX03_LANG
161#  endif
162
163#  ifndef __has_attribute
164#    define __has_attribute(__x) 0
165#  endif
166
167#  ifndef __has_builtin
168#    define __has_builtin(__x) 0
169#  endif
170
171#  ifndef __has_extension
172#    define __has_extension(__x) 0
173#  endif
174
175#  ifndef __has_feature
176#    define __has_feature(__x) 0
177#  endif
178
179#  ifndef __has_cpp_attribute
180#    define __has_cpp_attribute(__x) 0
181#  endif
182
183// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
184// the compiler and '1' otherwise.
185#  ifndef __is_identifier
186#    define __is_identifier(__x) 1
187#  endif
188
189#  ifndef __has_declspec_attribute
190#    define __has_declspec_attribute(__x) 0
191#  endif
192
193#  define __has_keyword(__x) !(__is_identifier(__x))
194
195#  ifndef __has_include
196#    define __has_include(...) 0
197#  endif
198
199#  if defined(__apple_build_version__)
200#    define _LIBCPP_COMPILER_CLANG_BASED
201#    define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
202#  elif defined(__clang__)
203#    define _LIBCPP_COMPILER_CLANG_BASED
204#    define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
205#  elif defined(__GNUC__)
206#    define _LIBCPP_COMPILER_GCC
207#  elif defined(_MSC_VER)
208#    define _LIBCPP_COMPILER_MSVC
209#  elif defined(__IBMCPP__)
210#    define _LIBCPP_COMPILER_IBM
211#  endif
212
213#  if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
214#    error "libc++ does not support using GCC with C++03. Please enable C++11"
215#  endif
216
217// FIXME: ABI detection should be done via compiler builtin macros. This
218// is just a placeholder until Clang implements such macros. For now assume
219// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
220// and allow the user to explicitly specify the ABI to handle cases where this
221// heuristic falls short.
222#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
223#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
224#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
225#    define _LIBCPP_ABI_ITANIUM
226#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
227#    define _LIBCPP_ABI_MICROSOFT
228#  else
229#    if defined(_WIN32) && defined(_MSC_VER)
230#      define _LIBCPP_ABI_MICROSOFT
231#    else
232#      define _LIBCPP_ABI_ITANIUM
233#    endif
234#  endif
235
236#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
237#    define _LIBCPP_ABI_VCRUNTIME
238#  endif
239
240// Need to detect which libc we're using if we're on Linux.
241#  if defined(__linux__)
242#    include <features.h>
243#    if defined(__GLIBC_PREREQ)
244#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
245#    else
246#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
247#    endif // defined(__GLIBC_PREREQ)
248#  endif   // defined(__linux__)
249
250#  if defined(__MVS__)
251#    include <features.h> // for __NATIVE_ASCII_F
252#  endif
253
254#  ifdef __LITTLE_ENDIAN__
255#    if __LITTLE_ENDIAN__
256#      define _LIBCPP_LITTLE_ENDIAN
257#    endif // __LITTLE_ENDIAN__
258#  endif   // __LITTLE_ENDIAN__
259
260#  ifdef __BIG_ENDIAN__
261#    if __BIG_ENDIAN__
262#      define _LIBCPP_BIG_ENDIAN
263#    endif // __BIG_ENDIAN__
264#  endif   // __BIG_ENDIAN__
265
266#  ifdef __BYTE_ORDER__
267#    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
268#      define _LIBCPP_LITTLE_ENDIAN
269#    elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
270#      define _LIBCPP_BIG_ENDIAN
271#    endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
272#  endif   // __BYTE_ORDER__
273
274#  ifdef __FreeBSD__
275#    include <sys/endian.h>
276#    include <osreldate.h>
277#    if _BYTE_ORDER == _LITTLE_ENDIAN
278#      define _LIBCPP_LITTLE_ENDIAN
279#    else // _BYTE_ORDER == _LITTLE_ENDIAN
280#      define _LIBCPP_BIG_ENDIAN
281#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
282#  endif   // __FreeBSD__
283
284#  if defined(__NetBSD__) || defined(__OpenBSD__)
285#    include <sys/endian.h>
286#    if _BYTE_ORDER == _LITTLE_ENDIAN
287#      define _LIBCPP_LITTLE_ENDIAN
288#    else // _BYTE_ORDER == _LITTLE_ENDIAN
289#      define _LIBCPP_BIG_ENDIAN
290#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
291#  endif   // defined(__NetBSD__) || defined(__OpenBSD__)
292
293#  if defined(_WIN32)
294#    define _LIBCPP_WIN32API
295#    define _LIBCPP_LITTLE_ENDIAN
296#    define _LIBCPP_SHORT_WCHAR 1
297// Both MinGW and native MSVC provide a "MSVC"-like environment
298#    define _LIBCPP_MSVCRT_LIKE
299// If mingw not explicitly detected, assume using MS C runtime only if
300// a MS compatibility version is specified.
301#    if defined(_MSC_VER) && !defined(__MINGW32__)
302#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
303#    endif
304#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
305#      define _LIBCPP_HAS_BITSCAN64
306#    endif
307#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
308#  endif // defined(_WIN32)
309
310#  ifdef __sun__
311#    include <sys/isa_defs.h>
312#    ifdef _LITTLE_ENDIAN
313#      define _LIBCPP_LITTLE_ENDIAN
314#    else
315#      define _LIBCPP_BIG_ENDIAN
316#    endif
317#  endif // __sun__
318
319#  if defined(_AIX) && !defined(__64BIT__)
320// The size of wchar is 2 byte on 32-bit mode on AIX.
321#    define _LIBCPP_SHORT_WCHAR 1
322#  endif
323
324// Libc++ supports various implementations of std::random_device.
325//
326// _LIBCPP_USING_DEV_RANDOM
327//      Read entropy from the given file, by default `/dev/urandom`.
328//      If a token is provided, it is assumed to be the path to a file
329//      to read entropy from. This is the default behavior if nothing
330//      else is specified. This implementation requires storing state
331//      inside `std::random_device`.
332//
333// _LIBCPP_USING_ARC4_RANDOM
334//      Use arc4random(). This allows obtaining random data even when
335//      using sandboxing mechanisms. On some platforms like Apple, this
336//      is the recommended source of entropy for user-space programs.
337//      When this option is used, the token passed to `std::random_device`'s
338//      constructor *must* be "/dev/urandom" -- anything else is an error.
339//
340// _LIBCPP_USING_GETENTROPY
341//      Use getentropy().
342//      When this option is used, the token passed to `std::random_device`'s
343//      constructor *must* be "/dev/urandom" -- anything else is an error.
344//
345// _LIBCPP_USING_FUCHSIA_CPRNG
346//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
347//      deliver high-quality entropy and cannot fail.
348//      When this option is used, the token passed to `std::random_device`'s
349//      constructor *must* be "/dev/urandom" -- anything else is an error.
350//
351// _LIBCPP_USING_NACL_RANDOM
352//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
353//      including accesses to the special files under `/dev`. This implementation
354//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
355//      When this option is used, the token passed to `std::random_device`'s
356//      constructor *must* be "/dev/urandom" -- anything else is an error.
357//
358// _LIBCPP_USING_WIN32_RANDOM
359//      Use rand_s(), for use on Windows.
360//      When this option is used, the token passed to `std::random_device`'s
361//      constructor *must* be "/dev/urandom" -- anything else is an error.
362#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
363      defined(__DragonFly__) || defined(__sun__)
364#    define _LIBCPP_USING_ARC4_RANDOM
365#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
366#    define _LIBCPP_USING_GETENTROPY
367#  elif defined(__Fuchsia__)
368#    define _LIBCPP_USING_FUCHSIA_CPRNG
369#  elif defined(__native_client__)
370#    define _LIBCPP_USING_NACL_RANDOM
371#  elif defined(_LIBCPP_WIN32API)
372#    define _LIBCPP_USING_WIN32_RANDOM
373#  else
374#    define _LIBCPP_USING_DEV_RANDOM
375#  endif
376
377#  if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
378#    include <endian.h>
379#    if __BYTE_ORDER == __LITTLE_ENDIAN
380#      define _LIBCPP_LITTLE_ENDIAN
381#    elif __BYTE_ORDER == __BIG_ENDIAN
382#      define _LIBCPP_BIG_ENDIAN
383#    else // __BYTE_ORDER == __BIG_ENDIAN
384#      error unable to determine endian
385#    endif
386#  endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
387
388#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
389#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
390#  else
391#    define _LIBCPP_NO_CFI
392#  endif
393
394#  ifndef _LIBCPP_CXX03_LANG
395#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
396#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
397#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
398#  else
399#    error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang"
400#  endif
401
402#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
403
404#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
405
406#    if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
407#      define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
408#    endif
409
410#    if __has_feature(cxx_alignas)
411#      define _ALIGNAS_TYPE(x) alignas(x)
412#      define _ALIGNAS(x) alignas(x)
413#    else
414#      define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
415#      define _ALIGNAS(x) __attribute__((__aligned__(x)))
416#    endif
417
418#    if __cplusplus < 201103L
419typedef __char16_t char16_t;
420typedef __char32_t char32_t;
421#    endif
422
423#    if !__has_feature(cxx_exceptions)
424#      define _LIBCPP_NO_EXCEPTIONS
425#    endif
426
427#    if __has_feature(cxx_attributes)
428#      define _LIBCPP_NORETURN [[noreturn]]
429#    else
430#      define _LIBCPP_NORETURN __attribute__((noreturn))
431#    endif
432
433#    ifdef _LIBCPP_CXX03_LANG
434#      define nullptr __nullptr
435#    endif
436
437// Objective-C++ features (opt-in)
438#    if __has_feature(objc_arc)
439#      define _LIBCPP_HAS_OBJC_ARC
440#    endif
441
442#    if __has_feature(objc_arc_weak)
443#      define _LIBCPP_HAS_OBJC_ARC_WEAK
444#    endif
445
446#    if __has_extension(blocks)
447#      define _LIBCPP_HAS_EXTENSION_BLOCKS
448#    endif
449
450#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
451#      define _LIBCPP_HAS_BLOCKS_RUNTIME
452#    endif
453
454#    if !(__has_feature(cxx_noexcept))
455#      define _LIBCPP_HAS_NO_NOEXCEPT
456#    endif
457
458#    if !__has_feature(address_sanitizer)
459#      define _LIBCPP_HAS_NO_ASAN
460#    endif
461
462// Allow for build-time disabling of unsigned integer sanitization
463#    if __has_attribute(no_sanitize)
464#      define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
465#    endif
466
467#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
468
469#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
470
471#  elif defined(_LIBCPP_COMPILER_GCC)
472
473#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
474#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
475
476#    define _LIBCPP_NORETURN __attribute__((noreturn))
477
478#    if !defined(__EXCEPTIONS)
479#      define _LIBCPP_NO_EXCEPTIONS
480#    endif
481
482#    if !defined(__SANITIZE_ADDRESS__)
483#      define _LIBCPP_HAS_NO_ASAN
484#    endif
485
486#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
487
488#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
489
490#  elif defined(_LIBCPP_COMPILER_MSVC)
491
492#    define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
493
494#    if _MSC_VER < 1900
495#      error "MSVC versions prior to Visual Studio 2015 are not supported"
496#    endif
497
498#    define __alignof__ __alignof
499#    define _LIBCPP_NORETURN __declspec(noreturn)
500#    define _ALIGNAS(x) __declspec(align(x))
501#    define _ALIGNAS_TYPE(x) alignas(x)
502
503#    define _LIBCPP_WEAK
504
505#    define _LIBCPP_HAS_NO_ASAN
506
507#    define _LIBCPP_ALWAYS_INLINE __forceinline
508
509#    define _LIBCPP_HAS_NO_VECTOR_EXTENSION
510
511#    define _LIBCPP_DISABLE_EXTENSION_WARNING
512
513#  elif defined(_LIBCPP_COMPILER_IBM)
514
515#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
516#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
517#    define _ATTRIBUTE(x) __attribute__((x))
518#    define _LIBCPP_NORETURN __attribute__((noreturn))
519
520#    define _LIBCPP_HAS_NO_UNICODE_CHARS
521
522#    if defined(_AIX)
523#      define __MULTILOCALE_API
524#    endif
525
526#    define _LIBCPP_HAS_NO_ASAN
527
528#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
529
530#    define _LIBCPP_HAS_NO_VECTOR_EXTENSION
531
532#    define _LIBCPP_DISABLE_EXTENSION_WARNING
533
534#  endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
535
536#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
537
538#    ifdef _DLL
539#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
540#    else
541#      define _LIBCPP_CRT_FUNC
542#    endif
543
544#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
545#      define _LIBCPP_DLL_VIS
546#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
547#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
548#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
549#      define _LIBCPP_EXPORTED_FROM_ABI
550#    elif defined(_LIBCPP_BUILDING_LIBRARY)
551#      define _LIBCPP_DLL_VIS __declspec(dllexport)
552#      if defined(__MINGW32__)
553#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
554#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
555#      else
556#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
557#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
558#      endif
559#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
560#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
561#    else
562#      define _LIBCPP_DLL_VIS __declspec(dllimport)
563#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
564#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
565#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
566#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
567#    endif
568
569#    define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
570#    define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
571#    define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
572#    define _LIBCPP_HIDDEN
573#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
574#    define _LIBCPP_TEMPLATE_VIS
575#    define _LIBCPP_TEMPLATE_DATA_VIS
576#    define _LIBCPP_ENUM_VIS
577
578#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
579
580#  ifndef _LIBCPP_HIDDEN
581#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
582#      define _LIBCPP_HIDDEN __attribute__((__visibility__("hidden")))
583#    else
584#      define _LIBCPP_HIDDEN
585#    endif
586#  endif
587
588#  ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
589#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
590// The inline should be removed once PR32114 is resolved
591#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
592#    else
593#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
594#    endif
595#  endif
596
597#  ifndef _LIBCPP_FUNC_VIS
598#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
599#      define _LIBCPP_FUNC_VIS __attribute__((__visibility__("default")))
600#    else
601#      define _LIBCPP_FUNC_VIS
602#    endif
603#  endif
604
605#  ifndef _LIBCPP_TYPE_VIS
606#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
607#      define _LIBCPP_TYPE_VIS __attribute__((__visibility__("default")))
608#    else
609#      define _LIBCPP_TYPE_VIS
610#    endif
611#  endif
612
613#  ifndef _LIBCPP_TEMPLATE_VIS
614#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
615#      if __has_attribute(__type_visibility__)
616#        define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default")))
617#      else
618#        define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
619#      endif
620#    else
621#      define _LIBCPP_TEMPLATE_VIS
622#    endif
623#  endif
624
625#  ifndef _LIBCPP_TEMPLATE_DATA_VIS
626#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
627#      define _LIBCPP_TEMPLATE_DATA_VIS __attribute__((__visibility__("default")))
628#    else
629#      define _LIBCPP_TEMPLATE_DATA_VIS
630#    endif
631#  endif
632
633#  ifndef _LIBCPP_EXPORTED_FROM_ABI
634#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
635#      define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
636#    else
637#      define _LIBCPP_EXPORTED_FROM_ABI
638#    endif
639#  endif
640
641#  ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
642#    define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
643#  endif
644
645#  ifndef _LIBCPP_EXCEPTION_ABI
646#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
647#      define _LIBCPP_EXCEPTION_ABI __attribute__((__visibility__("default")))
648#    else
649#      define _LIBCPP_EXCEPTION_ABI
650#    endif
651#  endif
652
653#  ifndef _LIBCPP_ENUM_VIS
654#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
655#      define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default")))
656#    else
657#      define _LIBCPP_ENUM_VIS
658#    endif
659#  endif
660
661#  ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
662#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
663#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__((__visibility__("default")))
664#    else
665#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
666#    endif
667#  endif
668
669#  ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
670#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
671#  endif
672
673#  if __has_attribute(internal_linkage)
674#    define _LIBCPP_INTERNAL_LINKAGE __attribute__((internal_linkage))
675#  else
676#    define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
677#  endif
678
679#  if __has_attribute(exclude_from_explicit_instantiation)
680#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
681#  else
682// Try to approximate the effect of exclude_from_explicit_instantiation
683// (which is that entities are not assumed to be provided by explicit
684// template instantiations in the dylib) by always inlining those entities.
685#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
686#  endif
687
688#  ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
689#    ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
690#      define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
691#    else
692#      define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
693#    endif
694#  endif
695
696#  ifndef _LIBCPP_HIDE_FROM_ABI
697#    if _LIBCPP_HIDE_FROM_ABI_PER_TU
698#      define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
699#    else
700#      define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
701#    endif
702#  endif
703
704#  ifdef _LIBCPP_BUILDING_LIBRARY
705#    if _LIBCPP_ABI_VERSION > 1
706#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
707#    else
708#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
709#    endif
710#  else
711#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
712#  endif
713
714// Just so we can migrate to the new macros gradually.
715#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
716
717// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
718// clang-format off
719#  define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
720#  define _LIBCPP_END_NAMESPACE_STD }}
721#  define _VSTD std
722
723_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
724
725#  if _LIBCPP_STD_VER > 14
726#    define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM                                                                         \
727       _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
728#  else
729#    define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM                                                                         \
730      _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
731#  endif
732
733#  define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
734// clang-format on
735
736#  define _VSTD_FS std::__fs::filesystem
737
738#  if __has_attribute(__enable_if__)
739#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
740#  endif
741
742#  ifndef _LIBCPP_HAS_NO_NOEXCEPT
743#    define _NOEXCEPT noexcept
744#    define _NOEXCEPT_(x) noexcept(x)
745#  else
746#    define _NOEXCEPT throw()
747#    define _NOEXCEPT_(x)
748#  endif
749
750#  ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
751    typedef unsigned short char16_t;
752typedef unsigned int char32_t;
753#  endif
754
755#  ifndef __SIZEOF_INT128__
756#    define _LIBCPP_HAS_NO_INT128
757#  endif
758
759#  ifdef _LIBCPP_CXX03_LANG
760#    define static_assert(...) _Static_assert(__VA_ARGS__)
761#    define decltype(...) __decltype(__VA_ARGS__)
762#  endif // _LIBCPP_CXX03_LANG
763
764#  ifdef _LIBCPP_CXX03_LANG
765#    define _LIBCPP_CONSTEXPR
766#  else
767#    define _LIBCPP_CONSTEXPR constexpr
768#  endif
769
770#  ifndef __cpp_consteval
771#    define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
772#  else
773#    define _LIBCPP_CONSTEVAL consteval
774#  endif
775
776#  ifdef __GNUC__
777#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
778#  else
779#    define _LIBCPP_NOALIAS
780#  endif
781
782#  if __has_attribute(using_if_exists)
783#    define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
784#  else
785#    define _LIBCPP_USING_IF_EXISTS
786#  endif
787
788#  ifdef _LIBCPP_CXX03_LANG
789#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
790      struct _LIBCPP_TYPE_VIS x {                                                                                      \
791        enum __lx
792// clang-format off
793#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
794      __lx __v_;                                                                                                       \
795      _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {}                                                             \
796      _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                  \
797      _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; }                                                  \
798      };
799// clang-format on
800
801#  else // _LIBCPP_CXX03_LANG
802#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
803#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
804#  endif // _LIBCPP_CXX03_LANG
805
806#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) ||                \
807      defined(__NetBSD__)
808#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
809#  endif
810
811#  ifdef __FreeBSD__
812#    define _DECLARE_C99_LDBL_MATH 1
813#  endif
814
815// If we are getting operator new from the MSVC CRT, then allocation overloads
816// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
817#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
818#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
819#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
820// We're deferring to Microsoft's STL to provide aligned new et al. We don't
821// have it unless the language feature test macro is defined.
822#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
823#  elif defined(__MVS__)
824#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
825#  endif
826
827#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
828#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
829#  endif
830
831#  if defined(__APPLE__) || defined(__FreeBSD__)
832#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
833#  endif
834
835#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
836#    define _LIBCPP_WCTYPE_IS_MASK
837#  endif
838
839#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
840#    define _LIBCPP_HAS_NO_CHAR8_T
841#  endif
842
843// Deprecation macros.
844//
845// Deprecations warnings are always enabled, except when users explicitly opt-out
846// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
847#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
848#    if __has_attribute(deprecated)
849#      define _LIBCPP_DEPRECATED __attribute__((deprecated))
850#    elif _LIBCPP_STD_VER > 11
851#      define _LIBCPP_DEPRECATED [[deprecated]]
852#    else
853#      define _LIBCPP_DEPRECATED
854#    endif
855#  else
856#    define _LIBCPP_DEPRECATED
857#  endif
858
859#  if !defined(_LIBCPP_CXX03_LANG)
860#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
861#  else
862#    define _LIBCPP_DEPRECATED_IN_CXX11
863#  endif
864
865#  if _LIBCPP_STD_VER > 11
866#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
867#  else
868#    define _LIBCPP_DEPRECATED_IN_CXX14
869#  endif
870
871#  if _LIBCPP_STD_VER > 14
872#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
873#  else
874#    define _LIBCPP_DEPRECATED_IN_CXX17
875#  endif
876
877#  if _LIBCPP_STD_VER > 17
878#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
879#  else
880#    define _LIBCPP_DEPRECATED_IN_CXX20
881#  endif
882
883#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
884#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
885#  else
886#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
887#  endif
888
889// Macros to enter and leave a state where deprecation warnings are suppressed.
890#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
891#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
892      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
893          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
894#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
895#  else
896#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
897#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
898#  endif
899
900#  if _LIBCPP_STD_VER <= 11
901#    define _LIBCPP_EXPLICIT_AFTER_CXX11
902#  else
903#    define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
904#  endif
905
906#  if _LIBCPP_STD_VER > 11
907#    define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
908#  else
909#    define _LIBCPP_CONSTEXPR_AFTER_CXX11
910#  endif
911
912#  if _LIBCPP_STD_VER > 14
913#    define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
914#  else
915#    define _LIBCPP_CONSTEXPR_AFTER_CXX14
916#  endif
917
918#  if _LIBCPP_STD_VER > 17
919#    define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
920#  else
921#    define _LIBCPP_CONSTEXPR_AFTER_CXX17
922#  endif
923
924#  if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
925#    define _LIBCPP_NODISCARD [[nodiscard]]
926#  elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
927#    define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
928#  else
929// We can't use GCC's [[gnu::warn_unused_result]] and
930// __attribute__((warn_unused_result)), because GCC does not silence them via
931// (void) cast.
932#    define _LIBCPP_NODISCARD
933#  endif
934
935// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
936// specified as such as an extension.
937#  if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
938#    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
939#  else
940#    define _LIBCPP_NODISCARD_EXT
941#  endif
942
943#  if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
944#    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
945#  else
946#    define _LIBCPP_NODISCARD_AFTER_CXX17
947#  endif
948
949#  if __has_attribute(no_destroy)
950#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
951#  else
952#    define _LIBCPP_NO_DESTROY
953#  endif
954
955#  ifndef _LIBCPP_HAS_NO_ASAN
956extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(const void*, const void*, const void*,
957                                                                           const void*);
958#  endif
959
960// Try to find out if RTTI is disabled.
961#  if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
962#    define _LIBCPP_NO_RTTI
963#  elif defined(__GNUC__) && !defined(__GXX_RTTI)
964#    define _LIBCPP_NO_RTTI
965#  elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
966#    define _LIBCPP_NO_RTTI
967#  endif
968
969#  ifndef _LIBCPP_WEAK
970#    define _LIBCPP_WEAK __attribute__((__weak__))
971#  endif
972
973// Thread API
974// clang-format off
975#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
976      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
977      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
978      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
979
980#    if defined(__FreeBSD__) ||                                                                                        \
981        defined(__wasi__) ||                                                                                           \
982        defined(__NetBSD__) ||                                                                                         \
983        defined(__OpenBSD__) ||                                                                                        \
984        defined(__NuttX__) ||                                                                                          \
985        defined(__linux__) ||                                                                                          \
986        defined(__GNU__) ||                                                                                            \
987        defined(__APPLE__) ||                                                                                          \
988        defined(__sun__) ||                                                                                            \
989        defined(__MVS__) ||                                                                                            \
990        defined(_AIX) ||                                                                                               \
991        defined(__EMSCRIPTEN__)
992// clang-format on
993#      define _LIBCPP_HAS_THREAD_API_PTHREAD
994#    elif defined(__Fuchsia__)
995// TODO(44575): Switch to C11 thread API when possible.
996#      define _LIBCPP_HAS_THREAD_API_PTHREAD
997#    elif defined(_LIBCPP_WIN32API)
998#      define _LIBCPP_HAS_THREAD_API_WIN32
999#    else
1000#      error "No thread API"
1001#    endif // _LIBCPP_HAS_THREAD_API
1002#  endif   // _LIBCPP_HAS_NO_THREADS
1003
1004#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1005#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
1006#      define _LIBCPP_HAS_COND_CLOCKWAIT
1007#    elif defined(_LIBCPP_GLIBC_PREREQ)
1008#      if _LIBCPP_GLIBC_PREREQ(2, 30)
1009#        define _LIBCPP_HAS_COND_CLOCKWAIT
1010#      endif
1011#    endif
1012#  endif
1013
1014#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1015#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1016       _LIBCPP_HAS_NO_THREADS is not defined.
1017#  endif
1018
1019#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1020#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1021       _LIBCPP_HAS_NO_THREADS is defined.
1022#  endif
1023
1024#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
1025#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1026       _LIBCPP_HAS_NO_THREADS is defined.
1027#  endif
1028
1029#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1030#    define __STDCPP_THREADS__ 1
1031#  endif
1032
1033// The glibc and Bionic implementation of pthreads implements
1034// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1035// mutexes have no destroy mechanism.
1036//
1037// This optimization can't be performed on Apple platforms, where
1038// pthread_mutex_destroy can allow the kernel to release resources.
1039// See https://llvm.org/D64298 for details.
1040//
1041// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1042//               respective stakeholders.
1043// clang-format off
1044#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
1045      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
1046       defined(_LIBCPP_HAS_THREAD_API_WIN32)
1047// clang-format on
1048#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1049#  endif
1050
1051// Destroying a condvar is a nop on Windows.
1052//
1053// This optimization can't be performed on Apple platforms, where
1054// pthread_cond_destroy can allow the kernel to release resources.
1055// See https://llvm.org/D64298 for details.
1056//
1057// TODO(EricWF): This is potentially true for some pthread implementations
1058// as well.
1059#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1060#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1061#  endif
1062
1063// Some systems do not provide gets() in their C library, for security reasons.
1064#  if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
1065#    define _LIBCPP_C_HAS_NO_GETS
1066#  endif
1067
1068#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
1069      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1070#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1071#  endif
1072
1073#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1074#    define _LIBCPP_HAS_C_ATOMIC_IMP
1075#  elif defined(_LIBCPP_COMPILER_GCC)
1076#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
1077#  endif
1078
1079#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
1080      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1081#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
1082#  else
1083#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1084#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
1085#    endif
1086#    ifdef _LIBCPP_FREESTANDING
1087#      define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1088#    endif
1089#  endif
1090
1091#  ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1092#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1093#  endif
1094
1095#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1096#    if defined(__clang__) && __has_attribute(acquire_capability)
1097// Work around the attribute handling in clang.  When both __declspec and
1098// __attribute__ are present, the processing goes awry preventing the definition
1099// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1100// combining the two does work.
1101#      if !defined(_MSC_VER)
1102#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1103#      endif
1104#    endif
1105#  endif
1106
1107#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1108#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1109#  else
1110#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1111#  endif
1112
1113#  if _LIBCPP_STD_VER > 17
1114#    define _LIBCPP_CONSTINIT constinit
1115#  elif __has_attribute(require_constant_initialization)
1116#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1117#  else
1118#    define _LIBCPP_CONSTINIT
1119#  endif
1120
1121#  if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1122#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1123#    define _LIBCPP_DIAGNOSE_ERROR(...) __attribute__((diagnose_if(__VA_ARGS__, "error")))
1124#  else
1125#    define _LIBCPP_DIAGNOSE_WARNING(...)
1126#    define _LIBCPP_DIAGNOSE_ERROR(...)
1127#  endif
1128
1129// Use a function like macro to imply that it must be followed by a semicolon
1130#  if _LIBCPP_STD_VER > 14 && __has_cpp_attribute(fallthrough)
1131#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1132#  elif __has_cpp_attribute(clang::fallthrough)
1133#    define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
1134#  elif __has_attribute(__fallthrough__)
1135#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1136#  else
1137#    define _LIBCPP_FALLTHROUGH() ((void)0)
1138#  endif
1139
1140#  if __has_attribute(__nodebug__)
1141#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1142#  else
1143#    define _LIBCPP_NODEBUG
1144#  endif
1145
1146#  if __has_attribute(__standalone_debug__)
1147#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1148#  else
1149#    define _LIBCPP_STANDALONE_DEBUG
1150#  endif
1151
1152#  if __has_attribute(__preferred_name__)
1153#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1154#  else
1155#    define _LIBCPP_PREFERRED_NAME(x)
1156#  endif
1157
1158// We often repeat things just for handling wide characters in the library.
1159// When wide characters are disabled, it can be useful to have a quick way of
1160// disabling it without having to resort to #if-#endif, which has a larger
1161// impact on readability.
1162#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1163#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
1164#  else
1165#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1166#  endif
1167
1168#  if defined(_LIBCPP_ABI_MICROSOFT) && (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1169#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1170#  else
1171#    define _LIBCPP_DECLSPEC_EMPTY_BASES
1172#  endif
1173
1174#  if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1175#    define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1176#    define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1177#    define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1178#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1179#  endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1180
1181#  if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1182#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1183#    define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1184#    define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1185#    define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1186#    define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1187#  endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1188
1189#  if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1190#    define _LIBCPP_HAS_NO_CXX20_COROUTINES
1191#  endif
1192
1193#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")")
1194#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")")
1195
1196#  ifndef _LIBCPP_NO_AUTO_LINK
1197#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1198#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1199#        pragma comment(lib, "c++.lib")
1200#      else
1201#        pragma comment(lib, "libc++.lib")
1202#      endif
1203#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1204#  endif   // _LIBCPP_NO_AUTO_LINK
1205
1206// Configures the fopen close-on-exec mode character, if any. This string will
1207// be appended to any mode string used by fstream for fopen/fdopen.
1208//
1209// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1210// do.
1211#  if defined(__BIONIC__)
1212#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1213#  else
1214#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1215#  endif
1216
1217// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1218// of functions used in cstdio may not be available for low API levels when
1219// using 64-bit file offsets on LP32.
1220#  if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1221#    define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1222#  endif
1223
1224#  if __has_attribute(init_priority)
1225// TODO: Remove this once we drop support for building libc++ with old Clangs
1226#    if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) ||                                                    \
1227        (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1228#      define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1229#    else
1230#      define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1231#    endif
1232#  else
1233#    define _LIBCPP_INIT_PRIORITY_MAX
1234#  endif
1235
1236#  if defined(__GNUC__) || defined(__clang__)
1237// The attribute uses 1-based indices for ordinary and static member functions.
1238// The attribute uses 2-based indices for non-static member functions.
1239#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
1240      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1241#  else
1242#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1243#  endif
1244
1245#  if __has_cpp_attribute(msvc::no_unique_address)
1246// MSVC implements [[no_unique_address]] as a silent no-op currently.
1247// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1248// However, MSVC implements [[msvc::no_unique_address]] which does what
1249// [[no_unique_address]] is supposed to do, in general.
1250
1251// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1252// [[msvc::no_unique_address]] though. If/when it does implement
1253// [[msvc::no_unique_address]], this should be preferred though.
1254#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1255#  elif __has_cpp_attribute(no_unique_address)
1256#    define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
1257#  else
1258#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1259// Note that this can be replaced by #error as soon as clang-cl
1260// implements msvc::no_unique_address, since there should be no C++20
1261// compiler that doesn't support one of the two attributes at that point.
1262// We generally don't want to use this macro outside of C++20-only code,
1263// because using it conditionally in one language version only would make
1264// the ABI inconsistent.
1265#  endif
1266
1267#  ifdef _LIBCPP_COMPILER_CLANG_BASED
1268#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1269#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1270#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1271#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1272#  elif defined(_LIBCPP_COMPILER_GCC)
1273#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1274#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1275#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1276#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1277#  else
1278#    define _LIBCPP_DIAGNOSTIC_PUSH
1279#    define _LIBCPP_DIAGNOSTIC_POP
1280#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1281#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1282#  endif
1283
1284#  if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
1285#    define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
1286#    define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
1287#  else
1288#    define _LIBCPP_PACKED_BYTE_FOR_AIX     /* empty */
1289#    define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
1290#  endif
1291
1292#endif // __cplusplus
1293
1294#endif // _LIBCPP___CONFIG
1295