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