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