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