1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP___CONFIG 11#define _LIBCPP___CONFIG 12 13#include <__config_site> 14 15#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 16# pragma GCC system_header 17#endif 18 19#if defined(__apple_build_version__) 20// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 21# define _LIBCPP_COMPILER_CLANG_BASED 22# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 23#elif defined(__clang__) 24# define _LIBCPP_COMPILER_CLANG_BASED 25# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 26#elif defined(__GNUC__) 27# define _LIBCPP_COMPILER_GCC 28# define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__) 29#endif 30 31#ifdef __cplusplus 32 33// Warn if a compiler version is used that is not supported anymore 34// LLVM RELEASE Update the minimum compiler versions 35# if defined(_LIBCPP_CLANG_VER) 36# if _LIBCPP_CLANG_VER < 1700 37# warning "Libc++ only supports Clang 17 and later" 38# endif 39# elif defined(_LIBCPP_APPLE_CLANG_VER) 40# if _LIBCPP_APPLE_CLANG_VER < 1500 41# warning "Libc++ only supports AppleClang 15 and later" 42# endif 43# elif defined(_LIBCPP_GCC_VER) 44# if _LIBCPP_GCC_VER < 1300 45# warning "Libc++ only supports GCC 13 and later" 46# endif 47# endif 48 49// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html 50 51// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 52// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 53// defined to XXYYZZ. 54# define _LIBCPP_VERSION 190000 55 56# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 57# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 58 59# if __STDC_HOSTED__ == 0 60# define _LIBCPP_FREESTANDING 61# endif 62 63// NOLINTBEGIN(libcpp-cpp-version-check) 64# ifndef _LIBCPP_STD_VER 65# if __cplusplus <= 201103L 66# define _LIBCPP_STD_VER 11 67# elif __cplusplus <= 201402L 68# define _LIBCPP_STD_VER 14 69# elif __cplusplus <= 201703L 70# define _LIBCPP_STD_VER 17 71# elif __cplusplus <= 202002L 72# define _LIBCPP_STD_VER 20 73# elif __cplusplus <= 202302L 74# define _LIBCPP_STD_VER 23 75# else 76// Expected release year of the next C++ standard 77# define _LIBCPP_STD_VER 26 78# endif 79# endif // _LIBCPP_STD_VER 80// NOLINTEND(libcpp-cpp-version-check) 81 82# if defined(__ELF__) 83# define _LIBCPP_OBJECT_FORMAT_ELF 1 84# elif defined(__MACH__) 85# define _LIBCPP_OBJECT_FORMAT_MACHO 1 86# elif defined(_WIN32) 87# define _LIBCPP_OBJECT_FORMAT_COFF 1 88# elif defined(__wasm__) 89# define _LIBCPP_OBJECT_FORMAT_WASM 1 90# elif defined(_AIX) 91# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 92# else 93// ... add new file formats here ... 94# endif 95 96// ABI { 97 98# if _LIBCPP_ABI_VERSION >= 2 99// Change short string representation so that string data starts at offset 0, 100// improving its alignment in some cases. 101# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 102// Fix deque iterator type in order to support incomplete types. 103# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 104// Fix undefined behavior in how std::list stores its linked nodes. 105# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 106// Fix undefined behavior in how __tree stores its end and parent nodes. 107# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 108// Fix undefined behavior in how __hash_table stores its pointer types. 109# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 110# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 111# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 112// Override the default return value of exception::what() for bad_function_call::what() 113// with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). 114// This is an ABI break on platforms that sign and authenticate vtable function pointers 115// because it changes the mangling of the virtual function located in the vtable, which 116// changes how it gets signed. 117# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 118// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 119# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 120// Give reverse_iterator<T> one data member of type T, not two. 121// Also, in C++17 and later, don't derive iterator types from std::iterator. 122# define _LIBCPP_ABI_NO_ITERATOR_BASES 123// Use the smallest possible integer type to represent the index of the variant. 124// Previously libc++ used "unsigned int" exclusively. 125# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 126// Unstable attempt to provide a more optimized std::function 127# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 128// All the regex constants must be distinct and nonzero. 129# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 130// Re-worked external template instantiations for std::string with a focus on 131// performance and fast-path inlining. 132# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 133// Enable clang::trivial_abi on std::unique_ptr. 134# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 135// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 136# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 137// std::random_device holds some state when it uses an implementation that gets 138// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 139// implementation to another one on a platform that has already shipped 140// std::random_device, one needs to retain the same object layout to remain ABI 141// compatible. This switch removes these workarounds for platforms that don't care 142// about ABI compatibility. 143# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 144// Don't export the legacy __basic_string_common class and its methods from the built library. 145# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 146// Don't export the legacy __vector_base_common class and its methods from the built library. 147# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 148// According to the Standard, `bitset::operator[] const` returns bool 149# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 150// Fix the implementation of CityHash used for std::hash<fundamental-type>. 151// This is an ABI break because `std::hash` will return a different result, 152// which means that hashing the same object in translation units built against 153// different versions of libc++ can return inconsistent results. This is especially 154// tricky since std::hash is used in the implementation of unordered containers. 155// 156// The incorrect implementation of CityHash has the problem that it drops some 157// bits on the floor. 158# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 159// Remove the base 10 implementation of std::to_chars from the dylib. 160// The implementation moved to the header, but we still export the symbols from 161// the dylib for backwards compatibility. 162# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 163// Define std::array/std::string_view iterators to be __wrap_iters instead of raw 164// pointers, which prevents people from relying on a non-portable implementation 165// detail. This is especially useful because enabling bounded iterators hardening 166// requires code not to make these assumptions. 167# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY 168# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW 169# elif _LIBCPP_ABI_VERSION == 1 170# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 171// Enable compiling copies of now inline methods into the dylib to support 172// applications compiled against older libraries. This is unnecessary with 173// COFF dllexport semantics, since dllexport forces a non-inline definition 174// of inline functions to be emitted anyway. Our own non-inline copy would 175// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 176// the linker will take issue with the symbols in the shared object if the 177// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 178// so disable it. 179# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 180# endif 181// Feature macros for disabling pre ABI v1 features. All of these options 182// are deprecated. 183# if defined(__FreeBSD__) && __FreeBSD__ < 14 184# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 185# endif 186# endif 187 188// We had some bugs where we use [[no_unique_address]] together with construct_at, 189// which causes UB as the call on construct_at could write to overlapping subobjects 190// 191// https://github.com/llvm/llvm-project/issues/70506 192// https://github.com/llvm/llvm-project/issues/70494 193// 194// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. 195// The macro below is used for all classes whose ABI have changed as part of fixing these bugs. 196# define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) 197 198// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's 199// within the bounds of the original container and asserts it on every dereference. 200// 201// ABI impact: changes the iterator type of the relevant containers. 202// 203// Supported containers: 204// - `span`; 205// - `string_view`; 206// - `array`. 207// #define _LIBCPP_ABI_BOUNDED_ITERATORS 208 209// } ABI 210 211// HARDENING { 212 213// TODO(hardening): deprecate this in LLVM 19. 214// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) 215// equivalent to setting the extensive mode. 216# ifdef _LIBCPP_ENABLE_ASSERTIONS 217# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 218# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 219# endif 220# if _LIBCPP_ENABLE_ASSERTIONS 221# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE 222# endif 223# endif 224 225// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: 226// 227// - `_LIBCPP_HARDENING_MODE_NONE`; 228// - `_LIBCPP_HARDENING_MODE_FAST`; 229// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; 230// - `_LIBCPP_HARDENING_MODE_DEBUG`. 231// 232// These values have the following effects: 233// 234// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; 235// 236// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks 237// that can be done with relatively little runtime overhead in constant time; 238// 239// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of 240// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors 241// but are not necessarily security-critical; 242// 243// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive 244// mode and enables all checks available in the library, including internal assertions. Checks that are part of the 245// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. 246 247// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These 248// macros are only for internal use -- users should only pick one of the high-level hardening modes described above. 249// 250// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and 251// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: 252// - the sentinel is reachable from the begin iterator; 253// - TODO(hardening): both iterators refer to the same container. 254// 255// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through 256// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access 257// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like 258// `optional` and `function` are considered one-element containers for the purposes of this check. 259// 260// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero 261// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the 262// memory security of a program (however, it is still undefined behavior that can result in strange errors due to 263// compiler optimizations). 264// 265// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the 266// given ranges do not overlap. 267// 268// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object 269// was allocated by the given allocator). Violating this category typically results in a memory leak. 270// 271// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in 272// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like 273// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category 274// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or 275// otherwise create an immediate security issue. 276// 277// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure 278// the containers have compatible allocators. 279// 280// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments 281// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the 282// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. 283// a string view where only a subset of elements is possible to access). This category is for assertions violating 284// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the 285// user code. 286// 287// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to 288// be benign in our implementation. 289// 290// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed 291// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; 292// thus, this would often be a heuristic check and it might be quite expensive. 293// 294// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on 295// user input. 296// 297// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. 298 299// clang-format off 300# define _LIBCPP_HARDENING_MODE_NONE (1 << 1) 301# define _LIBCPP_HARDENING_MODE_FAST (1 << 2) 302# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. 303# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) 304// clang-format on 305 306# ifndef _LIBCPP_HARDENING_MODE 307 308# ifndef _LIBCPP_HARDENING_MODE_DEFAULT 309# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ 310`__config_site` header, please make sure your installation of libc++ is not broken. 311# endif 312 313# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT 314# endif 315 316# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ 317 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ 318 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ 319 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG 320# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ 321_LIBCPP_HARDENING_MODE_NONE, \ 322_LIBCPP_HARDENING_MODE_FAST, \ 323_LIBCPP_HARDENING_MODE_EXTENSIVE, \ 324_LIBCPP_HARDENING_MODE_DEBUG 325# endif 326 327// } HARDENING 328 329# define _LIBCPP_TOSTRING2(x) #x 330# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 331 332// NOLINTNEXTLINE(libcpp-cpp-version-check) 333# if __cplusplus < 201103L 334# define _LIBCPP_CXX03_LANG 335# endif 336 337// TODO: Remove once we switch to GCC 14 338# ifndef __has_extension 339# define __has_extension(__x) 0 340# endif 341 342// TODO: Remove once we switch to GCC 14 343# ifndef __has_feature 344# define __has_feature(__x) 0 345# endif 346 347# ifndef __has_constexpr_builtin 348# define __has_constexpr_builtin(x) 0 349# endif 350 351// This checks wheter a Clang module is built 352# ifndef __building_module 353# define __building_module(...) 0 354# endif 355 356// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 357// the compiler and '1' otherwise. 358# ifndef __is_identifier 359# define __is_identifier(__x) 1 360# endif 361 362# ifndef __has_declspec_attribute 363# define __has_declspec_attribute(__x) 0 364# endif 365 366# define __has_keyword(__x) !(__is_identifier(__x)) 367 368# ifndef __has_warning 369# define __has_warning(...) 0 370# endif 371 372# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 373# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 374# endif 375 376// FIXME: ABI detection should be done via compiler builtin macros. This 377// is just a placeholder until Clang implements such macros. For now assume 378// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 379// and allow the user to explicitly specify the ABI to handle cases where this 380// heuristic falls short. 381# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 382# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 383# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 384# define _LIBCPP_ABI_ITANIUM 385# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 386# define _LIBCPP_ABI_MICROSOFT 387# else 388# if defined(_WIN32) && defined(_MSC_VER) 389# define _LIBCPP_ABI_MICROSOFT 390# else 391# define _LIBCPP_ABI_ITANIUM 392# endif 393# endif 394 395# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 396# define _LIBCPP_ABI_VCRUNTIME 397# endif 398 399# if __has_feature(experimental_library) 400# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 401# define _LIBCPP_ENABLE_EXPERIMENTAL 402# endif 403# endif 404 405// Incomplete features get their own specific disabling flags. This makes it 406// easier to grep for target specific flags once the feature is complete. 407# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 408# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL 409# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN 410# define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB 411# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM 412# endif 413 414// Need to detect which libc we're using if we're on Linux. 415# if defined(__linux__) 416# include <features.h> 417# if defined(__GLIBC_PREREQ) 418# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 419# else 420# define _LIBCPP_GLIBC_PREREQ(a, b) 0 421# endif // defined(__GLIBC_PREREQ) 422# endif // defined(__linux__) 423 424# if defined(__MVS__) 425# include <features.h> // for __NATIVE_ASCII_F 426# endif 427 428# ifndef __BYTE_ORDER__ 429# error \ 430 "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform" 431# endif 432 433# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 434# define _LIBCPP_LITTLE_ENDIAN 435# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 436# define _LIBCPP_BIG_ENDIAN 437# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 438 439# if defined(_WIN32) 440# define _LIBCPP_WIN32API 441# define _LIBCPP_SHORT_WCHAR 1 442// Both MinGW and native MSVC provide a "MSVC"-like environment 443# define _LIBCPP_MSVCRT_LIKE 444// If mingw not explicitly detected, assume using MS C runtime only if 445// a MS compatibility version is specified. 446# if defined(_MSC_VER) && !defined(__MINGW32__) 447# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 448# endif 449# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 450# define _LIBCPP_HAS_BITSCAN64 451# endif 452# define _LIBCPP_HAS_OPEN_WITH_WCHAR 453# endif // defined(_WIN32) 454 455# if defined(_AIX) && !defined(__64BIT__) 456// The size of wchar is 2 byte on 32-bit mode on AIX. 457# define _LIBCPP_SHORT_WCHAR 1 458# endif 459 460// Libc++ supports various implementations of std::random_device. 461// 462// _LIBCPP_USING_DEV_RANDOM 463// Read entropy from the given file, by default `/dev/urandom`. 464// If a token is provided, it is assumed to be the path to a file 465// to read entropy from. This is the default behavior if nothing 466// else is specified. This implementation requires storing state 467// inside `std::random_device`. 468// 469// _LIBCPP_USING_ARC4_RANDOM 470// Use arc4random(). This allows obtaining random data even when 471// using sandboxing mechanisms. On some platforms like Apple, this 472// is the recommended source of entropy for user-space programs. 473// When this option is used, the token passed to `std::random_device`'s 474// constructor *must* be "/dev/urandom" -- anything else is an error. 475// 476// _LIBCPP_USING_GETENTROPY 477// Use getentropy(). 478// When this option is used, the token passed to `std::random_device`'s 479// constructor *must* be "/dev/urandom" -- anything else is an error. 480// 481// _LIBCPP_USING_FUCHSIA_CPRNG 482// Use Fuchsia's zx_cprng_draw() system call, which is specified to 483// deliver high-quality entropy and cannot fail. 484// When this option is used, the token passed to `std::random_device`'s 485// constructor *must* be "/dev/urandom" -- anything else is an error. 486// 487// _LIBCPP_USING_NACL_RANDOM 488// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 489// including accesses to the special files under `/dev`. This implementation 490// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 491// When this option is used, the token passed to `std::random_device`'s 492// constructor *must* be "/dev/urandom" -- anything else is an error. 493// 494// _LIBCPP_USING_WIN32_RANDOM 495// Use rand_s(), for use on Windows. 496// When this option is used, the token passed to `std::random_device`'s 497// constructor *must* be "/dev/urandom" -- anything else is an error. 498# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 499 defined(__DragonFly__) 500# define _LIBCPP_USING_ARC4_RANDOM 501# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 502# define _LIBCPP_USING_GETENTROPY 503# elif defined(__Fuchsia__) 504# define _LIBCPP_USING_FUCHSIA_CPRNG 505# elif defined(__native_client__) 506# define _LIBCPP_USING_NACL_RANDOM 507# elif defined(_LIBCPP_WIN32API) 508# define _LIBCPP_USING_WIN32_RANDOM 509# else 510# define _LIBCPP_USING_DEV_RANDOM 511# endif 512 513# ifndef _LIBCPP_CXX03_LANG 514 515# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 516# define _ALIGNAS_TYPE(x) alignas(x) 517# define _ALIGNAS(x) alignas(x) 518# define _LIBCPP_NORETURN [[noreturn]] 519# define _NOEXCEPT noexcept 520# define _NOEXCEPT_(...) noexcept(__VA_ARGS__) 521# define _LIBCPP_CONSTEXPR constexpr 522 523# else 524 525# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 526# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 527# define _ALIGNAS(x) __attribute__((__aligned__(x))) 528# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 529# define _LIBCPP_HAS_NO_NOEXCEPT 530# define nullptr __nullptr 531# define _NOEXCEPT throw() 532# define _NOEXCEPT_(...) 533# define static_assert(...) _Static_assert(__VA_ARGS__) 534# define decltype(...) __decltype(__VA_ARGS__) 535# define _LIBCPP_CONSTEXPR 536 537typedef __char16_t char16_t; 538typedef __char32_t char32_t; 539 540# endif 541 542# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 543# define _LIBCPP_HAS_NO_EXCEPTIONS 544# endif 545 546# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 547 548# if defined(_LIBCPP_COMPILER_CLANG_BASED) 549 550# if defined(__APPLE__) 551# if defined(__i386__) || defined(__x86_64__) 552// use old string layout on x86_64 and i386 553# elif defined(__arm__) 554// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs 555# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 556# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 557# endif 558# else 559# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 560# endif 561# endif 562 563// Objective-C++ features (opt-in) 564# if __has_feature(objc_arc) 565# define _LIBCPP_HAS_OBJC_ARC 566# endif 567 568# if __has_feature(objc_arc_weak) 569# define _LIBCPP_HAS_OBJC_ARC_WEAK 570# endif 571 572# if __has_extension(blocks) 573# define _LIBCPP_HAS_EXTENSION_BLOCKS 574# endif 575 576# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 577# define _LIBCPP_HAS_BLOCKS_RUNTIME 578# endif 579 580# if !__has_feature(address_sanitizer) 581# define _LIBCPP_HAS_NO_ASAN 582# endif 583 584# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 585 586# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 587 588# elif defined(_LIBCPP_COMPILER_GCC) 589 590# if !defined(__SANITIZE_ADDRESS__) 591# define _LIBCPP_HAS_NO_ASAN 592# endif 593 594# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 595 596# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 597 598# endif // _LIBCPP_COMPILER_[CLANG|GCC] 599 600# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 601 602# ifdef _DLL 603# define _LIBCPP_CRT_FUNC __declspec(dllimport) 604# else 605# define _LIBCPP_CRT_FUNC 606# endif 607 608# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 609# define _LIBCPP_DLL_VIS 610# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 611# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 612# define _LIBCPP_OVERRIDABLE_FUNC_VIS 613# define _LIBCPP_EXPORTED_FROM_ABI 614# elif defined(_LIBCPP_BUILDING_LIBRARY) 615# define _LIBCPP_DLL_VIS __declspec(dllexport) 616# if defined(__MINGW32__) 617# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 618# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 619# else 620# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 621# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 622# endif 623# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 624# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 625# else 626# define _LIBCPP_DLL_VIS __declspec(dllimport) 627# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 628# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 629# define _LIBCPP_OVERRIDABLE_FUNC_VIS 630# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 631# endif 632 633# define _LIBCPP_HIDDEN 634# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 635# define _LIBCPP_TEMPLATE_VIS 636# define _LIBCPP_TEMPLATE_DATA_VIS 637# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 638 639# else 640 641# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 642# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 643# else 644# define _LIBCPP_VISIBILITY(vis) 645# endif 646 647# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 648# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 649# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 650# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 651# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 652 653// TODO: Make this a proper customization point or remove the option to override it. 654# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 655# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 656# endif 657 658# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 659// The inline should be removed once PR32114 is resolved 660# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 661# else 662# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 663# endif 664 665// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates 666# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) 667# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 668# else 669# define _LIBCPP_TEMPLATE_VIS 670# endif 671 672# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 673# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) 674# else 675# define _LIBCPP_TYPE_VISIBILITY_DEFAULT 676# endif 677 678# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 679 680# if __has_attribute(exclude_from_explicit_instantiation) 681# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 682# else 683// Try to approximate the effect of exclude_from_explicit_instantiation 684// (which is that entities are not assumed to be provided by explicit 685// template instantiations in the dylib) by always inlining those entities. 686# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 687# endif 688 689# ifdef _LIBCPP_COMPILER_CLANG_BASED 690# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 691# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 692# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 693# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 694# elif defined(_LIBCPP_COMPILER_GCC) 695# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 696# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 697# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 698# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 699# else 700# define _LIBCPP_DIAGNOSTIC_PUSH 701# define _LIBCPP_DIAGNOSTIC_POP 702# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 703# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 704# endif 705 706# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST 707# define _LIBCPP_HARDENING_SIG f 708# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE 709# define _LIBCPP_HARDENING_SIG s 710# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG 711# define _LIBCPP_HARDENING_SIG d 712# else 713# define _LIBCPP_HARDENING_SIG n // "none" 714# endif 715 716# ifdef _LIBCPP_HAS_NO_EXCEPTIONS 717# define _LIBCPP_EXCEPTIONS_SIG n 718# else 719# define _LIBCPP_EXCEPTIONS_SIG e 720# endif 721 722# define _LIBCPP_ODR_SIGNATURE \ 723 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) 724 725// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 726// on two levels: 727// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 728// symbols from their dynamic library by means of using the libc++ headers. This ensures 729// that those symbols stay private to the dynamic library in which it is defined. 730// 731// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. 732// This ensures that no ODR violation can arise from mixing two TUs compiled with different 733// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the 734// program contains two definitions of a function, the ODR requires them to be token-by-token 735// equivalent, and the linker is allowed to pick either definition and discard the other one. 736// 737// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled 738// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs 739// compiled with different settings), the two definitions are both visible by the linker and they 740// have the same name, but they have a meaningfully different implementation (one throws an exception 741// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in 742// practice what will happen is that the linker will pick one of the definitions at random and will 743// discard the other one. This can quite clearly lead to incorrect program behavior. 744// 745// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any 746// property that causes the code of a function to differ from the code in another configuration 747// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI 748// tag, but we encode the ones that we think are most important: library version, exceptions, and 749// hardening mode. 750// 751// Note that historically, solving this problem has been achieved in various ways, including 752// force-inlining all functions or giving internal linkage to all functions. Both these previous 753// solutions suffer from drawbacks that lead notably to code bloat. 754// 755// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 756// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 757// 758// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 759// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 760// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 761// the virtual function pointer in the vtable based on the mangled name of the function. Since 762// we use an ABI tag that changes with each released version, the mangled name of the virtual 763// function would change, which is incorrect. Note that it doesn't make much sense to change 764// the implementation of a virtual function in an ABI-incompatible way in the first place, 765// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 766// 767// The macro can be applied to record and enum types. When the tagged type is nested in 768// a record this "parent" record needs to have the macro too. Another use case for applying 769// this macro to records and unions is to apply an ABI tag to inline constexpr variables. 770// This can be useful for inline variables that are implementation details which are expected 771// to change in the future. 772// 773// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 774// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 775// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 776# ifndef _LIBCPP_NO_ABI_TAG 777# define _LIBCPP_HIDE_FROM_ABI \ 778 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 779 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) 780# else 781# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 782# endif 783# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 784 785// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 786// "C" function, as those lack mangling. 787# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 788 789# ifdef _LIBCPP_BUILDING_LIBRARY 790# if _LIBCPP_ABI_VERSION > 1 791# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 792# else 793# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 794# endif 795# else 796# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 797# endif 798 799// TODO: Remove this workaround once we drop support for Clang 16 800#if __has_warning("-Wc++23-extensions") 801# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 802#else 803# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions") 804#endif 805 806// Clang modules take a significant compile time hit when pushing and popping diagnostics. 807// Since all the headers are marked as system headers in the modulemap, we can simply disable this 808// pushing and popping when building with clang modules. 809# if !__has_feature(modules) 810# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 811 _LIBCPP_DIAGNOSTIC_PUSH \ 812 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ 813 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 814 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 815 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 816 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \ 817 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ 818 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ 819 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ 820 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") 821# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP 822# else 823# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS 824# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS 825# endif 826 827// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 828// clang-format off 829# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ 830 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ 831 inline namespace _LIBCPP_ABI_NAMESPACE { 832# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS 833 834# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ 835 inline namespace __fs { namespace filesystem { 836 837# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD 838// clang-format on 839 840# if __has_attribute(__enable_if__) 841# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 842# endif 843 844# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) 845# define _LIBCPP_HAS_NO_INT128 846# endif 847 848# ifdef _LIBCPP_CXX03_LANG 849# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 850 struct _LIBCPP_EXPORTED_FROM_ABI x { \ 851 enum __lx 852// clang-format off 853# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 854 __lx __v_; \ 855 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ 856 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 857 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ 858 }; 859// clang-format on 860 861# else // _LIBCPP_CXX03_LANG 862# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x 863# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 864# endif // _LIBCPP_CXX03_LANG 865 866# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) 867# define _LIBCPP_LOCALE__L_EXTENSIONS 1 868# endif 869 870# ifdef __FreeBSD__ 871# define _DECLARE_C99_LDBL_MATH 1 872# endif 873 874// If we are getting operator new from the MSVC CRT, then allocation overloads 875// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 876# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 877# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 878# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 879// We're deferring to Microsoft's STL to provide aligned new et al. We don't 880// have it unless the language feature test macro is defined. 881# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 882# elif defined(__MVS__) 883# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 884# endif 885 886# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 887# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 888# endif 889 890// It is not yet possible to use aligned_alloc() on all Apple platforms since 891// 10.15 was the first version to ship an implementation of aligned_alloc(). 892# if defined(__APPLE__) 893# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 894 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 895# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 896# endif 897# elif defined(__ANDROID__) && __ANDROID_API__ < 28 898// Android only provides aligned_alloc when targeting API 28 or higher. 899# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 900# endif 901 902# if defined(__APPLE__) || defined(__FreeBSD__) 903# define _LIBCPP_HAS_DEFAULTRUNELOCALE 904# endif 905 906# if defined(__APPLE__) || defined(__FreeBSD__) 907# define _LIBCPP_WCTYPE_IS_MASK 908# endif 909 910# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 911# define _LIBCPP_HAS_NO_CHAR8_T 912# endif 913 914// Deprecation macros. 915// 916// Deprecations warnings are always enabled, except when users explicitly opt-out 917// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 918# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 919# if __has_attribute(__deprecated__) 920# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 921# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 922# elif _LIBCPP_STD_VER >= 14 923# define _LIBCPP_DEPRECATED [[deprecated]] 924# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 925# else 926# define _LIBCPP_DEPRECATED 927# define _LIBCPP_DEPRECATED_(m) 928# endif 929# else 930# define _LIBCPP_DEPRECATED 931# define _LIBCPP_DEPRECATED_(m) 932# endif 933 934# if _LIBCPP_STD_VER < 20 935# define _LIBCPP_DEPRECATED_ATOMIC_SYNC \ 936 _LIBCPP_DEPRECATED_("The C++20 synchronization library has been deprecated prior to C++20. Please update to " \ 937 "using -std=c++20 if you need to use these facilities.") 938# else 939# define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */ 940# endif 941 942# if !defined(_LIBCPP_CXX03_LANG) 943# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 944# else 945# define _LIBCPP_DEPRECATED_IN_CXX11 946# endif 947 948# if _LIBCPP_STD_VER >= 14 949# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 950# else 951# define _LIBCPP_DEPRECATED_IN_CXX14 952# endif 953 954# if _LIBCPP_STD_VER >= 17 955# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 956# else 957# define _LIBCPP_DEPRECATED_IN_CXX17 958# endif 959 960# if _LIBCPP_STD_VER >= 20 961# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 962# else 963# define _LIBCPP_DEPRECATED_IN_CXX20 964# endif 965 966# if _LIBCPP_STD_VER >= 23 967# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 968# else 969# define _LIBCPP_DEPRECATED_IN_CXX23 970# endif 971 972# if _LIBCPP_STD_VER >= 26 973# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED 974# else 975# define _LIBCPP_DEPRECATED_IN_CXX26 976# endif 977 978# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 979# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 980# else 981# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 982# endif 983 984// Macros to enter and leave a state where deprecation warnings are suppressed. 985# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 986# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 987 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 988 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 989# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 990# else 991# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 992# define _LIBCPP_SUPPRESS_DEPRECATED_POP 993# endif 994 995# if _LIBCPP_STD_VER <= 11 996# define _LIBCPP_EXPLICIT_SINCE_CXX14 997# else 998# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 999# endif 1000 1001# if _LIBCPP_STD_VER >= 23 1002# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 1003# else 1004# define _LIBCPP_EXPLICIT_SINCE_CXX23 1005# endif 1006 1007# if _LIBCPP_STD_VER >= 14 1008# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 1009# else 1010# define _LIBCPP_CONSTEXPR_SINCE_CXX14 1011# endif 1012 1013# if _LIBCPP_STD_VER >= 17 1014# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 1015# else 1016# define _LIBCPP_CONSTEXPR_SINCE_CXX17 1017# endif 1018 1019# if _LIBCPP_STD_VER >= 20 1020# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 1021# else 1022# define _LIBCPP_CONSTEXPR_SINCE_CXX20 1023# endif 1024 1025# if _LIBCPP_STD_VER >= 23 1026# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 1027# else 1028# define _LIBCPP_CONSTEXPR_SINCE_CXX23 1029# endif 1030 1031// Try to find out if RTTI is disabled. 1032# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 1033# define _LIBCPP_HAS_NO_RTTI 1034# endif 1035 1036# ifndef _LIBCPP_WEAK 1037# define _LIBCPP_WEAK __attribute__((__weak__)) 1038# endif 1039 1040// Thread API 1041// clang-format off 1042# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 1043 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 1044 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 1045 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 1046 1047# if defined(__FreeBSD__) || \ 1048 defined(__wasi__) || \ 1049 defined(__NetBSD__) || \ 1050 defined(__OpenBSD__) || \ 1051 defined(__NuttX__) || \ 1052 defined(__linux__) || \ 1053 defined(__GNU__) || \ 1054 defined(__APPLE__) || \ 1055 defined(__MVS__) || \ 1056 defined(_AIX) || \ 1057 defined(__EMSCRIPTEN__) 1058// clang-format on 1059# define _LIBCPP_HAS_THREAD_API_PTHREAD 1060# elif defined(__Fuchsia__) 1061// TODO(44575): Switch to C11 thread API when possible. 1062# define _LIBCPP_HAS_THREAD_API_PTHREAD 1063# elif defined(_LIBCPP_WIN32API) 1064# define _LIBCPP_HAS_THREAD_API_WIN32 1065# else 1066# error "No thread API" 1067# endif // _LIBCPP_HAS_THREAD_API 1068# endif // _LIBCPP_HAS_NO_THREADS 1069 1070# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1071# if defined(__ANDROID__) && __ANDROID_API__ >= 30 1072# define _LIBCPP_HAS_COND_CLOCKWAIT 1073# elif defined(_LIBCPP_GLIBC_PREREQ) 1074# if _LIBCPP_GLIBC_PREREQ(2, 30) 1075# define _LIBCPP_HAS_COND_CLOCKWAIT 1076# endif 1077# endif 1078# endif 1079 1080# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1081# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 1082 _LIBCPP_HAS_NO_THREADS is not defined. 1083# endif 1084 1085# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 1086# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 1087 _LIBCPP_HAS_NO_THREADS is defined. 1088# endif 1089 1090# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 1091# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 1092 _LIBCPP_HAS_NO_THREADS is defined. 1093# endif 1094 1095# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1096# define __STDCPP_THREADS__ 1 1097# endif 1098 1099// The glibc and Bionic implementation of pthreads implements 1100// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 1101// mutexes have no destroy mechanism. 1102// 1103// This optimization can't be performed on Apple platforms, where 1104// pthread_mutex_destroy can allow the kernel to release resources. 1105// See https://llvm.org/D64298 for details. 1106// 1107// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1108// respective stakeholders. 1109// clang-format off 1110# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 1111 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 1112 defined(_LIBCPP_HAS_THREAD_API_WIN32) 1113// clang-format on 1114# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1115# endif 1116 1117// Destroying a condvar is a nop on Windows. 1118// 1119// This optimization can't be performed on Apple platforms, where 1120// pthread_cond_destroy can allow the kernel to release resources. 1121// See https://llvm.org/D64298 for details. 1122// 1123// TODO(EricWF): This is potentially true for some pthread implementations 1124// as well. 1125# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 1126# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1127# endif 1128 1129# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 1130 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 1131# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 1132# endif 1133 1134# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 1135# define _LIBCPP_HAS_C_ATOMIC_IMP 1136# elif defined(_LIBCPP_COMPILER_GCC) 1137# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1138# endif 1139 1140# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1141 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 1142# define _LIBCPP_HAS_NO_ATOMIC_HEADER 1143# else 1144# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 1145# define _LIBCPP_ATOMIC_FLAG_TYPE bool 1146# endif 1147# endif 1148 1149# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) 1150# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) 1151# else 1152# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS 1153# endif 1154 1155# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 1156# if defined(__clang__) && __has_attribute(acquire_capability) 1157// Work around the attribute handling in clang. When both __declspec and 1158// __attribute__ are present, the processing goes awry preventing the definition 1159// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 1160// combining the two does work. 1161# if !defined(_MSC_VER) 1162# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1163# endif 1164# endif 1165# endif 1166 1167# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1168# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1169# else 1170# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1171# endif 1172 1173# if _LIBCPP_STD_VER >= 20 1174# define _LIBCPP_CONSTINIT constinit 1175# elif __has_attribute(__require_constant_initialization__) 1176# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 1177# else 1178# define _LIBCPP_CONSTINIT 1179# endif 1180 1181# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) 1182// The CUDA SDK contains an unfortunate definition for the __noinline__ macro, 1183// which breaks the regular __attribute__((__noinline__)) syntax. Therefore, 1184// when compiling for CUDA we use the non-underscored version of the noinline 1185// attribute. 1186// 1187// This is a temporary workaround and we still expect the CUDA SDK team to solve 1188// this issue properly in the SDK headers. 1189// 1190// See https://github.com/llvm/llvm-project/pull/73838 for more details. 1191# define _LIBCPP_NOINLINE __attribute__((noinline)) 1192# elif __has_attribute(__noinline__) 1193# define _LIBCPP_NOINLINE __attribute__((__noinline__)) 1194# else 1195# define _LIBCPP_NOINLINE 1196# endif 1197 1198// We often repeat things just for handling wide characters in the library. 1199// When wide characters are disabled, it can be useful to have a quick way of 1200// disabling it without having to resort to #if-#endif, which has a larger 1201// impact on readability. 1202# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1203# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1204# else 1205# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1206# endif 1207 1208// clang-format off 1209# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") 1210# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") 1211// clang-format on 1212 1213# ifndef _LIBCPP_NO_AUTO_LINK 1214# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1215# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 1216# pragma comment(lib, "c++.lib") 1217# else 1218# pragma comment(lib, "libc++.lib") 1219# endif 1220# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1221# endif // _LIBCPP_NO_AUTO_LINK 1222 1223// Configures the fopen close-on-exec mode character, if any. This string will 1224// be appended to any mode string used by fstream for fopen/fdopen. 1225// 1226// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1227// do. 1228# if defined(__BIONIC__) 1229# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1230# else 1231# define _LIBCPP_FOPEN_CLOEXEC_MODE 1232# endif 1233 1234# if __has_cpp_attribute(msvc::no_unique_address) 1235// MSVC implements [[no_unique_address]] as a silent no-op currently. 1236// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 1237// However, MSVC implements [[msvc::no_unique_address]] which does what 1238// [[no_unique_address]] is supposed to do, in general. 1239 1240// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 1241// [[msvc::no_unique_address]] though. If/when it does implement 1242// [[msvc::no_unique_address]], this should be preferred though. 1243# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 1244# elif __has_cpp_attribute(no_unique_address) 1245# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 1246# else 1247# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 1248// Note that this can be replaced by #error as soon as clang-cl 1249// implements msvc::no_unique_address, since there should be no C++20 1250// compiler that doesn't support one of the two attributes at that point. 1251// We generally don't want to use this macro outside of C++20-only code, 1252// because using it conditionally in one language version only would make 1253// the ABI inconsistent. 1254# endif 1255 1256// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1257// functions is gradually being added to existing C libraries. The conditions 1258// below check for known C library versions and conditions under which these 1259// functions are declared by the C library. 1260# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1261// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 1262// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 1263// the latter depends on internal GNU libc details that are not appropriate 1264// to depend on here, so any declarations present when __cpp_char8_t is not 1265// defined are ignored. 1266# if defined(_LIBCPP_GLIBC_PREREQ) 1267# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1268# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1269# endif 1270# endif 1271 1272// There are a handful of public standard library types that are intended to 1273// support CTAD but don't need any explicit deduction guides to do so. This 1274// macro is used to mark them as such, which suppresses the 1275// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1276// with these classes. 1277# if _LIBCPP_STD_VER >= 17 1278# ifdef _LIBCPP_COMPILER_CLANG_BASED 1279# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1280 template <class... _Tag> \ 1281 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 1282# else 1283# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 1284 template <class... _Tag> \ 1285 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 1286# endif 1287# else 1288# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1289# endif 1290 1291// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 1292// compiler intrinsics in the Objective-C++ mode. 1293# ifdef __OBJC__ 1294# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 1295# endif 1296 1297# define _PSTL_PRAGMA(x) _Pragma(#x) 1298 1299// Enable SIMD for compilers that support OpenMP 4.0 1300# if (defined(_OPENMP) && _OPENMP >= 201307) 1301 1302# define _PSTL_UDR_PRESENT 1303# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) 1304# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) 1305# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) 1306# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) 1307# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) 1308# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) 1309 1310// Declaration of reduction functor, where 1311// NAME - the name of the functor 1312// OP - type of the callable object with the reduction operation 1313// omp_in - refers to the local partial result 1314// omp_out - refers to the final value of the combiner operator 1315// omp_priv - refers to the private copy of the initial value 1316// omp_orig - refers to the original variable to be reduced 1317# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ 1318 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) 1319 1320# elif defined(_LIBCPP_COMPILER_CLANG_BASED) 1321 1322# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") 1323# define _PSTL_PRAGMA_DECLARE_SIMD 1324# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1325# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") 1326# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1327# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1328# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1329 1330# else // (defined(_OPENMP) && _OPENMP >= 201307) 1331 1332# define _PSTL_PRAGMA_SIMD 1333# define _PSTL_PRAGMA_DECLARE_SIMD 1334# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) 1335# define _PSTL_PRAGMA_SIMD_SCAN(PRM) 1336# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) 1337# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) 1338# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) 1339 1340# endif // (defined(_OPENMP) && _OPENMP >= 201307) 1341 1342# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED 1343 1344// Optional attributes - these are useful for a better QoI, but not required to be available 1345 1346# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 1347# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 1348# else 1349# define _LIBCPP_NO_CFI 1350# endif 1351 1352# if __has_attribute(__malloc__) 1353# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 1354# else 1355# define _LIBCPP_NOALIAS 1356# endif 1357 1358# if __has_attribute(__using_if_exists__) 1359# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 1360# else 1361# define _LIBCPP_USING_IF_EXISTS 1362# endif 1363 1364# if __has_cpp_attribute(__nodiscard__) 1365# define _LIBCPP_NODISCARD [[__nodiscard__]] 1366# else 1367// We can't use GCC's [[gnu::warn_unused_result]] and 1368// __attribute__((warn_unused_result)), because GCC does not silence them via 1369// (void) cast. 1370# define _LIBCPP_NODISCARD 1371# endif 1372 1373# if __has_attribute(__no_destroy__) 1374# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 1375# else 1376# define _LIBCPP_NO_DESTROY 1377# endif 1378 1379# if __has_attribute(__diagnose_if__) 1380# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 1381# else 1382# define _LIBCPP_DIAGNOSE_WARNING(...) 1383# endif 1384 1385// Use a function like macro to imply that it must be followed by a semicolon 1386# if __has_cpp_attribute(fallthrough) 1387# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1388# elif __has_attribute(__fallthrough__) 1389# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1390# else 1391# define _LIBCPP_FALLTHROUGH() ((void)0) 1392# endif 1393 1394# if __has_cpp_attribute(_Clang::__lifetimebound__) 1395# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1396# else 1397# define _LIBCPP_LIFETIMEBOUND 1398# endif 1399 1400# if __has_attribute(__nodebug__) 1401# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1402# else 1403# define _LIBCPP_NODEBUG 1404# endif 1405 1406# if __has_attribute(__standalone_debug__) 1407# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1408# else 1409# define _LIBCPP_STANDALONE_DEBUG 1410# endif 1411 1412# if __has_attribute(__preferred_name__) 1413# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1414# else 1415# define _LIBCPP_PREFERRED_NAME(x) 1416# endif 1417 1418# if __has_attribute(__no_sanitize__) 1419# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) 1420# else 1421# define _LIBCPP_NO_SANITIZE(...) 1422# endif 1423 1424# if __has_attribute(__init_priority__) 1425# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1426# else 1427# define _LIBCPP_INIT_PRIORITY_MAX 1428# endif 1429 1430# if __has_attribute(__format__) 1431// The attribute uses 1-based indices for ordinary and static member functions. 1432// The attribute uses 2-based indices for non-static member functions. 1433# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1434 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1435# else 1436# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1437# endif 1438 1439# if __has_attribute(__packed__) 1440# define _LIBCPP_PACKED __attribute__((__packed__)) 1441# else 1442# define _LIBCPP_PACKED 1443# endif 1444 1445# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1446# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1447# else 1448# define _LIBCPP_DECLSPEC_EMPTY_BASES 1449# endif 1450 1451// Allow for build-time disabling of unsigned integer sanitization 1452# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) 1453# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 1454# else 1455# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1456# endif 1457 1458// Clang-18 has support for deducing this, but it does not set the FTM. 1459# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) 1460# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1461# endif 1462 1463#endif // __cplusplus 1464 1465#endif // _LIBCPP___CONFIG 1466