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