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