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