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 28*5f757f3fSDimitry Andric# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) 296246ae0bSDimitry Andric#endif 306246ae0bSDimitry Andric 310b57cec5SDimitry Andric#ifdef __cplusplus 320b57cec5SDimitry Andric 33*5f757f3fSDimitry Andric// Warn if a compiler version is used that is not supported anymore 34*5f757f3fSDimitry Andric// LLVM RELEASE Update the minimum compiler versions 35*5f757f3fSDimitry Andric# if defined(_LIBCPP_CLANG_VER) 36*5f757f3fSDimitry Andric# if _LIBCPP_CLANG_VER < 1600 37*5f757f3fSDimitry Andric# warning "Libc++ only supports Clang 16 and later" 38*5f757f3fSDimitry Andric# endif 39*5f757f3fSDimitry Andric# elif defined(_LIBCPP_APPLE_CLANG_VER) 40*5f757f3fSDimitry Andric# if _LIBCPP_APPLE_CLANG_VER < 1500 41*5f757f3fSDimitry Andric# warning "Libc++ only supports AppleClang 15 and later" 42*5f757f3fSDimitry Andric# endif 43*5f757f3fSDimitry Andric# elif defined(_LIBCPP_GCC_VER) 44*5f757f3fSDimitry Andric# if _LIBCPP_GCC_VER < 1300 45*5f757f3fSDimitry Andric# warning "Libc++ only supports GCC 13 and later" 46*5f757f3fSDimitry Andric# endif 47*5f757f3fSDimitry Andric# endif 48*5f757f3fSDimitry Andric 4906c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 5006c3fb27SDimitry Andric 51bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 5206c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 53bdd1243dSDimitry Andric// defined to XXYYZZ. 54*5f757f3fSDimitry Andric# define _LIBCPP_VERSION 180000 550b57cec5SDimitry Andric 56753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 57753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 58753f127fSDimitry Andric 59e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 600b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 610b57cec5SDimitry Andric# endif 620b57cec5SDimitry Andric 6306c3fb27SDimitry Andric// NOLINTBEGIN(libcpp-cpp-version-check) 640b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 650b57cec5SDimitry Andric# if __cplusplus <= 201103L 660b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 670b57cec5SDimitry Andric# elif __cplusplus <= 201402L 680b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 690b57cec5SDimitry Andric# elif __cplusplus <= 201703L 700b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 71e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 72e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 7306c3fb27SDimitry Andric# elif __cplusplus <= 202302L 7406c3fb27SDimitry Andric# define _LIBCPP_STD_VER 23 750b57cec5SDimitry Andric# else 76bdd1243dSDimitry Andric// Expected release year of the next C++ standard 7706c3fb27SDimitry Andric# define _LIBCPP_STD_VER 26 780b57cec5SDimitry Andric# endif 790b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 8006c3fb27SDimitry Andric// NOLINTEND(libcpp-cpp-version-check) 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric# if defined(__ELF__) 830b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 840b57cec5SDimitry Andric# elif defined(__MACH__) 850b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 860b57cec5SDimitry Andric# elif defined(_WIN32) 870b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 880b57cec5SDimitry Andric# elif defined(__wasm__) 890b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 9081ad6265SDimitry Andric# elif defined(_AIX) 9181ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 920b57cec5SDimitry Andric# else 93e8d8bef9SDimitry Andric// ... add new file formats here ... 940b57cec5SDimitry Andric# endif 950b57cec5SDimitry Andric 9606c3fb27SDimitry Andric// ABI { 9706c3fb27SDimitry Andric 9881ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 990b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 1000b57cec5SDimitry Andric// improving its alignment in some cases. 1010b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 1020b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 1030b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 1040b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 1050b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 1060b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 1070b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 1080b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 1090b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 1100b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 1110b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 1120b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 1130b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 1140b57cec5SDimitry Andric// using that class define their own copies. 1150b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 116349cc55cSDimitry Andric// Override the default return value of exception::what() for 117349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 118349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 119349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 120349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1210b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1220b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 123fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 124fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 125fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1260b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1270b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1280b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1290b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1300b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1310b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1320b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1335ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1345ffd83dbSDimitry Andric// performance and fast-path inlining. 1355ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 136e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 137e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 138e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 139e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 14004eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 14104eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 14204eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 14304eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 14404eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 14504eeddc0SDimitry Andric// about ABI compatibility. 14604eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 14781ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1481838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 14981ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 150d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 15181ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 15281ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 1531ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 1541ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 1551ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 1561ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 1571ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 1581ac55f4cSDimitry Andric// 1591ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 1601ac55f4cSDimitry Andric// bits on the floor. 1611ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 16281ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 16381ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 16481ad6265SDimitry Andric// the dylib for backwards compatibility. 16581ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 166*5f757f3fSDimitry Andric// Save memory by providing the allocator more freedom to allocate the most 167*5f757f3fSDimitry Andric// efficient size class by dropping the alignment requirements for std::string's 168*5f757f3fSDimitry Andric// pointer from 16 to 8. This changes the output of std::string::max_size, 169*5f757f3fSDimitry Andric// which makes it ABI breaking 170*5f757f3fSDimitry Andric# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT 1710b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 17281ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1730b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1740b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1750b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1760b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 17781ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 17881ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 17981ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 18081ad6265SDimitry Andric// so disable it. 1810b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1820b57cec5SDimitry Andric# endif 1830b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1840b57cec5SDimitry Andric// are deprecated. 185*5f757f3fSDimitry Andric# if defined(__FreeBSD__) && __FreeBSD__ < 14 1860b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1870b57cec5SDimitry Andric# endif 18806c3fb27SDimitry Andric// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 18906c3fb27SDimitry Andric// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 19006c3fb27SDimitry Andric// in the library, so we need to always rely on the library version. 19106c3fb27SDimitry Andric# if defined(_AIX) 19206c3fb27SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 19306c3fb27SDimitry Andric# endif 1940b57cec5SDimitry Andric# endif 1950b57cec5SDimitry Andric 19681ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 197349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 198349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 199349cc55cSDimitry Andric// using that class define their own copies. 200349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 2010b57cec5SDimitry Andric# endif 2020b57cec5SDimitry Andric 20306c3fb27SDimitry Andric// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 20406c3fb27SDimitry Andric// within the bounds of the original container and asserts it on every dereference. 20506c3fb27SDimitry Andric// 20606c3fb27SDimitry Andric// ABI impact: changes the iterator type of the relevant containers. 20706c3fb27SDimitry Andric// 20806c3fb27SDimitry Andric// Supported containers: 20906c3fb27SDimitry Andric// - `span`; 21006c3fb27SDimitry Andric// - `string_view`; 21106c3fb27SDimitry Andric// - `array`. 21206c3fb27SDimitry Andric// #define _LIBCPP_ABI_BOUNDED_ITERATORS 21306c3fb27SDimitry Andric 21406c3fb27SDimitry Andric// } ABI 21506c3fb27SDimitry Andric 21606c3fb27SDimitry Andric// HARDENING { 21706c3fb27SDimitry Andric 218*5f757f3fSDimitry Andric// TODO(hardening): deprecate this in LLVM 19. 219*5f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 220*5f757f3fSDimitry Andric// equivalent to setting the extensive mode. 221*5f757f3fSDimitry Andric# ifdef _LIBCPP_ENABLE_ASSERTIONS 22206c3fb27SDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 22306c3fb27SDimitry Andric# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 22406c3fb27SDimitry Andric# endif 225*5f757f3fSDimitry Andric# if _LIBCPP_ENABLE_ASSERTIONS 226*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE 227*5f757f3fSDimitry Andric# endif 228*5f757f3fSDimitry Andric# endif 22906c3fb27SDimitry Andric 230*5f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 2318a4dda33SDimitry Andric// 232*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`; 233*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`; 234*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 235*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`. 23606c3fb27SDimitry Andric// 237*5f757f3fSDimitry Andric// These values have the following effects: 23806c3fb27SDimitry Andric// 239*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 240*5f757f3fSDimitry Andric// 241*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 242*5f757f3fSDimitry Andric// that can be done with relatively little runtime overhead in constant time; 243*5f757f3fSDimitry Andric// 244*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 245*5f757f3fSDimitry Andric// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 246*5f757f3fSDimitry Andric// but are not necessarily security-critical; 247*5f757f3fSDimitry Andric// 248*5f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 249*5f757f3fSDimitry Andric// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 250*5f757f3fSDimitry Andric// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 25106c3fb27SDimitry Andric 25206c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 25306c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 25406c3fb27SDimitry Andric// 25506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 25606c3fb27SDimitry Andric// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 25706c3fb27SDimitry Andric// - the sentinel is reachable from the begin iterator; 25806c3fb27SDimitry Andric// - TODO(hardening): both iterators refer to the same container. 25906c3fb27SDimitry Andric// 26006c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 26106c3fb27SDimitry Andric// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 26206c3fb27SDimitry Andric// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 26306c3fb27SDimitry Andric// `optional` and `function` are considered one-element containers for the purposes of this check. 26406c3fb27SDimitry Andric// 265*5f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 266*5f757f3fSDimitry Andric// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 267*5f757f3fSDimitry Andric// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 268*5f757f3fSDimitry Andric// compiler optimizations). 269*5f757f3fSDimitry Andric// 27006c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 27106c3fb27SDimitry Andric// given ranges do not overlap. 27206c3fb27SDimitry Andric// 27306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 27406c3fb27SDimitry Andric// the containers have compatible allocators. 27506c3fb27SDimitry Andric// 27606c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 27706c3fb27SDimitry Andric// user input. 27806c3fb27SDimitry Andric// 27906c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 28006c3fb27SDimitry Andric 281*5f757f3fSDimitry Andric// clang-format off 282*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 283*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 284*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 285*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 286*5f757f3fSDimitry Andric// clang-format on 287*5f757f3fSDimitry Andric 288*5f757f3fSDimitry Andric# ifndef _LIBCPP_HARDENING_MODE 289*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 29006c3fb27SDimitry Andric# endif 29106c3fb27SDimitry Andric 292*5f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 293*5f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 294*5f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 295*5f757f3fSDimitry Andric _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 296*5f757f3fSDimitry Andric# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 297*5f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \ 298*5f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \ 299*5f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 300*5f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG 30106c3fb27SDimitry Andric# endif 30206c3fb27SDimitry Andric 30306c3fb27SDimitry Andric// clang-format off 304*5f757f3fSDimitry Andric// Fast hardening mode checks. 305*5f757f3fSDimitry Andric 306*5f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 30706c3fb27SDimitry Andric 30806c3fb27SDimitry Andric// Enabled checks. 30906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 31006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 31106c3fb27SDimitry Andric// Disabled checks. 312*5f757f3fSDimitry Andric// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. 313*5f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 31406c3fb27SDimitry Andric// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security 31506c3fb27SDimitry Andric// vulnerability. 31606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 31706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 31806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 31906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 32006c3fb27SDimitry Andric 321*5f757f3fSDimitry Andric// Extensive hardening mode checks. 32206c3fb27SDimitry Andric 323*5f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 32406c3fb27SDimitry Andric 325*5f757f3fSDimitry Andric// Enabled checks. 32606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 32706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 328*5f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 32906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 33006c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 33106c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 332*5f757f3fSDimitry Andric// Disabled checks. 333*5f757f3fSDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 33406c3fb27SDimitry Andric 335*5f757f3fSDimitry Andric// Debug hardening mode checks. 3368a4dda33SDimitry Andric 337*5f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 3388a4dda33SDimitry Andric 3398a4dda33SDimitry Andric// All checks enabled. 3408a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) 3418a4dda33SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) 342*5f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) 3438a4dda33SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message) 3448a4dda33SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) 3458a4dda33SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) 3468a4dda33SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) 3478a4dda33SDimitry Andric 34806c3fb27SDimitry Andric// Disable all checks if hardening is not enabled. 34906c3fb27SDimitry Andric 35006c3fb27SDimitry Andric# else 35106c3fb27SDimitry Andric 35206c3fb27SDimitry Andric// All checks disabled. 35306c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) 35406c3fb27SDimitry Andric# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) 355*5f757f3fSDimitry Andric# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) 35606c3fb27SDimitry Andric# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) 35706c3fb27SDimitry Andric# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) 35806c3fb27SDimitry Andric# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) 35906c3fb27SDimitry Andric# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) 36006c3fb27SDimitry Andric 361*5f757f3fSDimitry Andric# endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 36206c3fb27SDimitry Andric// clang-format on 36306c3fb27SDimitry Andric 36406c3fb27SDimitry Andric// } HARDENING 36506c3fb27SDimitry Andric 36681ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 36781ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 3680b57cec5SDimitry Andric 36906c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check) 3700b57cec5SDimitry Andric# if __cplusplus < 201103L 3710b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 3720b57cec5SDimitry Andric# endif 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andric# ifndef __has_attribute 3750b57cec5SDimitry Andric# define __has_attribute(__x) 0 3760b57cec5SDimitry Andric# endif 3770b57cec5SDimitry Andric 3780b57cec5SDimitry Andric# ifndef __has_builtin 3790b57cec5SDimitry Andric# define __has_builtin(__x) 0 3800b57cec5SDimitry Andric# endif 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andric# ifndef __has_extension 3830b57cec5SDimitry Andric# define __has_extension(__x) 0 3840b57cec5SDimitry Andric# endif 3850b57cec5SDimitry Andric 3860b57cec5SDimitry Andric# ifndef __has_feature 3870b57cec5SDimitry Andric# define __has_feature(__x) 0 3880b57cec5SDimitry Andric# endif 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andric# ifndef __has_cpp_attribute 3910b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 3920b57cec5SDimitry Andric# endif 3930b57cec5SDimitry Andric 394bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 395bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 396bdd1243dSDimitry Andric# endif 397bdd1243dSDimitry Andric 3980b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 3990b57cec5SDimitry Andric// the compiler and '1' otherwise. 4000b57cec5SDimitry Andric# ifndef __is_identifier 4010b57cec5SDimitry Andric# define __is_identifier(__x) 1 4020b57cec5SDimitry Andric# endif 4030b57cec5SDimitry Andric 4040b57cec5SDimitry Andric# ifndef __has_declspec_attribute 4050b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 4060b57cec5SDimitry Andric# endif 4070b57cec5SDimitry Andric 4080b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric# ifndef __has_include 4110b57cec5SDimitry Andric# define __has_include(...) 0 4120b57cec5SDimitry Andric# endif 4130b57cec5SDimitry Andric 41481ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 41581ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 4160b57cec5SDimitry Andric# endif 4170b57cec5SDimitry Andric 4180b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 4190b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 4200b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 4210b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 4220b57cec5SDimitry Andric// heuristic falls short. 4230b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4240b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 4250b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 4260b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4270b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 4280b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4290b57cec5SDimitry Andric# else 4300b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 4310b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 4320b57cec5SDimitry Andric# else 4330b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 4340b57cec5SDimitry Andric# endif 4350b57cec5SDimitry Andric# endif 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 4380b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 4390b57cec5SDimitry Andric# endif 4400b57cec5SDimitry Andric 441fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 442fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 443fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 444fcaf7f86SDimitry Andric# endif 445fcaf7f86SDimitry Andric# endif 446fcaf7f86SDimitry Andric 447fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 448fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 449fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 45006c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 45106c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 452*5f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_TZDB 453*5f757f3fSDimitry Andric# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 454fcaf7f86SDimitry Andric# endif 455fcaf7f86SDimitry Andric 4560b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 4570b57cec5SDimitry Andric# if defined(__linux__) 4580b57cec5SDimitry Andric# include <features.h> 4590b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 4600b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 4610b57cec5SDimitry Andric# else 4620b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 4630b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 4640b57cec5SDimitry Andric# endif // defined(__linux__) 4650b57cec5SDimitry Andric 46604eeddc0SDimitry Andric# if defined(__MVS__) 46704eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 46804eeddc0SDimitry Andric# endif 46904eeddc0SDimitry Andric 470*5f757f3fSDimitry Andric# ifndef __BYTE_ORDER__ 471*5f757f3fSDimitry Andric# error \ 472*5f757f3fSDimitry Andric "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" 473*5f757f3fSDimitry Andric# endif 4740b57cec5SDimitry Andric 4750b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 4760b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4770b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4780b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4790b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 4800b57cec5SDimitry Andric 4810b57cec5SDimitry Andric# if defined(_WIN32) 4820b57cec5SDimitry Andric# define _LIBCPP_WIN32API 4830b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 4840b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 4850b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 4860b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 4870b57cec5SDimitry Andric// a MS compatibility version is specified. 4880b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 4890b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 4900b57cec5SDimitry Andric# endif 4910b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 4920b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 4930b57cec5SDimitry Andric# endif 4940b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 4950b57cec5SDimitry Andric# endif // defined(_WIN32) 4960b57cec5SDimitry Andric 497349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 498349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 499349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 500349cc55cSDimitry Andric# endif 501349cc55cSDimitry Andric 5020eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 5030eae32dcSDimitry Andric// 5040eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 5050eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 5060eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 5070eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 5080eae32dcSDimitry Andric// else is specified. This implementation requires storing state 5090eae32dcSDimitry Andric// inside `std::random_device`. 5100eae32dcSDimitry Andric// 5110eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 5120eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 5130eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 5140eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 5150eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5160eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5170eae32dcSDimitry Andric// 5180eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 5190eae32dcSDimitry Andric// Use getentropy(). 5200eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5210eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5220eae32dcSDimitry Andric// 52304eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 52404eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 52504eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 52604eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 52704eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 52804eeddc0SDimitry Andric// 5290eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 5300eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 5310eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 5320eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 5330eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5340eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 5350eae32dcSDimitry Andric// 5360eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 5370eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 5380eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 5390eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 54081ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 54106c3fb27SDimitry Andric defined(__DragonFly__) 5420b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 54381ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 5440b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 54504eeddc0SDimitry Andric# elif defined(__Fuchsia__) 54604eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 5470b57cec5SDimitry Andric# elif defined(__native_client__) 5480b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 5490b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 5500b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 5510b57cec5SDimitry Andric# else 5520b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 5530b57cec5SDimitry Andric# endif 5540b57cec5SDimitry Andric 5550b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 55681ad6265SDimitry Andric 5570b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 55881ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 55981ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 56081ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 56181ad6265SDimitry Andric# define _NOEXCEPT noexcept 56281ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 563bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 56481ad6265SDimitry Andric 5650b57cec5SDimitry Andric# else 56681ad6265SDimitry Andric 56781ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 56881ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 56981ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 570bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 57181ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 57281ad6265SDimitry Andric# define nullptr __nullptr 57381ad6265SDimitry Andric# define _NOEXCEPT throw() 57481ad6265SDimitry Andric# define _NOEXCEPT_(x) 575bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 576bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 577bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 57881ad6265SDimitry Andric 57981ad6265SDimitry Andrictypedef __char16_t char16_t; 58081ad6265SDimitry Andrictypedef __char32_t char32_t; 58181ad6265SDimitry Andric 58281ad6265SDimitry Andric# endif 58381ad6265SDimitry Andric 58481ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 58506c3fb27SDimitry Andric# define _LIBCPP_HAS_NO_EXCEPTIONS 5860b57cec5SDimitry Andric# endif 5870b57cec5SDimitry Andric 5880b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 5890b57cec5SDimitry Andric 590fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 5910b57cec5SDimitry Andric 59206c3fb27SDimitry Andric# if defined(__APPLE__) 59306c3fb27SDimitry Andric# if defined(__i386__) || defined(__x86_64__) 59406c3fb27SDimitry Andric// use old string layout on x86_64 and i386 59506c3fb27SDimitry Andric# elif defined(__arm__) 59606c3fb27SDimitry Andric// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 59706c3fb27SDimitry Andric# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 5980b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 5990b57cec5SDimitry Andric# endif 60006c3fb27SDimitry Andric# else 60106c3fb27SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 60206c3fb27SDimitry Andric# endif 60306c3fb27SDimitry Andric# endif 6040b57cec5SDimitry Andric 6050b57cec5SDimitry Andric// Objective-C++ features (opt-in) 6060b57cec5SDimitry Andric# if __has_feature(objc_arc) 6070b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 6080b57cec5SDimitry Andric# endif 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 6110b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 6120b57cec5SDimitry Andric# endif 6130b57cec5SDimitry Andric 6145ffd83dbSDimitry Andric# if __has_extension(blocks) 6155ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 6165ffd83dbSDimitry Andric# endif 6175ffd83dbSDimitry Andric 6185ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 6195ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 6205ffd83dbSDimitry Andric# endif 6215ffd83dbSDimitry Andric 622fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 6230b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6240b57cec5SDimitry Andric# endif 6250b57cec5SDimitry Andric 6260b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6270b57cec5SDimitry Andric 628e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 629e40139ffSDimitry Andric 6300b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 6310b57cec5SDimitry Andric 632fe6060f1SDimitry Andric# if !defined(__SANITIZE_ADDRESS__) 6330b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 6340b57cec5SDimitry Andric# endif 6350b57cec5SDimitry Andric 6360b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 6370b57cec5SDimitry Andric 638e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 639e40139ffSDimitry Andric 640bdd1243dSDimitry Andric# endif // _LIBCPP_COMPILER_[CLANG|GCC] 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andric# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 6430b57cec5SDimitry Andric 6440b57cec5SDimitry Andric# ifdef _DLL 6450b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC __declspec(dllimport) 6460b57cec5SDimitry Andric# else 6470b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC 6480b57cec5SDimitry Andric# endif 6490b57cec5SDimitry Andric 65081ad6265SDimitry Andric# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 6510b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS 6520b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6530b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6540b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6550b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI 6560b57cec5SDimitry Andric# elif defined(_LIBCPP_BUILDING_LIBRARY) 6570b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllexport) 6580b57cec5SDimitry Andric# if defined(__MINGW32__) 6590b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6600b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6610b57cec5SDimitry Andric# else 6620b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 6630b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 6640b57cec5SDimitry Andric# endif 6650b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 6660b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 6670b57cec5SDimitry Andric# else 6680b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllimport) 6690b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 6700b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 6710b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 6720b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 6730b57cec5SDimitry Andric# endif 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andric# define _LIBCPP_HIDDEN 6760b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 6770b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 678fe6060f1SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS 679*5f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 6800b57cec5SDimitry Andric 6810b57cec5SDimitry Andric# else 68281ad6265SDimitry Andric 68381ad6265SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 68481ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 68581ad6265SDimitry Andric# else 68681ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) 6870b57cec5SDimitry Andric# endif 6880b57cec5SDimitry Andric 68981ad6265SDimitry Andric# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 69081ad6265SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 69181ad6265SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 69281ad6265SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 69381ad6265SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 69481ad6265SDimitry Andric 695fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it. 696fcaf7f86SDimitry Andric# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 697fcaf7f86SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 698fcaf7f86SDimitry Andric# endif 699fcaf7f86SDimitry Andric 7000b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 7010b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved 7020b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 7030b57cec5SDimitry Andric# else 7040b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 7050b57cec5SDimitry Andric# endif 7060b57cec5SDimitry Andric 707*5f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 708*5f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 7090b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 7100b57cec5SDimitry Andric# else 7110b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 7120b57cec5SDimitry Andric# endif 7130b57cec5SDimitry Andric 7140b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 715*5f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 7160b57cec5SDimitry Andric# else 717*5f757f3fSDimitry Andric# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 7180b57cec5SDimitry Andric# endif 7190b57cec5SDimitry Andric 72081ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 7210b57cec5SDimitry Andric 7220b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 7230b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 7240b57cec5SDimitry Andric# else 7250b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 7260b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 7270b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 7280b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 7290b57cec5SDimitry Andric# endif 7300b57cec5SDimitry Andric 731*5f757f3fSDimitry Andric# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 732*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG f 733*5f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 734b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG s 735*5f757f3fSDimitry Andric# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 736b121cb00SDimitry Andric# define _LIBCPP_HARDENING_SIG d 737b121cb00SDimitry Andric# else 738*5f757f3fSDimitry Andric# define _LIBCPP_HARDENING_SIG n // "none" 739b121cb00SDimitry Andric# endif 740b121cb00SDimitry Andric 741b121cb00SDimitry Andric# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 742b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG n 743b121cb00SDimitry Andric# else 744b121cb00SDimitry Andric# define _LIBCPP_EXCEPTIONS_SIG e 745b121cb00SDimitry Andric# endif 746b121cb00SDimitry Andric 747b121cb00SDimitry Andric# define _LIBCPP_ODR_SIGNATURE \ 748b121cb00SDimitry Andric _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 749b121cb00SDimitry Andric 750753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 751753f127fSDimitry Andric// on two levels: 752753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 753753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 754753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 755753f127fSDimitry Andric// 756b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 757b121cb00SDimitry Andric// This ensures that no ODR violation can arise from mixing two TUs compiled with different 758b121cb00SDimitry Andric// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 759b121cb00SDimitry Andric// program contains two definitions of a function, the ODR requires them to be token-by-token 760b121cb00SDimitry Andric// equivalent, and the linker is allowed to pick either definition and discard the other one. 761b121cb00SDimitry Andric// 762b121cb00SDimitry Andric// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 763b121cb00SDimitry Andric// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 764b121cb00SDimitry Andric// compiled with different settings), the two definitions are both visible by the linker and they 765b121cb00SDimitry Andric// have the same name, but they have a meaningfully different implementation (one throws an exception 766b121cb00SDimitry Andric// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 767b121cb00SDimitry Andric// practice what will happen is that the linker will pick one of the definitions at random and will 768b121cb00SDimitry Andric// discard the other one. This can quite clearly lead to incorrect program behavior. 769b121cb00SDimitry Andric// 770b121cb00SDimitry Andric// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 771b121cb00SDimitry Andric// property that causes the code of a function to differ from the code in another configuration 772b121cb00SDimitry Andric// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 773b121cb00SDimitry Andric// tag, but we encode the ones that we think are most important: library version, exceptions, and 774b121cb00SDimitry Andric// hardening mode. 775b121cb00SDimitry Andric// 776b121cb00SDimitry Andric// Note that historically, solving this problem has been achieved in various ways, including 777b121cb00SDimitry Andric// force-inlining all functions or giving internal linkage to all functions. Both these previous 778b121cb00SDimitry Andric// solutions suffer from drawbacks that lead notably to code bloat. 779753f127fSDimitry Andric// 780753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 781753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 782753f127fSDimitry Andric// 783bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 784bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 785bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 786bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 787bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 788bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 789bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 790bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 791bdd1243dSDimitry Andric// 792753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 793753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 794753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 795753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 796753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 797753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 798b121cb00SDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 7990b57cec5SDimitry Andric# else 8000b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8010b57cec5SDimitry Andric# endif 802bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8030b57cec5SDimitry Andric 8041ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 8051ac55f4cSDimitry Andric// "C" function, as those lack mangling. 8061ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 8071ac55f4cSDimitry Andric 8080b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 8090b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 8100b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8110b57cec5SDimitry Andric# else 8120b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 8130b57cec5SDimitry Andric# endif 8140b57cec5SDimitry Andric# else 8150b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 8160b57cec5SDimitry Andric# endif 8170b57cec5SDimitry Andric 818*5f757f3fSDimitry Andric// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around 819*5f757f3fSDimitry Andric// only to ease the renaming for downstreams. 8200b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 821*5f757f3fSDimitry Andric# define _VSTD std 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 82481ad6265SDimitry Andric// clang-format off 825*5f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 826*5f757f3fSDimitry Andric inline namespace _LIBCPP_ABI_NAMESPACE { 8270b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 82881ad6265SDimitry Andric 829*5f757f3fSDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 830*5f757f3fSDimitry Andric inline namespace __fs { namespace filesystem { 8310b57cec5SDimitry Andric 83281ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 83381ad6265SDimitry Andric// clang-format on 8340b57cec5SDimitry Andric 8350b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 8360b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 8370b57cec5SDimitry Andric# endif 8380b57cec5SDimitry Andric 83906c3fb27SDimitry Andric# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 8400b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 8410b57cec5SDimitry Andric# endif 8420b57cec5SDimitry Andric 84381ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 84481ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 84506c3fb27SDimitry Andric struct _LIBCPP_EXPORTED_FROM_ABI x { \ 84681ad6265SDimitry Andric enum __lx 84781ad6265SDimitry Andric// clang-format off 8480b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 8490b57cec5SDimitry Andric __lx __v_; \ 850*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 851*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 852*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 8530b57cec5SDimitry Andric }; 85481ad6265SDimitry Andric// clang-format on 85581ad6265SDimitry Andric 85681ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 857*5f757f3fSDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 8580b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 85981ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 8600b57cec5SDimitry Andric 86106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 8620b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 8630b57cec5SDimitry Andric# endif 8640b57cec5SDimitry Andric 8650b57cec5SDimitry Andric# ifdef __FreeBSD__ 8660b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 8670b57cec5SDimitry Andric# endif 8680b57cec5SDimitry Andric 8690b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 8700b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 8710b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 8720b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8730b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 8740b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 8750b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 8760b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 877e8d8bef9SDimitry Andric# elif defined(__MVS__) 878e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 8790b57cec5SDimitry Andric# endif 8800b57cec5SDimitry Andric 88181ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 8820b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 8830b57cec5SDimitry Andric# endif 8840b57cec5SDimitry Andric 885bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 886bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 887bdd1243dSDimitry Andric# if defined(__APPLE__) 888bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 889bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 890bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 891bdd1243dSDimitry Andric# endif 892bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 893bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 894bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 895bdd1243dSDimitry Andric# endif 896bdd1243dSDimitry Andric 8970b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 8980b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 8990b57cec5SDimitry Andric# endif 9000b57cec5SDimitry Andric 90106c3fb27SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 9020b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 9030b57cec5SDimitry Andric# endif 9040b57cec5SDimitry Andric 9050b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 906fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 9070b57cec5SDimitry Andric# endif 9080b57cec5SDimitry Andric 9090b57cec5SDimitry Andric// Deprecation macros. 9100b57cec5SDimitry Andric// 9110b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 9120b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 9130b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 91406c3fb27SDimitry Andric# if __has_attribute(__deprecated__) 91506c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 91606c3fb27SDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 91706c3fb27SDimitry Andric# elif _LIBCPP_STD_VER >= 14 9180b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 91981ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 9200b57cec5SDimitry Andric# else 9210b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 92281ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9230b57cec5SDimitry Andric# endif 9240b57cec5SDimitry Andric# else 9250b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 92681ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 9270b57cec5SDimitry Andric# endif 9280b57cec5SDimitry Andric 9290b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 9300b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 9310b57cec5SDimitry Andric# else 9320b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 9330b57cec5SDimitry Andric# endif 9340b57cec5SDimitry Andric 93506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 9360b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 9370b57cec5SDimitry Andric# else 9380b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 9390b57cec5SDimitry Andric# endif 9400b57cec5SDimitry Andric 94106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 9420b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 9430b57cec5SDimitry Andric# else 9440b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 9450b57cec5SDimitry Andric# endif 9460b57cec5SDimitry Andric 94706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 948e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 949e8d8bef9SDimitry Andric# else 950e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 951e8d8bef9SDimitry Andric# endif 952e8d8bef9SDimitry Andric 953bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 23 954bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 955bdd1243dSDimitry Andric# else 956bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 957bdd1243dSDimitry Andric# endif 958bdd1243dSDimitry Andric 959fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 960e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 961e8d8bef9SDimitry Andric# else 962e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 963e8d8bef9SDimitry Andric# endif 964e8d8bef9SDimitry Andric 965e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 966fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 967e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 96881ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 969fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 97081ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 971fe6060f1SDimitry Andric# else 972e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 973e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 974e40139ffSDimitry Andric# endif 975e40139ffSDimitry Andric 9760b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 97706c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 9780b57cec5SDimitry Andric# else 97906c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 9800b57cec5SDimitry Andric# endif 9810b57cec5SDimitry Andric 98206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 98306c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 98406c3fb27SDimitry Andric# else 98506c3fb27SDimitry Andric# define _LIBCPP_EXPLICIT_SINCE_CXX23 98606c3fb27SDimitry Andric# endif 98706c3fb27SDimitry Andric 98806c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 989bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 9900b57cec5SDimitry Andric# else 991bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 9920b57cec5SDimitry Andric# endif 9930b57cec5SDimitry Andric 99406c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 995bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 9960b57cec5SDimitry Andric# else 997bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 9980b57cec5SDimitry Andric# endif 9990b57cec5SDimitry Andric 100006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1001bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 10020b57cec5SDimitry Andric# else 1003bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 10040b57cec5SDimitry Andric# endif 10050b57cec5SDimitry Andric 100606c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 1007bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1008bdd1243dSDimitry Andric# else 1009bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1010bdd1243dSDimitry Andric# endif 1011bdd1243dSDimitry Andric 10120b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 101306c3fb27SDimitry Andric extern "C" _LIBCPP_EXPORTED_FROM_ABI void 101481ad6265SDimitry Andric __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 101506c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container( 101606c3fb27SDimitry Andric const void*, const void*, const void*, const void*, const void*, const void*); 101706c3fb27SDimitry Andricextern "C" _LIBCPP_EXPORTED_FROM_ABI int 101806c3fb27SDimitry Andric__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); 101906c3fb27SDimitry Andric# endif 10200b57cec5SDimitry Andric 10210b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 102281ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 10231ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 10240b57cec5SDimitry Andric# endif 10250b57cec5SDimitry Andric 10260b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 10270b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 10280b57cec5SDimitry Andric# endif 10290b57cec5SDimitry Andric 10300b57cec5SDimitry Andric// Thread API 103181ad6265SDimitry Andric// clang-format off 10320b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 10330b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 10340b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 10350b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 103681ad6265SDimitry Andric 10370b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 10380b57cec5SDimitry Andric defined(__wasi__) || \ 10390b57cec5SDimitry Andric defined(__NetBSD__) || \ 1040e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 1041e8d8bef9SDimitry Andric defined(__NuttX__) || \ 10420b57cec5SDimitry Andric defined(__linux__) || \ 10430b57cec5SDimitry Andric defined(__GNU__) || \ 10440b57cec5SDimitry Andric defined(__APPLE__) || \ 1045e8d8bef9SDimitry Andric defined(__MVS__) || \ 104681ad6265SDimitry Andric defined(_AIX) || \ 104781ad6265SDimitry Andric defined(__EMSCRIPTEN__) 104881ad6265SDimitry Andric// clang-format on 10490b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 1050480093f4SDimitry Andric# elif defined(__Fuchsia__) 10515ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 10525ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 10530b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 10540b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 10550b57cec5SDimitry Andric# else 10560b57cec5SDimitry Andric# error "No thread API" 10570b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 10580b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 10590b57cec5SDimitry Andric 1060e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1061e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1062e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1063e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 1064e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 1065e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 1066e40139ffSDimitry Andric# endif 1067e40139ffSDimitry Andric# endif 1068e40139ffSDimitry Andric# endif 1069e40139ffSDimitry Andric 10700b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 10710b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 10720b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 10730b57cec5SDimitry Andric# endif 10740b57cec5SDimitry Andric 10750b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 10760b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 10770b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 10780b57cec5SDimitry Andric# endif 10790b57cec5SDimitry Andric 10800b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 10810b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 10820b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 10830b57cec5SDimitry Andric# endif 10840b57cec5SDimitry Andric 1085e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1086e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 1087e40139ffSDimitry Andric# endif 1088e40139ffSDimitry Andric 1089e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 10900b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 10910b57cec5SDimitry Andric// mutexes have no destroy mechanism. 1092e40139ffSDimitry Andric// 1093e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1094e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 1095e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1096e40139ffSDimitry Andric// 1097e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1098e40139ffSDimitry Andric// respective stakeholders. 109981ad6265SDimitry Andric// clang-format off 110081ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 110181ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 110281ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 110381ad6265SDimitry Andric// clang-format on 11040b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 11050b57cec5SDimitry Andric# endif 11060b57cec5SDimitry Andric 11070b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 1108e40139ffSDimitry Andric// 1109e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 1110e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 1111e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 1112e40139ffSDimitry Andric// 11130b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 11140b57cec5SDimitry Andric// as well. 111581ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 11160b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 11170b57cec5SDimitry Andric# endif 11180b57cec5SDimitry Andric 11190b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons. 112081ad6265SDimitry Andric# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 11210b57cec5SDimitry Andric# define _LIBCPP_C_HAS_NO_GETS 11220b57cec5SDimitry Andric# endif 11230b57cec5SDimitry Andric 112481ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 112504eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 11260b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 11270b57cec5SDimitry Andric# endif 11280b57cec5SDimitry Andric 11290b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 11300b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 11310b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 11320b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 11330b57cec5SDimitry Andric# endif 11340b57cec5SDimitry Andric 113581ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1136349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 11370b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 11380b57cec5SDimitry Andric# else 11390b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 11400b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 11410b57cec5SDimitry Andric# endif 11420b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 11430b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 11440b57cec5SDimitry Andric# endif 11450b57cec5SDimitry Andric# endif 11460b57cec5SDimitry Andric 114706c3fb27SDimitry Andric# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 114806c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 114906c3fb27SDimitry Andric# else 115006c3fb27SDimitry Andric# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 115106c3fb27SDimitry Andric# endif 115206c3fb27SDimitry Andric 11530b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 11540b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 11550b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 11560b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 11571fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 11581fd87a68SDimitry Andric// combining the two does work. 11591fd87a68SDimitry Andric# if !defined(_MSC_VER) 11600b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 11610b57cec5SDimitry Andric# endif 11620b57cec5SDimitry Andric# endif 11630b57cec5SDimitry Andric# endif 11640b57cec5SDimitry Andric 1165480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1166480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1167480093f4SDimitry Andric# else 1168480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1169480093f4SDimitry Andric# endif 1170480093f4SDimitry Andric 117106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 117281ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1173bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 117481ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 11750b57cec5SDimitry Andric# else 117681ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 11770b57cec5SDimitry Andric# endif 11780b57cec5SDimitry Andric 1179*5f757f3fSDimitry Andric# if __has_attribute(__noinline__) 1180*5f757f3fSDimitry Andric# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 11810b57cec5SDimitry Andric# else 1182*5f757f3fSDimitry Andric# define _LIBCPP_NOINLINE 118306c3fb27SDimitry Andric# endif 118406c3fb27SDimitry Andric 1185349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1186349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1187349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1188349cc55cSDimitry Andric// impact on readability. 1189349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1190349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1191349cc55cSDimitry Andric# else 1192349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1193349cc55cSDimitry Andric# endif 1194349cc55cSDimitry Andric 11950b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 11960b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 11970b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1198fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1199fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 120081ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 12010b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 12020b57cec5SDimitry Andric 1203fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1204fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 120581ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1206fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1207fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1208fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1209fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1210fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1211fe6060f1SDimitry Andric 121206c3fb27SDimitry Andric// clang-format off 121306c3fb27SDimitry 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()\")") 121406c3fb27SDimitry 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()\")") 121506c3fb27SDimitry Andric// clang-format on 12160b57cec5SDimitry Andric 12170b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 12180b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1219fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 12200b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 12210b57cec5SDimitry Andric# else 12220b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 12230b57cec5SDimitry Andric# endif 12240b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 12250b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 12260b57cec5SDimitry Andric 1227e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1228e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1229e40139ffSDimitry Andric// 1230e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1231e40139ffSDimitry Andric// do. 1232e40139ffSDimitry Andric# if defined(__BIONIC__) 1233e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1234e40139ffSDimitry Andric# else 1235e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1236e40139ffSDimitry Andric# endif 1237e40139ffSDimitry Andric 123881ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 123981ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 124081ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 124181ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 124281ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 124381ad6265SDimitry Andric 124481ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 124581ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 124681ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 124781ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 124881ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 124906c3fb27SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 125081ad6265SDimitry Andric# else 125181ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 125281ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 125381ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 125481ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 125581ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 125681ad6265SDimitry Andric// because using it conditionally in one language version only would make 125781ad6265SDimitry Andric// the ABI inconsistent. 125881ad6265SDimitry Andric# endif 125981ad6265SDimitry Andric 126081ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 126181ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 126281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 126381ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 126481ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 126581ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 126681ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 126781ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 126881ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 126981ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 127081ad6265SDimitry Andric# else 127181ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 127281ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 127381ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 127481ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 127581ad6265SDimitry Andric# endif 127681ad6265SDimitry Andric 1277bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1278bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1279bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1280bdd1243dSDimitry Andric// functions are declared by the C library. 1281bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1282bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 12831ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 12841ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 12851ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 12861ac55f4cSDimitry Andric// defined are ignored. 12871ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 12881ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1289bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1290bdd1243dSDimitry Andric# endif 1291bdd1243dSDimitry Andric# endif 1292bdd1243dSDimitry Andric 1293bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1294bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1295bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1296bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1297bdd1243dSDimitry Andric// with these classes. 1298bdd1243dSDimitry Andric# if _LIBCPP_STD_VER >= 17 129906c3fb27SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 1300bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1301bdd1243dSDimitry Andric template <class... _Tag> \ 130206c3fb27SDimitry Andric [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 130306c3fb27SDimitry Andric# else 130406c3fb27SDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 130506c3fb27SDimitry Andric template <class... _Tag> \ 130606c3fb27SDimitry Andric ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 130706c3fb27SDimitry Andric# endif 1308bdd1243dSDimitry Andric# else 1309bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1310bdd1243dSDimitry Andric# endif 1311bdd1243dSDimitry Andric 13121ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 13131ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 13141ac55f4cSDimitry Andric# ifdef __OBJC__ 13151ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 13161ac55f4cSDimitry Andric# endif 13171ac55f4cSDimitry Andric 131806c3fb27SDimitry Andric# define _PSTL_PRAGMA(x) _Pragma(#x) 131906c3fb27SDimitry Andric 132006c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0 132106c3fb27SDimitry Andric# if (defined(_OPENMP) && _OPENMP >= 201307) 132206c3fb27SDimitry Andric 132306c3fb27SDimitry Andric# define _PSTL_UDR_PRESENT 132406c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 132506c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 132606c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 132706c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 132806c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 132906c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 133006c3fb27SDimitry Andric 133106c3fb27SDimitry Andric// Declaration of reduction functor, where 133206c3fb27SDimitry Andric// NAME - the name of the functor 133306c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation 133406c3fb27SDimitry Andric// omp_in - refers to the local partial result 133506c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator 133606c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value 133706c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced 133806c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 133906c3fb27SDimitry Andric _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 134006c3fb27SDimitry Andric 1341*5f757f3fSDimitry Andric# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 1342*5f757f3fSDimitry Andric 1343*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 1344*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 1345*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1346*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1347*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1348*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1349*5f757f3fSDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1350*5f757f3fSDimitry Andric 135106c3fb27SDimitry Andric# else // (defined(_OPENMP) && _OPENMP >= 201307) 135206c3fb27SDimitry Andric 135306c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD 135406c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_SIMD 135506c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 135606c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 135706c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 135806c3fb27SDimitry Andric# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 135906c3fb27SDimitry Andric# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 136006c3fb27SDimitry Andric 136106c3fb27SDimitry Andric# endif // (defined(_OPENMP) && _OPENMP >= 201307) 136206c3fb27SDimitry Andric 136306c3fb27SDimitry Andric# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 136406c3fb27SDimitry Andric 1365*5f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available 1366*5f757f3fSDimitry Andric 1367*5f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 1368*5f757f3fSDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 1369*5f757f3fSDimitry Andric# else 1370*5f757f3fSDimitry Andric# define _LIBCPP_NO_CFI 1371*5f757f3fSDimitry Andric# endif 1372*5f757f3fSDimitry Andric 1373*5f757f3fSDimitry Andric# if __has_attribute(__malloc__) 1374*5f757f3fSDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 1375*5f757f3fSDimitry Andric# else 1376*5f757f3fSDimitry Andric# define _LIBCPP_NOALIAS 1377*5f757f3fSDimitry Andric# endif 1378*5f757f3fSDimitry Andric 1379*5f757f3fSDimitry Andric# if __has_attribute(__using_if_exists__) 1380*5f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 1381*5f757f3fSDimitry Andric# else 1382*5f757f3fSDimitry Andric# define _LIBCPP_USING_IF_EXISTS 1383*5f757f3fSDimitry Andric# endif 1384*5f757f3fSDimitry Andric 1385*5f757f3fSDimitry Andric# if __has_cpp_attribute(nodiscard) 1386*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD [[__nodiscard__]] 1387*5f757f3fSDimitry Andric# else 1388*5f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 1389*5f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 1390*5f757f3fSDimitry Andric// (void) cast. 1391*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD 1392*5f757f3fSDimitry Andric# endif 1393*5f757f3fSDimitry Andric 1394*5f757f3fSDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 1395*5f757f3fSDimitry Andric// specified as such as an extension. 1396*5f757f3fSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1397*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 1398*5f757f3fSDimitry Andric# else 1399*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_EXT 1400*5f757f3fSDimitry Andric# endif 1401*5f757f3fSDimitry Andric 1402*5f757f3fSDimitry Andric# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 1403*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 1404*5f757f3fSDimitry Andric# else 1405*5f757f3fSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 1406*5f757f3fSDimitry Andric# endif 1407*5f757f3fSDimitry Andric 1408*5f757f3fSDimitry Andric# if __has_attribute(__no_destroy__) 1409*5f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 1410*5f757f3fSDimitry Andric# else 1411*5f757f3fSDimitry Andric# define _LIBCPP_NO_DESTROY 1412*5f757f3fSDimitry Andric# endif 1413*5f757f3fSDimitry Andric 1414*5f757f3fSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1415*5f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 1416*5f757f3fSDimitry Andric# else 1417*5f757f3fSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 1418*5f757f3fSDimitry Andric# endif 1419*5f757f3fSDimitry Andric 1420*5f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 1421*5f757f3fSDimitry Andric# if __has_cpp_attribute(fallthrough) 1422*5f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1423*5f757f3fSDimitry Andric# elif __has_attribute(__fallthrough__) 1424*5f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1425*5f757f3fSDimitry Andric# else 1426*5f757f3fSDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 1427*5f757f3fSDimitry Andric# endif 1428*5f757f3fSDimitry Andric 1429*5f757f3fSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 1430*5f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1431*5f757f3fSDimitry Andric# else 1432*5f757f3fSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 1433*5f757f3fSDimitry Andric# endif 1434*5f757f3fSDimitry Andric 1435*5f757f3fSDimitry Andric# if __has_attribute(__nodebug__) 1436*5f757f3fSDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1437*5f757f3fSDimitry Andric# else 1438*5f757f3fSDimitry Andric# define _LIBCPP_NODEBUG 1439*5f757f3fSDimitry Andric# endif 1440*5f757f3fSDimitry Andric 1441*5f757f3fSDimitry Andric# if __has_attribute(__standalone_debug__) 1442*5f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1443*5f757f3fSDimitry Andric# else 1444*5f757f3fSDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 1445*5f757f3fSDimitry Andric# endif 1446*5f757f3fSDimitry Andric 1447*5f757f3fSDimitry Andric# if __has_attribute(__preferred_name__) 1448*5f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1449*5f757f3fSDimitry Andric# else 1450*5f757f3fSDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 1451*5f757f3fSDimitry Andric# endif 1452*5f757f3fSDimitry Andric 1453*5f757f3fSDimitry Andric# if __has_attribute(__no_sanitize__) 1454*5f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1455*5f757f3fSDimitry Andric# else 1456*5f757f3fSDimitry Andric# define _LIBCPP_NO_SANITIZE(...) 1457*5f757f3fSDimitry Andric# endif 1458*5f757f3fSDimitry Andric 1459*5f757f3fSDimitry Andric# if __has_attribute(__init_priority__) 1460*5f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1461*5f757f3fSDimitry Andric# else 1462*5f757f3fSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 1463*5f757f3fSDimitry Andric# endif 1464*5f757f3fSDimitry Andric 1465*5f757f3fSDimitry Andric# if __has_attribute(__format__) 1466*5f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 1467*5f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 1468*5f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1469*5f757f3fSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1470*5f757f3fSDimitry Andric# else 1471*5f757f3fSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1472*5f757f3fSDimitry Andric# endif 1473*5f757f3fSDimitry Andric 1474*5f757f3fSDimitry Andric# if __has_attribute(__packed__) 1475*5f757f3fSDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 1476*5f757f3fSDimitry Andric# else 1477*5f757f3fSDimitry Andric# define _LIBCPP_PACKED 1478*5f757f3fSDimitry Andric# endif 1479*5f757f3fSDimitry Andric 1480*5f757f3fSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1481*5f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1482*5f757f3fSDimitry Andric# else 1483*5f757f3fSDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 1484*5f757f3fSDimitry Andric# endif 1485*5f757f3fSDimitry Andric 1486*5f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 1487*5f757f3fSDimitry Andric# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 1488*5f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 1489*5f757f3fSDimitry Andric# else 1490*5f757f3fSDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1491*5f757f3fSDimitry Andric# endif 1492*5f757f3fSDimitry Andric 14930b57cec5SDimitry Andric#endif // __cplusplus 14940b57cec5SDimitry Andric 149581ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1496