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 1081ad6265SDimitry Andric#ifndef _LIBCPP___CONFIG 1181ad6265SDimitry 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 256246ae0bSDimitry Andric#if defined(__apple_build_version__) 261ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 276246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 286246ae0bSDimitry Andric# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 296246ae0bSDimitry Andric#elif defined(__clang__) 306246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 316246ae0bSDimitry Andric# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 326246ae0bSDimitry Andric#elif defined(__GNUC__) 336246ae0bSDimitry Andric# define _LIBCPP_COMPILER_GCC 346246ae0bSDimitry Andric#endif 356246ae0bSDimitry Andric 360b57cec5SDimitry Andric#ifdef __cplusplus 370b57cec5SDimitry Andric 3806c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 3906c3fb27SDimitry Andric 40bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 4106c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 42bdd1243dSDimitry Andric// defined to XXYYZZ. 43*b121cb00SDimitry Andric# define _LIBCPP_VERSION 170005 440b57cec5SDimitry Andric 45753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 46753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 47753f127fSDimitry Andric 48e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 490b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 500b57cec5SDimitry Andric# endif 510b57cec5SDimitry Andric 5206c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check) 530b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 540b57cec5SDimitry Andric# if __cplusplus <= 201103L 550b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 560b57cec5SDimitry Andric# elif __cplusplus <= 201402L 570b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 580b57cec5SDimitry Andric# elif __cplusplus <= 201703L 590b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 60e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 61e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 6206c3fb27SDimitry Andric# elif __cplusplus <= 202302L 6306c3fb27SDimitry Andric# define _LIBCPP_STD_VER 23 640b57cec5SDimitry Andric# else 65bdd1243dSDimitry Andric// Expected release year of the next C++ standard 6606c3fb27SDimitry Andric# define _LIBCPP_STD_VER 26 670b57cec5SDimitry Andric# endif 680b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 6906c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check) 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric# if defined(__ELF__) 720b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 730b57cec5SDimitry Andric# elif defined(__MACH__) 740b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 750b57cec5SDimitry Andric# elif defined(_WIN32) 760b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 770b57cec5SDimitry Andric# elif defined(__wasm__) 780b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 7981ad6265SDimitry Andric# elif defined(_AIX) 8081ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 810b57cec5SDimitry Andric# else 82e8d8bef9SDimitry Andric// ... add new file formats here ... 830b57cec5SDimitry Andric# endif 840b57cec5SDimitry Andric 8506c3fb27SDimitry Andric// ABI { 8606c3fb27SDimitry Andric 8781ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 880b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 890b57cec5SDimitry Andric// improving its alignment in some cases. 900b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 910b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 920b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 930b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 940b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 950b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 960b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 970b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 980b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 990b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 1000b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 1010b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 1020b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 1030b57cec5SDimitry Andric// using that class define their own copies. 1040b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 105349cc55cSDimitry Andric// Override the default return value of exception::what() for 106349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 107349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 108349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 109349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1100b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1110b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 112fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 113fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 114fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1150b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1160b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1170b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1180b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1190b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1200b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1210b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1225ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1235ffd83dbSDimitry Andric// performance and fast-path inlining. 1245ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 125e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 126e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 127e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 128e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 12904eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 13004eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 13104eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 13204eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 13304eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 13404eeddc0SDimitry Andric// about ABI compatibility. 13504eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 13681ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1371838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 13881ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 139d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 14081ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 14181ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 1421ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 1431ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 1441ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 1451ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 1461ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 1471ac55f4cSDimitry Andric// 1481ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 1491ac55f4cSDimitry Andric// bits on the floor. 1501ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 15181ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 15281ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 15381ad6265SDimitry Andric// the dylib for backwards compatibility. 15481ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 1550b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 15681ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1570b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1580b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1590b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1600b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 16181ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 16281ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 16381ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 16481ad6265SDimitry Andric// so disable it. 1650b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1660b57cec5SDimitry Andric# endif 1670b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1680b57cec5SDimitry Andric// are deprecated. 1690b57cec5SDimitry Andric# if defined(__FreeBSD__) 1700b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1710b57cec5SDimitry Andric# endif 17206c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 17306c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 17406c3fb27SDimitry Andric// in the library, so we need to always rely on the library version. 17506c3fb27SDimitry Andric# if defined(_AIX) 17606c3fb27SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 17706c3fb27SDimitry Andric# endif 1780b57cec5SDimitry Andric# endif 1790b57cec5SDimitry Andric 18081ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 181e8d8bef9SDimitry Andric// Enable additional explicit instantiations of iostreams components. This 182e8d8bef9SDimitry Andric// reduces the number of weak definitions generated in programs that use 183e8d8bef9SDimitry Andric// iostreams by providing a single strong definition in the shared library. 184e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 185349cc55cSDimitry Andric 186349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 187349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 188349cc55cSDimitry Andric// using that class define their own copies. 189349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 1900b57cec5SDimitry Andric# endif 1910b57cec5SDimitry Andric 19206c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 19306c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference. 19406c3fb27SDimitry Andric// 19506c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers. 19606c3fb27SDimitry Andric// 19706c3fb27SDimitry Andric// Supported containers: 19806c3fb27SDimitry Andric// - `span`; 19906c3fb27SDimitry Andric// - `string_view`; 20006c3fb27SDimitry Andric// - `array`. 20106c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS 20206c3fb27SDimitry Andric 20306c3fb27SDimitry Andric// } ABI 20406c3fb27SDimitry Andric 20506c3fb27SDimitry Andric// HARDENING { 20606c3fb27SDimitry Andric 2078a4dda33SDimitry Andric# ifndef _LIBCPP_ENABLE_ASSERTIONS 2088a4dda33SDimitry Andric# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT 2098a4dda33SDimitry Andric# endif 21006c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 21106c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 21206c3fb27SDimitry Andric# endif 21306c3fb27SDimitry Andric 2148a4dda33SDimitry Andric// NOTE: These modes are experimental and are not stable yet in LLVM 17. Please refrain from using them and use the 2158a4dda33SDimitry Andric// documented libc++ "safe" mode instead. 2168a4dda33SDimitry Andric// 21706c3fb27SDimitry Andric// Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes 21806c3fb27SDimitry Andric// security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with 21906c3fb27SDimitry Andric// `_LIBCPP_ENABLE_DEBUG_MODE`. 22006c3fb27SDimitry Andric// 22106c3fb27SDimitry Andric// #define _LIBCPP_ENABLE_HARDENED_MODE 1 22206c3fb27SDimitry Andric 22306c3fb27SDimitry Andric// Enables the debug mode which contains all the checks from the hardened mode and additionally more expensive checks 22406c3fb27SDimitry Andric// that may affect the complexity of algorithms. The debug mode is intended to be used for testing, not in production. 22506c3fb27SDimitry Andric// Mutually exclusive with `_LIBCPP_ENABLE_HARDENED_MODE`. 22606c3fb27SDimitry Andric// 22706c3fb27SDimitry Andric// #define _LIBCPP_ENABLE_DEBUG_MODE 1 22806c3fb27SDimitry Andric 22906c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 23006c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 23106c3fb27SDimitry Andric// 23206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 23306c3fb27SDimitry Andric// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 23406c3fb27SDimitry Andric// - the sentinel is reachable from the begin iterator; 23506c3fb27SDimitry Andric// - TODO(hardening): both iterators refer to the same container. 23606c3fb27SDimitry Andric// 23706c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 23806c3fb27SDimitry Andric// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 23906c3fb27SDimitry Andric// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 24006c3fb27SDimitry Andric// `optional` and `function` are considered one-element containers for the purposes of this check. 24106c3fb27SDimitry Andric// 24206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 24306c3fb27SDimitry Andric// given ranges do not overlap. 24406c3fb27SDimitry Andric// 24506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 24606c3fb27SDimitry Andric// the containers have compatible allocators. 24706c3fb27SDimitry Andric// 24806c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 24906c3fb27SDimitry Andric// user input. 25006c3fb27SDimitry Andric// 25106c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 25206c3fb27SDimitry Andric 25306c3fb27SDimitry Andric# ifndef _LIBCPP_ENABLE_HARDENED_MODE 25406c3fb27SDimitry Andric# define _LIBCPP_ENABLE_HARDENED_MODE _LIBCPP_ENABLE_HARDENED_MODE_DEFAULT 25506c3fb27SDimitry Andric# endif 25606c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE != 0 && _LIBCPP_ENABLE_HARDENED_MODE != 1 25706c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_HARDENED_MODE must be set to 0 or 1." 25806c3fb27SDimitry Andric# endif 25906c3fb27SDimitry Andric 26006c3fb27SDimitry Andric# ifndef _LIBCPP_ENABLE_DEBUG_MODE 26106c3fb27SDimitry Andric# define _LIBCPP_ENABLE_DEBUG_MODE _LIBCPP_ENABLE_DEBUG_MODE_DEFAULT 26206c3fb27SDimitry Andric# endif 26306c3fb27SDimitry Andric# if _LIBCPP_ENABLE_DEBUG_MODE != 0 && _LIBCPP_ENABLE_DEBUG_MODE != 1 26406c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_DEBUG_MODE must be set to 0 or 1." 26506c3fb27SDimitry Andric# endif 26606c3fb27SDimitry Andric 26706c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE && _LIBCPP_ENABLE_DEBUG_MODE 26806c3fb27SDimitry Andric# error "Only one of _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled." 26906c3fb27SDimitry Andric# endif 27006c3fb27SDimitry Andric 2718a4dda33SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS && (_LIBCPP_ENABLE_HARDENED_MODE || _LIBCPP_ENABLE_DEBUG_MODE) 2728a4dda33SDimitry Andric# error \ 2738a4dda33SDimitry Andric "_LIBCPP_ENABLE_ASSERTIONS is mutually exclusive with _LIBCPP_ENABLE_HARDENED_MODE and _LIBCPP_ENABLE_DEBUG_MODE." 2748a4dda33SDimitry Andric# endif 2758a4dda33SDimitry Andric 27606c3fb27SDimitry Andric// Hardened mode checks. 27706c3fb27SDimitry Andric 27806c3fb27SDimitry Andric// clang-format off 27906c3fb27SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE 28006c3fb27SDimitry Andric 28106c3fb27SDimitry Andric// Enabled checks. 28206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 28306c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 28406c3fb27SDimitry Andric// Disabled checks. 28506c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 28606c3fb27SDimitry Andric// vulnerability. 28706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 28806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 28906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 29006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 29106c3fb27SDimitry Andric 29206c3fb27SDimitry Andric// Debug mode checks. 29306c3fb27SDimitry Andric 29406c3fb27SDimitry Andric# elif _LIBCPP_ENABLE_DEBUG_MODE 29506c3fb27SDimitry Andric 29606c3fb27SDimitry Andric// All checks enabled. 29706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 29806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 29906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 30006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 30106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 30206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 30306c3fb27SDimitry Andric 3048a4dda33SDimitry Andric// Safe mode checks. 3058a4dda33SDimitry Andric 3068a4dda33SDimitry Andric# elif _LIBCPP_ENABLE_ASSERTIONS 3078a4dda33SDimitry Andric 3088a4dda33SDimitry Andric// All checks enabled. 3098a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 3108a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 3118a4dda33SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 3128a4dda33SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 3138a4dda33SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 3148a4dda33SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3158a4dda33SDimitry Andric 31606c3fb27SDimitry Andric// Disable all checks if hardening is not enabled. 31706c3fb27SDimitry Andric 31806c3fb27SDimitry Andric# else 31906c3fb27SDimitry Andric 32006c3fb27SDimitry Andric// All checks disabled. 32106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 32206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 32306c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 32406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 32506c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 32606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 32706c3fb27SDimitry Andric 32806c3fb27SDimitry Andric# endif // _LIBCPP_ENABLE_HARDENED_MODE 32906c3fb27SDimitry Andric// clang-format on 33006c3fb27SDimitry Andric 33106c3fb27SDimitry Andric// } HARDENING 33206c3fb27SDimitry Andric 33381ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 33481ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 3350b57cec5SDimitry Andric 33606c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check) 3370b57cec5SDimitry Andric# if __cplusplus < 201103L 3380b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 3390b57cec5SDimitry Andric# endif 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric# ifndef __has_attribute 3420b57cec5SDimitry Andric# define __has_attribute(__x) 0 3430b57cec5SDimitry Andric# endif 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric# ifndef __has_builtin 3460b57cec5SDimitry Andric# define __has_builtin(__x) 0 3470b57cec5SDimitry Andric# endif 3480b57cec5SDimitry Andric 3490b57cec5SDimitry Andric# ifndef __has_extension 3500b57cec5SDimitry Andric# define __has_extension(__x) 0 3510b57cec5SDimitry Andric# endif 3520b57cec5SDimitry Andric 3530b57cec5SDimitry Andric# ifndef __has_feature 3540b57cec5SDimitry Andric# define __has_feature(__x) 0 3550b57cec5SDimitry Andric# endif 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric# ifndef __has_cpp_attribute 3580b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 3590b57cec5SDimitry Andric# endif 3600b57cec5SDimitry Andric 361bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 362bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 363bdd1243dSDimitry Andric# endif 364bdd1243dSDimitry Andric 3650b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 3660b57cec5SDimitry Andric// the compiler and '1' otherwise. 3670b57cec5SDimitry Andric# ifndef __is_identifier 3680b57cec5SDimitry Andric# define __is_identifier(__x) 1 3690b57cec5SDimitry Andric# endif 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric# ifndef __has_declspec_attribute 3720b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 3730b57cec5SDimitry Andric# endif 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric# ifndef __has_include 3780b57cec5SDimitry Andric# define __has_include(...) 0 3790b57cec5SDimitry Andric# endif 3800b57cec5SDimitry Andric 38181ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 38281ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 3830b57cec5SDimitry Andric# endif 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 3860b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 3870b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 3880b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 3890b57cec5SDimitry Andric// heuristic falls short. 3900b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 3910b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 3920b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 3930b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 3940b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 3950b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 3960b57cec5SDimitry Andric# else 3970b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 3980b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 3990b57cec5SDimitry Andric# else 4000b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4010b57cec5SDimitry Andric# endif 4020b57cec5SDimitry Andric# endif 4030b57cec5SDimitry Andric 4040b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 4050b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 4060b57cec5SDimitry Andric# endif 4070b57cec5SDimitry Andric 408fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 409fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 410fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 411fcaf7f86SDimitry Andric# endif 412fcaf7f86SDimitry Andric# endif 413fcaf7f86SDimitry Andric 414fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 415fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 416fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 41706c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 41806c3fb27SDimitry Andric# endif 41906c3fb27SDimitry Andric 42006c3fb27SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 42106c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 422fcaf7f86SDimitry Andric# endif 423fcaf7f86SDimitry Andric 4240b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 4250b57cec5SDimitry Andric# if defined(__linux__) 4260b57cec5SDimitry Andric# include <features.h> 4270b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 4280b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 4290b57cec5SDimitry Andric# else 4300b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 4310b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 4320b57cec5SDimitry Andric# endif // defined(__linux__) 4330b57cec5SDimitry Andric 43404eeddc0SDimitry Andric# if defined(__MVS__) 43504eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 43604eeddc0SDimitry Andric# endif 43704eeddc0SDimitry Andric 4380b57cec5SDimitry Andric# ifdef __LITTLE_ENDIAN__ 4390b57cec5SDimitry Andric# if __LITTLE_ENDIAN__ 4400b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4410b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 4420b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 4430b57cec5SDimitry Andric 4440b57cec5SDimitry Andric# ifdef __BIG_ENDIAN__ 4450b57cec5SDimitry Andric# if __BIG_ENDIAN__ 4460b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4470b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 4480b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andric# ifdef __BYTE_ORDER__ 4510b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 4520b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4530b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4540b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4550b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4560b57cec5SDimitry Andric# endif // __BYTE_ORDER__ 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andric# ifdef __FreeBSD__ 4590b57cec5SDimitry Andric# include <osreldate.h> 46006c3fb27SDimitry Andric# include <sys/endian.h> 4610b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 4620b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4630b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 4640b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4650b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 4660b57cec5SDimitry Andric# endif // __FreeBSD__ 4670b57cec5SDimitry Andric 468e8d8bef9SDimitry Andric# if defined(__NetBSD__) || defined(__OpenBSD__) 4690b57cec5SDimitry Andric# include <sys/endian.h> 4700b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 4710b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4720b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 4730b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4740b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 475e8d8bef9SDimitry Andric# endif // defined(__NetBSD__) || defined(__OpenBSD__) 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric# if defined(_WIN32) 4780b57cec5SDimitry Andric# define _LIBCPP_WIN32API 4790b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4800b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 4810b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 4820b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 4830b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 4840b57cec5SDimitry Andric// a MS compatibility version is specified. 4850b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 4860b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 4870b57cec5SDimitry Andric# endif 4880b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 4890b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 4900b57cec5SDimitry Andric# endif 4910b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 4920b57cec5SDimitry Andric# endif // defined(_WIN32) 4930b57cec5SDimitry Andric 494349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 495349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 496349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 497349cc55cSDimitry Andric# endif 498349cc55cSDimitry Andric 4990eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 5000eae32dcSDimitry Andric// 5010eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 5020eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 5030eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 5040eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 5050eae32dcSDimitry Andric// else is specified. This implementation requires storing state 5060eae32dcSDimitry Andric// inside `std::random_device`. 5070eae32dcSDimitry Andric// 5080eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 5090eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 5100eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 5110eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 5120eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5130eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5140eae32dcSDimitry Andric// 5150eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 5160eae32dcSDimitry Andric// Use getentropy(). 5170eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5180eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5190eae32dcSDimitry Andric// 52004eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 52104eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 52204eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 52304eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 52404eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 52504eeddc0SDimitry Andric// 5260eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 5270eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 5280eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 5290eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 5300eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5310eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5320eae32dcSDimitry Andric// 5330eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 5340eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 5350eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5360eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 53781ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 53806c3fb27SDimitry Andric defined(__DragonFly__) 5390b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 54081ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 5410b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 54204eeddc0SDimitry Andric# elif defined(__Fuchsia__) 54304eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 5440b57cec5SDimitry Andric# elif defined(__native_client__) 5450b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 5460b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 5470b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 5480b57cec5SDimitry Andric# else 5490b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 5500b57cec5SDimitry Andric# endif 5510b57cec5SDimitry Andric 5520b57cec5SDimitry Andric# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 5530b57cec5SDimitry Andric# include <endian.h> 5540b57cec5SDimitry Andric# if __BYTE_ORDER == __LITTLE_ENDIAN 5550b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 5560b57cec5SDimitry Andric# elif __BYTE_ORDER == __BIG_ENDIAN 5570b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 5580b57cec5SDimitry Andric# else // __BYTE_ORDER == __BIG_ENDIAN 5590b57cec5SDimitry Andric# error unable to determine endian 5600b57cec5SDimitry Andric# endif 5610b57cec5SDimitry Andric# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 5620b57cec5SDimitry Andric 5630b57cec5SDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 5640b57cec5SDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 5650b57cec5SDimitry Andric# else 5660b57cec5SDimitry Andric# define _LIBCPP_NO_CFI 5670b57cec5SDimitry Andric# endif 5680b57cec5SDimitry Andric 5690b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 57081ad6265SDimitry Andric 5710b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 57281ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 57381ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 57481ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 57581ad6265SDimitry Andric# define _NOEXCEPT noexcept 57681ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 577bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 57881ad6265SDimitry Andric 5790b57cec5SDimitry Andric# else 58081ad6265SDimitry Andric 58181ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 58281ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 58381ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 584bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 58581ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 58681ad6265SDimitry Andric# define nullptr __nullptr 58781ad6265SDimitry Andric# define _NOEXCEPT throw() 58881ad6265SDimitry Andric# define _NOEXCEPT_(x) 589bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 590bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 591bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 59281ad6265SDimitry Andric 59381ad6265SDimitry Andrictypedef __char16_t char16_t; 59481ad6265SDimitry Andrictypedef __char32_t char32_t; 59581ad6265SDimitry Andric 59681ad6265SDimitry Andric# endif 59781ad6265SDimitry Andric 59881ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 59906c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXCEPTIONS 6000b57cec5SDimitry Andric# endif 6010b57cec5SDimitry Andric 6020b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 6030b57cec5SDimitry Andric 604fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 6050b57cec5SDimitry Andric 60606c3fb27SDimitry Andric# if defined(__APPLE__) 60706c3fb27SDimitry Andric# if defined(__i386__) || defined(__x86_64__) 60806c3fb27SDimitry Andric// use old string layout on x86_64 and i386 60906c3fb27SDimitry Andric# elif defined(__arm__) 61006c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 61106c3fb27SDimitry Andric# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 6120b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 6130b57cec5SDimitry Andric# endif 61406c3fb27SDimitry Andric# else 61506c3fb27SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 61606c3fb27SDimitry Andric# endif 61706c3fb27SDimitry Andric# endif 6180b57cec5SDimitry Andric 6190b57cec5SDimitry Andric// Objective-C++ features (opt-in) 6200b57cec5SDimitry Andric# if __has_feature(objc_arc) 6210b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 6220b57cec5SDimitry Andric# endif 6230b57cec5SDimitry Andric 6240b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 6250b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 6260b57cec5SDimitry Andric# endif 6270b57cec5SDimitry Andric 6285ffd83dbSDimitry Andric# if __has_extension(blocks) 6295ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 6305ffd83dbSDimitry Andric# endif 6315ffd83dbSDimitry Andric 6325ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 6335ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 6345ffd83dbSDimitry Andric# endif 6355ffd83dbSDimitry Andric 636fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 6370b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6380b57cec5SDimitry Andric# endif 6390b57cec5SDimitry Andric 6400b57cec5SDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 641fe6060f1SDimitry Andric# if __has_attribute(no_sanitize) 6420b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 6430b57cec5SDimitry Andric# endif 6440b57cec5SDimitry Andric 6450b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6460b57cec5SDimitry Andric 647e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 648e40139ffSDimitry Andric 6490b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 6500b57cec5SDimitry Andric 651fe6060f1SDimitry Andric# if !defined(__SANITIZE_ADDRESS__) 6520b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6530b57cec5SDimitry Andric# endif 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6560b57cec5SDimitry Andric 657e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 658e40139ffSDimitry Andric 659bdd1243dSDimitry Andric# endif // _LIBCPP_COMPILER_[CLANG|GCC] 6600b57cec5SDimitry Andric 6610b57cec5SDimitry Andric# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric# ifdef _DLL 6640b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC __declspec(dllimport) 6650b57cec5SDimitry Andric# else 6660b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC 6670b57cec5SDimitry Andric# endif 6680b57cec5SDimitry Andric 66981ad6265SDimitry Andric# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 6700b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS 6710b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6720b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6730b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6740b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI 6750b57cec5SDimitry Andric# elif defined(_LIBCPP_BUILDING_LIBRARY) 6760b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllexport) 6770b57cec5SDimitry Andric# if defined(__MINGW32__) 6780b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6790b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6800b57cec5SDimitry Andric# else 6810b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6820b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 6830b57cec5SDimitry Andric# endif 6840b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 6850b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 6860b57cec5SDimitry Andric# else 6870b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllimport) 6880b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6890b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6900b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6910b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 6920b57cec5SDimitry Andric# endif 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andric# define _LIBCPP_HIDDEN 6950b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 6960b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 697fe6060f1SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS 6980b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 6990b57cec5SDimitry Andric 7000b57cec5SDimitry Andric# else 70181ad6265SDimitry Andric 70281ad6265SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 70381ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 70481ad6265SDimitry Andric# else 70581ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) 7060b57cec5SDimitry Andric# endif 7070b57cec5SDimitry Andric 70881ad6265SDimitry Andric# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 70981ad6265SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 71081ad6265SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 71181ad6265SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 71281ad6265SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 71381ad6265SDimitry Andric 714fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it. 715fcaf7f86SDimitry Andric# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 716fcaf7f86SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 717fcaf7f86SDimitry Andric# endif 718fcaf7f86SDimitry Andric 7190b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7200b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved 7210b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 7220b57cec5SDimitry Andric# else 7230b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 7240b57cec5SDimitry Andric# endif 7250b57cec5SDimitry Andric 7260b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7270b57cec5SDimitry Andric# if __has_attribute(__type_visibility__) 7280b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default"))) 7290b57cec5SDimitry Andric# else 7300b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 7310b57cec5SDimitry Andric# endif 7320b57cec5SDimitry Andric# else 7330b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 7340b57cec5SDimitry Andric# endif 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 7370b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default"))) 7380b57cec5SDimitry Andric# else 7390b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 7400b57cec5SDimitry Andric# endif 7410b57cec5SDimitry Andric 74281ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 7450b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 7460b57cec5SDimitry Andric# else 7470b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 7480b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 7490b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 7500b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 7510b57cec5SDimitry Andric# endif 7520b57cec5SDimitry Andric 753*b121cb00SDimitry Andric# if _LIBCPP_ENABLE_HARDENED_MODE 754*b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG h 755*b121cb00SDimitry Andric# elif _LIBCPP_ENABLE_ASSERTIONS 756*b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG s 757*b121cb00SDimitry Andric# elif _LIBCPP_ENABLE_DEBUG_MODE 758*b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG d 759*b121cb00SDimitry Andric# else 760*b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG u // for unchecked 761*b121cb00SDimitry Andric# endif 762*b121cb00SDimitry Andric 763*b121cb00SDimitry Andric# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 764*b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG n 765*b121cb00SDimitry Andric# else 766*b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG e 767*b121cb00SDimitry Andric# endif 768*b121cb00SDimitry Andric 769*b121cb00SDimitry Andric# define _LIBCPP_ODR_SIGNATURE \ 770*b121cb00SDimitry Andric _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 771*b121cb00SDimitry Andric 772753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 773753f127fSDimitry Andric// on two levels: 774753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 775753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 776753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 777753f127fSDimitry Andric// 778*b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 779*b121cb00SDimitry Andric// This ensures that no ODR violation can arise from mixing two TUs compiled with different 780*b121cb00SDimitry Andric// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 781*b121cb00SDimitry Andric// program contains two definitions of a function, the ODR requires them to be token-by-token 782*b121cb00SDimitry Andric// equivalent, and the linker is allowed to pick either definition and discard the other one. 783*b121cb00SDimitry Andric// 784*b121cb00SDimitry Andric// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 785*b121cb00SDimitry Andric// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 786*b121cb00SDimitry Andric// compiled with different settings), the two definitions are both visible by the linker and they 787*b121cb00SDimitry Andric// have the same name, but they have a meaningfully different implementation (one throws an exception 788*b121cb00SDimitry Andric// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 789*b121cb00SDimitry Andric// practice what will happen is that the linker will pick one of the definitions at random and will 790*b121cb00SDimitry Andric// discard the other one. This can quite clearly lead to incorrect program behavior. 791*b121cb00SDimitry Andric// 792*b121cb00SDimitry Andric// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 793*b121cb00SDimitry Andric// property that causes the code of a function to differ from the code in another configuration 794*b121cb00SDimitry Andric// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 795*b121cb00SDimitry Andric// tag, but we encode the ones that we think are most important: library version, exceptions, and 796*b121cb00SDimitry Andric// hardening mode. 797*b121cb00SDimitry Andric// 798*b121cb00SDimitry Andric// Note that historically, solving this problem has been achieved in various ways, including 799*b121cb00SDimitry Andric// force-inlining all functions or giving internal linkage to all functions. Both these previous 800*b121cb00SDimitry Andric// solutions suffer from drawbacks that lead notably to code bloat. 801753f127fSDimitry Andric// 802753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 803753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 804753f127fSDimitry Andric// 805bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 806bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 807bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 808bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 809bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 810bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 811bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 812bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 813bdd1243dSDimitry Andric// 814753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 815753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 816753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 817753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 818753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 819753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 820*b121cb00SDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 8210b57cec5SDimitry Andric# else 8220b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8230b57cec5SDimitry Andric# endif 824bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8250b57cec5SDimitry Andric 8261ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 8271ac55f4cSDimitry Andric// "C" function, as those lack mangling. 8281ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8291ac55f4cSDimitry Andric 8300b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 8310b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 8320b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8330b57cec5SDimitry Andric# else 8340b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 8350b57cec5SDimitry Andric# endif 8360b57cec5SDimitry Andric# else 8370b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8380b57cec5SDimitry Andric# endif 8390b57cec5SDimitry Andric 8400b57cec5SDimitry Andric// Just so we can migrate to the new macros gradually. 8410b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 84481ad6265SDimitry Andric// clang-format off 8450b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { 8460b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 8471fd87a68SDimitry Andric# define _VSTD std 84881ad6265SDimitry Andric 8490b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD 8500b57cec5SDimitry Andric 85106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 8520b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 8530b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { 8540b57cec5SDimitry Andric# else 8550b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 8560b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { 8570b57cec5SDimitry Andric# endif 8580b57cec5SDimitry Andric 85981ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 86081ad6265SDimitry Andric// clang-format on 8610b57cec5SDimitry Andric 86281ad6265SDimitry Andric# define _VSTD_FS std::__fs::filesystem 8630b57cec5SDimitry Andric 8640b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 8650b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 8660b57cec5SDimitry Andric# endif 8670b57cec5SDimitry Andric 86806c3fb27SDimitry Andric# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 8690b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 8700b57cec5SDimitry Andric# endif 8710b57cec5SDimitry Andric 872bdd1243dSDimitry Andric# if __has_attribute(__malloc__) 8730b57cec5SDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 8740b57cec5SDimitry Andric# else 8750b57cec5SDimitry Andric# define _LIBCPP_NOALIAS 8760b57cec5SDimitry Andric# endif 8770b57cec5SDimitry Andric 878bdd1243dSDimitry Andric# if __has_attribute(__using_if_exists__) 879bdd1243dSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 8800b57cec5SDimitry Andric# else 881fe6060f1SDimitry Andric# define _LIBCPP_USING_IF_EXISTS 8820b57cec5SDimitry Andric# endif 8830b57cec5SDimitry Andric 88481ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 88581ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 88606c3fb27SDimitry Andric struct _LIBCPP_EXPORTED_FROM_ABI x { \ 88781ad6265SDimitry Andric enum __lx 88881ad6265SDimitry Andric// clang-format off 8890b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 8900b57cec5SDimitry Andric __lx __v_; \ 8910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ 8920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 8930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \ 8940b57cec5SDimitry Andric }; 89581ad6265SDimitry Andric// clang-format on 89681ad6265SDimitry Andric 89781ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 8980b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x 8990b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 90081ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 9010b57cec5SDimitry Andric 90206c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 9030b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 9040b57cec5SDimitry Andric# endif 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andric# ifdef __FreeBSD__ 9070b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 9080b57cec5SDimitry Andric# endif 9090b57cec5SDimitry Andric 9100b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 9110b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 9120b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 9130b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 9140b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 9150b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 9160b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 9170b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 918e8d8bef9SDimitry Andric# elif defined(__MVS__) 919e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 9200b57cec5SDimitry Andric# endif 9210b57cec5SDimitry Andric 92281ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 9230b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 9240b57cec5SDimitry Andric# endif 9250b57cec5SDimitry Andric 926bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 927bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 928bdd1243dSDimitry Andric# if defined(__APPLE__) 929bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 930bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 931bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 932bdd1243dSDimitry Andric# endif 933bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 934bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 935bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 936bdd1243dSDimitry Andric# endif 937bdd1243dSDimitry Andric 9380b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9390b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 9400b57cec5SDimitry Andric# endif 9410b57cec5SDimitry Andric 94206c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9430b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 9440b57cec5SDimitry Andric# endif 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 947fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 9480b57cec5SDimitry Andric# endif 9490b57cec5SDimitry Andric 9500b57cec5SDimitry Andric// Deprecation macros. 9510b57cec5SDimitry Andric// 9520b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 9530b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 9540b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 95506c3fb27SDimitry Andric# if __has_attribute(__deprecated__) 95606c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 95706c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 95806c3fb27SDimitry Andric# elif _LIBCPP_STD_VER >= 14 9590b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 96081ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 9610b57cec5SDimitry Andric# else 9620b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 96381ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9640b57cec5SDimitry Andric# endif 9650b57cec5SDimitry Andric# else 9660b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 96781ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9680b57cec5SDimitry Andric# endif 9690b57cec5SDimitry Andric 9700b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 9710b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 9720b57cec5SDimitry Andric# else 9730b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 9740b57cec5SDimitry Andric# endif 9750b57cec5SDimitry Andric 97606c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 9770b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 9780b57cec5SDimitry Andric# else 9790b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 9800b57cec5SDimitry Andric# endif 9810b57cec5SDimitry Andric 98206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 9830b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 9840b57cec5SDimitry Andric# else 9850b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 9860b57cec5SDimitry Andric# endif 9870b57cec5SDimitry Andric 98806c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 989e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 990e8d8bef9SDimitry Andric# else 991e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 992e8d8bef9SDimitry Andric# endif 993e8d8bef9SDimitry Andric 994bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 23 995bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 996bdd1243dSDimitry Andric# else 997bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 998bdd1243dSDimitry Andric# endif 999bdd1243dSDimitry Andric 1000fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 1001e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 1002e8d8bef9SDimitry Andric# else 1003e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 1004e8d8bef9SDimitry Andric# endif 1005e8d8bef9SDimitry Andric 1006e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 1007fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 1008e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 100981ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 1010fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 101181ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 1012fe6060f1SDimitry Andric# else 1013e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 1014e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 1015e40139ffSDimitry Andric# endif 1016e40139ffSDimitry Andric 10170b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 101806c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 10190b57cec5SDimitry Andric# else 102006c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 10210b57cec5SDimitry Andric# endif 10220b57cec5SDimitry Andric 102306c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 102406c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 102506c3fb27SDimitry Andric# else 102606c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 102706c3fb27SDimitry Andric# endif 102806c3fb27SDimitry Andric 102906c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 1030bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 10310b57cec5SDimitry Andric# else 1032bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 10330b57cec5SDimitry Andric# endif 10340b57cec5SDimitry Andric 103506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 1036bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 10370b57cec5SDimitry Andric# else 1038bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 10390b57cec5SDimitry Andric# endif 10400b57cec5SDimitry Andric 104106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1042bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 10430b57cec5SDimitry Andric# else 1044bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 10450b57cec5SDimitry Andric# endif 10460b57cec5SDimitry Andric 104706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 1048bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1049bdd1243dSDimitry Andric# else 1050bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1051bdd1243dSDimitry Andric# endif 1052bdd1243dSDimitry Andric 1053bdd1243dSDimitry Andric# if __has_cpp_attribute(nodiscard) 105406c3fb27SDimitry Andric# define _LIBCPP_NODISCARD [[__nodiscard__]] 10550b57cec5SDimitry Andric# else 10560b57cec5SDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 10570b57cec5SDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 10580b57cec5SDimitry Andric// (void) cast. 1059349cc55cSDimitry Andric# define _LIBCPP_NODISCARD 10600b57cec5SDimitry Andric# endif 10610b57cec5SDimitry Andric 10620b57cec5SDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 10630b57cec5SDimitry Andric// specified as such as an extension. 1064bdd1243dSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1065349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 10660b57cec5SDimitry Andric# else 10670b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_EXT 10680b57cec5SDimitry Andric# endif 10690b57cec5SDimitry Andric 107006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1071349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 10720b57cec5SDimitry Andric# else 10730b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 10740b57cec5SDimitry Andric# endif 10750b57cec5SDimitry Andric 1076bdd1243dSDimitry Andric# if __has_attribute(__no_destroy__) 10770b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 10780b57cec5SDimitry Andric# else 10790b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY 10800b57cec5SDimitry Andric# endif 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 108306c3fb27SDimitry Andric extern "C" _LIBCPP_EXPORTED_FROM_ABI void 108481ad6265SDimitry Andric __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 108506c3fb27SDimitry Andric# if _LIBCPP_CLANG_VER >= 1600 108606c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 108706c3fb27SDimitry Andric const void*, const void*, const void*, const void*, const void*, const void*); 108806c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int 108906c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 109006c3fb27SDimitry Andric# endif 10910b57cec5SDimitry Andric# endif 10920b57cec5SDimitry Andric 10930b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 109481ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 10951ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 10960b57cec5SDimitry Andric# endif 10970b57cec5SDimitry Andric 10980b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 10990b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 11000b57cec5SDimitry Andric# endif 11010b57cec5SDimitry Andric 11020b57cec5SDimitry Andric// Thread API 110381ad6265SDimitry Andric// clang-format off 11040b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 11050b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 11060b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 11070b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 110881ad6265SDimitry Andric 11090b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 11100b57cec5SDimitry Andric defined(__wasi__) || \ 11110b57cec5SDimitry Andric defined(__NetBSD__) || \ 1112e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 1113e8d8bef9SDimitry Andric defined(__NuttX__) || \ 11140b57cec5SDimitry Andric defined(__linux__) || \ 11150b57cec5SDimitry Andric defined(__GNU__) || \ 11160b57cec5SDimitry Andric defined(__APPLE__) || \ 1117e8d8bef9SDimitry Andric defined(__MVS__) || \ 111881ad6265SDimitry Andric defined(_AIX) || \ 111981ad6265SDimitry Andric defined(__EMSCRIPTEN__) 112081ad6265SDimitry Andric// clang-format on 11210b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 1122480093f4SDimitry Andric# elif defined(__Fuchsia__) 11235ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 11245ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 11250b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 11260b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 11270b57cec5SDimitry Andric# else 11280b57cec5SDimitry Andric# error "No thread API" 11290b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 11300b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 11310b57cec5SDimitry Andric 1132e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1133e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1134e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1135e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 1136e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 1137e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1138e40139ffSDimitry Andric# endif 1139e40139ffSDimitry Andric# endif 1140e40139ffSDimitry Andric# endif 1141e40139ffSDimitry Andric 11420b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 11430b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 11440b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 11450b57cec5SDimitry Andric# endif 11460b57cec5SDimitry Andric 11470b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 11480b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 11490b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 11500b57cec5SDimitry Andric# endif 11510b57cec5SDimitry Andric 11520b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 11530b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 11540b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 11550b57cec5SDimitry Andric# endif 11560b57cec5SDimitry Andric 1157e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1158e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 1159e40139ffSDimitry Andric# endif 1160e40139ffSDimitry Andric 1161e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 11620b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 11630b57cec5SDimitry Andric// mutexes have no destroy mechanism. 1164e40139ffSDimitry Andric// 1165e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1166e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 1167e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1168e40139ffSDimitry Andric// 1169e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1170e40139ffSDimitry Andric// respective stakeholders. 117181ad6265SDimitry Andric// clang-format off 117281ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 117381ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 117481ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 117581ad6265SDimitry Andric// clang-format on 11760b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 11770b57cec5SDimitry Andric# endif 11780b57cec5SDimitry Andric 11790b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 1180e40139ffSDimitry Andric// 1181e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1182e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 1183e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1184e40139ffSDimitry Andric// 11850b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 11860b57cec5SDimitry Andric// as well. 118781ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 11880b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 11890b57cec5SDimitry Andric# endif 11900b57cec5SDimitry Andric 11910b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons. 119281ad6265SDimitry Andric# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 11930b57cec5SDimitry Andric# define _LIBCPP_C_HAS_NO_GETS 11940b57cec5SDimitry Andric# endif 11950b57cec5SDimitry Andric 119681ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 119704eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 11980b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 11990b57cec5SDimitry Andric# endif 12000b57cec5SDimitry Andric 12010b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 12020b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 12030b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 12040b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 12050b57cec5SDimitry Andric# endif 12060b57cec5SDimitry Andric 120781ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1208349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 12090b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 12100b57cec5SDimitry Andric# else 12110b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 12120b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 12130b57cec5SDimitry Andric# endif 12140b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 12150b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 12160b57cec5SDimitry Andric# endif 12170b57cec5SDimitry Andric# endif 12180b57cec5SDimitry Andric 12190b57cec5SDimitry Andric# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 12200b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 12210b57cec5SDimitry Andric# endif 12220b57cec5SDimitry Andric 122306c3fb27SDimitry Andric# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 122406c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 122506c3fb27SDimitry Andric# else 122606c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 122706c3fb27SDimitry Andric# endif 122806c3fb27SDimitry Andric 12290b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 12300b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 12310b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 12320b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 12331fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 12341fd87a68SDimitry Andric// combining the two does work. 12351fd87a68SDimitry Andric# if !defined(_MSC_VER) 12360b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 12370b57cec5SDimitry Andric# endif 12380b57cec5SDimitry Andric# endif 12390b57cec5SDimitry Andric# endif 12400b57cec5SDimitry Andric 1241480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1242480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1243480093f4SDimitry Andric# else 1244480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1245480093f4SDimitry Andric# endif 1246480093f4SDimitry Andric 124706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 124881ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1249bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 125081ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 12510b57cec5SDimitry Andric# else 125281ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 12530b57cec5SDimitry Andric# endif 12540b57cec5SDimitry Andric 1255bdd1243dSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1256bdd1243dSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 12570b57cec5SDimitry Andric# else 12580b57cec5SDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 12590b57cec5SDimitry Andric# endif 12600b57cec5SDimitry Andric 12610b57cec5SDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 126281ad6265SDimitry Andric# if __has_cpp_attribute(fallthrough) 12630b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1264349cc55cSDimitry Andric# elif __has_attribute(__fallthrough__) 12650b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 12660b57cec5SDimitry Andric# else 12670b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 12680b57cec5SDimitry Andric# endif 12690b57cec5SDimitry Andric 1270bdd1243dSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 1271bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1272bdd1243dSDimitry Andric# else 1273bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 1274bdd1243dSDimitry Andric# endif 1275bdd1243dSDimitry Andric 12760b57cec5SDimitry Andric# if __has_attribute(__nodebug__) 12770b57cec5SDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 12780b57cec5SDimitry Andric# else 12790b57cec5SDimitry Andric# define _LIBCPP_NODEBUG 12800b57cec5SDimitry Andric# endif 12810b57cec5SDimitry Andric 1282fe6060f1SDimitry Andric# if __has_attribute(__standalone_debug__) 1283fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1284fe6060f1SDimitry Andric# else 1285fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 1286fe6060f1SDimitry Andric# endif 12870b57cec5SDimitry Andric 1288e8d8bef9SDimitry Andric# if __has_attribute(__preferred_name__) 1289e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1290e8d8bef9SDimitry Andric# else 1291e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 1292e8d8bef9SDimitry Andric# endif 1293e8d8bef9SDimitry Andric 129406c3fb27SDimitry Andric# if __has_attribute(__no_sanitize__) 129506c3fb27SDimitry Andric# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 129606c3fb27SDimitry Andric# else 129706c3fb27SDimitry Andric# define _LIBCPP_NO_SANITIZE(...) 129806c3fb27SDimitry Andric# endif 129906c3fb27SDimitry Andric 1300349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1301349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1302349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1303349cc55cSDimitry Andric// impact on readability. 1304349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1305349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1306349cc55cSDimitry Andric# else 1307349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1308349cc55cSDimitry Andric# endif 1309349cc55cSDimitry Andric 1310bdd1243dSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 13110b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 13120b57cec5SDimitry Andric# else 13130b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 13140b57cec5SDimitry Andric# endif 13150b57cec5SDimitry Andric 13160b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 13170b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 13180b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1319fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1320fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 132181ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 13220b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 13230b57cec5SDimitry Andric 1324fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1325fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 132681ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1327fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1328fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1329fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1330fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1331fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1332fe6060f1SDimitry Andric 133306c3fb27SDimitry Andric// clang-format off 133406c3fb27SDimitry Andric# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh()\")") _Pragma("push_macro(\"move(int, int)\")") _Pragma("push_macro(\"erase()\")") 133506c3fb27SDimitry Andric# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh()\")") _Pragma("pop_macro(\"move(int, int)\")") _Pragma("pop_macro(\"erase()\")") 133606c3fb27SDimitry Andric// clang-format on 13370b57cec5SDimitry Andric 13380b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 13390b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1340fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 13410b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 13420b57cec5SDimitry Andric# else 13430b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 13440b57cec5SDimitry Andric# endif 13450b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 13460b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 13470b57cec5SDimitry Andric 1348e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1349e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1350e40139ffSDimitry Andric// 1351e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1352e40139ffSDimitry Andric// do. 1353e40139ffSDimitry Andric# if defined(__BIONIC__) 1354e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1355e40139ffSDimitry Andric# else 1356e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1357e40139ffSDimitry Andric# endif 1358e40139ffSDimitry Andric 13595ffd83dbSDimitry Andric// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set 13605ffd83dbSDimitry Andric// of functions used in cstdio may not be available for low API levels when 13615ffd83dbSDimitry Andric// using 64-bit file offsets on LP32. 13625ffd83dbSDimitry Andric# if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 13635ffd83dbSDimitry Andric# define _LIBCPP_HAS_NO_FGETPOS_FSETPOS 13645ffd83dbSDimitry Andric# endif 13655ffd83dbSDimitry Andric 1366bdd1243dSDimitry Andric# if __has_attribute(__init_priority__) 1367bdd1243dSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1368349cc55cSDimitry Andric# else 1369e8d8bef9SDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 1370e8d8bef9SDimitry Andric# endif 1371e8d8bef9SDimitry Andric 1372bdd1243dSDimitry Andric# if __has_attribute(__format__) 13734824e7fdSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 13744824e7fdSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 13754824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 13764824e7fdSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1377fe6060f1SDimitry Andric# else 13784824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1379fe6060f1SDimitry Andric# endif 1380fe6060f1SDimitry Andric 138181ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 138281ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 138381ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 138481ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 138581ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 138681ad6265SDimitry Andric 138781ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 138881ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 138981ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 139081ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 139181ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 139206c3fb27SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 139381ad6265SDimitry Andric# else 139481ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 139581ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 139681ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 139781ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 139881ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 139981ad6265SDimitry Andric// because using it conditionally in one language version only would make 140081ad6265SDimitry Andric// the ABI inconsistent. 140181ad6265SDimitry Andric# endif 140281ad6265SDimitry Andric 140381ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 140481ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 140581ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 140681ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 140781ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 140881ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 140981ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 141081ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 141181ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 141281ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 141381ad6265SDimitry Andric# else 141481ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 141581ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 141681ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 141781ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 141881ad6265SDimitry Andric# endif 141981ad6265SDimitry Andric 142081ad6265SDimitry Andric# if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) 142181ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") 142281ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") 142381ad6265SDimitry Andric# else 142481ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ 142581ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ 142681ad6265SDimitry Andric# endif 142781ad6265SDimitry Andric 142881ad6265SDimitry Andric# if __has_attribute(__packed__) 142981ad6265SDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 143081ad6265SDimitry Andric# else 143181ad6265SDimitry Andric# define _LIBCPP_PACKED 143281ad6265SDimitry Andric# endif 143381ad6265SDimitry Andric 1434bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1435bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1436bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1437bdd1243dSDimitry Andric// functions are declared by the C library. 1438bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1439bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 14401ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 14411ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 14421ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 14431ac55f4cSDimitry Andric// defined are ignored. 14441ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 14451ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1446bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1447bdd1243dSDimitry Andric# endif 1448bdd1243dSDimitry Andric# endif 1449bdd1243dSDimitry Andric 1450bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1451bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1452bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1453bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1454bdd1243dSDimitry Andric// with these classes. 1455bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 17 145606c3fb27SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 1457bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1458bdd1243dSDimitry Andric template <class... _Tag> \ 145906c3fb27SDimitry Andric [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 146006c3fb27SDimitry Andric# else 146106c3fb27SDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 146206c3fb27SDimitry Andric template <class... _Tag> \ 146306c3fb27SDimitry Andric ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 146406c3fb27SDimitry Andric# endif 1465bdd1243dSDimitry Andric# else 1466bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1467bdd1243dSDimitry Andric# endif 1468bdd1243dSDimitry Andric 14691ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 14701ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 14711ac55f4cSDimitry Andric# ifdef __OBJC__ 14721ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 14731ac55f4cSDimitry Andric# endif 14741ac55f4cSDimitry Andric 147506c3fb27SDimitry Andric# define _PSTL_PRAGMA(x) _Pragma(#x) 147606c3fb27SDimitry Andric 147706c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0 147806c3fb27SDimitry Andric# if (defined(_OPENMP) && _OPENMP >= 201307) 147906c3fb27SDimitry Andric 148006c3fb27SDimitry Andric# define _PSTL_UDR_PRESENT 148106c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 148206c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 148306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 148406c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 148506c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 148606c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 148706c3fb27SDimitry Andric 148806c3fb27SDimitry Andric// Declaration of reduction functor, where 148906c3fb27SDimitry Andric// NAME - the name of the functor 149006c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation 149106c3fb27SDimitry Andric// omp_in - refers to the local partial result 149206c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator 149306c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value 149406c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced 149506c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 149606c3fb27SDimitry Andric _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 149706c3fb27SDimitry Andric 149806c3fb27SDimitry Andric# else // (defined(_OPENMP) && _OPENMP >= 201307) 149906c3fb27SDimitry Andric 150006c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD 150106c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 150206c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 150306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 150406c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 150506c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 150606c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 150706c3fb27SDimitry Andric 150806c3fb27SDimitry Andric# endif // (defined(_OPENMP) && _OPENMP >= 201307) 150906c3fb27SDimitry Andric 151006c3fb27SDimitry Andric# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 151106c3fb27SDimitry Andric 15120b57cec5SDimitry Andric#endif // __cplusplus 15130b57cec5SDimitry Andric 151481ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1515