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#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \ 796 defined(__sun__) || defined(__NetBSD__) 797#define _LIBCPP_LOCALE__L_EXTENSIONS 1 798#endif 799 800#ifdef __FreeBSD__ 801#define _DECLARE_C99_LDBL_MATH 1 802#endif 803 804// If we are getting operator new from the MSVC CRT, then allocation overloads 805// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 806#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 807# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 808#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 809 // We're deferring to Microsoft's STL to provide aligned new et al. We don't 810 // have it unless the language feature test macro is defined. 811# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 812#elif defined(__MVS__) 813# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 814#endif 815 816#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \ 817 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 818# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 819#endif 820 821#if defined(__APPLE__) || defined(__FreeBSD__) 822#define _LIBCPP_HAS_DEFAULTRUNELOCALE 823#endif 824 825#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) 826#define _LIBCPP_WCTYPE_IS_MASK 827#endif 828 829#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 830#define _LIBCPP_HAS_NO_CHAR8_T 831#endif 832 833// Deprecation macros. 834// 835// Deprecations warnings are always enabled, except when users explicitly opt-out 836// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 837#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 838# if __has_attribute(deprecated) 839# define _LIBCPP_DEPRECATED __attribute__ ((deprecated)) 840# elif _LIBCPP_STD_VER > 11 841# define _LIBCPP_DEPRECATED [[deprecated]] 842# else 843# define _LIBCPP_DEPRECATED 844# endif 845#else 846# define _LIBCPP_DEPRECATED 847#endif 848 849#if !defined(_LIBCPP_CXX03_LANG) 850# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 851#else 852# define _LIBCPP_DEPRECATED_IN_CXX11 853#endif 854 855#if _LIBCPP_STD_VER > 11 856# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 857#else 858# define _LIBCPP_DEPRECATED_IN_CXX14 859#endif 860 861#if _LIBCPP_STD_VER > 14 862# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 863#else 864# define _LIBCPP_DEPRECATED_IN_CXX17 865#endif 866 867#if _LIBCPP_STD_VER > 17 868# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 869#else 870# define _LIBCPP_DEPRECATED_IN_CXX20 871#endif 872 873#if !defined(_LIBCPP_HAS_NO_CHAR8_T) 874# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 875#else 876# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 877#endif 878 879// Macros to enter and leave a state where deprecation warnings are suppressed. 880#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 881# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 882 _Pragma("GCC diagnostic push") \ 883 _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 884 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 885# define _LIBCPP_SUPPRESS_DEPRECATED_POP \ 886 _Pragma("GCC diagnostic pop") 887#else 888# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 889# define _LIBCPP_SUPPRESS_DEPRECATED_POP 890#endif 891 892#if _LIBCPP_STD_VER <= 11 893# define _LIBCPP_EXPLICIT_AFTER_CXX11 894#else 895# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit 896#endif 897 898#if _LIBCPP_STD_VER > 11 899# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr 900#else 901# define _LIBCPP_CONSTEXPR_AFTER_CXX11 902#endif 903 904#if _LIBCPP_STD_VER > 14 905# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr 906#else 907# define _LIBCPP_CONSTEXPR_AFTER_CXX14 908#endif 909 910#if _LIBCPP_STD_VER > 17 911# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr 912#else 913# define _LIBCPP_CONSTEXPR_AFTER_CXX17 914#endif 915 916#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC) 917# define _LIBCPP_NODISCARD [[nodiscard]] 918#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG) 919# define _LIBCPP_NODISCARD [[clang::warn_unused_result]] 920#else 921// We can't use GCC's [[gnu::warn_unused_result]] and 922// __attribute__((warn_unused_result)), because GCC does not silence them via 923// (void) cast. 924# define _LIBCPP_NODISCARD 925#endif 926 927// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 928// specified as such as an extension. 929#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 930# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 931#else 932# define _LIBCPP_NODISCARD_EXT 933#endif 934 935#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \ 936 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD)) 937# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 938#else 939# define _LIBCPP_NODISCARD_AFTER_CXX17 940#endif 941 942#if __has_attribute(no_destroy) 943# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 944#else 945# define _LIBCPP_NO_DESTROY 946#endif 947 948#ifndef _LIBCPP_HAS_NO_ASAN 949extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container( 950 const void *, const void *, const void *, const void *); 951#endif 952 953// Try to find out if RTTI is disabled. 954#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti) 955# define _LIBCPP_NO_RTTI 956#elif defined(__GNUC__) && !defined(__GXX_RTTI) 957# define _LIBCPP_NO_RTTI 958#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI) 959# define _LIBCPP_NO_RTTI 960#endif 961 962#ifndef _LIBCPP_WEAK 963#define _LIBCPP_WEAK __attribute__((__weak__)) 964#endif 965 966// Thread API 967#if !defined(_LIBCPP_HAS_NO_THREADS) && \ 968 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 969 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 970 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 971# if defined(__FreeBSD__) || \ 972 defined(__wasi__) || \ 973 defined(__NetBSD__) || \ 974 defined(__OpenBSD__) || \ 975 defined(__NuttX__) || \ 976 defined(__linux__) || \ 977 defined(__GNU__) || \ 978 defined(__APPLE__) || \ 979 defined(__sun__) || \ 980 defined(__MVS__) || \ 981 defined(_AIX) || \ 982 defined(__EMSCRIPTEN__) 983# define _LIBCPP_HAS_THREAD_API_PTHREAD 984# elif defined(__Fuchsia__) 985 // TODO(44575): Switch to C11 thread API when possible. 986# define _LIBCPP_HAS_THREAD_API_PTHREAD 987# elif defined(_LIBCPP_WIN32API) 988# define _LIBCPP_HAS_THREAD_API_WIN32 989# else 990# error "No thread API" 991# endif // _LIBCPP_HAS_THREAD_API 992#endif // _LIBCPP_HAS_NO_THREADS 993 994#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 995#if defined(__ANDROID__) && __ANDROID_API__ >= 30 996#define _LIBCPP_HAS_COND_CLOCKWAIT 997#elif defined(_LIBCPP_GLIBC_PREREQ) 998#if _LIBCPP_GLIBC_PREREQ(2, 30) 999#define _LIBCPP_HAS_COND_CLOCKWAIT 1000#endif 1001#endif 1002#endif 1003 1004#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 1005#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 1006 _LIBCPP_HAS_NO_THREADS is not defined. 1007#endif 1008 1009#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 1010#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 1011 _LIBCPP_HAS_NO_THREADS is defined. 1012#endif 1013 1014#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 1015#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 1016 _LIBCPP_HAS_NO_THREADS is defined. 1017#endif 1018 1019#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 1020#define __STDCPP_THREADS__ 1 1021#endif 1022 1023// The glibc and Bionic implementation of pthreads implements 1024// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 1025// mutexes have no destroy mechanism. 1026// 1027// This optimization can't be performed on Apple platforms, where 1028// pthread_mutex_destroy can allow the kernel to release resources. 1029// See https://llvm.org/D64298 for details. 1030// 1031// TODO(EricWF): Enable this optimization on Bionic after speaking to their 1032// respective stakeholders. 1033#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \ 1034 || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \ 1035 || defined(_LIBCPP_HAS_THREAD_API_WIN32) 1036# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1037#endif 1038 1039// Destroying a condvar is a nop on Windows. 1040// 1041// This optimization can't be performed on Apple platforms, where 1042// pthread_cond_destroy can allow the kernel to release resources. 1043// See https://llvm.org/D64298 for details. 1044// 1045// TODO(EricWF): This is potentially true for some pthread implementations 1046// as well. 1047#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 1048 defined(_LIBCPP_HAS_THREAD_API_WIN32) 1049# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1050#endif 1051 1052// Some systems do not provide gets() in their C library, for security reasons. 1053#if defined(_LIBCPP_MSVCRT) || \ 1054 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \ 1055 defined(__OpenBSD__) 1056# define _LIBCPP_C_HAS_NO_GETS 1057#endif 1058 1059#if defined(__BIONIC__) || defined(__NuttX__) || \ 1060 defined(__Fuchsia__) || defined(__wasi__) || \ 1061 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 1062#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 1063#endif 1064 1065#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 1066# define _LIBCPP_HAS_C_ATOMIC_IMP 1067#elif defined(_LIBCPP_COMPILER_GCC) 1068# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1069#endif 1070 1071#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \ 1072 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1073 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 1074# define _LIBCPP_HAS_NO_ATOMIC_HEADER 1075#else 1076# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 1077# define _LIBCPP_ATOMIC_FLAG_TYPE bool 1078# endif 1079# ifdef _LIBCPP_FREESTANDING 1080# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 1081# endif 1082#endif 1083 1084#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1085#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 1086#endif 1087 1088#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 1089# if defined(__clang__) && __has_attribute(acquire_capability) 1090// Work around the attribute handling in clang. When both __declspec and 1091// __attribute__ are present, the processing goes awry preventing the definition 1092// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 1093// combining the two does work. 1094# if !defined(_MSC_VER) 1095# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1096# endif 1097# endif 1098#endif 1099 1100#ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1101# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1102#else 1103# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1104#endif 1105 1106#if _LIBCPP_STD_VER > 17 1107# define _LIBCPP_CONSTINIT constinit 1108#elif __has_attribute(require_constant_initialization) 1109# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 1110#else 1111# define _LIBCPP_CONSTINIT 1112#endif 1113 1114#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1115# define _LIBCPP_DIAGNOSE_WARNING(...) \ 1116 __attribute__((diagnose_if(__VA_ARGS__, "warning"))) 1117# define _LIBCPP_DIAGNOSE_ERROR(...) \ 1118 __attribute__((diagnose_if(__VA_ARGS__, "error"))) 1119#else 1120# define _LIBCPP_DIAGNOSE_WARNING(...) 1121# define _LIBCPP_DIAGNOSE_ERROR(...) 1122#endif 1123 1124// Use a function like macro to imply that it must be followed by a semicolon 1125#if _LIBCPP_STD_VER > 14 && __has_cpp_attribute(fallthrough) 1126# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1127#elif __has_cpp_attribute(clang::fallthrough) 1128# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]] 1129#elif __has_attribute(__fallthrough__) 1130# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 1131#else 1132# define _LIBCPP_FALLTHROUGH() ((void)0) 1133#endif 1134 1135#if __has_attribute(__nodebug__) 1136#define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 1137#else 1138#define _LIBCPP_NODEBUG 1139#endif 1140 1141#if __has_attribute(__standalone_debug__) 1142#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1143#else 1144#define _LIBCPP_STANDALONE_DEBUG 1145#endif 1146 1147#if __has_attribute(__preferred_name__) 1148#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1149#else 1150#define _LIBCPP_PREFERRED_NAME(x) 1151#endif 1152 1153// We often repeat things just for handling wide characters in the library. 1154// When wide characters are disabled, it can be useful to have a quick way of 1155// disabling it without having to resort to #if-#endif, which has a larger 1156// impact on readability. 1157#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1158# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1159#else 1160# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1161#endif 1162 1163#if defined(_LIBCPP_ABI_MICROSOFT) && \ 1164 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) 1165# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 1166#else 1167# define _LIBCPP_DECLSPEC_EMPTY_BASES 1168#endif 1169 1170#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 1171#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 1172#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1173#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1174#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 1175#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 1176 1177#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1178#define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 1179#define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1180#define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1181#define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1182#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1183#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1184 1185#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L 1186#define _LIBCPP_HAS_NO_CXX20_COROUTINES 1187#endif 1188 1189# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") 1190# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") 1191 1192#ifndef _LIBCPP_NO_AUTO_LINK 1193# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1194# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 1195# pragma comment(lib, "c++.lib") 1196# else 1197# pragma comment(lib, "libc++.lib") 1198# endif 1199# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1200#endif // _LIBCPP_NO_AUTO_LINK 1201 1202// Configures the fopen close-on-exec mode character, if any. This string will 1203// be appended to any mode string used by fstream for fopen/fdopen. 1204// 1205// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1206// do. 1207#if defined(__BIONIC__) 1208# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1209#else 1210# define _LIBCPP_FOPEN_CLOEXEC_MODE 1211#endif 1212 1213// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set 1214// of functions used in cstdio may not be available for low API levels when 1215// using 64-bit file offsets on LP32. 1216#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 1217#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS 1218#endif 1219 1220#if __has_attribute(init_priority) 1221 // TODO: Remove this once we drop support for building libc++ with old Clangs 1222# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \ 1223 (defined(__apple_build_version__) && __apple_build_version__ < 13000000) 1224# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) 1225# else 1226# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100))) 1227# endif 1228#else 1229# define _LIBCPP_INIT_PRIORITY_MAX 1230#endif 1231 1232#if defined(__GNUC__) || defined(__clang__) 1233 // The attribute uses 1-based indices for ordinary and static member functions. 1234 // The attribute uses 2-based indices for non-static member functions. 1235# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 1236 __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1237#else 1238# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1239#endif 1240 1241#if __has_cpp_attribute(msvc::no_unique_address) 1242 // MSVC implements [[no_unique_address]] as a silent no-op currently. 1243 // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 1244 // However, MSVC implements [[msvc::no_unique_address]] which does what 1245 // [[no_unique_address]] is supposed to do, in general. 1246 1247 // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 1248 // [[msvc::no_unique_address]] though. If/when it does implement 1249 // [[msvc::no_unique_address]], this should be preferred though. 1250# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 1251#elif __has_cpp_attribute(no_unique_address) 1252# define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]] 1253#else 1254# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 1255 // Note that this can be replaced by #error as soon as clang-cl 1256 // implements msvc::no_unique_address, since there should be no C++20 1257 // compiler that doesn't support one of the two attributes at that point. 1258 // We generally don't want to use this macro outside of C++20-only code, 1259 // because using it conditionally in one language version only would make 1260 // the ABI inconsistent. 1261#endif 1262 1263#ifdef _LIBCPP_COMPILER_CLANG_BASED 1264# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 1265# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 1266# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 1267# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1268#elif defined(_LIBCPP_COMPILER_GCC) 1269# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 1270# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 1271# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1272# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 1273#else 1274# define _LIBCPP_DIAGNOSTIC_PUSH 1275# define _LIBCPP_DIAGNOSTIC_POP 1276# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 1277# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 1278#endif 1279 1280#if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) 1281# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") 1282# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") 1283#else 1284# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ 1285# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ 1286#endif 1287 1288#endif // __cplusplus 1289 1290#endif // _LIBCPP___CONFIG 1291