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#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 160b57cec5SDimitry Andric# pragma GCC system_header 170b57cec5SDimitry Andric#endif 180b57cec5SDimitry Andric 196246ae0bSDimitry Andric#if defined(__apple_build_version__) 201ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 216246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 226246ae0bSDimitry Andric# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 236246ae0bSDimitry Andric#elif defined(__clang__) 246246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 256246ae0bSDimitry Andric# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 266246ae0bSDimitry Andric#elif defined(__GNUC__) 276246ae0bSDimitry Andric# define _LIBCPP_COMPILER_GCC 285f757f3fSDimitry Andric# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) 296246ae0bSDimitry Andric#endif 306246ae0bSDimitry Andric 310b57cec5SDimitry Andric#ifdef __cplusplus 320b57cec5SDimitry Andric 335f757f3fSDimitry Andric// Warn if a compiler version is used that is not supported anymore 345f757f3fSDimitry Andric// LLVM RELEASE Update the minimum compiler versions 35412fa343SDimitry Andric#if defined(_LIBCPP_ENABLE_COMPILER_VERSION_CHECKS) // FreeBSD customization 365f757f3fSDimitry Andric# if defined(_LIBCPP_CLANG_VER) 375f757f3fSDimitry Andric# if _LIBCPP_CLANG_VER < 1600 385f757f3fSDimitry Andric# warning "Libc++ only supports Clang 16 and later" 395f757f3fSDimitry Andric# endif 405f757f3fSDimitry Andric# elif defined(_LIBCPP_APPLE_CLANG_VER) 415f757f3fSDimitry Andric# if _LIBCPP_APPLE_CLANG_VER < 1500 425f757f3fSDimitry Andric# warning "Libc++ only supports AppleClang 15 and later" 435f757f3fSDimitry Andric# endif 445f757f3fSDimitry Andric# elif defined(_LIBCPP_GCC_VER) 455f757f3fSDimitry Andric# if _LIBCPP_GCC_VER < 1300 465f757f3fSDimitry Andric# warning "Libc++ only supports GCC 13 and later" 475f757f3fSDimitry Andric# endif 485f757f3fSDimitry Andric# endif 49412fa343SDimitry Andric#endif // _LIBCPP_ENABLE_COMPILER_VERSION_CHECKS 505f757f3fSDimitry Andric 5106c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 5206c3fb27SDimitry Andric 53bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 5406c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 55bdd1243dSDimitry Andric// defined to XXYYZZ. 565f757f3fSDimitry Andric# define _LIBCPP_VERSION 180000 570b57cec5SDimitry Andric 58753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 59753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 60753f127fSDimitry Andric 61e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 620b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 630b57cec5SDimitry Andric# endif 640b57cec5SDimitry Andric 6506c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check) 660b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 670b57cec5SDimitry Andric# if __cplusplus <= 201103L 680b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 690b57cec5SDimitry Andric# elif __cplusplus <= 201402L 700b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 710b57cec5SDimitry Andric# elif __cplusplus <= 201703L 720b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 73e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 74e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 7506c3fb27SDimitry Andric# elif __cplusplus <= 202302L 7606c3fb27SDimitry Andric# define _LIBCPP_STD_VER 23 770b57cec5SDimitry Andric# else 78bdd1243dSDimitry Andric// Expected release year of the next C++ standard 7906c3fb27SDimitry Andric# define _LIBCPP_STD_VER 26 800b57cec5SDimitry Andric# endif 810b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 8206c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check) 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric# if defined(__ELF__) 850b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 860b57cec5SDimitry Andric# elif defined(__MACH__) 870b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 880b57cec5SDimitry Andric# elif defined(_WIN32) 890b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 900b57cec5SDimitry Andric# elif defined(__wasm__) 910b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 9281ad6265SDimitry Andric# elif defined(_AIX) 9381ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 940b57cec5SDimitry Andric# else 95e8d8bef9SDimitry Andric// ... add new file formats here ... 960b57cec5SDimitry Andric# endif 970b57cec5SDimitry Andric 9806c3fb27SDimitry Andric// ABI { 9906c3fb27SDimitry Andric 10081ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 1010b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 1020b57cec5SDimitry Andric// improving its alignment in some cases. 1030b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 1040b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 1050b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 1060b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 1070b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 1080b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 1090b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 1100b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 1110b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 1120b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 1130b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 1140b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 1150b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 1160b57cec5SDimitry Andric// using that class define their own copies. 1170b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 118349cc55cSDimitry Andric// Override the default return value of exception::what() for 119349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 120349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 121349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 122349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1230b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1240b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 125fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 126fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 127fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1280b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1290b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1300b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1310b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1320b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1330b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1340b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1355ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1365ffd83dbSDimitry Andric// performance and fast-path inlining. 1375ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 138e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 139e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 140e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 141e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 14204eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 14304eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 14404eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 14504eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 14604eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 14704eeddc0SDimitry Andric// about ABI compatibility. 14804eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 14981ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1501838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 15181ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 152d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 15381ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 15481ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 1551ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 1561ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 1571ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 1581ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 1591ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 1601ac55f4cSDimitry Andric// 1611ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 1621ac55f4cSDimitry Andric// bits on the floor. 1631ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 16481ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 16581ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 16681ad6265SDimitry Andric// the dylib for backwards compatibility. 16781ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 1685f757f3fSDimitry Andric// Save memory by providing the allocator more freedom to allocate the most 1695f757f3fSDimitry Andric// efficient size class by dropping the alignment requirements for std::string's 1705f757f3fSDimitry Andric// pointer from 16 to 8. This changes the output of std::string::max_size, 1715f757f3fSDimitry Andric// which makes it ABI breaking 1725f757f3fSDimitry Andric# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT 1730b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 17481ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1750b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1760b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1770b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1780b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 17981ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 18081ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 18181ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 18281ad6265SDimitry Andric// so disable it. 1830b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1840b57cec5SDimitry Andric# endif 1850b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1860b57cec5SDimitry Andric// are deprecated. 1875f757f3fSDimitry Andric# if defined(__FreeBSD__) && __FreeBSD__ < 14 1880b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1890b57cec5SDimitry Andric# endif 19006c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 19106c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 19206c3fb27SDimitry Andric// in the library, so we need to always rely on the library version. 19306c3fb27SDimitry Andric# if defined(_AIX) 19406c3fb27SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 19506c3fb27SDimitry Andric# endif 1960b57cec5SDimitry Andric# endif 1970b57cec5SDimitry Andric 19881ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 199349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 200349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 201349cc55cSDimitry Andric// using that class define their own copies. 202349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 2030b57cec5SDimitry Andric# endif 2040b57cec5SDimitry Andric 205647cbc5dSDimitry Andric// We had some bugs where we use [[no_unique_address]] together with construct_at, 206647cbc5dSDimitry Andric// which causes UB as the call on construct_at could write to overlapping subobjects 207647cbc5dSDimitry Andric// 208647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70506 209647cbc5dSDimitry Andric// https://github.com/llvm/llvm-project/issues/70494 210647cbc5dSDimitry Andric// 211647cbc5dSDimitry Andric// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. 212647cbc5dSDimitry Andric// The below macro is used for all classes whose ABI have changed as part of fixing these bugs. 213647cbc5dSDimitry Andric# define _LIBCPP_ABI_2023_OVERLAPPING_SUBOBJECT_FIX_TAG __attribute__((__abi_tag__("subobj_fix_2023"))) 214647cbc5dSDimitry Andric 21506c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 21606c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference. 21706c3fb27SDimitry Andric// 21806c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers. 21906c3fb27SDimitry Andric// 22006c3fb27SDimitry Andric// Supported containers: 22106c3fb27SDimitry Andric// - `span`; 22206c3fb27SDimitry Andric// - `string_view`; 22306c3fb27SDimitry Andric// - `array`. 22406c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS 22506c3fb27SDimitry Andric 22606c3fb27SDimitry Andric// } ABI 22706c3fb27SDimitry Andric 22806c3fb27SDimitry Andric// HARDENING { 22906c3fb27SDimitry Andric 2305f757f3fSDimitry Andric// TODO(hardening): deprecate this in LLVM 19. 2315f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 2325f757f3fSDimitry Andric// equivalent to setting the extensive mode. 2335f757f3fSDimitry Andric# ifdef _LIBCPP_ENABLE_ASSERTIONS 23406c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 23506c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 23606c3fb27SDimitry Andric# endif 2375f757f3fSDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS 2385f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE 2395f757f3fSDimitry Andric# endif 2405f757f3fSDimitry Andric# endif 24106c3fb27SDimitry Andric 2425f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 2438a4dda33SDimitry Andric// 2445f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`; 2455f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`; 2465f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 2475f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`. 24806c3fb27SDimitry Andric// 2495f757f3fSDimitry Andric// These values have the following effects: 25006c3fb27SDimitry Andric// 2515f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 2525f757f3fSDimitry Andric// 2535f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 2545f757f3fSDimitry Andric// that can be done with relatively little runtime overhead in constant time; 2555f757f3fSDimitry Andric// 2565f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 2575f757f3fSDimitry Andric// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 2585f757f3fSDimitry Andric// but are not necessarily security-critical; 2595f757f3fSDimitry Andric// 2605f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 2615f757f3fSDimitry Andric// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 2625f757f3fSDimitry Andric// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 26306c3fb27SDimitry Andric 26406c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 26506c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 26606c3fb27SDimitry Andric// 26706c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 26806c3fb27SDimitry Andric// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 26906c3fb27SDimitry Andric// - the sentinel is reachable from the begin iterator; 27006c3fb27SDimitry Andric// - TODO(hardening): both iterators refer to the same container. 27106c3fb27SDimitry Andric// 27206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 27306c3fb27SDimitry Andric// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 27406c3fb27SDimitry Andric// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 27506c3fb27SDimitry Andric// `optional` and `function` are considered one-element containers for the purposes of this check. 27606c3fb27SDimitry Andric// 2775f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 2785f757f3fSDimitry Andric// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 2795f757f3fSDimitry Andric// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 2805f757f3fSDimitry Andric// compiler optimizations). 2815f757f3fSDimitry Andric// 28206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 28306c3fb27SDimitry Andric// given ranges do not overlap. 28406c3fb27SDimitry Andric// 28506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 28606c3fb27SDimitry Andric// the containers have compatible allocators. 28706c3fb27SDimitry Andric// 2881db9f3b2SDimitry Andric// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to 2891db9f3b2SDimitry Andric// be benign in our implementation. 2901db9f3b2SDimitry Andric// 29106c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 29206c3fb27SDimitry Andric// user input. 29306c3fb27SDimitry Andric// 29406c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 29506c3fb27SDimitry Andric 2965f757f3fSDimitry Andric// clang-format off 2975f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 2985f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 2995f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 3005f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 3015f757f3fSDimitry Andric// clang-format on 3025f757f3fSDimitry Andric 3035f757f3fSDimitry Andric# ifndef _LIBCPP_HARDENING_MODE 3045f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 30506c3fb27SDimitry Andric# endif 30606c3fb27SDimitry Andric 3075f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 3085f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 3095f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 3105f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 3115f757f3fSDimitry Andric# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 3125f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \ 3135f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \ 3145f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 3155f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG 31606c3fb27SDimitry Andric# endif 31706c3fb27SDimitry Andric 31806c3fb27SDimitry Andric// clang-format off 3195f757f3fSDimitry Andric// Fast hardening mode checks. 3205f757f3fSDimitry Andric 3215f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 32206c3fb27SDimitry Andric 32306c3fb27SDimitry Andric// Enabled checks. 32406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 32506c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 32606c3fb27SDimitry Andric// Disabled checks. 3275f757f3fSDimitry Andric// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. 3285f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 32906c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 33006c3fb27SDimitry Andric// vulnerability. 33106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 33206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 3331db9f3b2SDimitry Andric# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) 33406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 33506c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 33606c3fb27SDimitry Andric 3375f757f3fSDimitry Andric// Extensive hardening mode checks. 33806c3fb27SDimitry Andric 3395f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 34006c3fb27SDimitry Andric 3415f757f3fSDimitry Andric// Enabled checks. 34206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 34306c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 3445f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 34506c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 34606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 34706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3481db9f3b2SDimitry Andric# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) 3495f757f3fSDimitry Andric// Disabled checks. 3505f757f3fSDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 35106c3fb27SDimitry Andric 3525f757f3fSDimitry Andric// Debug hardening mode checks. 3538a4dda33SDimitry Andric 3545f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 3558a4dda33SDimitry Andric 3568a4dda33SDimitry Andric// All checks enabled. 3578a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 3588a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 3595f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 3608a4dda33SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 3618a4dda33SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 3621db9f3b2SDimitry Andric# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) 3638a4dda33SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 3648a4dda33SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3658a4dda33SDimitry Andric 36606c3fb27SDimitry Andric// Disable all checks if hardening is not enabled. 36706c3fb27SDimitry Andric 36806c3fb27SDimitry Andric# else 36906c3fb27SDimitry Andric 37006c3fb27SDimitry Andric// All checks disabled. 37106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 37206c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 3735f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 37406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 37506c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 3761db9f3b2SDimitry Andric# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) 37706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 37806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 37906c3fb27SDimitry Andric 3805f757f3fSDimitry Andric# endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 38106c3fb27SDimitry Andric// clang-format on 38206c3fb27SDimitry Andric 38306c3fb27SDimitry Andric// } HARDENING 38406c3fb27SDimitry Andric 38581ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 38681ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 3870b57cec5SDimitry Andric 38806c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check) 3890b57cec5SDimitry Andric# if __cplusplus < 201103L 3900b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 3910b57cec5SDimitry Andric# endif 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric# ifndef __has_attribute 3940b57cec5SDimitry Andric# define __has_attribute(__x) 0 3950b57cec5SDimitry Andric# endif 3960b57cec5SDimitry Andric 3970b57cec5SDimitry Andric# ifndef __has_builtin 3980b57cec5SDimitry Andric# define __has_builtin(__x) 0 3990b57cec5SDimitry Andric# endif 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andric# ifndef __has_extension 4020b57cec5SDimitry Andric# define __has_extension(__x) 0 4030b57cec5SDimitry Andric# endif 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric# ifndef __has_feature 4060b57cec5SDimitry Andric# define __has_feature(__x) 0 4070b57cec5SDimitry Andric# endif 4080b57cec5SDimitry Andric 4090b57cec5SDimitry Andric# ifndef __has_cpp_attribute 4100b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 4110b57cec5SDimitry Andric# endif 4120b57cec5SDimitry Andric 413bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 414bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 415bdd1243dSDimitry Andric# endif 416bdd1243dSDimitry Andric 4170b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 4180b57cec5SDimitry Andric// the compiler and '1' otherwise. 4190b57cec5SDimitry Andric# ifndef __is_identifier 4200b57cec5SDimitry Andric# define __is_identifier(__x) 1 4210b57cec5SDimitry Andric# endif 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andric# ifndef __has_declspec_attribute 4240b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 4250b57cec5SDimitry Andric# endif 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 4280b57cec5SDimitry Andric 4290b57cec5SDimitry Andric# ifndef __has_include 4300b57cec5SDimitry Andric# define __has_include(...) 0 4310b57cec5SDimitry Andric# endif 4320b57cec5SDimitry Andric 43381ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 43481ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 4350b57cec5SDimitry Andric# endif 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 4380b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 4390b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 4400b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 4410b57cec5SDimitry Andric// heuristic falls short. 4420b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4430b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 4440b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 4450b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4460b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4470b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4480b57cec5SDimitry Andric# else 4490b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 4500b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4510b57cec5SDimitry Andric# else 4520b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4530b57cec5SDimitry Andric# endif 4540b57cec5SDimitry Andric# endif 4550b57cec5SDimitry Andric 4560b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 4570b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 4580b57cec5SDimitry Andric# endif 4590b57cec5SDimitry Andric 460fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 461fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 462fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 463fcaf7f86SDimitry Andric# endif 464fcaf7f86SDimitry Andric# endif 465fcaf7f86SDimitry Andric 466fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 467fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 468fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 46906c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 47006c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 4715f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_TZDB 4725f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 473fcaf7f86SDimitry Andric# endif 474fcaf7f86SDimitry Andric 4750b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 4760b57cec5SDimitry Andric# if defined(__linux__) 4770b57cec5SDimitry Andric# include <features.h> 4780b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 4790b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 4800b57cec5SDimitry Andric# else 4810b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 4820b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 4830b57cec5SDimitry Andric# endif // defined(__linux__) 4840b57cec5SDimitry Andric 48504eeddc0SDimitry Andric# if defined(__MVS__) 48604eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 48704eeddc0SDimitry Andric# endif 48804eeddc0SDimitry Andric 4895f757f3fSDimitry Andric# ifndef __BYTE_ORDER__ 4905f757f3fSDimitry Andric# error \ 4915f757f3fSDimitry Andric "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" 4925f757f3fSDimitry Andric# endif 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 4950b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4960b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4970b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4980b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4990b57cec5SDimitry Andric 5000b57cec5SDimitry Andric# if defined(_WIN32) 5010b57cec5SDimitry Andric# define _LIBCPP_WIN32API 5020b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 5030b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 5040b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 5050b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 5060b57cec5SDimitry Andric// a MS compatibility version is specified. 5070b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 5080b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 5090b57cec5SDimitry Andric# endif 5100b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 5110b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 5120b57cec5SDimitry Andric# endif 5130b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 5140b57cec5SDimitry Andric# endif // defined(_WIN32) 5150b57cec5SDimitry Andric 516349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 517349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 518349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 519349cc55cSDimitry Andric# endif 520349cc55cSDimitry Andric 5210eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 5220eae32dcSDimitry Andric// 5230eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 5240eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 5250eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 5260eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 5270eae32dcSDimitry Andric// else is specified. This implementation requires storing state 5280eae32dcSDimitry Andric// inside `std::random_device`. 5290eae32dcSDimitry Andric// 5300eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 5310eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 5320eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 5330eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 5340eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5350eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5360eae32dcSDimitry Andric// 5370eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 5380eae32dcSDimitry Andric// Use getentropy(). 5390eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5400eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5410eae32dcSDimitry Andric// 54204eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 54304eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 54404eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 54504eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 54604eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 54704eeddc0SDimitry Andric// 5480eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 5490eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 5500eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 5510eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 5520eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5530eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5540eae32dcSDimitry Andric// 5550eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 5560eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 5570eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5580eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 55981ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 56006c3fb27SDimitry Andric defined(__DragonFly__) 5610b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 56281ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 5630b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 56404eeddc0SDimitry Andric# elif defined(__Fuchsia__) 56504eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 5660b57cec5SDimitry Andric# elif defined(__native_client__) 5670b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 5680b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 5690b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 5700b57cec5SDimitry Andric# else 5710b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 5720b57cec5SDimitry Andric# endif 5730b57cec5SDimitry Andric 5740b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 57581ad6265SDimitry Andric 5760b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 57781ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 57881ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 57981ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 58081ad6265SDimitry Andric# define _NOEXCEPT noexcept 58181ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 582bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 58381ad6265SDimitry Andric 5840b57cec5SDimitry Andric# else 58581ad6265SDimitry Andric 58681ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 58781ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 58881ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 589bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 59081ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 59181ad6265SDimitry Andric# define nullptr __nullptr 59281ad6265SDimitry Andric# define _NOEXCEPT throw() 59381ad6265SDimitry Andric# define _NOEXCEPT_(x) 594bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 595bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 596bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 59781ad6265SDimitry Andric 59881ad6265SDimitry Andrictypedef __char16_t char16_t; 59981ad6265SDimitry Andrictypedef __char32_t char32_t; 60081ad6265SDimitry Andric 60181ad6265SDimitry Andric# endif 60281ad6265SDimitry Andric 60381ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 60406c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXCEPTIONS 6050b57cec5SDimitry Andric# endif 6060b57cec5SDimitry Andric 6070b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 6080b57cec5SDimitry Andric 609fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 6100b57cec5SDimitry Andric 61106c3fb27SDimitry Andric# if defined(__APPLE__) 61206c3fb27SDimitry Andric# if defined(__i386__) || defined(__x86_64__) 61306c3fb27SDimitry Andric// use old string layout on x86_64 and i386 61406c3fb27SDimitry Andric# elif defined(__arm__) 61506c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 61606c3fb27SDimitry Andric# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 6170b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 6180b57cec5SDimitry Andric# endif 61906c3fb27SDimitry Andric# else 62006c3fb27SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 62106c3fb27SDimitry Andric# endif 62206c3fb27SDimitry Andric# endif 6230b57cec5SDimitry Andric 6240b57cec5SDimitry Andric// Objective-C++ features (opt-in) 6250b57cec5SDimitry Andric# if __has_feature(objc_arc) 6260b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 6270b57cec5SDimitry Andric# endif 6280b57cec5SDimitry Andric 6290b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 6300b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 6310b57cec5SDimitry Andric# endif 6320b57cec5SDimitry Andric 6335ffd83dbSDimitry Andric# if __has_extension(blocks) 6345ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 6355ffd83dbSDimitry Andric# endif 6365ffd83dbSDimitry Andric 6375ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 6385ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 6395ffd83dbSDimitry Andric# endif 6405ffd83dbSDimitry Andric 641fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 6420b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 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 6985f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 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 7265f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 7275f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 7280b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 7290b57cec5SDimitry Andric# else 7300b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 7310b57cec5SDimitry Andric# endif 7320b57cec5SDimitry Andric 733*46c59ea9SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \ 734*46c59ea9SDimitry Andric _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization 7355f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 7360b57cec5SDimitry Andric# else 7375f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 7380b57cec5SDimitry Andric# endif 7390b57cec5SDimitry Andric 74081ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 7410b57cec5SDimitry Andric 7420b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 7430b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 7440b57cec5SDimitry Andric# else 7450b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 7460b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 7470b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 7480b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 7490b57cec5SDimitry Andric# endif 7500b57cec5SDimitry Andric 7515f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 7525f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG f 7535f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 754b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG s 7555f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 756b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG d 757b121cb00SDimitry Andric# else 7585f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG n // "none" 759b121cb00SDimitry Andric# endif 760b121cb00SDimitry Andric 761b121cb00SDimitry Andric# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 762b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG n 763b121cb00SDimitry Andric# else 764b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG e 765b121cb00SDimitry Andric# endif 766b121cb00SDimitry Andric 767b121cb00SDimitry Andric# define _LIBCPP_ODR_SIGNATURE \ 768b121cb00SDimitry Andric _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 769b121cb00SDimitry Andric 770753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 771753f127fSDimitry Andric// on two levels: 772753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 773753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 774753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 775753f127fSDimitry Andric// 776b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 777b121cb00SDimitry Andric// This ensures that no ODR violation can arise from mixing two TUs compiled with different 778b121cb00SDimitry Andric// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 779b121cb00SDimitry Andric// program contains two definitions of a function, the ODR requires them to be token-by-token 780b121cb00SDimitry Andric// equivalent, and the linker is allowed to pick either definition and discard the other one. 781b121cb00SDimitry Andric// 782b121cb00SDimitry Andric// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 783b121cb00SDimitry Andric// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 784b121cb00SDimitry Andric// compiled with different settings), the two definitions are both visible by the linker and they 785b121cb00SDimitry Andric// have the same name, but they have a meaningfully different implementation (one throws an exception 786b121cb00SDimitry Andric// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 787b121cb00SDimitry Andric// practice what will happen is that the linker will pick one of the definitions at random and will 788b121cb00SDimitry Andric// discard the other one. This can quite clearly lead to incorrect program behavior. 789b121cb00SDimitry Andric// 790b121cb00SDimitry Andric// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 791b121cb00SDimitry Andric// property that causes the code of a function to differ from the code in another configuration 792b121cb00SDimitry Andric// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 793b121cb00SDimitry Andric// tag, but we encode the ones that we think are most important: library version, exceptions, and 794b121cb00SDimitry Andric// hardening mode. 795b121cb00SDimitry Andric// 796b121cb00SDimitry Andric// Note that historically, solving this problem has been achieved in various ways, including 797b121cb00SDimitry Andric// force-inlining all functions or giving internal linkage to all functions. Both these previous 798b121cb00SDimitry Andric// solutions suffer from drawbacks that lead notably to code bloat. 799753f127fSDimitry Andric// 800753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 801753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 802753f127fSDimitry Andric// 803bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 804bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 805bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 806bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 807bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 808bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 809bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 810bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 811bdd1243dSDimitry Andric// 812753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 813753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 814753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 815753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 816753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 817753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 818b121cb00SDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 8190b57cec5SDimitry Andric# else 8200b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8210b57cec5SDimitry Andric# endif 822bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8230b57cec5SDimitry Andric 8241ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 8251ac55f4cSDimitry Andric// "C" function, as those lack mangling. 8261ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8271ac55f4cSDimitry Andric 8280b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 8290b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 8300b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8310b57cec5SDimitry Andric# else 8320b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 8330b57cec5SDimitry Andric# endif 8340b57cec5SDimitry Andric# else 8350b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8360b57cec5SDimitry Andric# endif 8370b57cec5SDimitry Andric 8385f757f3fSDimitry Andric// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around 8395f757f3fSDimitry Andric// only to ease the renaming for downstreams. 8400b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 8415f757f3fSDimitry Andric# define _VSTD std 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 84481ad6265SDimitry Andric// clang-format off 8455f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 8465f757f3fSDimitry Andric inline namespace _LIBCPP_ABI_NAMESPACE { 8470b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 84881ad6265SDimitry Andric 8495f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 8505f757f3fSDimitry Andric inline namespace __fs { namespace filesystem { 8510b57cec5SDimitry Andric 85281ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 85381ad6265SDimitry Andric// clang-format on 8540b57cec5SDimitry Andric 8550b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 8560b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 8570b57cec5SDimitry Andric# endif 8580b57cec5SDimitry Andric 85906c3fb27SDimitry Andric# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 8600b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 8610b57cec5SDimitry Andric# endif 8620b57cec5SDimitry Andric 86381ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 86481ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 86506c3fb27SDimitry Andric struct _LIBCPP_EXPORTED_FROM_ABI x { \ 86681ad6265SDimitry Andric enum __lx 86781ad6265SDimitry Andric// clang-format off 8680b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 8690b57cec5SDimitry Andric __lx __v_; \ 8705f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 8715f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 8725f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 8730b57cec5SDimitry Andric }; 87481ad6265SDimitry Andric// clang-format on 87581ad6265SDimitry Andric 87681ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 8775f757f3fSDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 8780b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 87981ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 8800b57cec5SDimitry Andric 88106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 8820b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 8830b57cec5SDimitry Andric# endif 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andric# ifdef __FreeBSD__ 8860b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 8870b57cec5SDimitry Andric# endif 8880b57cec5SDimitry Andric 8890b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 8900b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 8910b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 8920b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8930b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 8940b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 8950b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 8960b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 897e8d8bef9SDimitry Andric# elif defined(__MVS__) 898e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8990b57cec5SDimitry Andric# endif 9000b57cec5SDimitry Andric 90181ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 9020b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 9030b57cec5SDimitry Andric# endif 9040b57cec5SDimitry Andric 905bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 906bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 907bdd1243dSDimitry Andric# if defined(__APPLE__) 908bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 909bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 910bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 911bdd1243dSDimitry Andric# endif 912bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 913bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 914bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 915bdd1243dSDimitry Andric# endif 916bdd1243dSDimitry Andric 9170b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9180b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 9190b57cec5SDimitry Andric# endif 9200b57cec5SDimitry Andric 92106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9220b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 9230b57cec5SDimitry Andric# endif 9240b57cec5SDimitry Andric 9250b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 926fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 9270b57cec5SDimitry Andric# endif 9280b57cec5SDimitry Andric 9290b57cec5SDimitry Andric// Deprecation macros. 9300b57cec5SDimitry Andric// 9310b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 9320b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 9330b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 93406c3fb27SDimitry Andric# if __has_attribute(__deprecated__) 93506c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 93606c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 93706c3fb27SDimitry Andric# elif _LIBCPP_STD_VER >= 14 9380b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 93981ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 9400b57cec5SDimitry Andric# else 9410b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 94281ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9430b57cec5SDimitry Andric# endif 9440b57cec5SDimitry Andric# else 9450b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 94681ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9470b57cec5SDimitry Andric# endif 9480b57cec5SDimitry Andric 9490b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 9500b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 9510b57cec5SDimitry Andric# else 9520b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 9530b57cec5SDimitry Andric# endif 9540b57cec5SDimitry Andric 95506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 9560b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 9570b57cec5SDimitry Andric# else 9580b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 9590b57cec5SDimitry Andric# endif 9600b57cec5SDimitry Andric 96106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 9620b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 9630b57cec5SDimitry Andric# else 9640b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 9650b57cec5SDimitry Andric# endif 9660b57cec5SDimitry Andric 96706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 968e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 969e8d8bef9SDimitry Andric# else 970e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 971e8d8bef9SDimitry Andric# endif 972e8d8bef9SDimitry Andric 973bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 23 974bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 975bdd1243dSDimitry Andric# else 976bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 977bdd1243dSDimitry Andric# endif 978bdd1243dSDimitry Andric 979fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 980e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 981e8d8bef9SDimitry Andric# else 982e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 983e8d8bef9SDimitry Andric# endif 984e8d8bef9SDimitry Andric 985e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 986fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 987e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 98881ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 989fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 99081ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 991fe6060f1SDimitry Andric# else 992e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 993e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 994e40139ffSDimitry Andric# endif 995e40139ffSDimitry Andric 9960b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 99706c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 9980b57cec5SDimitry Andric# else 99906c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 10000b57cec5SDimitry Andric# endif 10010b57cec5SDimitry Andric 100206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 100306c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 100406c3fb27SDimitry Andric# else 100506c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 100606c3fb27SDimitry Andric# endif 100706c3fb27SDimitry Andric 100806c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 1009bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 10100b57cec5SDimitry Andric# else 1011bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 10120b57cec5SDimitry Andric# endif 10130b57cec5SDimitry Andric 101406c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 1015bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 10160b57cec5SDimitry Andric# else 1017bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 10180b57cec5SDimitry Andric# endif 10190b57cec5SDimitry Andric 102006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1021bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 10220b57cec5SDimitry Andric# else 1023bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 10240b57cec5SDimitry Andric# endif 10250b57cec5SDimitry Andric 102606c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 1027bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1028bdd1243dSDimitry Andric# else 1029bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1030bdd1243dSDimitry Andric# endif 1031bdd1243dSDimitry Andric 10320b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 103306c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void 103481ad6265SDimitry Andric__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 103506c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 103606c3fb27SDimitry Andric const void*, const void*, const void*, const void*, const void*, const void*); 103706c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int 103806c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 103906c3fb27SDimitry Andric# endif 10400b57cec5SDimitry Andric 10410b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 104281ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 10431ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 10440b57cec5SDimitry Andric# endif 10450b57cec5SDimitry Andric 10460b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 10470b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 10480b57cec5SDimitry Andric# endif 10490b57cec5SDimitry Andric 10500b57cec5SDimitry Andric// Thread API 105181ad6265SDimitry Andric// clang-format off 10520b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 10530b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 10540b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 10550b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 105681ad6265SDimitry Andric 10570b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 10580b57cec5SDimitry Andric defined(__wasi__) || \ 10590b57cec5SDimitry Andric defined(__NetBSD__) || \ 1060e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 1061e8d8bef9SDimitry Andric defined(__NuttX__) || \ 10620b57cec5SDimitry Andric defined(__linux__) || \ 10630b57cec5SDimitry Andric defined(__GNU__) || \ 10640b57cec5SDimitry Andric defined(__APPLE__) || \ 1065e8d8bef9SDimitry Andric defined(__MVS__) || \ 106681ad6265SDimitry Andric defined(_AIX) || \ 106781ad6265SDimitry Andric defined(__EMSCRIPTEN__) 106881ad6265SDimitry Andric// clang-format on 10690b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 1070480093f4SDimitry Andric# elif defined(__Fuchsia__) 10715ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 10725ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 10730b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 10740b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 10750b57cec5SDimitry Andric# else 10760b57cec5SDimitry Andric# error "No thread API" 10770b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 10780b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 10790b57cec5SDimitry Andric 1080e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1081e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1082e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1083e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 1084e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 1085e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1086e40139ffSDimitry Andric# endif 1087e40139ffSDimitry Andric# endif 1088e40139ffSDimitry Andric# endif 1089e40139ffSDimitry Andric 10900b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 10910b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 10920b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 10930b57cec5SDimitry Andric# endif 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 10960b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 10970b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 10980b57cec5SDimitry Andric# endif 10990b57cec5SDimitry Andric 11000b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 11010b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 11020b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 11030b57cec5SDimitry Andric# endif 11040b57cec5SDimitry Andric 1105e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1106e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 1107e40139ffSDimitry Andric# endif 1108e40139ffSDimitry Andric 1109e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 11100b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 11110b57cec5SDimitry Andric// mutexes have no destroy mechanism. 1112e40139ffSDimitry Andric// 1113e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1114e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 1115e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1116e40139ffSDimitry Andric// 1117e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1118e40139ffSDimitry Andric// respective stakeholders. 111981ad6265SDimitry Andric// clang-format off 112081ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 112181ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 112281ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 112381ad6265SDimitry Andric// clang-format on 11240b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 11250b57cec5SDimitry Andric# endif 11260b57cec5SDimitry Andric 11270b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 1128e40139ffSDimitry Andric// 1129e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1130e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 1131e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1132e40139ffSDimitry Andric// 11330b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 11340b57cec5SDimitry Andric// as well. 113581ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 11360b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 11370b57cec5SDimitry Andric# endif 11380b57cec5SDimitry Andric 113981ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 114004eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 11410b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 11420b57cec5SDimitry Andric# endif 11430b57cec5SDimitry Andric 11440b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 11450b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 11460b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 11470b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 11480b57cec5SDimitry Andric# endif 11490b57cec5SDimitry Andric 115081ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1151349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 11520b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 11530b57cec5SDimitry Andric# else 11540b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 11550b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 11560b57cec5SDimitry Andric# endif 11570b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 11580b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 11590b57cec5SDimitry Andric# endif 11600b57cec5SDimitry Andric# endif 11610b57cec5SDimitry Andric 116206c3fb27SDimitry Andric# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 116306c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 116406c3fb27SDimitry Andric# else 116506c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 116606c3fb27SDimitry Andric# endif 116706c3fb27SDimitry Andric 11680b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 11690b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 11700b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 11710b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 11721fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 11731fd87a68SDimitry Andric// combining the two does work. 11741fd87a68SDimitry Andric# if !defined(_MSC_VER) 11750b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 11760b57cec5SDimitry Andric# endif 11770b57cec5SDimitry Andric# endif 11780b57cec5SDimitry Andric# endif 11790b57cec5SDimitry Andric 1180480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1181480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1182480093f4SDimitry Andric# else 1183480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1184480093f4SDimitry Andric# endif 1185480093f4SDimitry Andric 118606c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 118781ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1188bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 118981ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 11900b57cec5SDimitry Andric# else 119181ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 11920b57cec5SDimitry Andric# endif 11930b57cec5SDimitry Andric 11945f757f3fSDimitry Andric# if __has_attribute(__noinline__) 11955f757f3fSDimitry Andric# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 11960b57cec5SDimitry Andric# else 11975f757f3fSDimitry Andric# define _LIBCPP_NOINLINE 119806c3fb27SDimitry Andric# endif 119906c3fb27SDimitry Andric 1200349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1201349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1202349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1203349cc55cSDimitry Andric// impact on readability. 1204349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1205349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1206349cc55cSDimitry Andric# else 1207349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1208349cc55cSDimitry Andric# endif 1209349cc55cSDimitry Andric 12100b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 12110b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 12120b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1213fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1214fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 121581ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 12160b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 12170b57cec5SDimitry Andric 1218fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1219fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 122081ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1221fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1222fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1223fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1224fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1225fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1226fe6060f1SDimitry Andric 122706c3fb27SDimitry Andric// clang-format off 122806c3fb27SDimitry 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()\")") 122906c3fb27SDimitry 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()\")") 123006c3fb27SDimitry Andric// clang-format on 12310b57cec5SDimitry Andric 12320b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 12330b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1234fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 12350b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 12360b57cec5SDimitry Andric# else 12370b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 12380b57cec5SDimitry Andric# endif 12390b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 12400b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 12410b57cec5SDimitry Andric 1242e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1243e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1244e40139ffSDimitry Andric// 1245e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1246e40139ffSDimitry Andric// do. 1247e40139ffSDimitry Andric# if defined(__BIONIC__) 1248e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1249e40139ffSDimitry Andric# else 1250e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1251e40139ffSDimitry Andric# endif 1252e40139ffSDimitry Andric 125381ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 125481ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 125581ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 125681ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 125781ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 125881ad6265SDimitry Andric 125981ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 126081ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 126181ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 126281ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 126381ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 126406c3fb27SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 126581ad6265SDimitry Andric# else 126681ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 126781ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 126881ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 126981ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 127081ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 127181ad6265SDimitry Andric// because using it conditionally in one language version only would make 127281ad6265SDimitry Andric// the ABI inconsistent. 127381ad6265SDimitry Andric# endif 127481ad6265SDimitry Andric 127581ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 127681ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 127781ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 127881ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 127981ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 128081ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 128181ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 128281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 128381ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 128481ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 128581ad6265SDimitry Andric# else 128681ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 128781ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 128881ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 128981ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 129081ad6265SDimitry Andric# endif 129181ad6265SDimitry Andric 1292bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1293bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1294bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1295bdd1243dSDimitry Andric// functions are declared by the C library. 1296bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1297bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 12981ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 12991ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 13001ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 13011ac55f4cSDimitry Andric// defined are ignored. 13021ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 13031ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1304bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1305bdd1243dSDimitry Andric# endif 1306bdd1243dSDimitry Andric# endif 1307bdd1243dSDimitry Andric 1308bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1309bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1310bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1311bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1312bdd1243dSDimitry Andric// with these classes. 1313bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 17 131406c3fb27SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 1315bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1316bdd1243dSDimitry Andric template <class... _Tag> \ 131706c3fb27SDimitry Andric [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 131806c3fb27SDimitry Andric# else 131906c3fb27SDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 132006c3fb27SDimitry Andric template <class... _Tag> \ 132106c3fb27SDimitry Andric ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 132206c3fb27SDimitry Andric# endif 1323bdd1243dSDimitry Andric# else 1324bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1325bdd1243dSDimitry Andric# endif 1326bdd1243dSDimitry Andric 13271ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 13281ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 13291ac55f4cSDimitry Andric# ifdef __OBJC__ 13301ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 13311ac55f4cSDimitry Andric# endif 13321ac55f4cSDimitry Andric 133306c3fb27SDimitry Andric# define _PSTL_PRAGMA(x) _Pragma(#x) 133406c3fb27SDimitry Andric 133506c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0 133606c3fb27SDimitry Andric# if (defined(_OPENMP) && _OPENMP >= 201307) 133706c3fb27SDimitry Andric 133806c3fb27SDimitry Andric# define _PSTL_UDR_PRESENT 133906c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 134006c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 134106c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 134206c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 134306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 134406c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 134506c3fb27SDimitry Andric 134606c3fb27SDimitry Andric// Declaration of reduction functor, where 134706c3fb27SDimitry Andric// NAME - the name of the functor 134806c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation 134906c3fb27SDimitry Andric// omp_in - refers to the local partial result 135006c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator 135106c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value 135206c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced 135306c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 135406c3fb27SDimitry Andric _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 135506c3fb27SDimitry Andric 13565f757f3fSDimitry Andric# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 13575f757f3fSDimitry Andric 13585f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 13595f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 13605f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 13615f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 13625f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 13635f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 13645f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 13655f757f3fSDimitry Andric 136606c3fb27SDimitry Andric# else // (defined(_OPENMP) && _OPENMP >= 201307) 136706c3fb27SDimitry Andric 136806c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD 136906c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 137006c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 137106c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 137206c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 137306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 137406c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 137506c3fb27SDimitry Andric 137606c3fb27SDimitry Andric# endif // (defined(_OPENMP) && _OPENMP >= 201307) 137706c3fb27SDimitry Andric 137806c3fb27SDimitry Andric# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 137906c3fb27SDimitry Andric 13805f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available 13815f757f3fSDimitry Andric 13825f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 13835f757f3fSDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 13845f757f3fSDimitry Andric# else 13855f757f3fSDimitry Andric# define _LIBCPP_NO_CFI 13865f757f3fSDimitry Andric# endif 13875f757f3fSDimitry Andric 13885f757f3fSDimitry Andric# if __has_attribute(__malloc__) 13895f757f3fSDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 13905f757f3fSDimitry Andric# else 13915f757f3fSDimitry Andric# define _LIBCPP_NOALIAS 13925f757f3fSDimitry Andric# endif 13935f757f3fSDimitry Andric 13945f757f3fSDimitry Andric# if __has_attribute(__using_if_exists__) 13955f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 13965f757f3fSDimitry Andric# else 13975f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS 13985f757f3fSDimitry Andric# endif 13995f757f3fSDimitry Andric 14005f757f3fSDimitry Andric# if __has_cpp_attribute(nodiscard) 14015f757f3fSDimitry Andric# define _LIBCPP_NODISCARD [[__nodiscard__]] 14025f757f3fSDimitry Andric# else 14035f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 14045f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 14055f757f3fSDimitry Andric// (void) cast. 14065f757f3fSDimitry Andric# define _LIBCPP_NODISCARD 14075f757f3fSDimitry Andric# endif 14085f757f3fSDimitry Andric 14095f757f3fSDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 14105f757f3fSDimitry Andric// specified as such as an extension. 14115f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 14125f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 14135f757f3fSDimitry Andric# else 14145f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT 14155f757f3fSDimitry Andric# endif 14165f757f3fSDimitry Andric 14175f757f3fSDimitry Andric# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 14185f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 14195f757f3fSDimitry Andric# else 14205f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 14215f757f3fSDimitry Andric# endif 14225f757f3fSDimitry Andric 14235f757f3fSDimitry Andric# if __has_attribute(__no_destroy__) 14245f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 14255f757f3fSDimitry Andric# else 14265f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY 14275f757f3fSDimitry Andric# endif 14285f757f3fSDimitry Andric 14295f757f3fSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 14305f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 14315f757f3fSDimitry Andric# else 14325f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 14335f757f3fSDimitry Andric# endif 14345f757f3fSDimitry Andric 14355f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 14365f757f3fSDimitry Andric# if __has_cpp_attribute(fallthrough) 14375f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 14385f757f3fSDimitry Andric# elif __has_attribute(__fallthrough__) 14395f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 14405f757f3fSDimitry Andric# else 14415f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 14425f757f3fSDimitry Andric# endif 14435f757f3fSDimitry Andric 14445f757f3fSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 14455f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 14465f757f3fSDimitry Andric# else 14475f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 14485f757f3fSDimitry Andric# endif 14495f757f3fSDimitry Andric 14505f757f3fSDimitry Andric# if __has_attribute(__nodebug__) 14515f757f3fSDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 14525f757f3fSDimitry Andric# else 14535f757f3fSDimitry Andric# define _LIBCPP_NODEBUG 14545f757f3fSDimitry Andric# endif 14555f757f3fSDimitry Andric 14565f757f3fSDimitry Andric# if __has_attribute(__standalone_debug__) 14575f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 14585f757f3fSDimitry Andric# else 14595f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 14605f757f3fSDimitry Andric# endif 14615f757f3fSDimitry Andric 14625f757f3fSDimitry Andric# if __has_attribute(__preferred_name__) 14635f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 14645f757f3fSDimitry Andric# else 14655f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 14665f757f3fSDimitry Andric# endif 14675f757f3fSDimitry Andric 14685f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) 14695f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 14705f757f3fSDimitry Andric# else 14715f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) 14725f757f3fSDimitry Andric# endif 14735f757f3fSDimitry Andric 14745f757f3fSDimitry Andric# if __has_attribute(__init_priority__) 14755f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 14765f757f3fSDimitry Andric# else 14775f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 14785f757f3fSDimitry Andric# endif 14795f757f3fSDimitry Andric 14805f757f3fSDimitry Andric# if __has_attribute(__format__) 14815f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 14825f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 14835f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 14845f757f3fSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 14855f757f3fSDimitry Andric# else 14865f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 14875f757f3fSDimitry Andric# endif 14885f757f3fSDimitry Andric 14895f757f3fSDimitry Andric# if __has_attribute(__packed__) 14905f757f3fSDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 14915f757f3fSDimitry Andric# else 14925f757f3fSDimitry Andric# define _LIBCPP_PACKED 14935f757f3fSDimitry Andric# endif 14945f757f3fSDimitry Andric 14955f757f3fSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 14965f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 14975f757f3fSDimitry Andric# else 14985f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 14995f757f3fSDimitry Andric# endif 15005f757f3fSDimitry Andric 15015f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 15025f757f3fSDimitry Andric# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 15035f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 15045f757f3fSDimitry Andric# else 15055f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 15065f757f3fSDimitry Andric# endif 15075f757f3fSDimitry Andric 15080b57cec5SDimitry Andric#endif // __cplusplus 15090b57cec5SDimitry Andric 151081ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1511