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// Incomplete features get their own specific disabling flags. This makes it
247// easier to grep for target specific flags once the feature is complete.
248#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
249#    define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
250#    define _LIBCPP_HAS_NO_INCOMPLETE_RANGES
251#  endif
252
253// Need to detect which libc we're using if we're on Linux.
254#  if defined(__linux__)
255#    include <features.h>
256#    if defined(__GLIBC_PREREQ)
257#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
258#    else
259#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
260#    endif // defined(__GLIBC_PREREQ)
261#  endif   // defined(__linux__)
262
263#  if defined(__MVS__)
264#    include <features.h> // for __NATIVE_ASCII_F
265#  endif
266
267#  ifdef __LITTLE_ENDIAN__
268#    if __LITTLE_ENDIAN__
269#      define _LIBCPP_LITTLE_ENDIAN
270#    endif // __LITTLE_ENDIAN__
271#  endif   // __LITTLE_ENDIAN__
272
273#  ifdef __BIG_ENDIAN__
274#    if __BIG_ENDIAN__
275#      define _LIBCPP_BIG_ENDIAN
276#    endif // __BIG_ENDIAN__
277#  endif   // __BIG_ENDIAN__
278
279#  ifdef __BYTE_ORDER__
280#    if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
281#      define _LIBCPP_LITTLE_ENDIAN
282#    elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
283#      define _LIBCPP_BIG_ENDIAN
284#    endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
285#  endif   // __BYTE_ORDER__
286
287#  ifdef __FreeBSD__
288#    include <sys/endian.h>
289#    include <osreldate.h>
290#    if _BYTE_ORDER == _LITTLE_ENDIAN
291#      define _LIBCPP_LITTLE_ENDIAN
292#    else // _BYTE_ORDER == _LITTLE_ENDIAN
293#      define _LIBCPP_BIG_ENDIAN
294#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
295#  endif   // __FreeBSD__
296
297#  if defined(__NetBSD__) || defined(__OpenBSD__)
298#    include <sys/endian.h>
299#    if _BYTE_ORDER == _LITTLE_ENDIAN
300#      define _LIBCPP_LITTLE_ENDIAN
301#    else // _BYTE_ORDER == _LITTLE_ENDIAN
302#      define _LIBCPP_BIG_ENDIAN
303#    endif // _BYTE_ORDER == _LITTLE_ENDIAN
304#  endif   // defined(__NetBSD__) || defined(__OpenBSD__)
305
306#  if defined(_WIN32)
307#    define _LIBCPP_WIN32API
308#    define _LIBCPP_LITTLE_ENDIAN
309#    define _LIBCPP_SHORT_WCHAR 1
310// Both MinGW and native MSVC provide a "MSVC"-like environment
311#    define _LIBCPP_MSVCRT_LIKE
312// If mingw not explicitly detected, assume using MS C runtime only if
313// a MS compatibility version is specified.
314#    if defined(_MSC_VER) && !defined(__MINGW32__)
315#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
316#    endif
317#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
318#      define _LIBCPP_HAS_BITSCAN64
319#    endif
320#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
321#  endif // defined(_WIN32)
322
323#  ifdef __sun__
324#    include <sys/isa_defs.h>
325#    ifdef _LITTLE_ENDIAN
326#      define _LIBCPP_LITTLE_ENDIAN
327#    else
328#      define _LIBCPP_BIG_ENDIAN
329#    endif
330#  endif // __sun__
331
332#  if defined(_AIX) && !defined(__64BIT__)
333// The size of wchar is 2 byte on 32-bit mode on AIX.
334#    define _LIBCPP_SHORT_WCHAR 1
335#  endif
336
337// Libc++ supports various implementations of std::random_device.
338//
339// _LIBCPP_USING_DEV_RANDOM
340//      Read entropy from the given file, by default `/dev/urandom`.
341//      If a token is provided, it is assumed to be the path to a file
342//      to read entropy from. This is the default behavior if nothing
343//      else is specified. This implementation requires storing state
344//      inside `std::random_device`.
345//
346// _LIBCPP_USING_ARC4_RANDOM
347//      Use arc4random(). This allows obtaining random data even when
348//      using sandboxing mechanisms. On some platforms like Apple, this
349//      is the recommended source of entropy for user-space programs.
350//      When this option is used, the token passed to `std::random_device`'s
351//      constructor *must* be "/dev/urandom" -- anything else is an error.
352//
353// _LIBCPP_USING_GETENTROPY
354//      Use getentropy().
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_FUCHSIA_CPRNG
359//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
360//      deliver high-quality entropy and cannot fail.
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_NACL_RANDOM
365//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
366//      including accesses to the special files under `/dev`. This implementation
367//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
368//      When this option is used, the token passed to `std::random_device`'s
369//      constructor *must* be "/dev/urandom" -- anything else is an error.
370//
371// _LIBCPP_USING_WIN32_RANDOM
372//      Use rand_s(), for use on Windows.
373//      When this option is used, the token passed to `std::random_device`'s
374//      constructor *must* be "/dev/urandom" -- anything else is an error.
375#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
376      defined(__DragonFly__) || defined(__sun__)
377#    define _LIBCPP_USING_ARC4_RANDOM
378#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
379#    define _LIBCPP_USING_GETENTROPY
380#  elif defined(__Fuchsia__)
381#    define _LIBCPP_USING_FUCHSIA_CPRNG
382#  elif defined(__native_client__)
383#    define _LIBCPP_USING_NACL_RANDOM
384#  elif defined(_LIBCPP_WIN32API)
385#    define _LIBCPP_USING_WIN32_RANDOM
386#  else
387#    define _LIBCPP_USING_DEV_RANDOM
388#  endif
389
390#  if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
391#    include <endian.h>
392#    if __BYTE_ORDER == __LITTLE_ENDIAN
393#      define _LIBCPP_LITTLE_ENDIAN
394#    elif __BYTE_ORDER == __BIG_ENDIAN
395#      define _LIBCPP_BIG_ENDIAN
396#    else // __BYTE_ORDER == __BIG_ENDIAN
397#      error unable to determine endian
398#    endif
399#  endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
400
401#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
402#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
403#  else
404#    define _LIBCPP_NO_CFI
405#  endif
406
407#  ifndef _LIBCPP_CXX03_LANG
408
409#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
410#    define _ALIGNAS_TYPE(x) alignas(x)
411#    define _ALIGNAS(x) alignas(x)
412#    define _LIBCPP_NORETURN [[noreturn]]
413#    define _NOEXCEPT noexcept
414#    define _NOEXCEPT_(x) noexcept(x)
415
416#  else
417
418#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
419#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
420#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
421#    define _LIBCPP_NORETURN __attribute__((noreturn))
422#    define _LIBCPP_HAS_NO_NOEXCEPT
423#    define nullptr __nullptr
424#    define _NOEXCEPT throw()
425#    define _NOEXCEPT_(x)
426
427typedef __char16_t char16_t;
428typedef __char32_t char32_t;
429
430#  endif
431
432#  if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
433#    define _LIBCPP_NO_EXCEPTIONS
434#  endif
435
436#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
437
438#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
439
440#    if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
441#      define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
442#    endif
443
444// Objective-C++ features (opt-in)
445#    if __has_feature(objc_arc)
446#      define _LIBCPP_HAS_OBJC_ARC
447#    endif
448
449#    if __has_feature(objc_arc_weak)
450#      define _LIBCPP_HAS_OBJC_ARC_WEAK
451#    endif
452
453#    if __has_extension(blocks)
454#      define _LIBCPP_HAS_EXTENSION_BLOCKS
455#    endif
456
457#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
458#      define _LIBCPP_HAS_BLOCKS_RUNTIME
459#    endif
460
461#    if !__has_feature(address_sanitizer)
462#      define _LIBCPP_HAS_NO_ASAN
463#    endif
464
465// Allow for build-time disabling of unsigned integer sanitization
466#    if __has_attribute(no_sanitize)
467#      define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
468#    endif
469
470#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
471
472#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
473
474#  elif defined(_LIBCPP_COMPILER_GCC)
475
476#    if !defined(__SANITIZE_ADDRESS__)
477#      define _LIBCPP_HAS_NO_ASAN
478#    endif
479
480#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
481
482#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
483
484#  elif defined(_LIBCPP_COMPILER_MSVC)
485
486#    define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
487
488#    if _MSC_VER < 1900
489#      error "MSVC versions prior to Visual Studio 2015 are not supported"
490#    endif
491
492#    define _LIBCPP_NORETURN __declspec(noreturn)
493
494#    define _LIBCPP_WEAK
495
496#    define _LIBCPP_HAS_NO_ASAN
497
498#    define _LIBCPP_ALWAYS_INLINE __forceinline
499
500#    define _LIBCPP_HAS_NO_VECTOR_EXTENSION
501
502#    define _LIBCPP_DISABLE_EXTENSION_WARNING
503
504#  endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC]
505
506#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
507
508#    ifdef _DLL
509#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
510#    else
511#      define _LIBCPP_CRT_FUNC
512#    endif
513
514#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
515#      define _LIBCPP_DLL_VIS
516#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
517#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
518#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
519#      define _LIBCPP_EXPORTED_FROM_ABI
520#    elif defined(_LIBCPP_BUILDING_LIBRARY)
521#      define _LIBCPP_DLL_VIS __declspec(dllexport)
522#      if defined(__MINGW32__)
523#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
524#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
525#      else
526#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
527#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
528#      endif
529#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
530#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
531#    else
532#      define _LIBCPP_DLL_VIS __declspec(dllimport)
533#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
534#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
535#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
536#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
537#    endif
538
539#    define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
540#    define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
541#    define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
542#    define _LIBCPP_HIDDEN
543#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
544#    define _LIBCPP_TEMPLATE_VIS
545#    define _LIBCPP_TEMPLATE_DATA_VIS
546#    define _LIBCPP_ENUM_VIS
547
548#  else
549
550#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
551#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
552#    else
553#      define _LIBCPP_VISIBILITY(vis)
554#    endif
555
556#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
557#    define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default")
558#    define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default")
559#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
560#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
561#    define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default")
562#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
563#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
564
565// TODO: Make this a proper customization point or remove the option to override it.
566#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
567#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
568#    endif
569
570#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
571// The inline should be removed once PR32114 is resolved
572#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
573#    else
574#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
575#    endif
576
577#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
578#      if __has_attribute(__type_visibility__)
579#        define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default")))
580#      else
581#        define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
582#      endif
583#    else
584#      define _LIBCPP_TEMPLATE_VIS
585#    endif
586
587#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
588#      define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default")))
589#    else
590#      define _LIBCPP_ENUM_VIS
591#    endif
592
593#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
594
595#  if __has_attribute(exclude_from_explicit_instantiation)
596#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
597#  else
598// Try to approximate the effect of exclude_from_explicit_instantiation
599// (which is that entities are not assumed to be provided by explicit
600// template instantiations in the dylib) by always inlining those entities.
601#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
602#  endif
603
604// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
605// on two levels:
606// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
607//    symbols from their dynamic library by means of using the libc++ headers. This ensures
608//    that those symbols stay private to the dynamic library in which it is defined.
609//
610// 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures
611//    that no ODR violation can arise from mixing two TUs compiled with different versions
612//    of libc++ where we would have changed the definition of a symbol. If the symbols shared
613//    the same name, the ODR would require that their definitions be token-by-token equivalent,
614//    which basically prevents us from being able to make any change to any function in our
615//    headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at
616//    each release, which lets us change the definition of these symbols at our leisure.
617//    Note that historically, this has been achieved in various ways, including force-inlining
618//    all functions or giving internal linkage to all functions. Both these (previous) solutions
619//    suffer from drawbacks that lead notably to code bloat.
620//
621// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
622// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
623//
624// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
625//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
626//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
627#  ifndef _LIBCPP_NO_ABI_TAG
628#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
629      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
630          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
631#  else
632#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
633#  endif
634
635#  ifdef _LIBCPP_BUILDING_LIBRARY
636#    if _LIBCPP_ABI_VERSION > 1
637#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
638#    else
639#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
640#    endif
641#  else
642#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
643#  endif
644
645// Just so we can migrate to the new macros gradually.
646#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
647
648// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
649// clang-format off
650#  define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
651#  define _LIBCPP_END_NAMESPACE_STD }}
652#  define _VSTD std
653
654_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
655
656#  if _LIBCPP_STD_VER > 14
657#    define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM                                                                         \
658       _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
659#  else
660#    define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM                                                                         \
661      _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
662#  endif
663
664#  define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
665// clang-format on
666
667#  define _VSTD_FS std::__fs::filesystem
668
669#  if __has_attribute(__enable_if__)
670#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
671#  endif
672
673#  ifndef __SIZEOF_INT128__
674#    define _LIBCPP_HAS_NO_INT128
675#  endif
676
677#  ifdef _LIBCPP_CXX03_LANG
678#    define static_assert(...) _Static_assert(__VA_ARGS__)
679#    define decltype(...) __decltype(__VA_ARGS__)
680#  endif // _LIBCPP_CXX03_LANG
681
682#  ifdef _LIBCPP_CXX03_LANG
683#    define _LIBCPP_CONSTEXPR
684#  else
685#    define _LIBCPP_CONSTEXPR constexpr
686#  endif
687
688#  ifndef __cpp_consteval
689#    define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
690#  else
691#    define _LIBCPP_CONSTEVAL consteval
692#  endif
693
694#  ifdef __GNUC__
695#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
696#  else
697#    define _LIBCPP_NOALIAS
698#  endif
699
700#  if __has_attribute(using_if_exists)
701#    define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
702#  else
703#    define _LIBCPP_USING_IF_EXISTS
704#  endif
705
706#  ifdef _LIBCPP_CXX03_LANG
707#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
708      struct _LIBCPP_TYPE_VIS x {                                                                                      \
709        enum __lx
710// clang-format off
711#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
712      __lx __v_;                                                                                                       \
713      _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {}                                                             \
714      _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                  \
715      _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; }                                                  \
716      };
717// clang-format on
718
719#  else // _LIBCPP_CXX03_LANG
720#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
721#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
722#  endif // _LIBCPP_CXX03_LANG
723
724#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) ||                \
725      defined(__NetBSD__)
726#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
727#  endif
728
729#  ifdef __FreeBSD__
730#    define _DECLARE_C99_LDBL_MATH 1
731#  endif
732
733// If we are getting operator new from the MSVC CRT, then allocation overloads
734// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
735#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
736#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
737#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
738// We're deferring to Microsoft's STL to provide aligned new et al. We don't
739// have it unless the language feature test macro is defined.
740#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
741#  elif defined(__MVS__)
742#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
743#  endif
744
745#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
746#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
747#  endif
748
749#  if defined(__APPLE__) || defined(__FreeBSD__)
750#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
751#  endif
752
753#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
754#    define _LIBCPP_WCTYPE_IS_MASK
755#  endif
756
757#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
758#    define _LIBCPP_HAS_NO_CHAR8_T
759#  endif
760
761// Deprecation macros.
762//
763// Deprecations warnings are always enabled, except when users explicitly opt-out
764// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
765#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
766#    if __has_attribute(deprecated)
767#      define _LIBCPP_DEPRECATED __attribute__((deprecated))
768#      define _LIBCPP_DEPRECATED_(m) __attribute__((deprected(m)))
769#    elif _LIBCPP_STD_VER > 11
770#      define _LIBCPP_DEPRECATED [[deprecated]]
771#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
772#    else
773#      define _LIBCPP_DEPRECATED
774#      define _LIBCPP_DEPRECATED_(m)
775#    endif
776#  else
777#    define _LIBCPP_DEPRECATED
778#    define _LIBCPP_DEPRECATED_(m)
779#  endif
780
781#  if !defined(_LIBCPP_CXX03_LANG)
782#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
783#  else
784#    define _LIBCPP_DEPRECATED_IN_CXX11
785#  endif
786
787#  if _LIBCPP_STD_VER > 11
788#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
789#  else
790#    define _LIBCPP_DEPRECATED_IN_CXX14
791#  endif
792
793#  if _LIBCPP_STD_VER > 14
794#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
795#  else
796#    define _LIBCPP_DEPRECATED_IN_CXX17
797#  endif
798
799#  if _LIBCPP_STD_VER > 17
800#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
801#  else
802#    define _LIBCPP_DEPRECATED_IN_CXX20
803#  endif
804
805#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
806#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
807#  else
808#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
809#  endif
810
811// Macros to enter and leave a state where deprecation warnings are suppressed.
812#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
813#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
814      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
815          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
816#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
817#  else
818#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
819#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
820#  endif
821
822#  if _LIBCPP_STD_VER <= 11
823#    define _LIBCPP_EXPLICIT_AFTER_CXX11
824#  else
825#    define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
826#  endif
827
828#  if _LIBCPP_STD_VER > 11
829#    define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
830#  else
831#    define _LIBCPP_CONSTEXPR_AFTER_CXX11
832#  endif
833
834#  if _LIBCPP_STD_VER > 14
835#    define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
836#  else
837#    define _LIBCPP_CONSTEXPR_AFTER_CXX14
838#  endif
839
840#  if _LIBCPP_STD_VER > 17
841#    define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
842#  else
843#    define _LIBCPP_CONSTEXPR_AFTER_CXX17
844#  endif
845
846#  if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
847#    define _LIBCPP_NODISCARD [[nodiscard]]
848#  elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
849#    define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
850#  else
851// We can't use GCC's [[gnu::warn_unused_result]] and
852// __attribute__((warn_unused_result)), because GCC does not silence them via
853// (void) cast.
854#    define _LIBCPP_NODISCARD
855#  endif
856
857// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
858// specified as such as an extension.
859#  if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
860#    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
861#  else
862#    define _LIBCPP_NODISCARD_EXT
863#  endif
864
865#  if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
866#    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
867#  else
868#    define _LIBCPP_NODISCARD_AFTER_CXX17
869#  endif
870
871#  if __has_attribute(no_destroy)
872#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
873#  else
874#    define _LIBCPP_NO_DESTROY
875#  endif
876
877#  ifndef _LIBCPP_HAS_NO_ASAN
878    extern "C" _LIBCPP_FUNC_VIS void
879    __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
880#  endif
881
882// Try to find out if RTTI is disabled.
883#  if !defined(__cpp_rtti) || __cpp_rtti < 199711L
884#    define _LIBCPP_NO_RTTI
885#  endif
886
887#  ifndef _LIBCPP_WEAK
888#    define _LIBCPP_WEAK __attribute__((__weak__))
889#  endif
890
891// Thread API
892// clang-format off
893#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
894      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
895      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
896      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
897
898#    if defined(__FreeBSD__) ||                                                                                        \
899        defined(__wasi__) ||                                                                                           \
900        defined(__NetBSD__) ||                                                                                         \
901        defined(__OpenBSD__) ||                                                                                        \
902        defined(__NuttX__) ||                                                                                          \
903        defined(__linux__) ||                                                                                          \
904        defined(__GNU__) ||                                                                                            \
905        defined(__APPLE__) ||                                                                                          \
906        defined(__sun__) ||                                                                                            \
907        defined(__MVS__) ||                                                                                            \
908        defined(_AIX) ||                                                                                               \
909        defined(__EMSCRIPTEN__)
910// clang-format on
911#      define _LIBCPP_HAS_THREAD_API_PTHREAD
912#    elif defined(__Fuchsia__)
913// TODO(44575): Switch to C11 thread API when possible.
914#      define _LIBCPP_HAS_THREAD_API_PTHREAD
915#    elif defined(_LIBCPP_WIN32API)
916#      define _LIBCPP_HAS_THREAD_API_WIN32
917#    else
918#      error "No thread API"
919#    endif // _LIBCPP_HAS_THREAD_API
920#  endif   // _LIBCPP_HAS_NO_THREADS
921
922#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
923#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
924#      define _LIBCPP_HAS_COND_CLOCKWAIT
925#    elif defined(_LIBCPP_GLIBC_PREREQ)
926#      if _LIBCPP_GLIBC_PREREQ(2, 30)
927#        define _LIBCPP_HAS_COND_CLOCKWAIT
928#      endif
929#    endif
930#  endif
931
932#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
933#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
934       _LIBCPP_HAS_NO_THREADS is not defined.
935#  endif
936
937#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
938#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
939       _LIBCPP_HAS_NO_THREADS is defined.
940#  endif
941
942#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
943#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
944       _LIBCPP_HAS_NO_THREADS is defined.
945#  endif
946
947#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
948#    define __STDCPP_THREADS__ 1
949#  endif
950
951// The glibc and Bionic implementation of pthreads implements
952// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
953// mutexes have no destroy mechanism.
954//
955// This optimization can't be performed on Apple platforms, where
956// pthread_mutex_destroy can allow the kernel to release resources.
957// See https://llvm.org/D64298 for details.
958//
959// TODO(EricWF): Enable this optimization on Bionic after speaking to their
960//               respective stakeholders.
961// clang-format off
962#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
963      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
964       defined(_LIBCPP_HAS_THREAD_API_WIN32)
965// clang-format on
966#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
967#  endif
968
969// Destroying a condvar is a nop on Windows.
970//
971// This optimization can't be performed on Apple platforms, where
972// pthread_cond_destroy can allow the kernel to release resources.
973// See https://llvm.org/D64298 for details.
974//
975// TODO(EricWF): This is potentially true for some pthread implementations
976// as well.
977#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
978#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
979#  endif
980
981// Some systems do not provide gets() in their C library, for security reasons.
982#  if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
983#    define _LIBCPP_C_HAS_NO_GETS
984#  endif
985
986#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
987      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
988#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
989#  endif
990
991#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
992#    define _LIBCPP_HAS_C_ATOMIC_IMP
993#  elif defined(_LIBCPP_COMPILER_GCC)
994#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
995#  endif
996
997#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
998      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
999#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
1000#  else
1001#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1002#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
1003#    endif
1004#    ifdef _LIBCPP_FREESTANDING
1005#      define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1006#    endif
1007#  endif
1008
1009#  ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1010#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1011#  endif
1012
1013#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1014#    if defined(__clang__) && __has_attribute(acquire_capability)
1015// Work around the attribute handling in clang.  When both __declspec and
1016// __attribute__ are present, the processing goes awry preventing the definition
1017// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1018// combining the two does work.
1019#      if !defined(_MSC_VER)
1020#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1021#      endif
1022#    endif
1023#  endif
1024
1025#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1026#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1027#  else
1028#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1029#  endif
1030
1031#  if _LIBCPP_STD_VER > 17
1032#    define _LIBCPP_CONSTINIT constinit
1033#  elif __has_attribute(require_constant_initialization)
1034#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1035#  else
1036#    define _LIBCPP_CONSTINIT
1037#  endif
1038
1039#  if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1040#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1041#    define _LIBCPP_DIAGNOSE_ERROR(...) __attribute__((diagnose_if(__VA_ARGS__, "error")))
1042#  else
1043#    define _LIBCPP_DIAGNOSE_WARNING(...)
1044#    define _LIBCPP_DIAGNOSE_ERROR(...)
1045#  endif
1046
1047// Use a function like macro to imply that it must be followed by a semicolon
1048#  if __has_cpp_attribute(fallthrough)
1049#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1050#  elif __has_attribute(__fallthrough__)
1051#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1052#  else
1053#    define _LIBCPP_FALLTHROUGH() ((void)0)
1054#  endif
1055
1056#  if __has_attribute(__nodebug__)
1057#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1058#  else
1059#    define _LIBCPP_NODEBUG
1060#  endif
1061
1062#  if __has_attribute(__standalone_debug__)
1063#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1064#  else
1065#    define _LIBCPP_STANDALONE_DEBUG
1066#  endif
1067
1068#  if __has_attribute(__preferred_name__)
1069#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1070#  else
1071#    define _LIBCPP_PREFERRED_NAME(x)
1072#  endif
1073
1074// We often repeat things just for handling wide characters in the library.
1075// When wide characters are disabled, it can be useful to have a quick way of
1076// disabling it without having to resort to #if-#endif, which has a larger
1077// impact on readability.
1078#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1079#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
1080#  else
1081#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1082#  endif
1083
1084#  if defined(_LIBCPP_ABI_MICROSOFT) && (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1085#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1086#  else
1087#    define _LIBCPP_DECLSPEC_EMPTY_BASES
1088#  endif
1089
1090#  if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1091#    define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1092#    define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1093#    define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1094#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1095#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1096#  endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1097
1098#  if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1099#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1100#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1101#    define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1102#    define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1103#    define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1104#    define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1105#  endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1106
1107#  if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1108#    define _LIBCPP_HAS_NO_CXX20_COROUTINES
1109#  endif
1110
1111#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")")
1112#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")")
1113
1114#  ifndef _LIBCPP_NO_AUTO_LINK
1115#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1116#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1117#        pragma comment(lib, "c++.lib")
1118#      else
1119#        pragma comment(lib, "libc++.lib")
1120#      endif
1121#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1122#  endif   // _LIBCPP_NO_AUTO_LINK
1123
1124// Configures the fopen close-on-exec mode character, if any. This string will
1125// be appended to any mode string used by fstream for fopen/fdopen.
1126//
1127// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1128// do.
1129#  if defined(__BIONIC__)
1130#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1131#  else
1132#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1133#  endif
1134
1135// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1136// of functions used in cstdio may not be available for low API levels when
1137// using 64-bit file offsets on LP32.
1138#  if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1139#    define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1140#  endif
1141
1142#  if __has_attribute(init_priority)
1143// TODO: Remove this once we drop support for building libc++ with old Clangs
1144#    if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) ||                                                    \
1145        (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1146#      define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1147#    else
1148#      define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1149#    endif
1150#  else
1151#    define _LIBCPP_INIT_PRIORITY_MAX
1152#  endif
1153
1154#  if defined(__GNUC__) || defined(__clang__)
1155// The attribute uses 1-based indices for ordinary and static member functions.
1156// The attribute uses 2-based indices for non-static member functions.
1157#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
1158      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1159#  else
1160#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1161#  endif
1162
1163#  if __has_cpp_attribute(msvc::no_unique_address)
1164// MSVC implements [[no_unique_address]] as a silent no-op currently.
1165// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1166// However, MSVC implements [[msvc::no_unique_address]] which does what
1167// [[no_unique_address]] is supposed to do, in general.
1168
1169// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1170// [[msvc::no_unique_address]] though. If/when it does implement
1171// [[msvc::no_unique_address]], this should be preferred though.
1172#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1173#  elif __has_cpp_attribute(no_unique_address)
1174#    define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
1175#  else
1176#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1177// Note that this can be replaced by #error as soon as clang-cl
1178// implements msvc::no_unique_address, since there should be no C++20
1179// compiler that doesn't support one of the two attributes at that point.
1180// We generally don't want to use this macro outside of C++20-only code,
1181// because using it conditionally in one language version only would make
1182// the ABI inconsistent.
1183#  endif
1184
1185#  ifdef _LIBCPP_COMPILER_CLANG_BASED
1186#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1187#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1188#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1189#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1190#  elif defined(_LIBCPP_COMPILER_GCC)
1191#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1192#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1193#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1194#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1195#  else
1196#    define _LIBCPP_DIAGNOSTIC_PUSH
1197#    define _LIBCPP_DIAGNOSTIC_POP
1198#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1199#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1200#  endif
1201
1202#  if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
1203#    define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
1204#    define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
1205#  else
1206#    define _LIBCPP_PACKED_BYTE_FOR_AIX     /* empty */
1207#    define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
1208#  endif
1209
1210#  if __has_attribute(__packed__)
1211#    define _LIBCPP_PACKED __attribute__((__packed__))
1212#  else
1213#    define _LIBCPP_PACKED
1214#  endif
1215
1216#endif // __cplusplus
1217
1218#endif // _LIBCPP___CONFIG
1219