xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision 1838bd0f4839006b42d41a02a787b7f578655223)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_CONFIG
110b57cec5SDimitry Andric#define _LIBCPP_CONFIG
120b57cec5SDimitry Andric
13fe6060f1SDimitry Andric#include <__config_site>
14fe6060f1SDimitry Andric
150b57cec5SDimitry Andric#if defined(_MSC_VER) && !defined(__clang__)
160b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
170b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
180b57cec5SDimitry Andric#  endif
190b57cec5SDimitry Andric#endif
200b57cec5SDimitry Andric
210b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
220b57cec5SDimitry Andric#pragma GCC system_header
230b57cec5SDimitry Andric#endif
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric#ifdef __cplusplus
260b57cec5SDimitry Andric
27349cc55cSDimitry Andric#define _LIBCPP_VERSION 14000
280b57cec5SDimitry Andric
290b57cec5SDimitry Andric#ifndef _LIBCPP_ABI_VERSION
300b57cec5SDimitry Andric#  define _LIBCPP_ABI_VERSION 1
310b57cec5SDimitry Andric#endif
320b57cec5SDimitry Andric
33e8d8bef9SDimitry Andric#if __STDC_HOSTED__ == 0
340b57cec5SDimitry Andric#  define _LIBCPP_FREESTANDING
350b57cec5SDimitry Andric#endif
360b57cec5SDimitry Andric
370b57cec5SDimitry Andric#ifndef _LIBCPP_STD_VER
380b57cec5SDimitry Andric#  if  __cplusplus <= 201103L
390b57cec5SDimitry Andric#    define _LIBCPP_STD_VER 11
400b57cec5SDimitry Andric#  elif __cplusplus <= 201402L
410b57cec5SDimitry Andric#    define _LIBCPP_STD_VER 14
420b57cec5SDimitry Andric#  elif __cplusplus <= 201703L
430b57cec5SDimitry Andric#    define _LIBCPP_STD_VER 17
44e8d8bef9SDimitry Andric#  elif __cplusplus <= 202002L
45e8d8bef9SDimitry Andric#    define _LIBCPP_STD_VER 20
460b57cec5SDimitry Andric#  else
47e8d8bef9SDimitry Andric#    define _LIBCPP_STD_VER 21  // current year, or date of c++2b ratification
480b57cec5SDimitry Andric#  endif
490b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER
500b57cec5SDimitry Andric
510b57cec5SDimitry Andric#if defined(__ELF__)
520b57cec5SDimitry Andric#  define _LIBCPP_OBJECT_FORMAT_ELF   1
530b57cec5SDimitry Andric#elif defined(__MACH__)
540b57cec5SDimitry Andric#  define _LIBCPP_OBJECT_FORMAT_MACHO 1
550b57cec5SDimitry Andric#elif defined(_WIN32)
560b57cec5SDimitry Andric#  define _LIBCPP_OBJECT_FORMAT_COFF  1
570b57cec5SDimitry Andric#elif defined(__wasm__)
580b57cec5SDimitry Andric#  define _LIBCPP_OBJECT_FORMAT_WASM  1
590b57cec5SDimitry Andric#else
60e8d8bef9SDimitry Andric   // ... add new file formats here ...
610b57cec5SDimitry Andric#endif
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
640b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0,
650b57cec5SDimitry Andric// improving its alignment in some cases.
660b57cec5SDimitry Andric#  define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
670b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types.
680b57cec5SDimitry Andric#  define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
690b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes.
700b57cec5SDimitry Andric#  define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
710b57cec5SDimitry Andric// Fix undefined behavior in  how __tree stores its end and parent nodes.
720b57cec5SDimitry Andric#  define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
730b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types.
740b57cec5SDimitry Andric#  define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
750b57cec5SDimitry Andric#  define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
760b57cec5SDimitry Andric#  define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
770b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize
780b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries
790b57cec5SDimitry Andric// using that class define their own copies.
800b57cec5SDimitry Andric#  define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
81349cc55cSDimitry Andric// Override the default return value of exception::what() for
82349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to
83349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
84349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call.
85349cc55cSDimitry Andric#  define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
860b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
870b57cec5SDimitry Andric#  define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
88fe6060f1SDimitry Andric// In C++20 and later, don't derive std::plus from std::binary_function,
89fe6060f1SDimitry Andric// nor std::negate from std::unary_function.
90fe6060f1SDimitry Andric#  define _LIBCPP_ABI_NO_BINDER_BASES
91fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two.
92fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator.
93fe6060f1SDimitry Andric#  define _LIBCPP_ABI_NO_ITERATOR_BASES
940b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant.
950b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively.
960b57cec5SDimitry Andric#  define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
970b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function
980b57cec5SDimitry Andric#  define _LIBCPP_ABI_OPTIMIZED_FUNCTION
990b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero.
1000b57cec5SDimitry Andric#  define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
101fe6060f1SDimitry Andric// Use raw pointers, not wrapped ones, for std::span's iterator type.
102fe6060f1SDimitry Andric#  define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
1035ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on
1045ffd83dbSDimitry Andric// performance and fast-path inlining.
1055ffd83dbSDimitry Andric#  define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
106e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr.
107e8d8bef9SDimitry Andric#  define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
108e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
109e8d8bef9SDimitry Andric#  define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
11004eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets
11104eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
11204eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped
11304eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI
11404eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care
11504eeddc0SDimitry Andric// about ABI compatibility.
11604eeddc0SDimitry Andric#  define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
11704eeddc0SDimitry Andric// Remove basic_string common base
118*1838bd0fSDimitry Andric#  define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
1190b57cec5SDimitry Andric#elif _LIBCPP_ABI_VERSION == 1
1200b57cec5SDimitry Andric#  if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1210b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support
1220b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with
1230b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition
1240b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would
1250b57cec5SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it.
1260b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
1270b57cec5SDimitry Andric#  endif
1280b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options
1290b57cec5SDimitry Andric// are deprecated.
1300b57cec5SDimitry Andric#  if defined(__FreeBSD__)
1310b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
1320b57cec5SDimitry Andric#  endif
1330b57cec5SDimitry Andric#endif
1340b57cec5SDimitry Andric
1354824e7fdSDimitry Andric// By default, don't use a nullptr_t emulation type in C++03.
1364824e7fdSDimitry Andric//
1374824e7fdSDimitry Andric// This is technically an ABI break from previous releases, however it is
1384824e7fdSDimitry Andric// very unlikely to impact anyone. If a user is impacted by this break,
1394824e7fdSDimitry Andric// they can return to using the C++03 nullptr emulation by defining
1404824e7fdSDimitry Andric// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
1414824e7fdSDimitry Andric//
1424824e7fdSDimitry Andric// This switch will be removed entirely in favour of never providing a
1434824e7fdSDimitry Andric// C++03 emulation after one release.
1444824e7fdSDimitry Andric//
1454824e7fdSDimitry Andric// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
1464824e7fdSDimitry Andric//            A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
1474824e7fdSDimitry Andric//            IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
1484824e7fdSDimitry Andric#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
1494824e7fdSDimitry Andric# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
1504824e7fdSDimitry Andric#endif
1514824e7fdSDimitry Andric
152e8d8bef9SDimitry Andric#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
153e8d8bef9SDimitry Andric// Enable additional explicit instantiations of iostreams components. This
154e8d8bef9SDimitry Andric// reduces the number of weak definitions generated in programs that use
155e8d8bef9SDimitry Andric// iostreams by providing a single strong definition in the shared library.
156e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
157349cc55cSDimitry Andric
158349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize
159349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries
160349cc55cSDimitry Andric// using that class define their own copies.
161349cc55cSDimitry Andric#  define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1620b57cec5SDimitry Andric#endif
1630b57cec5SDimitry Andric
1640b57cec5SDimitry Andric#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
1650b57cec5SDimitry Andric#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
1660b57cec5SDimitry Andric
1670b57cec5SDimitry Andric#ifndef _LIBCPP_ABI_NAMESPACE
1680b57cec5SDimitry Andric# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
1690b57cec5SDimitry Andric#endif
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric#if __cplusplus < 201103L
1720b57cec5SDimitry Andric#define _LIBCPP_CXX03_LANG
1730b57cec5SDimitry Andric#endif
1740b57cec5SDimitry Andric
1750b57cec5SDimitry Andric#ifndef __has_attribute
1760b57cec5SDimitry Andric#define __has_attribute(__x) 0
1770b57cec5SDimitry Andric#endif
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andric#ifndef __has_builtin
1800b57cec5SDimitry Andric#define __has_builtin(__x) 0
1810b57cec5SDimitry Andric#endif
1820b57cec5SDimitry Andric
1830b57cec5SDimitry Andric#ifndef __has_extension
1840b57cec5SDimitry Andric#define __has_extension(__x) 0
1850b57cec5SDimitry Andric#endif
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric#ifndef __has_feature
1880b57cec5SDimitry Andric#define __has_feature(__x) 0
1890b57cec5SDimitry Andric#endif
1900b57cec5SDimitry Andric
1910b57cec5SDimitry Andric#ifndef __has_cpp_attribute
1920b57cec5SDimitry Andric#define __has_cpp_attribute(__x) 0
1930b57cec5SDimitry Andric#endif
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
1960b57cec5SDimitry Andric// the compiler and '1' otherwise.
1970b57cec5SDimitry Andric#ifndef __is_identifier
1980b57cec5SDimitry Andric#define __is_identifier(__x) 1
1990b57cec5SDimitry Andric#endif
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric#ifndef __has_declspec_attribute
2020b57cec5SDimitry Andric#define __has_declspec_attribute(__x) 0
2030b57cec5SDimitry Andric#endif
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andric#define __has_keyword(__x) !(__is_identifier(__x))
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andric#ifndef __has_include
2080b57cec5SDimitry Andric#define __has_include(...) 0
2090b57cec5SDimitry Andric#endif
2100b57cec5SDimitry Andric
211fe6060f1SDimitry Andric#if defined(__apple_build_version__)
212fe6060f1SDimitry Andric#  define _LIBCPP_COMPILER_CLANG_BASED
213fe6060f1SDimitry Andric#  define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
214fe6060f1SDimitry Andric#elif defined(__clang__)
215fe6060f1SDimitry Andric#  define _LIBCPP_COMPILER_CLANG_BASED
2160b57cec5SDimitry Andric#  define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
2170b57cec5SDimitry Andric#elif defined(__GNUC__)
2180b57cec5SDimitry Andric#  define _LIBCPP_COMPILER_GCC
2190b57cec5SDimitry Andric#elif defined(_MSC_VER)
2200b57cec5SDimitry Andric#  define _LIBCPP_COMPILER_MSVC
2210b57cec5SDimitry Andric#elif defined(__IBMCPP__)
2220b57cec5SDimitry Andric#  define _LIBCPP_COMPILER_IBM
2230b57cec5SDimitry Andric#endif
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
2260b57cec5SDimitry Andric#error "libc++ does not support using GCC with C++03. Please enable C++11"
2270b57cec5SDimitry Andric#endif
2280b57cec5SDimitry Andric
2290b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This
2300b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume
2310b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
2320b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this
2330b57cec5SDimitry Andric// heuristic falls short.
2340b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2350b57cec5SDimitry Andric#  error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
2360b57cec5SDimitry Andric#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
2370b57cec5SDimitry Andric#  define _LIBCPP_ABI_ITANIUM
2380b57cec5SDimitry Andric#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2390b57cec5SDimitry Andric#  define _LIBCPP_ABI_MICROSOFT
2400b57cec5SDimitry Andric#else
2410b57cec5SDimitry Andric#  if defined(_WIN32) && defined(_MSC_VER)
2420b57cec5SDimitry Andric#    define _LIBCPP_ABI_MICROSOFT
2430b57cec5SDimitry Andric#  else
2440b57cec5SDimitry Andric#    define _LIBCPP_ABI_ITANIUM
2450b57cec5SDimitry Andric#  endif
2460b57cec5SDimitry Andric#endif
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
2490b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME
2500b57cec5SDimitry Andric#endif
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux.
2530b57cec5SDimitry Andric#if defined(__linux__)
2540b57cec5SDimitry Andric#  include <features.h>
2550b57cec5SDimitry Andric#  if defined(__GLIBC_PREREQ)
2560b57cec5SDimitry Andric#    define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
2570b57cec5SDimitry Andric#  else
2580b57cec5SDimitry Andric#    define _LIBCPP_GLIBC_PREREQ(a, b) 0
2590b57cec5SDimitry Andric#  endif // defined(__GLIBC_PREREQ)
2600b57cec5SDimitry Andric#endif // defined(__linux__)
2610b57cec5SDimitry Andric
26204eeddc0SDimitry Andric#if defined(__MVS__)
26304eeddc0SDimitry Andric#  include <features.h> // for __NATIVE_ASCII_F
26404eeddc0SDimitry Andric#endif
26504eeddc0SDimitry Andric
2660b57cec5SDimitry Andric#ifdef __LITTLE_ENDIAN__
2670b57cec5SDimitry Andric#  if __LITTLE_ENDIAN__
2680b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
2690b57cec5SDimitry Andric#  endif  // __LITTLE_ENDIAN__
2700b57cec5SDimitry Andric#endif // __LITTLE_ENDIAN__
2710b57cec5SDimitry Andric
2720b57cec5SDimitry Andric#ifdef __BIG_ENDIAN__
2730b57cec5SDimitry Andric#  if __BIG_ENDIAN__
2740b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
2750b57cec5SDimitry Andric#  endif  // __BIG_ENDIAN__
2760b57cec5SDimitry Andric#endif // __BIG_ENDIAN__
2770b57cec5SDimitry Andric
2780b57cec5SDimitry Andric#ifdef __BYTE_ORDER__
2790b57cec5SDimitry Andric#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
2800b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
2810b57cec5SDimitry Andric#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2820b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
2830b57cec5SDimitry Andric#  endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
2840b57cec5SDimitry Andric#endif // __BYTE_ORDER__
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andric#ifdef __FreeBSD__
2870b57cec5SDimitry Andric#  include <sys/endian.h>
2880b57cec5SDimitry Andric#  include <osreldate.h>
2890b57cec5SDimitry Andric#  if _BYTE_ORDER == _LITTLE_ENDIAN
2900b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
2910b57cec5SDimitry Andric#  else  // _BYTE_ORDER == _LITTLE_ENDIAN
2920b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
2930b57cec5SDimitry Andric#  endif  // _BYTE_ORDER == _LITTLE_ENDIAN
2940b57cec5SDimitry Andric#endif // __FreeBSD__
2950b57cec5SDimitry Andric
296e8d8bef9SDimitry Andric#if defined(__NetBSD__) || defined(__OpenBSD__)
2970b57cec5SDimitry Andric#  include <sys/endian.h>
2980b57cec5SDimitry Andric#  if _BYTE_ORDER == _LITTLE_ENDIAN
2990b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
3000b57cec5SDimitry Andric#  else  // _BYTE_ORDER == _LITTLE_ENDIAN
3010b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
3020b57cec5SDimitry Andric#  endif  // _BYTE_ORDER == _LITTLE_ENDIAN
303e8d8bef9SDimitry Andric#endif // defined(__NetBSD__) || defined(__OpenBSD__)
3040b57cec5SDimitry Andric
3050b57cec5SDimitry Andric#if defined(_WIN32)
3060b57cec5SDimitry Andric#  define _LIBCPP_WIN32API
3070b57cec5SDimitry Andric#  define _LIBCPP_LITTLE_ENDIAN
3080b57cec5SDimitry Andric#  define _LIBCPP_SHORT_WCHAR   1
3090b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment
3100b57cec5SDimitry Andric#  define _LIBCPP_MSVCRT_LIKE
3110b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if
3120b57cec5SDimitry Andric// a MS compatibility version is specified.
3130b57cec5SDimitry Andric#  if defined(_MSC_VER) && !defined(__MINGW32__)
3140b57cec5SDimitry Andric#    define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
3150b57cec5SDimitry Andric#  endif
3160b57cec5SDimitry Andric#  if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
3170b57cec5SDimitry Andric#    define _LIBCPP_HAS_BITSCAN64
3180b57cec5SDimitry Andric#  endif
3190b57cec5SDimitry Andric#  define _LIBCPP_HAS_OPEN_WITH_WCHAR
3200b57cec5SDimitry Andric#  if defined(_LIBCPP_MSVCRT)
3210b57cec5SDimitry Andric#    define _LIBCPP_HAS_QUICK_EXIT
3220b57cec5SDimitry Andric#  endif
3230b57cec5SDimitry Andric
3240b57cec5SDimitry Andric// Some CRT APIs are unavailable to store apps
3250b57cec5SDimitry Andric#  if defined(WINAPI_FAMILY)
3260b57cec5SDimitry Andric#    include <winapifamily.h>
3270b57cec5SDimitry Andric#    if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) &&                  \
3280b57cec5SDimitry Andric        (!defined(WINAPI_PARTITION_SYSTEM) ||                                  \
3290b57cec5SDimitry Andric         !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
3300b57cec5SDimitry Andric#      define _LIBCPP_WINDOWS_STORE_APP
3310b57cec5SDimitry Andric#    endif
3320b57cec5SDimitry Andric#  endif
3330b57cec5SDimitry Andric#endif // defined(_WIN32)
3340b57cec5SDimitry Andric
3350b57cec5SDimitry Andric#ifdef __sun__
3360b57cec5SDimitry Andric#  include <sys/isa_defs.h>
3370b57cec5SDimitry Andric#  ifdef _LITTLE_ENDIAN
3380b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
3390b57cec5SDimitry Andric#  else
3400b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
3410b57cec5SDimitry Andric#  endif
3420b57cec5SDimitry Andric#endif // __sun__
3430b57cec5SDimitry Andric
344349cc55cSDimitry Andric#if defined(_AIX) && !defined(__64BIT__)
345349cc55cSDimitry Andric   // The size of wchar is 2 byte on 32-bit mode on AIX.
346349cc55cSDimitry Andric#  define _LIBCPP_SHORT_WCHAR   1
347349cc55cSDimitry Andric#endif
348349cc55cSDimitry Andric
3490eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device.
3500eae32dcSDimitry Andric//
3510eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM
3520eae32dcSDimitry Andric//      Read entropy from the given file, by default `/dev/urandom`.
3530eae32dcSDimitry Andric//      If a token is provided, it is assumed to be the path to a file
3540eae32dcSDimitry Andric//      to read entropy from. This is the default behavior if nothing
3550eae32dcSDimitry Andric//      else is specified. This implementation requires storing state
3560eae32dcSDimitry Andric//      inside `std::random_device`.
3570eae32dcSDimitry Andric//
3580eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM
3590eae32dcSDimitry Andric//      Use arc4random(). This allows obtaining random data even when
3600eae32dcSDimitry Andric//      using sandboxing mechanisms. On some platforms like Apple, this
3610eae32dcSDimitry Andric//      is the recommended source of entropy for user-space programs.
3620eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
3630eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
3640eae32dcSDimitry Andric//
3650eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY
3660eae32dcSDimitry Andric//      Use getentropy().
3670eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
3680eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
3690eae32dcSDimitry Andric//
37004eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG
37104eeddc0SDimitry Andric//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
37204eeddc0SDimitry Andric//      deliver high-quality entropy and cannot fail.
37304eeddc0SDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
37404eeddc0SDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
37504eeddc0SDimitry Andric//
3760eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM
3770eae32dcSDimitry Andric//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
3780eae32dcSDimitry Andric//      including accesses to the special files under `/dev`. This implementation
3790eae32dcSDimitry Andric//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
3800eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
3810eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
3820eae32dcSDimitry Andric//
3830eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM
3840eae32dcSDimitry Andric//      Use rand_s(), for use on Windows.
3850eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
3860eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
38704eeddc0SDimitry Andric#if defined(__OpenBSD__) || defined(__APPLE__)
3880b57cec5SDimitry Andric#  define _LIBCPP_USING_ARC4_RANDOM
38904eeddc0SDimitry Andric#elif defined(__wasi__)
3900b57cec5SDimitry Andric#  define _LIBCPP_USING_GETENTROPY
39104eeddc0SDimitry Andric#elif defined(__Fuchsia__)
39204eeddc0SDimitry Andric#  define _LIBCPP_USING_FUCHSIA_CPRNG
3930b57cec5SDimitry Andric#elif defined(__native_client__)
3940b57cec5SDimitry Andric#  define _LIBCPP_USING_NACL_RANDOM
3950b57cec5SDimitry Andric#elif defined(_LIBCPP_WIN32API)
3960b57cec5SDimitry Andric#  define _LIBCPP_USING_WIN32_RANDOM
3970b57cec5SDimitry Andric#else
3980b57cec5SDimitry Andric#  define _LIBCPP_USING_DEV_RANDOM
3990b57cec5SDimitry Andric#endif
4000b57cec5SDimitry Andric
4010b57cec5SDimitry Andric#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
4020b57cec5SDimitry Andric#  include <endian.h>
4030b57cec5SDimitry Andric#  if __BYTE_ORDER == __LITTLE_ENDIAN
4040b57cec5SDimitry Andric#    define _LIBCPP_LITTLE_ENDIAN
4050b57cec5SDimitry Andric#  elif __BYTE_ORDER == __BIG_ENDIAN
4060b57cec5SDimitry Andric#    define _LIBCPP_BIG_ENDIAN
4070b57cec5SDimitry Andric#  else  // __BYTE_ORDER == __BIG_ENDIAN
4080b57cec5SDimitry Andric#    error unable to determine endian
4090b57cec5SDimitry Andric#  endif
4100b57cec5SDimitry Andric#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
4130b57cec5SDimitry Andric#  define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
4140b57cec5SDimitry Andric#else
4150b57cec5SDimitry Andric#  define _LIBCPP_NO_CFI
4160b57cec5SDimitry Andric#endif
4170b57cec5SDimitry Andric
4186e75b2fbSDimitry Andric// If the compiler supports using_if_exists, pretend we have those functions and they'll
4196e75b2fbSDimitry Andric// be picked up if the C library provides them.
4206e75b2fbSDimitry Andric//
4216e75b2fbSDimitry Andric// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
4226e75b2fbSDimitry Andric//       for platforms that don't have a conforming C11 library, so we can drop this whole thing.
4236e75b2fbSDimitry Andric#if __has_attribute(using_if_exists)
4246e75b2fbSDimitry Andric# define _LIBCPP_HAS_TIMESPEC_GET
4256e75b2fbSDimitry Andric# define _LIBCPP_HAS_QUICK_EXIT
4266e75b2fbSDimitry Andric# define _LIBCPP_HAS_ALIGNED_ALLOC
4276e75b2fbSDimitry Andric#else
428fe6060f1SDimitry Andric#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
4290b57cec5SDimitry Andric#  if defined(__FreeBSD__)
430480093f4SDimitry Andric#    define _LIBCPP_HAS_ALIGNED_ALLOC
4310b57cec5SDimitry Andric#    define _LIBCPP_HAS_QUICK_EXIT
43213138422SDimitry Andric#    if __FreeBSD_version >= 1300064 || \
43313138422SDimitry Andric       (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
43413138422SDimitry Andric#      define _LIBCPP_HAS_TIMESPEC_GET
43513138422SDimitry Andric#    endif
436480093f4SDimitry Andric#  elif defined(__BIONIC__)
437480093f4SDimitry Andric#    if __ANDROID_API__ >= 21
438480093f4SDimitry Andric#      define _LIBCPP_HAS_QUICK_EXIT
439480093f4SDimitry Andric#    endif
440480093f4SDimitry Andric#    if __ANDROID_API__ >= 28
441480093f4SDimitry Andric#      define _LIBCPP_HAS_ALIGNED_ALLOC
442480093f4SDimitry Andric#    endif
443480093f4SDimitry Andric#    if __ANDROID_API__ >= 29
444480093f4SDimitry Andric#      define _LIBCPP_HAS_TIMESPEC_GET
445480093f4SDimitry Andric#    endif
446480093f4SDimitry Andric#  elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
447480093f4SDimitry Andric#    define _LIBCPP_HAS_ALIGNED_ALLOC
4480b57cec5SDimitry Andric#    define _LIBCPP_HAS_QUICK_EXIT
4490b57cec5SDimitry Andric#    define _LIBCPP_HAS_TIMESPEC_GET
450e8d8bef9SDimitry Andric#  elif defined(__OpenBSD__)
451e8d8bef9SDimitry Andric#    define _LIBCPP_HAS_ALIGNED_ALLOC
452e8d8bef9SDimitry Andric#    define _LIBCPP_HAS_TIMESPEC_GET
4530b57cec5SDimitry Andric#  elif defined(__linux__)
4540b57cec5SDimitry Andric#    if !defined(_LIBCPP_HAS_MUSL_LIBC)
4550b57cec5SDimitry Andric#      if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
4560b57cec5SDimitry Andric#        define _LIBCPP_HAS_QUICK_EXIT
4570b57cec5SDimitry Andric#      endif
4580b57cec5SDimitry Andric#      if _LIBCPP_GLIBC_PREREQ(2, 17)
459480093f4SDimitry Andric#        define _LIBCPP_HAS_ALIGNED_ALLOC
4600b57cec5SDimitry Andric#        define _LIBCPP_HAS_TIMESPEC_GET
4610b57cec5SDimitry Andric#      endif
4620b57cec5SDimitry Andric#    else // defined(_LIBCPP_HAS_MUSL_LIBC)
463480093f4SDimitry Andric#      define _LIBCPP_HAS_ALIGNED_ALLOC
4640b57cec5SDimitry Andric#      define _LIBCPP_HAS_QUICK_EXIT
4650b57cec5SDimitry Andric#      define _LIBCPP_HAS_TIMESPEC_GET
4660b57cec5SDimitry Andric#    endif
467fe6060f1SDimitry Andric#  elif defined(_LIBCPP_MSVCRT)
468fe6060f1SDimitry Andric     // Using Microsoft's C Runtime library, not MinGW
469fe6060f1SDimitry Andric#    define _LIBCPP_HAS_TIMESPEC_GET
470e8d8bef9SDimitry Andric#  elif defined(__APPLE__)
471e8d8bef9SDimitry Andric     // timespec_get and aligned_alloc were introduced in macOS 10.15 and
472e8d8bef9SDimitry Andric     // aligned releases
473fe6060f1SDimitry Andric#    if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
474fe6060f1SDimitry Andric         (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
475fe6060f1SDimitry Andric         (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
476fe6060f1SDimitry Andric         (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
477e8d8bef9SDimitry Andric#      define _LIBCPP_HAS_ALIGNED_ALLOC
478e8d8bef9SDimitry Andric#      define _LIBCPP_HAS_TIMESPEC_GET
479e8d8bef9SDimitry Andric#    endif
480e8d8bef9SDimitry Andric#  endif // __APPLE__
4810b57cec5SDimitry Andric#endif
4826e75b2fbSDimitry Andric#endif // __has_attribute(using_if_exists)
4830b57cec5SDimitry Andric
4840b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4850b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
486fe6060f1SDimitry Andric#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
4870b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
4880b57cec5SDimitry Andric#else
489e8d8bef9SDimitry Andric# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang"
4900b57cec5SDimitry Andric#endif
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andric#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
4930b57cec5SDimitry Andric
494fe6060f1SDimitry Andric#if defined(_LIBCPP_COMPILER_CLANG_BASED)
4950b57cec5SDimitry Andric
4965ffd83dbSDimitry Andric#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
4975ffd83dbSDimitry Andric#  error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
4985ffd83dbSDimitry Andric#endif
4995ffd83dbSDimitry Andric#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) &&       \
5005ffd83dbSDimitry Andric    (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
5010b57cec5SDimitry Andric#  define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
5020b57cec5SDimitry Andric#endif
5030b57cec5SDimitry Andric
5040b57cec5SDimitry Andric#if __has_feature(cxx_alignas)
5050b57cec5SDimitry Andric#  define _ALIGNAS_TYPE(x) alignas(x)
5060b57cec5SDimitry Andric#  define _ALIGNAS(x) alignas(x)
5070b57cec5SDimitry Andric#else
5080b57cec5SDimitry Andric#  define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
5090b57cec5SDimitry Andric#  define _ALIGNAS(x) __attribute__((__aligned__(x)))
5100b57cec5SDimitry Andric#endif
5110b57cec5SDimitry Andric
5120b57cec5SDimitry Andric#if __cplusplus < 201103L
5130b57cec5SDimitry Andrictypedef __char16_t char16_t;
5140b57cec5SDimitry Andrictypedef __char32_t char32_t;
5150b57cec5SDimitry Andric#endif
5160b57cec5SDimitry Andric
5175ffd83dbSDimitry Andric#if !__has_feature(cxx_exceptions)
5180b57cec5SDimitry Andric#  define _LIBCPP_NO_EXCEPTIONS
5190b57cec5SDimitry Andric#endif
5200b57cec5SDimitry Andric
5210b57cec5SDimitry Andric#if !(__has_feature(cxx_strong_enums))
5220b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_STRONG_ENUMS
5230b57cec5SDimitry Andric#endif
5240b57cec5SDimitry Andric
5250b57cec5SDimitry Andric#if __has_feature(cxx_attributes)
5260b57cec5SDimitry Andric#  define _LIBCPP_NORETURN [[noreturn]]
5270b57cec5SDimitry Andric#else
5280b57cec5SDimitry Andric#  define _LIBCPP_NORETURN __attribute__ ((noreturn))
5290b57cec5SDimitry Andric#endif
5300b57cec5SDimitry Andric
5310b57cec5SDimitry Andric#if !(__has_feature(cxx_nullptr))
5320b57cec5SDimitry Andric#  if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
5330b57cec5SDimitry Andric#    define nullptr __nullptr
5340b57cec5SDimitry Andric#  else
5350b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_NULLPTR
5360b57cec5SDimitry Andric#  endif
5370b57cec5SDimitry Andric#endif
5380b57cec5SDimitry Andric
5390b57cec5SDimitry Andric// Objective-C++ features (opt-in)
5400b57cec5SDimitry Andric#if __has_feature(objc_arc)
5410b57cec5SDimitry Andric#define _LIBCPP_HAS_OBJC_ARC
5420b57cec5SDimitry Andric#endif
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andric#if __has_feature(objc_arc_weak)
5450b57cec5SDimitry Andric#define _LIBCPP_HAS_OBJC_ARC_WEAK
5460b57cec5SDimitry Andric#endif
5470b57cec5SDimitry Andric
5485ffd83dbSDimitry Andric#if __has_extension(blocks)
5495ffd83dbSDimitry Andric#  define _LIBCPP_HAS_EXTENSION_BLOCKS
5505ffd83dbSDimitry Andric#endif
5515ffd83dbSDimitry Andric
5525ffd83dbSDimitry Andric#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
5535ffd83dbSDimitry Andric#  define _LIBCPP_HAS_BLOCKS_RUNTIME
5545ffd83dbSDimitry Andric#endif
5555ffd83dbSDimitry Andric
5560b57cec5SDimitry Andric#if !(__has_feature(cxx_noexcept))
5570b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_NOEXCEPT
5580b57cec5SDimitry Andric#endif
5590b57cec5SDimitry Andric
560fe6060f1SDimitry Andric#if !__has_feature(address_sanitizer)
5610b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_ASAN
5620b57cec5SDimitry Andric#endif
5630b57cec5SDimitry Andric
5640b57cec5SDimitry Andric// Allow for build-time disabling of unsigned integer sanitization
565fe6060f1SDimitry Andric#if __has_attribute(no_sanitize)
5660b57cec5SDimitry Andric#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
5670b57cec5SDimitry Andric#endif
5680b57cec5SDimitry Andric
5690b57cec5SDimitry Andric#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
5700b57cec5SDimitry Andric
571e40139ffSDimitry Andric#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
572e40139ffSDimitry Andric
5730b57cec5SDimitry Andric#elif defined(_LIBCPP_COMPILER_GCC)
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andric#define _ALIGNAS(x) __attribute__((__aligned__(x)))
5760b57cec5SDimitry Andric#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
5770b57cec5SDimitry Andric
5780b57cec5SDimitry Andric#define _LIBCPP_NORETURN __attribute__((noreturn))
5790b57cec5SDimitry Andric
580fe6060f1SDimitry Andric#if !defined(__EXCEPTIONS)
5810b57cec5SDimitry Andric#  define _LIBCPP_NO_EXCEPTIONS
5820b57cec5SDimitry Andric#endif
5830b57cec5SDimitry Andric
584fe6060f1SDimitry Andric#if !defined(__SANITIZE_ADDRESS__)
5850b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_ASAN
5860b57cec5SDimitry Andric#endif
5870b57cec5SDimitry Andric
5880b57cec5SDimitry Andric#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
5890b57cec5SDimitry Andric
590e40139ffSDimitry Andric#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
591e40139ffSDimitry Andric
5920b57cec5SDimitry Andric#elif defined(_LIBCPP_COMPILER_MSVC)
5930b57cec5SDimitry Andric
5940b57cec5SDimitry Andric#define _LIBCPP_TOSTRING2(x) #x
5950b57cec5SDimitry Andric#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
5960b57cec5SDimitry Andric#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
5970b57cec5SDimitry Andric
5980b57cec5SDimitry Andric#if _MSC_VER < 1900
5990b57cec5SDimitry Andric#error "MSVC versions prior to Visual Studio 2015 are not supported"
6000b57cec5SDimitry Andric#endif
6010b57cec5SDimitry Andric
6020b57cec5SDimitry Andric#define __alignof__ __alignof
6030b57cec5SDimitry Andric#define _LIBCPP_NORETURN __declspec(noreturn)
6040b57cec5SDimitry Andric#define _ALIGNAS(x) __declspec(align(x))
6050b57cec5SDimitry Andric#define _ALIGNAS_TYPE(x) alignas(x)
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andric#define _LIBCPP_WEAK
6080b57cec5SDimitry Andric
6090b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_ASAN
6100b57cec5SDimitry Andric
6110b57cec5SDimitry Andric#define _LIBCPP_ALWAYS_INLINE __forceinline
6120b57cec5SDimitry Andric
6130b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
6140b57cec5SDimitry Andric
615e40139ffSDimitry Andric#define _LIBCPP_DISABLE_EXTENSION_WARNING
616e40139ffSDimitry Andric
6170b57cec5SDimitry Andric#elif defined(_LIBCPP_COMPILER_IBM)
6180b57cec5SDimitry Andric
6190b57cec5SDimitry Andric#define _ALIGNAS(x) __attribute__((__aligned__(x)))
6200b57cec5SDimitry Andric#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
6210b57cec5SDimitry Andric#define _ATTRIBUTE(x) __attribute__((x))
6220b57cec5SDimitry Andric#define _LIBCPP_NORETURN __attribute__((noreturn))
6230b57cec5SDimitry Andric
6240b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_UNICODE_CHARS
6250b57cec5SDimitry Andric
6260b57cec5SDimitry Andric#if defined(_AIX)
6270b57cec5SDimitry Andric#define __MULTILOCALE_API
6280b57cec5SDimitry Andric#endif
6290b57cec5SDimitry Andric
6300b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_ASAN
6310b57cec5SDimitry Andric
6320b57cec5SDimitry Andric#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
6330b57cec5SDimitry Andric
6340b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
6350b57cec5SDimitry Andric
636e40139ffSDimitry Andric#define _LIBCPP_DISABLE_EXTENSION_WARNING
637e40139ffSDimitry Andric
6380b57cec5SDimitry Andric#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
6390b57cec5SDimitry Andric
6400b57cec5SDimitry Andric#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
6410b57cec5SDimitry Andric
6420b57cec5SDimitry Andric#ifdef _DLL
6430b57cec5SDimitry Andric#  define _LIBCPP_CRT_FUNC __declspec(dllimport)
6440b57cec5SDimitry Andric#else
6450b57cec5SDimitry Andric#  define _LIBCPP_CRT_FUNC
6460b57cec5SDimitry Andric#endif
6470b57cec5SDimitry Andric
6480b57cec5SDimitry Andric#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
6490b57cec5SDimitry Andric#  define _LIBCPP_DLL_VIS
6500b57cec5SDimitry Andric#  define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
6510b57cec5SDimitry Andric#  define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
6520b57cec5SDimitry Andric#  define _LIBCPP_OVERRIDABLE_FUNC_VIS
6530b57cec5SDimitry Andric#  define _LIBCPP_EXPORTED_FROM_ABI
6540b57cec5SDimitry Andric#elif defined(_LIBCPP_BUILDING_LIBRARY)
6550b57cec5SDimitry Andric#  define _LIBCPP_DLL_VIS __declspec(dllexport)
6560b57cec5SDimitry Andric#  if defined(__MINGW32__)
6570b57cec5SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
6580b57cec5SDimitry Andric#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
6590b57cec5SDimitry Andric#  else
6600b57cec5SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
6610b57cec5SDimitry Andric#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
6620b57cec5SDimitry Andric#  endif
6630b57cec5SDimitry Andric#  define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
6640b57cec5SDimitry Andric#  define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
6650b57cec5SDimitry Andric#else
6660b57cec5SDimitry Andric#  define _LIBCPP_DLL_VIS __declspec(dllimport)
6670b57cec5SDimitry Andric#  define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
6680b57cec5SDimitry Andric#  define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
6690b57cec5SDimitry Andric#  define _LIBCPP_OVERRIDABLE_FUNC_VIS
6700b57cec5SDimitry Andric#  define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
6710b57cec5SDimitry Andric#endif
6720b57cec5SDimitry Andric
6730b57cec5SDimitry Andric#define _LIBCPP_TYPE_VIS            _LIBCPP_DLL_VIS
6740b57cec5SDimitry Andric#define _LIBCPP_FUNC_VIS            _LIBCPP_DLL_VIS
6750b57cec5SDimitry Andric#define _LIBCPP_EXCEPTION_ABI       _LIBCPP_DLL_VIS
6760b57cec5SDimitry Andric#define _LIBCPP_HIDDEN
6770b57cec5SDimitry Andric#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
6780b57cec5SDimitry Andric#define _LIBCPP_TEMPLATE_VIS
679fe6060f1SDimitry Andric#define _LIBCPP_TEMPLATE_DATA_VIS
6800b57cec5SDimitry Andric#define _LIBCPP_ENUM_VIS
6810b57cec5SDimitry Andric
6820b57cec5SDimitry Andric#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
6830b57cec5SDimitry Andric
6840b57cec5SDimitry Andric#ifndef _LIBCPP_HIDDEN
6850b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
6860b57cec5SDimitry Andric#    define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
6870b57cec5SDimitry Andric#  else
6880b57cec5SDimitry Andric#    define _LIBCPP_HIDDEN
6890b57cec5SDimitry Andric#  endif
6900b57cec5SDimitry Andric#endif
6910b57cec5SDimitry Andric
6920b57cec5SDimitry Andric#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
6930b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
6940b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved
6950b57cec5SDimitry Andric#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
6960b57cec5SDimitry Andric#  else
6970b57cec5SDimitry Andric#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
6980b57cec5SDimitry Andric#  endif
6990b57cec5SDimitry Andric#endif
7000b57cec5SDimitry Andric
7010b57cec5SDimitry Andric#ifndef _LIBCPP_FUNC_VIS
7020b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7030b57cec5SDimitry Andric#    define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
7040b57cec5SDimitry Andric#  else
7050b57cec5SDimitry Andric#    define _LIBCPP_FUNC_VIS
7060b57cec5SDimitry Andric#  endif
7070b57cec5SDimitry Andric#endif
7080b57cec5SDimitry Andric
7090b57cec5SDimitry Andric#ifndef _LIBCPP_TYPE_VIS
7100b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7110b57cec5SDimitry Andric#    define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
7120b57cec5SDimitry Andric#  else
7130b57cec5SDimitry Andric#    define _LIBCPP_TYPE_VIS
7140b57cec5SDimitry Andric#  endif
7150b57cec5SDimitry Andric#endif
7160b57cec5SDimitry Andric
7170b57cec5SDimitry Andric#ifndef _LIBCPP_TEMPLATE_VIS
7180b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7190b57cec5SDimitry Andric#    if __has_attribute(__type_visibility__)
7200b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
7210b57cec5SDimitry Andric#    else
7220b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
7230b57cec5SDimitry Andric#    endif
7240b57cec5SDimitry Andric#  else
7250b57cec5SDimitry Andric#    define _LIBCPP_TEMPLATE_VIS
7260b57cec5SDimitry Andric#  endif
7270b57cec5SDimitry Andric#endif
7280b57cec5SDimitry Andric
729fe6060f1SDimitry Andric#ifndef _LIBCPP_TEMPLATE_DATA_VIS
730fe6060f1SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
731fe6060f1SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
732fe6060f1SDimitry Andric#  else
733fe6060f1SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS
734fe6060f1SDimitry Andric#  endif
735fe6060f1SDimitry Andric#endif
736fe6060f1SDimitry Andric
7370b57cec5SDimitry Andric#ifndef _LIBCPP_EXPORTED_FROM_ABI
7380b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7390b57cec5SDimitry Andric#    define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
7400b57cec5SDimitry Andric#  else
7410b57cec5SDimitry Andric#    define _LIBCPP_EXPORTED_FROM_ABI
7420b57cec5SDimitry Andric#  endif
7430b57cec5SDimitry Andric#endif
7440b57cec5SDimitry Andric
7450b57cec5SDimitry Andric#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
7460b57cec5SDimitry Andric#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
7470b57cec5SDimitry Andric#endif
7480b57cec5SDimitry Andric
7490b57cec5SDimitry Andric#ifndef _LIBCPP_EXCEPTION_ABI
7500b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7510b57cec5SDimitry Andric#    define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
7520b57cec5SDimitry Andric#  else
7530b57cec5SDimitry Andric#    define _LIBCPP_EXCEPTION_ABI
7540b57cec5SDimitry Andric#  endif
7550b57cec5SDimitry Andric#endif
7560b57cec5SDimitry Andric
7570b57cec5SDimitry Andric#ifndef _LIBCPP_ENUM_VIS
7580b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
7590b57cec5SDimitry Andric#    define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
7600b57cec5SDimitry Andric#  else
7610b57cec5SDimitry Andric#    define _LIBCPP_ENUM_VIS
7620b57cec5SDimitry Andric#  endif
7630b57cec5SDimitry Andric#endif
7640b57cec5SDimitry Andric
7650b57cec5SDimitry Andric#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
766e8d8bef9SDimitry Andric#  if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
7670b57cec5SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
7680b57cec5SDimitry Andric#  else
7690b57cec5SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
7700b57cec5SDimitry Andric#  endif
7710b57cec5SDimitry Andric#endif
7720b57cec5SDimitry Andric
7730b57cec5SDimitry Andric#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
7740b57cec5SDimitry Andric#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
7750b57cec5SDimitry Andric#endif
7760b57cec5SDimitry Andric
7770b57cec5SDimitry Andric#if __has_attribute(internal_linkage)
7780b57cec5SDimitry Andric#  define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
7790b57cec5SDimitry Andric#else
7800b57cec5SDimitry Andric#  define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
7810b57cec5SDimitry Andric#endif
7820b57cec5SDimitry Andric
7830b57cec5SDimitry Andric#if __has_attribute(exclude_from_explicit_instantiation)
7840b57cec5SDimitry Andric#  define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
7850b57cec5SDimitry Andric#else
7860b57cec5SDimitry Andric   // Try to approximate the effect of exclude_from_explicit_instantiation
7870b57cec5SDimitry Andric   // (which is that entities are not assumed to be provided by explicit
7880b57cec5SDimitry Andric   // template instantiations in the dylib) by always inlining those entities.
7890b57cec5SDimitry Andric#  define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
7900b57cec5SDimitry Andric#endif
7910b57cec5SDimitry Andric
7920b57cec5SDimitry Andric#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
7930b57cec5SDimitry Andric#  ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
7940b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
7950b57cec5SDimitry Andric#  else
7960b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
7970b57cec5SDimitry Andric#  endif
7980b57cec5SDimitry Andric#endif
7990b57cec5SDimitry Andric
8000b57cec5SDimitry Andric#ifndef _LIBCPP_HIDE_FROM_ABI
8010b57cec5SDimitry Andric#  if _LIBCPP_HIDE_FROM_ABI_PER_TU
8020b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
8030b57cec5SDimitry Andric#  else
8040b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
8050b57cec5SDimitry Andric#  endif
8060b57cec5SDimitry Andric#endif
8070b57cec5SDimitry Andric
8080b57cec5SDimitry Andric#ifdef _LIBCPP_BUILDING_LIBRARY
8090b57cec5SDimitry Andric#  if _LIBCPP_ABI_VERSION > 1
8100b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
8110b57cec5SDimitry Andric#  else
8120b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
8130b57cec5SDimitry Andric#  endif
8140b57cec5SDimitry Andric#else
8150b57cec5SDimitry Andric#  define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
8160b57cec5SDimitry Andric#endif
8170b57cec5SDimitry Andric
8180b57cec5SDimitry Andric// Just so we can migrate to the new macros gradually.
8190b57cec5SDimitry Andric#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
8200b57cec5SDimitry Andric
8210b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
8220b57cec5SDimitry Andric#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
8230b57cec5SDimitry Andric#define _LIBCPP_END_NAMESPACE_STD  } }
8241fd87a68SDimitry Andric#define _VSTD std
8250b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
8260b57cec5SDimitry Andric
8271fd87a68SDimitry Andric#if _LIBCPP_STD_VER > 14
8280b57cec5SDimitry Andric#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
8290b57cec5SDimitry Andric  _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
8300b57cec5SDimitry Andric#else
8310b57cec5SDimitry Andric#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
8320b57cec5SDimitry Andric  _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
8330b57cec5SDimitry Andric#endif
8340b57cec5SDimitry Andric
8350b57cec5SDimitry Andric#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
8360b57cec5SDimitry Andric  _LIBCPP_END_NAMESPACE_STD } }
8370b57cec5SDimitry Andric
8380b57cec5SDimitry Andric#define _VSTD_FS _VSTD::__fs::filesystem
8390b57cec5SDimitry Andric
8400b57cec5SDimitry Andric#if __has_attribute(__enable_if__)
8410b57cec5SDimitry Andric#   define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
8420b57cec5SDimitry Andric#endif
8430b57cec5SDimitry Andric
8440b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_NOEXCEPT
8450b57cec5SDimitry Andric#  define _NOEXCEPT noexcept
8460b57cec5SDimitry Andric#  define _NOEXCEPT_(x) noexcept(x)
8470b57cec5SDimitry Andric#else
8480b57cec5SDimitry Andric#  define _NOEXCEPT throw()
8490b57cec5SDimitry Andric#  define _NOEXCEPT_(x)
8500b57cec5SDimitry Andric#endif
8510b57cec5SDimitry Andric
8520b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
8530b57cec5SDimitry Andrictypedef unsigned short char16_t;
8540b57cec5SDimitry Andrictypedef unsigned int   char32_t;
855349cc55cSDimitry Andric#endif
8560b57cec5SDimitry Andric
8570b57cec5SDimitry Andric#ifndef __SIZEOF_INT128__
8580b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_INT128
8590b57cec5SDimitry Andric#endif
8600b57cec5SDimitry Andric
8610b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
8620b57cec5SDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__)
8630b57cec5SDimitry Andric# define decltype(...) __decltype(__VA_ARGS__)
8640b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
8650b57cec5SDimitry Andric
8660b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
8670b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR
8680b57cec5SDimitry Andric#else
8690b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR constexpr
8700b57cec5SDimitry Andric#endif
8710b57cec5SDimitry Andric
872e8d8bef9SDimitry Andric#ifndef __cpp_consteval
873e8d8bef9SDimitry Andric#  define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
874e8d8bef9SDimitry Andric#else
875e8d8bef9SDimitry Andric#  define _LIBCPP_CONSTEVAL consteval
876e8d8bef9SDimitry Andric#endif
877e8d8bef9SDimitry Andric
8781fd87a68SDimitry Andric#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_concepts) || __cpp_concepts < 201907L
879fe6060f1SDimitry Andric#define _LIBCPP_HAS_NO_CONCEPTS
880fe6060f1SDimitry Andric#endif
881fe6060f1SDimitry Andric
8820b57cec5SDimitry Andric#ifdef __GNUC__
8830b57cec5SDimitry Andric#  define _LIBCPP_NOALIAS __attribute__((__malloc__))
8840b57cec5SDimitry Andric#else
8850b57cec5SDimitry Andric#  define _LIBCPP_NOALIAS
8860b57cec5SDimitry Andric#endif
8870b57cec5SDimitry Andric
888fe6060f1SDimitry Andric#if __has_attribute(using_if_exists)
889fe6060f1SDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
8900b57cec5SDimitry Andric#else
891fe6060f1SDimitry Andric# define _LIBCPP_USING_IF_EXISTS
8920b57cec5SDimitry Andric#endif
8930b57cec5SDimitry Andric
8940b57cec5SDimitry Andric#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
8950b57cec5SDimitry Andric#  define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
8960b57cec5SDimitry Andric#  define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
8970b57cec5SDimitry Andric     __lx __v_; \
8980b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
8990b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
9000b57cec5SDimitry Andric     _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
9010b57cec5SDimitry Andric     };
9020b57cec5SDimitry Andric#else  // _LIBCPP_HAS_NO_STRONG_ENUMS
9030b57cec5SDimitry Andric#  define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
9040b57cec5SDimitry Andric#  define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
9050b57cec5SDimitry Andric#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
9060b57cec5SDimitry Andric
907e8d8bef9SDimitry Andric// _LIBCPP_DEBUG potential values:
908e8d8bef9SDimitry Andric//  - undefined: No assertions. This is the default.
909e8d8bef9SDimitry Andric//  - 0:         Basic assertions
910349cc55cSDimitry Andric//  - 1:         Basic assertions + iterator validity checks + unspecified behavior randomization.
911e8d8bef9SDimitry Andric#  if !defined(_LIBCPP_DEBUG)
912e8d8bef9SDimitry Andric#    define _LIBCPP_DEBUG_LEVEL 0
913e8d8bef9SDimitry Andric#  elif _LIBCPP_DEBUG == 0
9140b57cec5SDimitry Andric#    define _LIBCPP_DEBUG_LEVEL 1
9150b57cec5SDimitry Andric#  elif _LIBCPP_DEBUG == 1
9160b57cec5SDimitry Andric#    define _LIBCPP_DEBUG_LEVEL 2
9170b57cec5SDimitry Andric#  else
9180b57cec5SDimitry Andric#    error Supported values for _LIBCPP_DEBUG are 0 and 1
9190b57cec5SDimitry Andric#  endif
9200b57cec5SDimitry Andric
921349cc55cSDimitry Andric#  if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
922349cc55cSDimitry Andric#    define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
923349cc55cSDimitry Andric#  endif
924349cc55cSDimitry Andric
925349cc55cSDimitry Andric#  if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
926349cc55cSDimitry Andric#    if defined(_LIBCPP_CXX03_LANG)
927349cc55cSDimitry Andric#      error Support for unspecified stability is only for C++11 and higher
928349cc55cSDimitry Andric#    endif
929349cc55cSDimitry Andric#    define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last)                                                             \
930349cc55cSDimitry Andric      do {                                                                                                             \
931349cc55cSDimitry Andric        if (!__builtin_is_constant_evaluated())                                                                        \
932349cc55cSDimitry Andric          _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer());                                                \
933349cc55cSDimitry Andric      } while (false)
934349cc55cSDimitry Andric#  else
935349cc55cSDimitry Andric#    define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last)                                                             \
936349cc55cSDimitry Andric      do {                                                                                                             \
937349cc55cSDimitry Andric      } while (false)
938349cc55cSDimitry Andric#  endif
939349cc55cSDimitry Andric
940fe6060f1SDimitry Andric// Libc++ allows disabling extern template instantiation declarations by
941fe6060f1SDimitry Andric// means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
942fe6060f1SDimitry Andric//
943fe6060f1SDimitry Andric// Furthermore, when the Debug mode is enabled, we disable extern declarations
944fe6060f1SDimitry Andric// when building user code because we don't want to use the functions compiled
945fe6060f1SDimitry Andric// in the library, which might not have had the debug mode enabled when built.
946fe6060f1SDimitry Andric// However, some extern declarations need to be used, because code correctness
947fe6060f1SDimitry Andric// depends on it (several instances in <locale>). Those special declarations
948fe6060f1SDimitry Andric// are declared with _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE, which is enabled
949fe6060f1SDimitry Andric// even when the debug mode is enabled.
950fe6060f1SDimitry Andric#if defined(_LIBCPP_DISABLE_EXTERN_TEMPLATE)
951fe6060f1SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
952fe6060f1SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) /* nothing */
953fe6060f1SDimitry Andric#elif _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_BUILDING_LIBRARY)
954fe6060f1SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
955e8d8bef9SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
956fe6060f1SDimitry Andric#else
957fe6060f1SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
958fe6060f1SDimitry Andric#   define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
9595ffd83dbSDimitry Andric#endif
9605ffd83dbSDimitry Andric
9610b57cec5SDimitry Andric#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
962349cc55cSDimitry Andric    defined(__sun__) || defined(__NetBSD__)
9630b57cec5SDimitry Andric#define _LIBCPP_LOCALE__L_EXTENSIONS 1
9640b57cec5SDimitry Andric#endif
9650b57cec5SDimitry Andric
9660b57cec5SDimitry Andric#ifdef __FreeBSD__
9670b57cec5SDimitry Andric#define _DECLARE_C99_LDBL_MATH 1
9680b57cec5SDimitry Andric#endif
9690b57cec5SDimitry Andric
9700b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads
9710b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
9720b57cec5SDimitry Andric#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
9730b57cec5SDimitry Andric#  define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
9740b57cec5SDimitry Andric#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
9750b57cec5SDimitry Andric   // We're deferring to Microsoft's STL to provide aligned new et al. We don't
9760b57cec5SDimitry Andric   // have it unless the language feature test macro is defined.
9770b57cec5SDimitry Andric#  define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
978e8d8bef9SDimitry Andric#elif defined(__MVS__)
979e8d8bef9SDimitry Andric#  define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
9800b57cec5SDimitry Andric#endif
9810b57cec5SDimitry Andric
982fe6060f1SDimitry Andric#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
983fe6060f1SDimitry Andric    (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
9840b57cec5SDimitry Andric#  define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
9850b57cec5SDimitry Andric#endif
9860b57cec5SDimitry Andric
9870b57cec5SDimitry Andric#if defined(__APPLE__) || defined(__FreeBSD__)
9880b57cec5SDimitry Andric#define _LIBCPP_HAS_DEFAULTRUNELOCALE
9890b57cec5SDimitry Andric#endif
9900b57cec5SDimitry Andric
9910b57cec5SDimitry Andric#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
9920b57cec5SDimitry Andric#define _LIBCPP_WCTYPE_IS_MASK
9930b57cec5SDimitry Andric#endif
9940b57cec5SDimitry Andric
9950b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
996fe6060f1SDimitry Andric#define _LIBCPP_HAS_NO_CHAR8_T
9970b57cec5SDimitry Andric#endif
9980b57cec5SDimitry Andric
9990b57cec5SDimitry Andric// Deprecation macros.
10000b57cec5SDimitry Andric//
10010b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out
10020b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
10030b57cec5SDimitry Andric#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
10040b57cec5SDimitry Andric#  if __has_attribute(deprecated)
10050b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
10060b57cec5SDimitry Andric#  elif _LIBCPP_STD_VER > 11
10070b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED [[deprecated]]
10080b57cec5SDimitry Andric#  else
10090b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED
10100b57cec5SDimitry Andric#  endif
10110b57cec5SDimitry Andric#else
10120b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED
10130b57cec5SDimitry Andric#endif
10140b57cec5SDimitry Andric
10150b57cec5SDimitry Andric#if !defined(_LIBCPP_CXX03_LANG)
10160b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
10170b57cec5SDimitry Andric#else
10180b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX11
10190b57cec5SDimitry Andric#endif
10200b57cec5SDimitry Andric
10210b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
10220b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
10230b57cec5SDimitry Andric#else
10240b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX14
10250b57cec5SDimitry Andric#endif
10260b57cec5SDimitry Andric
10270b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 17
10280b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
10290b57cec5SDimitry Andric#else
10300b57cec5SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX17
10310b57cec5SDimitry Andric#endif
10320b57cec5SDimitry Andric
1033e8d8bef9SDimitry Andric#if _LIBCPP_STD_VER > 17
1034e8d8bef9SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1035e8d8bef9SDimitry Andric#else
1036e8d8bef9SDimitry Andric#  define _LIBCPP_DEPRECATED_IN_CXX20
1037e8d8bef9SDimitry Andric#endif
1038e8d8bef9SDimitry Andric
1039fe6060f1SDimitry Andric#if !defined(_LIBCPP_HAS_NO_CHAR8_T)
1040e8d8bef9SDimitry Andric#  define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1041e8d8bef9SDimitry Andric#else
1042e8d8bef9SDimitry Andric#  define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1043e8d8bef9SDimitry Andric#endif
1044e8d8bef9SDimitry Andric
1045e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed.
1046fe6060f1SDimitry Andric#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1047e40139ffSDimitry Andric#   define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
1048e40139ffSDimitry Andric        _Pragma("GCC diagnostic push") \
1049fe6060f1SDimitry Andric        _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
1050fe6060f1SDimitry Andric        _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1051e40139ffSDimitry Andric#   define _LIBCPP_SUPPRESS_DEPRECATED_POP \
1052e40139ffSDimitry Andric        _Pragma("GCC diagnostic pop")
1053fe6060f1SDimitry Andric#else
1054e40139ffSDimitry Andric#   define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1055e40139ffSDimitry Andric#   define _LIBCPP_SUPPRESS_DEPRECATED_POP
1056e40139ffSDimitry Andric#endif
1057e40139ffSDimitry Andric
10580b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 11
10590b57cec5SDimitry Andric#  define _LIBCPP_EXPLICIT_AFTER_CXX11
10600b57cec5SDimitry Andric#else
10610b57cec5SDimitry Andric#  define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
10620b57cec5SDimitry Andric#endif
10630b57cec5SDimitry Andric
1064349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 11
10650b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
10660b57cec5SDimitry Andric#else
10670b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX11
10680b57cec5SDimitry Andric#endif
10690b57cec5SDimitry Andric
1070349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 14
10710b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
10720b57cec5SDimitry Andric#else
10730b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX14
10740b57cec5SDimitry Andric#endif
10750b57cec5SDimitry Andric
1076349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 17
10770b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
10780b57cec5SDimitry Andric#else
10790b57cec5SDimitry Andric#  define _LIBCPP_CONSTEXPR_AFTER_CXX17
10800b57cec5SDimitry Andric#endif
10810b57cec5SDimitry Andric
10820b57cec5SDimitry Andric#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
1083349cc55cSDimitry Andric#  define _LIBCPP_NODISCARD [[nodiscard]]
1084fe6060f1SDimitry Andric#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
1085349cc55cSDimitry Andric#  define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
10860b57cec5SDimitry Andric#else
10870b57cec5SDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and
10880b57cec5SDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via
10890b57cec5SDimitry Andric// (void) cast.
1090349cc55cSDimitry Andric#  define _LIBCPP_NODISCARD
10910b57cec5SDimitry Andric#endif
10920b57cec5SDimitry Andric
10930b57cec5SDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
10940b57cec5SDimitry Andric// specified as such as an extension.
10950b57cec5SDimitry Andric#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1096349cc55cSDimitry Andric#  define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
10970b57cec5SDimitry Andric#else
10980b57cec5SDimitry Andric#  define _LIBCPP_NODISCARD_EXT
10990b57cec5SDimitry Andric#endif
11000b57cec5SDimitry Andric
11010b57cec5SDimitry Andric#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
11020b57cec5SDimitry Andric    (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
1103349cc55cSDimitry Andric#  define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
11040b57cec5SDimitry Andric#else
11050b57cec5SDimitry Andric#  define _LIBCPP_NODISCARD_AFTER_CXX17
11060b57cec5SDimitry Andric#endif
11070b57cec5SDimitry Andric
11080b57cec5SDimitry Andric#if __has_attribute(no_destroy)
11090b57cec5SDimitry Andric#  define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
11100b57cec5SDimitry Andric#else
11110b57cec5SDimitry Andric#  define _LIBCPP_NO_DESTROY
11120b57cec5SDimitry Andric#endif
11130b57cec5SDimitry Andric
11140b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
1115e8d8bef9SDimitry Andricextern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
11160b57cec5SDimitry Andric  const void *, const void *, const void *, const void *);
11170b57cec5SDimitry Andric#endif
11180b57cec5SDimitry Andric
11190b57cec5SDimitry Andric// Try to find out if RTTI is disabled.
1120fe6060f1SDimitry Andric#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
11215ffd83dbSDimitry Andric#  define _LIBCPP_NO_RTTI
11225ffd83dbSDimitry Andric#elif defined(__GNUC__) && !defined(__GXX_RTTI)
11230b57cec5SDimitry Andric#  define _LIBCPP_NO_RTTI
11240b57cec5SDimitry Andric#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
11250b57cec5SDimitry Andric#  define _LIBCPP_NO_RTTI
11260b57cec5SDimitry Andric#endif
11270b57cec5SDimitry Andric
11280b57cec5SDimitry Andric#ifndef _LIBCPP_WEAK
11290b57cec5SDimitry Andric#define _LIBCPP_WEAK __attribute__((__weak__))
11300b57cec5SDimitry Andric#endif
11310b57cec5SDimitry Andric
11320b57cec5SDimitry Andric// Thread API
11330b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_THREADS) && \
11340b57cec5SDimitry Andric    !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
11350b57cec5SDimitry Andric    !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
11360b57cec5SDimitry Andric    !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
11370b57cec5SDimitry Andric#  if defined(__FreeBSD__) || \
11380b57cec5SDimitry Andric      defined(__wasi__) || \
11390b57cec5SDimitry Andric      defined(__NetBSD__) || \
1140e8d8bef9SDimitry Andric      defined(__OpenBSD__) || \
1141e8d8bef9SDimitry Andric      defined(__NuttX__) || \
11420b57cec5SDimitry Andric      defined(__linux__) || \
11430b57cec5SDimitry Andric      defined(__GNU__) || \
11440b57cec5SDimitry Andric      defined(__APPLE__) || \
11450b57cec5SDimitry Andric      defined(__sun__) || \
1146e8d8bef9SDimitry Andric      defined(__MVS__) || \
1147349cc55cSDimitry Andric      defined(_AIX)
11480b57cec5SDimitry Andric#    define _LIBCPP_HAS_THREAD_API_PTHREAD
1149480093f4SDimitry Andric#  elif defined(__Fuchsia__)
11505ffd83dbSDimitry Andric     // TODO(44575): Switch to C11 thread API when possible.
11515ffd83dbSDimitry Andric#    define _LIBCPP_HAS_THREAD_API_PTHREAD
11520b57cec5SDimitry Andric#  elif defined(_LIBCPP_WIN32API)
11530b57cec5SDimitry Andric#    define _LIBCPP_HAS_THREAD_API_WIN32
11540b57cec5SDimitry Andric#  else
11550b57cec5SDimitry Andric#    error "No thread API"
11560b57cec5SDimitry Andric#  endif // _LIBCPP_HAS_THREAD_API
11570b57cec5SDimitry Andric#endif // _LIBCPP_HAS_NO_THREADS
11580b57cec5SDimitry Andric
1159e40139ffSDimitry Andric#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1160e40139ffSDimitry Andric#if defined(__ANDROID__) && __ANDROID_API__ >= 30
1161e40139ffSDimitry Andric#define _LIBCPP_HAS_COND_CLOCKWAIT
1162e40139ffSDimitry Andric#elif defined(_LIBCPP_GLIBC_PREREQ)
1163e40139ffSDimitry Andric#if _LIBCPP_GLIBC_PREREQ(2, 30)
1164e40139ffSDimitry Andric#define _LIBCPP_HAS_COND_CLOCKWAIT
1165e40139ffSDimitry Andric#endif
1166e40139ffSDimitry Andric#endif
1167e40139ffSDimitry Andric#endif
1168e40139ffSDimitry Andric
11690b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
11700b57cec5SDimitry Andric#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
11710b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is not defined.
11720b57cec5SDimitry Andric#endif
11730b57cec5SDimitry Andric
11740b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
11750b57cec5SDimitry Andric#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
11760b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
11770b57cec5SDimitry Andric#endif
11780b57cec5SDimitry Andric
11790b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
11800b57cec5SDimitry Andric#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
11810b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
11820b57cec5SDimitry Andric#endif
11830b57cec5SDimitry Andric
1184e40139ffSDimitry Andric#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1185e40139ffSDimitry Andric#define __STDCPP_THREADS__ 1
1186e40139ffSDimitry Andric#endif
1187e40139ffSDimitry Andric
1188e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements
11890b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
11900b57cec5SDimitry Andric// mutexes have no destroy mechanism.
1191e40139ffSDimitry Andric//
1192e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
1193e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources.
1194e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
1195e40139ffSDimitry Andric//
1196e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1197e40139ffSDimitry Andric//               respective stakeholders.
11980b57cec5SDimitry Andric#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
1199480093f4SDimitry Andric  || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \
12000b57cec5SDimitry Andric  || defined(_LIBCPP_HAS_THREAD_API_WIN32)
12010b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
12020b57cec5SDimitry Andric#endif
12030b57cec5SDimitry Andric
12040b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows.
1205e40139ffSDimitry Andric//
1206e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
1207e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources.
1208e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
1209e40139ffSDimitry Andric//
12100b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations
12110b57cec5SDimitry Andric// as well.
1212480093f4SDimitry Andric#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1213480093f4SDimitry Andric     defined(_LIBCPP_HAS_THREAD_API_WIN32)
12140b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
12150b57cec5SDimitry Andric#endif
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons.
12180b57cec5SDimitry Andric#if defined(_LIBCPP_MSVCRT) || \
1219e8d8bef9SDimitry Andric    (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
1220e8d8bef9SDimitry Andric    defined(__OpenBSD__)
12210b57cec5SDimitry Andric#   define _LIBCPP_C_HAS_NO_GETS
12220b57cec5SDimitry Andric#endif
12230b57cec5SDimitry Andric
1224349cc55cSDimitry Andric#if defined(__BIONIC__) || defined(__NuttX__) ||           \
122504eeddc0SDimitry Andric    defined(__Fuchsia__) || defined(__wasi__) ||           \
122604eeddc0SDimitry Andric    defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
12270b57cec5SDimitry Andric#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
12280b57cec5SDimitry Andric#endif
12290b57cec5SDimitry Andric
12300b57cec5SDimitry Andric#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
12310b57cec5SDimitry Andric#  define _LIBCPP_HAS_C_ATOMIC_IMP
12320b57cec5SDimitry Andric#elif defined(_LIBCPP_COMPILER_GCC)
12330b57cec5SDimitry Andric#  define _LIBCPP_HAS_GCC_ATOMIC_IMP
12340b57cec5SDimitry Andric#endif
12350b57cec5SDimitry Andric
1236349cc55cSDimitry Andric#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
12370b57cec5SDimitry Andric    !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1238349cc55cSDimitry Andric    !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
12390b57cec5SDimitry Andric#  define _LIBCPP_HAS_NO_ATOMIC_HEADER
12400b57cec5SDimitry Andric#else
12410b57cec5SDimitry Andric#  ifndef _LIBCPP_ATOMIC_FLAG_TYPE
12420b57cec5SDimitry Andric#    define _LIBCPP_ATOMIC_FLAG_TYPE bool
12430b57cec5SDimitry Andric#  endif
12440b57cec5SDimitry Andric#  ifdef _LIBCPP_FREESTANDING
12450b57cec5SDimitry Andric#    define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
12460b57cec5SDimitry Andric#  endif
12470b57cec5SDimitry Andric#endif
12480b57cec5SDimitry Andric
12490b57cec5SDimitry Andric#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
12500b57cec5SDimitry Andric#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
12510b57cec5SDimitry Andric#endif
12520b57cec5SDimitry Andric
12530b57cec5SDimitry Andric#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
12540b57cec5SDimitry Andric#  if defined(__clang__) && __has_attribute(acquire_capability)
12550b57cec5SDimitry Andric// Work around the attribute handling in clang.  When both __declspec and
12560b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition
12571fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
12581fd87a68SDimitry Andric// combining the two does work.
12591fd87a68SDimitry Andric#    if !defined(_MSC_VER)
12600b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
12610b57cec5SDimitry Andric#    endif
12620b57cec5SDimitry Andric#  endif
12630b57cec5SDimitry Andric#endif
12640b57cec5SDimitry Andric
1265480093f4SDimitry Andric#ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1266480093f4SDimitry Andric#   define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1267480093f4SDimitry Andric#else
1268480093f4SDimitry Andric#   define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1269480093f4SDimitry Andric#endif
1270480093f4SDimitry Andric
12710b57cec5SDimitry Andric#if __has_attribute(require_constant_initialization)
12720b57cec5SDimitry Andric#  define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
12730b57cec5SDimitry Andric#else
12740b57cec5SDimitry Andric#  define _LIBCPP_SAFE_STATIC
12750b57cec5SDimitry Andric#endif
12760b57cec5SDimitry Andric
12770b57cec5SDimitry Andric#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
12780b57cec5SDimitry Andric#  define _LIBCPP_DIAGNOSE_WARNING(...) \
12790b57cec5SDimitry Andric     __attribute__((diagnose_if(__VA_ARGS__, "warning")))
12800b57cec5SDimitry Andric#  define _LIBCPP_DIAGNOSE_ERROR(...) \
12810b57cec5SDimitry Andric     __attribute__((diagnose_if(__VA_ARGS__, "error")))
12820b57cec5SDimitry Andric#else
12830b57cec5SDimitry Andric#  define _LIBCPP_DIAGNOSE_WARNING(...)
12840b57cec5SDimitry Andric#  define _LIBCPP_DIAGNOSE_ERROR(...)
12850b57cec5SDimitry Andric#endif
12860b57cec5SDimitry Andric
12870b57cec5SDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon
12880b57cec5SDimitry Andric#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
12890b57cec5SDimitry Andric#  define _LIBCPP_FALLTHROUGH() [[fallthrough]]
12900b57cec5SDimitry Andric#elif __has_cpp_attribute(clang::fallthrough)
12910b57cec5SDimitry Andric#  define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
1292349cc55cSDimitry Andric#elif __has_attribute(__fallthrough__)
12930b57cec5SDimitry Andric#  define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
12940b57cec5SDimitry Andric#else
12950b57cec5SDimitry Andric#  define _LIBCPP_FALLTHROUGH() ((void)0)
12960b57cec5SDimitry Andric#endif
12970b57cec5SDimitry Andric
12980b57cec5SDimitry Andric#if __has_attribute(__nodebug__)
12990b57cec5SDimitry Andric#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
13000b57cec5SDimitry Andric#else
13010b57cec5SDimitry Andric#define _LIBCPP_NODEBUG
13020b57cec5SDimitry Andric#endif
13030b57cec5SDimitry Andric
1304fe6060f1SDimitry Andric#if __has_attribute(__standalone_debug__)
1305fe6060f1SDimitry Andric#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1306fe6060f1SDimitry Andric#else
1307fe6060f1SDimitry Andric#define _LIBCPP_STANDALONE_DEBUG
1308fe6060f1SDimitry Andric#endif
13090b57cec5SDimitry Andric
1310e8d8bef9SDimitry Andric#if __has_attribute(__preferred_name__)
1311e8d8bef9SDimitry Andric#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1312e8d8bef9SDimitry Andric#else
1313e8d8bef9SDimitry Andric#define _LIBCPP_PREFERRED_NAME(x)
1314e8d8bef9SDimitry Andric#endif
1315e8d8bef9SDimitry Andric
1316349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library.
1317349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of
1318349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger
1319349cc55cSDimitry Andric// impact on readability.
1320349cc55cSDimitry Andric#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1321349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1322349cc55cSDimitry Andric#else
1323349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1324349cc55cSDimitry Andric#endif
1325349cc55cSDimitry Andric
13260b57cec5SDimitry Andric#if defined(_LIBCPP_ABI_MICROSOFT) && \
13270b57cec5SDimitry Andric    (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
13280b57cec5SDimitry Andric#  define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
13290b57cec5SDimitry Andric#else
13300b57cec5SDimitry Andric#  define _LIBCPP_DECLSPEC_EMPTY_BASES
13310b57cec5SDimitry Andric#endif
13320b57cec5SDimitry Andric
13330b57cec5SDimitry Andric#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
13340b57cec5SDimitry Andric#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
13350b57cec5SDimitry Andric#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1336fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1337fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
13380b57cec5SDimitry Andric#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
13390b57cec5SDimitry Andric
1340fe6060f1SDimitry Andric#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1341fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1342fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1343fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1344fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1345fe6060f1SDimitry Andric#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1346fe6060f1SDimitry Andric#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1347fe6060f1SDimitry Andric
1348349cc55cSDimitry Andric#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1349349cc55cSDimitry Andric#define _LIBCPP_HAS_NO_CXX20_COROUTINES
135055e4f9d5SDimitry Andric#endif
13510b57cec5SDimitry Andric
13520b57cec5SDimitry Andric#if defined(_LIBCPP_COMPILER_IBM)
13530b57cec5SDimitry Andric#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
13540b57cec5SDimitry Andric#endif
13550b57cec5SDimitry Andric
13560b57cec5SDimitry Andric#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
13570b57cec5SDimitry Andric#  define _LIBCPP_PUSH_MACROS
13580b57cec5SDimitry Andric#  define _LIBCPP_POP_MACROS
13590b57cec5SDimitry Andric#else
13600b57cec5SDimitry Andric  // Don't warn about macro conflicts when we can restore them at the
13610b57cec5SDimitry Andric  // end of the header.
13620b57cec5SDimitry Andric#  ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
13630b57cec5SDimitry Andric#    define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
13640b57cec5SDimitry Andric#  endif
13650b57cec5SDimitry Andric#  if defined(_LIBCPP_COMPILER_MSVC)
13660b57cec5SDimitry Andric#    define _LIBCPP_PUSH_MACROS    \
13670b57cec5SDimitry Andric       __pragma(push_macro("min")) \
13680b57cec5SDimitry Andric       __pragma(push_macro("max"))
13690b57cec5SDimitry Andric#    define _LIBCPP_POP_MACROS     \
13700b57cec5SDimitry Andric       __pragma(pop_macro("min"))  \
13710b57cec5SDimitry Andric       __pragma(pop_macro("max"))
13720b57cec5SDimitry Andric#  else
13730b57cec5SDimitry Andric#    define _LIBCPP_PUSH_MACROS        \
13740b57cec5SDimitry Andric       _Pragma("push_macro(\"min\")")  \
13750b57cec5SDimitry Andric       _Pragma("push_macro(\"max\")")
13760b57cec5SDimitry Andric#    define _LIBCPP_POP_MACROS         \
13770b57cec5SDimitry Andric       _Pragma("pop_macro(\"min\")")   \
13780b57cec5SDimitry Andric       _Pragma("pop_macro(\"max\")")
13790b57cec5SDimitry Andric#  endif
13800b57cec5SDimitry Andric#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
13810b57cec5SDimitry Andric
13820b57cec5SDimitry Andric#ifndef _LIBCPP_NO_AUTO_LINK
13830b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1384fe6060f1SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
13850b57cec5SDimitry Andric#      pragma comment(lib, "c++.lib")
13860b57cec5SDimitry Andric#    else
13870b57cec5SDimitry Andric#      pragma comment(lib, "libc++.lib")
13880b57cec5SDimitry Andric#    endif
13890b57cec5SDimitry Andric#  endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
13900b57cec5SDimitry Andric#endif // _LIBCPP_NO_AUTO_LINK
13910b57cec5SDimitry Andric
1392e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will
1393e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen.
1394e40139ffSDimitry Andric//
1395e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1396e40139ffSDimitry Andric// do.
1397e40139ffSDimitry Andric#if defined(__BIONIC__)
1398e40139ffSDimitry Andric#  define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1399e40139ffSDimitry Andric#else
1400e40139ffSDimitry Andric#  define _LIBCPP_FOPEN_CLOEXEC_MODE
1401e40139ffSDimitry Andric#endif
1402e40139ffSDimitry Andric
14035ffd83dbSDimitry Andric// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
14045ffd83dbSDimitry Andric// of functions used in cstdio may not be available for low API levels when
14055ffd83dbSDimitry Andric// using 64-bit file offsets on LP32.
14065ffd83dbSDimitry Andric#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
14075ffd83dbSDimitry Andric#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
14085ffd83dbSDimitry Andric#endif
14095ffd83dbSDimitry Andric
1410e8d8bef9SDimitry Andric#if __has_attribute(init_priority)
1411349cc55cSDimitry Andric    // TODO: Remove this once we drop support for building libc++ with old Clangs
1412349cc55cSDimitry Andric#   if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1413349cc55cSDimitry Andric       (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1414e8d8bef9SDimitry Andric#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1415e8d8bef9SDimitry Andric#   else
1416349cc55cSDimitry Andric#     define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1417349cc55cSDimitry Andric#   endif
1418349cc55cSDimitry Andric#else
1419e8d8bef9SDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX
1420e8d8bef9SDimitry Andric#endif
1421e8d8bef9SDimitry Andric
1422fe6060f1SDimitry Andric#if defined(__GNUC__) || defined(__clang__)
14234824e7fdSDimitry Andric  // The attribute uses 1-based indices for ordinary and static member functions.
14244824e7fdSDimitry Andric  // The attribute uses 2-based indices for non-static member functions.
14254824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
14264824e7fdSDimitry Andric    __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1427fe6060f1SDimitry Andric#else
14284824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1429fe6060f1SDimitry Andric#endif
1430fe6060f1SDimitry Andric
14310b57cec5SDimitry Andric#endif // __cplusplus
14320b57cec5SDimitry Andric
14330b57cec5SDimitry Andric#endif // _LIBCPP_CONFIG
1434