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#if defined(_MSC_VER) && !defined(__clang__) 16# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 18# endif 19#endif 20 21#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 22# pragma GCC system_header 23#endif 24 25#if defined(__apple_build_version__) 26// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 27# define _LIBCPP_COMPILER_CLANG_BASED 28# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 29#elif defined(__clang__) 30# define _LIBCPP_COMPILER_CLANG_BASED 31# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 32#elif defined(__GNUC__) 33# define _LIBCPP_COMPILER_GCC 34#endif 35 36#ifdef __cplusplus 37 38// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 39// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is 40// defined to XXYYZZ. 41# define _LIBCPP_VERSION 170000 42 43# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 44# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 45 46// Valid C++ identifier that revs with every libc++ version. This can be used to 47// generate identifiers that must be unique for every released libc++ version. 48# define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION) 49 50# if __STDC_HOSTED__ == 0 51# define _LIBCPP_FREESTANDING 52# endif 53 54// NOLINTBEGIN(libcpp-cpp-version-check) 55# ifndef _LIBCPP_STD_VER 56# if __cplusplus <= 201103L 57# define _LIBCPP_STD_VER 11 58# elif __cplusplus <= 201402L 59# define _LIBCPP_STD_VER 14 60# elif __cplusplus <= 201703L 61# define _LIBCPP_STD_VER 17 62# elif __cplusplus <= 202002L 63# define _LIBCPP_STD_VER 20 64# else 65// Expected release year of the next C++ standard 66# define _LIBCPP_STD_VER 23 67# endif 68# endif // _LIBCPP_STD_VER 69// NOLINTEND(libcpp-cpp-version-check) 70 71# if defined(__ELF__) 72# define _LIBCPP_OBJECT_FORMAT_ELF 1 73# elif defined(__MACH__) 74# define _LIBCPP_OBJECT_FORMAT_MACHO 1 75# elif defined(_WIN32) 76# define _LIBCPP_OBJECT_FORMAT_COFF 1 77# elif defined(__wasm__) 78# define _LIBCPP_OBJECT_FORMAT_WASM 1 79# elif defined(_AIX) 80# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 81# else 82// ... add new file formats here ... 83# endif 84 85# if _LIBCPP_ABI_VERSION >= 2 86// Change short string representation so that string data starts at offset 0, 87// improving its alignment in some cases. 88# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 89// Fix deque iterator type in order to support incomplete types. 90# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 91// Fix undefined behavior in how std::list stores its linked nodes. 92# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 93// Fix undefined behavior in how __tree stores its end and parent nodes. 94# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 95// Fix undefined behavior in how __hash_table stores its pointer types. 96# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 97# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 98# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 99// Define a key function for `bad_function_call` in the library, to centralize 100// its vtable and typeinfo to libc++ rather than having all other libraries 101// using that class define their own copies. 102# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 103// Override the default return value of exception::what() for 104// bad_function_call::what() with a string that is specific to 105// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 106// because it changes the vtable layout of bad_function_call. 107# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 108// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 109# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 110// Give reverse_iterator<T> one data member of type T, not two. 111// Also, in C++17 and later, don't derive iterator types from std::iterator. 112# define _LIBCPP_ABI_NO_ITERATOR_BASES 113// Use the smallest possible integer type to represent the index of the variant. 114// Previously libc++ used "unsigned int" exclusively. 115# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 116// Unstable attempt to provide a more optimized std::function 117# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 118// All the regex constants must be distinct and nonzero. 119# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 120// Re-worked external template instantiations for std::string with a focus on 121// performance and fast-path inlining. 122# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 123// Enable clang::trivial_abi on std::unique_ptr. 124# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 125// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 126# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 127// std::random_device holds some state when it uses an implementation that gets 128// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 129// implementation to another one on a platform that has already shipped 130// std::random_device, one needs to retain the same object layout to remain ABI 131// compatible. This switch removes these workarounds for platforms that don't care 132// about ABI compatibility. 133# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 134// Don't export the legacy __basic_string_common class and its methods from the built library. 135# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 136// Don't export the legacy __vector_base_common class and its methods from the built library. 137# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 138// According to the Standard, `bitset::operator[] const` returns bool 139# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 140// Fix the implementation of CityHash used for std::hash<fundamental-type>. 141// This is an ABI break because `std::hash` will return a different result, 142// which means that hashing the same object in translation units built against 143// different versions of libc++ can return inconsistent results. This is especially 144// tricky since std::hash is used in the implementation of unordered containers. 145// 146// The incorrect implementation of CityHash has the problem that it drops some 147// bits on the floor. 148# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 149// Remove the base 10 implementation of std::to_chars from the dylib. 150// The implementation moved to the header, but we still export the symbols from 151// the dylib for backwards compatibility. 152# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 153# elif _LIBCPP_ABI_VERSION == 1 154# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 155// Enable compiling copies of now inline methods into the dylib to support 156// applications compiled against older libraries. This is unnecessary with 157// COFF dllexport semantics, since dllexport forces a non-inline definition 158// of inline functions to be emitted anyway. Our own non-inline copy would 159// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 160// the linker will take issue with the symbols in the shared object if the 161// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 162// so disable it. 163# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 164# endif 165// Feature macros for disabling pre ABI v1 features. All of these options 166// are deprecated. 167# if defined(__FreeBSD__) 168# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 169# endif 170// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol 171// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def 172// in the library, so we need to always rely on the library version. 173# if defined(_AIX) 174# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 175# endif 176# endif 177 178# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 179// Enable additional explicit instantiations of iostreams components. This 180// reduces the number of weak definitions generated in programs that use 181// iostreams by providing a single strong definition in the shared library. 182# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 183 184// Define a key function for `bad_function_call` in the library, to centralize 185// its vtable and typeinfo to libc++ rather than having all other libraries 186// using that class define their own copies. 187# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 188# endif 189 190# define _LIBCPP_TOSTRING2(x) #x 191# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 192 193// NOLINTNEXTLINE(libcpp-cpp-version-check) 194# if __cplusplus < 201103L 195# define _LIBCPP_CXX03_LANG 196# endif 197 198# ifndef __has_attribute 199# define __has_attribute(__x) 0 200# endif 201 202# ifndef __has_builtin 203# define __has_builtin(__x) 0 204# endif 205 206# ifndef __has_extension 207# define __has_extension(__x) 0 208# endif 209 210# ifndef __has_feature 211# define __has_feature(__x) 0 212# endif 213 214# ifndef __has_cpp_attribute 215# define __has_cpp_attribute(__x) 0 216# endif 217 218# ifndef __has_constexpr_builtin 219# define __has_constexpr_builtin(x) 0 220# endif 221 222// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 223// the compiler and '1' otherwise. 224# ifndef __is_identifier 225# define __is_identifier(__x) 1 226# endif 227 228# ifndef __has_declspec_attribute 229# define __has_declspec_attribute(__x) 0 230# endif 231 232# define __has_keyword(__x) !(__is_identifier(__x)) 233 234# ifndef __has_include 235# define __has_include(...) 0 236# endif 237 238# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 239# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 240# endif 241 242// FIXME: ABI detection should be done via compiler builtin macros. This 243// is just a placeholder until Clang implements such macros. For now assume 244// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 245// and allow the user to explicitly specify the ABI to handle cases where this 246// heuristic falls short. 247# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 248# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 249# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 250# define _LIBCPP_ABI_ITANIUM 251# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 252# define _LIBCPP_ABI_MICROSOFT 253# else 254# if defined(_WIN32) && defined(_MSC_VER) 255# define _LIBCPP_ABI_MICROSOFT 256# else 257# define _LIBCPP_ABI_ITANIUM 258# endif 259# endif 260 261# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 262# define _LIBCPP_ABI_VCRUNTIME 263# endif 264 265# if __has_feature(experimental_library) 266# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 267# define _LIBCPP_ENABLE_EXPERIMENTAL 268# endif 269# endif 270 271// Incomplete features get their own specific disabling flags. This makes it 272// easier to grep for target specific flags once the feature is complete. 273# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 274# define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT 275# endif 276 277// Need to detect which libc we're using if we're on Linux. 278# if defined(__linux__) 279# include <features.h> 280# if defined(__GLIBC_PREREQ) 281# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 282# else 283# define _LIBCPP_GLIBC_PREREQ(a, b) 0 284# endif // defined(__GLIBC_PREREQ) 285# endif // defined(__linux__) 286 287# if defined(__MVS__) 288# include <features.h> // for __NATIVE_ASCII_F 289# endif 290 291# ifdef __LITTLE_ENDIAN__ 292# if __LITTLE_ENDIAN__ 293# define _LIBCPP_LITTLE_ENDIAN 294# endif // __LITTLE_ENDIAN__ 295# endif // __LITTLE_ENDIAN__ 296 297# ifdef __BIG_ENDIAN__ 298# if __BIG_ENDIAN__ 299# define _LIBCPP_BIG_ENDIAN 300# endif // __BIG_ENDIAN__ 301# endif // __BIG_ENDIAN__ 302 303# ifdef __BYTE_ORDER__ 304# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 305# define _LIBCPP_LITTLE_ENDIAN 306# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 307# define _LIBCPP_BIG_ENDIAN 308# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 309# endif // __BYTE_ORDER__ 310 311# ifdef __FreeBSD__ 312# include <sys/endian.h> 313# include <osreldate.h> 314# if _BYTE_ORDER == _LITTLE_ENDIAN 315# define _LIBCPP_LITTLE_ENDIAN 316# else // _BYTE_ORDER == _LITTLE_ENDIAN 317# define _LIBCPP_BIG_ENDIAN 318# endif // _BYTE_ORDER == _LITTLE_ENDIAN 319# endif // __FreeBSD__ 320 321# if defined(__NetBSD__) || defined(__OpenBSD__) 322# include <sys/endian.h> 323# if _BYTE_ORDER == _LITTLE_ENDIAN 324# define _LIBCPP_LITTLE_ENDIAN 325# else // _BYTE_ORDER == _LITTLE_ENDIAN 326# define _LIBCPP_BIG_ENDIAN 327# endif // _BYTE_ORDER == _LITTLE_ENDIAN 328# endif // defined(__NetBSD__) || defined(__OpenBSD__) 329 330# if defined(_WIN32) 331# define _LIBCPP_WIN32API 332# define _LIBCPP_LITTLE_ENDIAN 333# define _LIBCPP_SHORT_WCHAR 1 334// Both MinGW and native MSVC provide a "MSVC"-like environment 335# define _LIBCPP_MSVCRT_LIKE 336// If mingw not explicitly detected, assume using MS C runtime only if 337// a MS compatibility version is specified. 338# if defined(_MSC_VER) && !defined(__MINGW32__) 339# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 340# endif 341# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 342# define _LIBCPP_HAS_BITSCAN64 343# endif 344# define _LIBCPP_HAS_OPEN_WITH_WCHAR 345# endif // defined(_WIN32) 346 347# ifdef __sun__ 348# include <sys/isa_defs.h> 349# ifdef _LITTLE_ENDIAN 350# define _LIBCPP_LITTLE_ENDIAN 351# else 352# define _LIBCPP_BIG_ENDIAN 353# endif 354# endif // __sun__ 355 356# if defined(_AIX) && !defined(__64BIT__) 357// The size of wchar is 2 byte on 32-bit mode on AIX. 358# define _LIBCPP_SHORT_WCHAR 1 359# endif 360 361// Libc++ supports various implementations of std::random_device. 362// 363// _LIBCPP_USING_DEV_RANDOM 364// Read entropy from the given file, by default `/dev/urandom`. 365// If a token is provided, it is assumed to be the path to a file 366// to read entropy from. This is the default behavior if nothing 367// else is specified. This implementation requires storing state 368// inside `std::random_device`. 369// 370// _LIBCPP_USING_ARC4_RANDOM 371// Use arc4random(). This allows obtaining random data even when 372// using sandboxing mechanisms. On some platforms like Apple, this 373// is the recommended source of entropy for user-space programs. 374// When this option is used, the token passed to `std::random_device`'s 375// constructor *must* be "/dev/urandom" -- anything else is an error. 376// 377// _LIBCPP_USING_GETENTROPY 378// Use getentropy(). 379// When this option is used, the token passed to `std::random_device`'s 380// constructor *must* be "/dev/urandom" -- anything else is an error. 381// 382// _LIBCPP_USING_FUCHSIA_CPRNG 383// Use Fuchsia's zx_cprng_draw() system call, which is specified to 384// deliver high-quality entropy and cannot fail. 385// When this option is used, the token passed to `std::random_device`'s 386// constructor *must* be "/dev/urandom" -- anything else is an error. 387// 388// _LIBCPP_USING_NACL_RANDOM 389// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 390// including accesses to the special files under `/dev`. This implementation 391// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 392// When this option is used, the token passed to `std::random_device`'s 393// constructor *must* be "/dev/urandom" -- anything else is an error. 394// 395// _LIBCPP_USING_WIN32_RANDOM 396// Use rand_s(), for use on Windows. 397// When this option is used, the token passed to `std::random_device`'s 398// constructor *must* be "/dev/urandom" -- anything else is an error. 399# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 400 defined(__DragonFly__) || defined(__sun__) 401# define _LIBCPP_USING_ARC4_RANDOM 402# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 403# define _LIBCPP_USING_GETENTROPY 404# elif defined(__Fuchsia__) 405# define _LIBCPP_USING_FUCHSIA_CPRNG 406# elif defined(__native_client__) 407# define _LIBCPP_USING_NACL_RANDOM 408# elif defined(_LIBCPP_WIN32API) 409# define _LIBCPP_USING_WIN32_RANDOM 410# else 411# define _LIBCPP_USING_DEV_RANDOM 412# endif 413 414# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 415# include <endian.h> 416# if __BYTE_ORDER == __LITTLE_ENDIAN 417# define _LIBCPP_LITTLE_ENDIAN 418# elif __BYTE_ORDER == __BIG_ENDIAN 419# define _LIBCPP_BIG_ENDIAN 420# else // __BYTE_ORDER == __BIG_ENDIAN 421# error unable to determine endian 422# endif 423# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 424 425# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 426# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 427# else 428# define _LIBCPP_NO_CFI 429# endif 430 431# ifndef _LIBCPP_CXX03_LANG 432 433# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 434# define _ALIGNAS_TYPE(x) alignas(x) 435# define _ALIGNAS(x) alignas(x) 436# define _LIBCPP_NORETURN [[noreturn]] 437# define _NOEXCEPT noexcept 438# define _NOEXCEPT_(x) noexcept(x) 439# define _LIBCPP_CONSTEXPR constexpr 440 441# else 442 443# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 444# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 445# define _ALIGNAS(x) __attribute__((__aligned__(x))) 446# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 447# define _LIBCPP_HAS_NO_NOEXCEPT 448# define nullptr __nullptr 449# define _NOEXCEPT throw() 450# define _NOEXCEPT_(x) 451# define static_assert(...) _Static_assert(__VA_ARGS__) 452# define decltype(...) __decltype(__VA_ARGS__) 453# define _LIBCPP_CONSTEXPR 454 455typedef __char16_t char16_t; 456typedef __char32_t char32_t; 457 458# endif 459 460# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 461# define _LIBCPP_HAS_NO_EXCEPTIONS 462# endif 463 464# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 465 466# if defined(_LIBCPP_COMPILER_CLANG_BASED) 467 468# if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2) 469# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 470# endif 471 472// Objective-C++ features (opt-in) 473# if __has_feature(objc_arc) 474# define _LIBCPP_HAS_OBJC_ARC 475# endif 476 477# if __has_feature(objc_arc_weak) 478# define _LIBCPP_HAS_OBJC_ARC_WEAK 479# endif 480 481# if __has_extension(blocks) 482# define _LIBCPP_HAS_EXTENSION_BLOCKS 483# endif 484 485# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 486# define _LIBCPP_HAS_BLOCKS_RUNTIME 487# endif 488 489# if !__has_feature(address_sanitizer) 490# define _LIBCPP_HAS_NO_ASAN 491# endif 492 493// Allow for build-time disabling of unsigned integer sanitization 494# if __has_attribute(no_sanitize) 495# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 496# endif 497 498# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 499 500# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 501 502# elif defined(_LIBCPP_COMPILER_GCC) 503 504# if !defined(__SANITIZE_ADDRESS__) 505# define _LIBCPP_HAS_NO_ASAN 506# endif 507 508# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 509 510# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 511 512# endif // _LIBCPP_COMPILER_[CLANG|GCC] 513 514# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 515 516# ifdef _DLL 517# define _LIBCPP_CRT_FUNC __declspec(dllimport) 518# else 519# define _LIBCPP_CRT_FUNC 520# endif 521 522# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 523# define _LIBCPP_DLL_VIS 524# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 525# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 526# define _LIBCPP_OVERRIDABLE_FUNC_VIS 527# define _LIBCPP_EXPORTED_FROM_ABI 528# elif defined(_LIBCPP_BUILDING_LIBRARY) 529# define _LIBCPP_DLL_VIS __declspec(dllexport) 530# if defined(__MINGW32__) 531# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 532# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 533# else 534# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 535# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 536# endif 537# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 538# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 539# else 540# define _LIBCPP_DLL_VIS __declspec(dllimport) 541# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 542# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 543# define _LIBCPP_OVERRIDABLE_FUNC_VIS 544# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 545# endif 546 547# define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS 548# define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS 549# define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS 550# define _LIBCPP_HIDDEN 551# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 552# define _LIBCPP_TEMPLATE_VIS 553# define _LIBCPP_TEMPLATE_DATA_VIS 554# define _LIBCPP_ENUM_VIS 555 556# else 557 558# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 559# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 560# else 561# define _LIBCPP_VISIBILITY(vis) 562# endif 563 564# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 565# define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default") 566# define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default") 567# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 568# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 569# define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default") 570# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 571# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 572 573// TODO: Make this a proper customization point or remove the option to override it. 574# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 575# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 576# endif 577 578# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 579// The inline should be removed once PR32114 is resolved 580# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 581# else 582# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 583# endif 584 585# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 586# if __has_attribute(__type_visibility__) 587# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default"))) 588# else 589# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 590# endif 591# else 592# define _LIBCPP_TEMPLATE_VIS 593# endif 594 595# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 596# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default"))) 597# else 598# define _LIBCPP_ENUM_VIS 599# endif 600 601# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 602 603# if __has_attribute(exclude_from_explicit_instantiation) 604# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 605# else 606// Try to approximate the effect of exclude_from_explicit_instantiation 607// (which is that entities are not assumed to be provided by explicit 608// template instantiations in the dylib) by always inlining those entities. 609# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 610# endif 611 612// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 613// on two levels: 614// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 615// symbols from their dynamic library by means of using the libc++ headers. This ensures 616// that those symbols stay private to the dynamic library in which it is defined. 617// 618// 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures 619// that no ODR violation can arise from mixing two TUs compiled with different versions 620// of libc++ where we would have changed the definition of a symbol. If the symbols shared 621// the same name, the ODR would require that their definitions be token-by-token equivalent, 622// which basically prevents us from being able to make any change to any function in our 623// headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at 624// each release, which lets us change the definition of these symbols at our leisure. 625// Note that historically, this has been achieved in various ways, including force-inlining 626// all functions or giving internal linkage to all functions. Both these (previous) solutions 627// suffer from drawbacks that lead notably to code bloat. 628// 629// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 630// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 631// 632// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 633// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 634// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 635// the virtual function pointer in the vtable based on the mangled name of the function. Since 636// we use an ABI tag that changes with each released version, the mangled name of the virtual 637// function would change, which is incorrect. Note that it doesn't make much sense to change 638// the implementation of a virtual function in an ABI-incompatible way in the first place, 639// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 640// 641// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 642// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 643// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 644# ifndef _LIBCPP_NO_ABI_TAG 645# define _LIBCPP_HIDE_FROM_ABI \ 646 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 647 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER)))) 648# else 649# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 650# endif 651# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 652 653// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 654// "C" function, as those lack mangling. 655# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 656 657# ifdef _LIBCPP_BUILDING_LIBRARY 658# if _LIBCPP_ABI_VERSION > 1 659# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 660# else 661# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 662# endif 663# else 664# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 665# endif 666 667// Just so we can migrate to the new macros gradually. 668# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 669 670// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 671// clang-format off 672# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { 673# define _LIBCPP_END_NAMESPACE_STD }} 674# define _VSTD std 675 676_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD 677 678# if _LIBCPP_STD_VER >= 17 679# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 680 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { 681# else 682# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 683 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { 684# endif 685 686# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 687// clang-format on 688 689# define _VSTD_FS std::__fs::filesystem 690 691# if __has_attribute(__enable_if__) 692# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 693# endif 694 695# ifndef __SIZEOF_INT128__ 696# define _LIBCPP_HAS_NO_INT128 697# endif 698 699# if __has_attribute(__malloc__) 700# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 701# else 702# define _LIBCPP_NOALIAS 703# endif 704 705# if __has_attribute(__using_if_exists__) 706# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 707# else 708# define _LIBCPP_USING_IF_EXISTS 709# endif 710 711# ifdef _LIBCPP_CXX03_LANG 712# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 713 struct _LIBCPP_TYPE_VIS x { \ 714 enum __lx 715// clang-format off 716# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 717 __lx __v_; \ 718 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ 719 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 720 _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \ 721 }; 722// clang-format on 723 724# else // _LIBCPP_CXX03_LANG 725# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x 726# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 727# endif // _LIBCPP_CXX03_LANG 728 729# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \ 730 defined(__NetBSD__) 731# define _LIBCPP_LOCALE__L_EXTENSIONS 1 732# endif 733 734# ifdef __FreeBSD__ 735# define _DECLARE_C99_LDBL_MATH 1 736# endif 737 738// If we are getting operator new from the MSVC CRT, then allocation overloads 739// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 740# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 741# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 742# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 743// We're deferring to Microsoft's STL to provide aligned new et al. We don't 744// have it unless the language feature test macro is defined. 745# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 746# elif defined(__MVS__) 747# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 748# endif 749 750# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 751# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 752# endif 753 754// It is not yet possible to use aligned_alloc() on all Apple platforms since 755// 10.15 was the first version to ship an implementation of aligned_alloc(). 756# if defined(__APPLE__) 757# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 758 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 759# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 760# endif 761# elif defined(__ANDROID__) && __ANDROID_API__ < 28 762// Android only provides aligned_alloc when targeting API 28 or higher. 763# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 764# endif 765 766# if defined(__APPLE__) || defined(__FreeBSD__) 767# define _LIBCPP_HAS_DEFAULTRUNELOCALE 768# endif 769 770# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) 771# define _LIBCPP_WCTYPE_IS_MASK 772# endif 773 774# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 775# define _LIBCPP_HAS_NO_CHAR8_T 776# endif 777 778// Deprecation macros. 779// 780// Deprecations warnings are always enabled, except when users explicitly opt-out 781// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 782# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 783# if __has_attribute(__deprecated__) 784# define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) 785# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) 786# elif _LIBCPP_STD_VER >= 14 787# define _LIBCPP_DEPRECATED [[deprecated]] 788# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 789# else 790# define _LIBCPP_DEPRECATED 791# define _LIBCPP_DEPRECATED_(m) 792# endif 793# else 794# define _LIBCPP_DEPRECATED 795# define _LIBCPP_DEPRECATED_(m) 796# endif 797 798# if !defined(_LIBCPP_CXX03_LANG) 799# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 800# else 801# define _LIBCPP_DEPRECATED_IN_CXX11 802# endif 803 804# if _LIBCPP_STD_VER >= 14 805# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 806# else 807# define _LIBCPP_DEPRECATED_IN_CXX14 808# endif 809 810# if _LIBCPP_STD_VER >= 17 811# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 812# else 813# define _LIBCPP_DEPRECATED_IN_CXX17 814# endif 815 816# if _LIBCPP_STD_VER >= 20 817# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 818# else 819# define _LIBCPP_DEPRECATED_IN_CXX20 820# endif 821 822#if _LIBCPP_STD_VER >= 23 823# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 824#else 825# define _LIBCPP_DEPRECATED_IN_CXX23 826#endif 827 828# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 829# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 830# else 831# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 832# endif 833 834// Macros to enter and leave a state where deprecation warnings are suppressed. 835# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 836# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 837 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 838 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 839# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 840# else 841# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 842# define _LIBCPP_SUPPRESS_DEPRECATED_POP 843# endif 844 845# if _LIBCPP_STD_VER <= 11 846# define _LIBCPP_EXPLICIT_SINCE_CXX14 847# else 848# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit 849# endif 850 851# if _LIBCPP_STD_VER >= 23 852# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit 853# else 854# define _LIBCPP_EXPLICIT_SINCE_CXX23 855# endif 856 857# if _LIBCPP_STD_VER >= 14 858# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 859# else 860# define _LIBCPP_CONSTEXPR_SINCE_CXX14 861# endif 862 863# if _LIBCPP_STD_VER >= 17 864# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 865# else 866# define _LIBCPP_CONSTEXPR_SINCE_CXX17 867# endif 868 869# if _LIBCPP_STD_VER >= 20 870# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 871# else 872# define _LIBCPP_CONSTEXPR_SINCE_CXX20 873# endif 874 875# if _LIBCPP_STD_VER >= 23 876# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 877# else 878# define _LIBCPP_CONSTEXPR_SINCE_CXX23 879# endif 880 881# if __has_cpp_attribute(nodiscard) 882# define _LIBCPP_NODISCARD [[__nodiscard__]] 883# else 884// We can't use GCC's [[gnu::warn_unused_result]] and 885// __attribute__((warn_unused_result)), because GCC does not silence them via 886// (void) cast. 887# define _LIBCPP_NODISCARD 888# endif 889 890// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 891// specified as such as an extension. 892# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 893# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 894# else 895# define _LIBCPP_NODISCARD_EXT 896# endif 897 898# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 899# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 900# else 901# define _LIBCPP_NODISCARD_AFTER_CXX17 902# endif 903 904# if __has_attribute(__no_destroy__) 905# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 906# else 907# define _LIBCPP_NO_DESTROY 908# endif 909 910# ifndef _LIBCPP_HAS_NO_ASAN 911 extern "C" _LIBCPP_FUNC_VIS void 912 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 913# endif 914 915// Try to find out if RTTI is disabled. 916# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 917# define _LIBCPP_HAS_NO_RTTI 918# endif 919 920# ifndef _LIBCPP_WEAK 921# define _LIBCPP_WEAK __attribute__((__weak__)) 922# endif 923 924// Thread API 925// clang-format off 926# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 927 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 928 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 929 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 930 931# if defined(__FreeBSD__) || \ 932 defined(__wasi__) || \ 933 defined(__NetBSD__) || \ 934 defined(__OpenBSD__) || \ 935 defined(__NuttX__) || \ 936 defined(__linux__) || \ 937 defined(__GNU__) || \ 938 defined(__APPLE__) || \ 939 defined(__sun__) || \ 940 defined(__MVS__) || \ 941 defined(_AIX) || \ 942 defined(__EMSCRIPTEN__) 943// clang-format on 944# define _LIBCPP_HAS_THREAD_API_PTHREAD 945# elif defined(__Fuchsia__) 946// TODO(44575): Switch to C11 thread API when possible. 947# define _LIBCPP_HAS_THREAD_API_PTHREAD 948# elif defined(_LIBCPP_WIN32API) 949# define _LIBCPP_HAS_THREAD_API_WIN32 950# else 951# error "No thread API" 952# endif // _LIBCPP_HAS_THREAD_API 953# endif // _LIBCPP_HAS_NO_THREADS 954 955# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 956# if defined(__ANDROID__) && __ANDROID_API__ >= 30 957# define _LIBCPP_HAS_COND_CLOCKWAIT 958# elif defined(_LIBCPP_GLIBC_PREREQ) 959# if _LIBCPP_GLIBC_PREREQ(2, 30) 960# define _LIBCPP_HAS_COND_CLOCKWAIT 961# endif 962# endif 963# endif 964 965# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 966# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 967 _LIBCPP_HAS_NO_THREADS is not defined. 968# endif 969 970# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 971# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 972 _LIBCPP_HAS_NO_THREADS is defined. 973# endif 974 975# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 976# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 977 _LIBCPP_HAS_NO_THREADS is defined. 978# endif 979 980# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 981# define __STDCPP_THREADS__ 1 982# endif 983 984// The glibc and Bionic implementation of pthreads implements 985// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 986// mutexes have no destroy mechanism. 987// 988// This optimization can't be performed on Apple platforms, where 989// pthread_mutex_destroy can allow the kernel to release resources. 990// See https://llvm.org/D64298 for details. 991// 992// TODO(EricWF): Enable this optimization on Bionic after speaking to their 993// respective stakeholders. 994// clang-format off 995# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 996 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 997 defined(_LIBCPP_HAS_THREAD_API_WIN32) 998// clang-format on 999# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1000# endif 1001 1002// Destroying a condvar is a nop on Windows. 1003// 1004// This optimization can't be performed on Apple platforms, where 1005// pthread_cond_destroy can allow the kernel to release resources. 1006// See https://llvm.org/D64298 for details. 1007// 1008// TODO(EricWF): This is potentially true for some pthread implementations 1009// as well. 1010# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 1011# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1012# endif 1013 1014// Some systems do not provide gets() in their C library, for security reasons. 1015# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 1016# define _LIBCPP_C_HAS_NO_GETS 1017# endif 1018 1019# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 1020 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 1021# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 1022# endif 1023 1024# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 1025# define _LIBCPP_HAS_C_ATOMIC_IMP 1026# elif defined(_LIBCPP_COMPILER_GCC) 1027# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1028# endif 1029 1030# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1031 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 1032# define _LIBCPP_HAS_NO_ATOMIC_HEADER 1033# else 1034# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 1035# define _LIBCPP_ATOMIC_FLAG_TYPE bool 1036# endif 1037# ifdef _LIBCPP_FREESTANDING 1038# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 1039# endif 1040# endif 1041 1042# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1043# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1044# endif 1045 1046# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 1047# if defined(__clang__) && __has_attribute(acquire_capability) 1048// Work around the attribute handling in clang. When both __declspec and 1049// __attribute__ are present, the processing goes awry preventing the definition 1050// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 1051// combining the two does work. 1052# if !defined(_MSC_VER) 1053# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1054# endif 1055# endif 1056# endif 1057 1058# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1059# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1060# else 1061# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1062# endif 1063 1064# if _LIBCPP_STD_VER >= 20 1065# define _LIBCPP_CONSTINIT constinit 1066# elif __has_attribute(__require_constant_initialization__) 1067# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 1068# else 1069# define _LIBCPP_CONSTINIT 1070# endif 1071 1072# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1073# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 1074# else 1075# define _LIBCPP_DIAGNOSE_WARNING(...) 1076# endif 1077 1078// Use a function like macro to imply that it must be followed by a semicolon 1079# if __has_cpp_attribute(fallthrough) 1080# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1081# elif __has_attribute(__fallthrough__) 1082# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1083# else 1084# define _LIBCPP_FALLTHROUGH() ((void)0) 1085# endif 1086 1087# if __has_cpp_attribute(_Clang::__lifetimebound__) 1088# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1089# else 1090# define _LIBCPP_LIFETIMEBOUND 1091# endif 1092 1093# if __has_attribute(__nodebug__) 1094# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1095# else 1096# define _LIBCPP_NODEBUG 1097# endif 1098 1099# if __has_attribute(__standalone_debug__) 1100# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1101# else 1102# define _LIBCPP_STANDALONE_DEBUG 1103# endif 1104 1105# if __has_attribute(__preferred_name__) 1106# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1107# else 1108# define _LIBCPP_PREFERRED_NAME(x) 1109# endif 1110 1111// We often repeat things just for handling wide characters in the library. 1112// When wide characters are disabled, it can be useful to have a quick way of 1113// disabling it without having to resort to #if-#endif, which has a larger 1114// impact on readability. 1115# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1116# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1117# else 1118# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1119# endif 1120 1121# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 1122# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1123# else 1124# define _LIBCPP_DECLSPEC_EMPTY_BASES 1125# endif 1126 1127# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 1128# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 1129# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1130# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1131# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 1132# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 1133# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 1134 1135# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1136# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 1137# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1138# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1139# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1140# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1141# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1142# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1143 1144# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") 1145# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") 1146 1147# ifndef _LIBCPP_NO_AUTO_LINK 1148# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1149# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 1150# pragma comment(lib, "c++.lib") 1151# else 1152# pragma comment(lib, "libc++.lib") 1153# endif 1154# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1155# endif // _LIBCPP_NO_AUTO_LINK 1156 1157// Configures the fopen close-on-exec mode character, if any. This string will 1158// be appended to any mode string used by fstream for fopen/fdopen. 1159// 1160// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1161// do. 1162# if defined(__BIONIC__) 1163# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1164# else 1165# define _LIBCPP_FOPEN_CLOEXEC_MODE 1166# endif 1167 1168// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set 1169// of functions used in cstdio may not be available for low API levels when 1170// using 64-bit file offsets on LP32. 1171# if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 1172# define _LIBCPP_HAS_NO_FGETPOS_FSETPOS 1173# endif 1174 1175# if __has_attribute(__init_priority__) 1176# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1177# else 1178# define _LIBCPP_INIT_PRIORITY_MAX 1179# endif 1180 1181# if __has_attribute(__format__) 1182// The attribute uses 1-based indices for ordinary and static member functions. 1183// The attribute uses 2-based indices for non-static member functions. 1184# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1185 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1186# else 1187# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1188# endif 1189 1190# if __has_cpp_attribute(msvc::no_unique_address) 1191// MSVC implements [[no_unique_address]] as a silent no-op currently. 1192// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 1193// However, MSVC implements [[msvc::no_unique_address]] which does what 1194// [[no_unique_address]] is supposed to do, in general. 1195 1196// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 1197// [[msvc::no_unique_address]] though. If/when it does implement 1198// [[msvc::no_unique_address]], this should be preferred though. 1199# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 1200# elif __has_cpp_attribute(no_unique_address) 1201# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] 1202# else 1203# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 1204// Note that this can be replaced by #error as soon as clang-cl 1205// implements msvc::no_unique_address, since there should be no C++20 1206// compiler that doesn't support one of the two attributes at that point. 1207// We generally don't want to use this macro outside of C++20-only code, 1208// because using it conditionally in one language version only would make 1209// the ABI inconsistent. 1210# endif 1211 1212# ifdef _LIBCPP_COMPILER_CLANG_BASED 1213# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 1214# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 1215# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 1216# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1217# elif defined(_LIBCPP_COMPILER_GCC) 1218# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 1219# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 1220# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1221# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 1222# else 1223# define _LIBCPP_DIAGNOSTIC_PUSH 1224# define _LIBCPP_DIAGNOSTIC_POP 1225# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1226# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1227# endif 1228 1229# if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) 1230# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") 1231# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") 1232# else 1233# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ 1234# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ 1235# endif 1236 1237# if __has_attribute(__packed__) 1238# define _LIBCPP_PACKED __attribute__((__packed__)) 1239# else 1240# define _LIBCPP_PACKED 1241# endif 1242 1243// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1244// functions is gradually being added to existing C libraries. The conditions 1245// below check for known C library versions and conditions under which these 1246// functions are declared by the C library. 1247# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1248// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 1249// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 1250// the latter depends on internal GNU libc details that are not appropriate 1251// to depend on here, so any declarations present when __cpp_char8_t is not 1252// defined are ignored. 1253# if defined(_LIBCPP_GLIBC_PREREQ) 1254# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1255# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1256# endif 1257# endif 1258 1259// There are a handful of public standard library types that are intended to 1260// support CTAD but don't need any explicit deduction guides to do so. This 1261// macro is used to mark them as such, which suppresses the 1262// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1263// with these classes. 1264# if _LIBCPP_STD_VER >= 17 1265# ifdef _LIBCPP_COMPILER_CLANG_BASED 1266# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1267 template <class... _Tag> \ 1268 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> 1269# else 1270# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ 1271 template <class... _Tag> \ 1272 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> 1273# endif 1274# else 1275# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1276# endif 1277 1278// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 1279// compiler intrinsics in the Objective-C++ mode. 1280# ifdef __OBJC__ 1281# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 1282# endif 1283 1284#endif // __cplusplus 1285 1286#endif // _LIBCPP___CONFIG 1287