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