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