master
   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/* zig patch: instead of including __config_site, zig adds -D flags when compiling */
  14#include <__configuration/abi.h>
  15#include <__configuration/availability.h>
  16#include <__configuration/compiler.h>
  17#include <__configuration/language.h>
  18#include <__configuration/platform.h>
  19
  20#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  21#  pragma GCC system_header
  22#endif
  23
  24#ifdef __cplusplus
  25
  26// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
  27
  28// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
  29// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
  30// defined to XXYYZZ.
  31#  define _LIBCPP_VERSION 210100
  32
  33#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
  34#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
  35#  define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z))
  36
  37#  if __STDC_HOSTED__ == 0
  38#    define _LIBCPP_FREESTANDING
  39#  endif
  40
  41// NOLINTNEXTLINE(libcpp-cpp-version-check)
  42#  if __cplusplus < 201103L
  43#    define _LIBCPP_CXX03_LANG
  44#  endif
  45
  46#  if __has_feature(experimental_library)
  47#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
  48#      define _LIBCPP_ENABLE_EXPERIMENTAL
  49#    endif
  50#  endif
  51
  52// Incomplete features get their own specific disabling flags. This makes it
  53// easier to grep for target specific flags once the feature is complete.
  54#  if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY)
  55#    define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1
  56#  else
  57#    define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0
  58#  endif
  59
  60#  define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
  61#  define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
  62#  define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
  63#  define _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
  64
  65// HARDENING {
  66
  67// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated.
  68//       Since hardening went through several changes (many of which impacted user-facing macros),
  69//       we're keeping these checks around for a bit longer than usual. Failure to properly configure
  70//       hardening results in checks being dropped silently, which is a pretty big deal.
  71#  if defined(_LIBCPP_ENABLE_ASSERTIONS)
  72#    error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
  73#  endif
  74#  if defined(_LIBCPP_ENABLE_HARDENED_MODE)
  75#    error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
  76#  endif
  77#  if defined(_LIBCPP_ENABLE_SAFE_MODE)
  78#    error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
  79#  endif
  80#  if defined(_LIBCPP_ENABLE_DEBUG_MODE)
  81#    error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
  82#  endif
  83
  84// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
  85//
  86// - `_LIBCPP_HARDENING_MODE_NONE`;
  87// - `_LIBCPP_HARDENING_MODE_FAST`;
  88// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
  89// - `_LIBCPP_HARDENING_MODE_DEBUG`.
  90//
  91// These values have the following effects:
  92//
  93// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
  94//
  95// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
  96//   that can be done with relatively little runtime overhead in constant time;
  97//
  98// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
  99//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
 100//   but are not necessarily security-critical;
 101//
 102// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
 103//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
 104//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
 105
 106// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
 107// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
 108//
 109// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
 110//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
 111//   - the sentinel is reachable from the begin iterator;
 112//   - TODO(hardening): both iterators refer to the same container.
 113//
 114// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
 115//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
 116//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
 117//   `optional` and `function` are considered one-element containers for the purposes of this check.
 118//
 119// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
 120//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
 121//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
 122//   compiler optimizations).
 123//
 124// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
 125//   given ranges do not overlap.
 126//
 127// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
 128//   was allocated by the given allocator). Violating this category typically results in a memory leak.
 129//
 130// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
 131//   an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
 132//   attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
 133//   (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
 134//   otherwise create an immediate security issue.
 135//
 136// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
 137//   the containers have compatible allocators.
 138//
 139// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
 140//   for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
 141//   original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
 142//   a string view where only a subset of elements is possible to access). This category is for assertions violating
 143//   which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
 144//   user code.
 145//
 146// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
 147//   be benign in our implementation.
 148//
 149// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
 150//   by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
 151//   thus, this would often be a heuristic check and it might be quite expensive.
 152//
 153// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
 154//   user input.
 155//
 156// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
 157
 158// clang-format off
 159#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
 160#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
 161#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
 162#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
 163// clang-format on
 164
 165#  ifndef _LIBCPP_HARDENING_MODE
 166
 167#    ifndef _LIBCPP_HARDENING_MODE_DEFAULT
 168#      error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
 169`__config_site` header, please make sure your installation of libc++ is not broken.
 170#    endif
 171
 172#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
 173#  endif
 174
 175#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
 176      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
 177      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
 178      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
 179#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
 180_LIBCPP_HARDENING_MODE_NONE, \
 181_LIBCPP_HARDENING_MODE_FAST, \
 182_LIBCPP_HARDENING_MODE_EXTENSIVE, \
 183_LIBCPP_HARDENING_MODE_DEBUG
 184#  endif
 185
 186// Hardening assertion semantics generally mirror the evaluation semantics of C++26 Contracts:
 187// - `ignore` evaluates the assertion but doesn't do anything if it fails (note that it differs from the Contracts
 188//   `ignore` semantic which wouldn't evaluate the assertion at all);
 189// - `observe` logs an error (indicating, if possible, that the error is fatal) and continues execution;
 190// - `quick-enforce` terminates the program as fast as possible (via trapping);
 191// - `enforce` logs an error and then terminates the program.
 192//
 193// Notes:
 194// - Continuing execution after a hardening check fails results in undefined behavior; the `observe` semantic is meant
 195//   to make adopting hardening easier but should not be used outside of this scenario;
 196// - C++26 wording for Library Hardening precludes a conforming Hardened implementation from using the Contracts
 197//   `ignore` semantic when evaluating hardened preconditions in the Library. Libc++ allows using this semantic for
 198//   hardened preconditions, however, be aware that using `ignore` does not produce a conforming "Hardened"
 199//   implementation, unlike the other semantics above.
 200// clang-format off
 201#  define _LIBCPP_ASSERTION_SEMANTIC_IGNORE        (1 << 1)
 202#  define _LIBCPP_ASSERTION_SEMANTIC_OBSERVE       (1 << 2)
 203#  define _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE (1 << 3)
 204#  define _LIBCPP_ASSERTION_SEMANTIC_ENFORCE       (1 << 4)
 205// clang-format on
 206
 207// Allow users to define an arbitrary assertion semantic; otherwise, use the default mapping from modes to semantics.
 208// The default is for production-capable modes to use `quick-enforce` (i.e., trap) and for the `debug` mode to use
 209// `enforce` (i.e., log and abort).
 210#  ifndef _LIBCPP_ASSERTION_SEMANTIC
 211
 212#    if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 213#      define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
 214#    else
 215#      define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE
 216#    endif
 217
 218#  else
 219#    if !_LIBCPP_HAS_EXPERIMENTAL_LIBRARY
 220#      error "Assertion semantics are an experimental feature."
 221#    endif
 222#    if defined(_LIBCPP_CXX03_LANG)
 223#      error "Assertion semantics are not available in the C++03 mode."
 224#    endif
 225
 226#  endif // _LIBCPP_ASSERTION_SEMANTIC
 227
 228// } HARDENING
 229
 230#  define _LIBCPP_TOSTRING2(x) #x
 231#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
 232
 233#  ifndef __has_constexpr_builtin
 234#    define __has_constexpr_builtin(x) 0
 235#  endif
 236
 237// This checks wheter a Clang module is built
 238#  ifndef __building_module
 239#    define __building_module(...) 0
 240#  endif
 241
 242// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
 243// the compiler and '1' otherwise.
 244#  ifndef __is_identifier
 245#    define __is_identifier(__x) 1
 246#  endif
 247
 248#  ifndef __has_declspec_attribute
 249#    define __has_declspec_attribute(__x) 0
 250#  endif
 251
 252#  define __has_keyword(__x) !(__is_identifier(__x))
 253
 254#  ifndef __has_warning
 255#    define __has_warning(...) 0
 256#  endif
 257
 258#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
 259#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
 260#  endif
 261
 262#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
 263#    define _LIBCPP_ABI_VCRUNTIME
 264#  endif
 265
 266#  if defined(__MVS__)
 267#    include <features.h> // for __NATIVE_ASCII_F
 268#  endif
 269
 270#  if defined(_WIN32)
 271#    define _LIBCPP_WIN32API
 272#    define _LIBCPP_SHORT_WCHAR 1
 273// Both MinGW and native MSVC provide a "MSVC"-like environment
 274#    define _LIBCPP_MSVCRT_LIKE
 275// If mingw not explicitly detected, assume using MS C runtime only if
 276// a MS compatibility version is specified.
 277#    if defined(_MSC_VER) && !defined(__MINGW32__)
 278#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
 279#    endif
 280#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
 281#      define _LIBCPP_HAS_BITSCAN64 1
 282#    else
 283#      define _LIBCPP_HAS_BITSCAN64 0
 284#    endif
 285#    define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
 286#  else
 287#    define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
 288#    define _LIBCPP_HAS_BITSCAN64 0
 289#  endif // defined(_WIN32)
 290
 291#  if defined(_AIX) && !defined(__64BIT__)
 292// The size of wchar is 2 byte on 32-bit mode on AIX.
 293#    define _LIBCPP_SHORT_WCHAR 1
 294#  endif
 295
 296// Libc++ supports various implementations of std::random_device.
 297//
 298// _LIBCPP_USING_DEV_RANDOM
 299//      Read entropy from the given file, by default `/dev/urandom`.
 300//      If a token is provided, it is assumed to be the path to a file
 301//      to read entropy from. This is the default behavior if nothing
 302//      else is specified. This implementation requires storing state
 303//      inside `std::random_device`.
 304//
 305// _LIBCPP_USING_ARC4_RANDOM
 306//      Use arc4random(). This allows obtaining random data even when
 307//      using sandboxing mechanisms. On some platforms like Apple, this
 308//      is the recommended source of entropy for user-space programs.
 309//      When this option is used, the token passed to `std::random_device`'s
 310//      constructor *must* be "/dev/urandom" -- anything else is an error.
 311//
 312// _LIBCPP_USING_GETENTROPY
 313//      Use getentropy().
 314//      When this option is used, the token passed to `std::random_device`'s
 315//      constructor *must* be "/dev/urandom" -- anything else is an error.
 316//
 317// _LIBCPP_USING_FUCHSIA_CPRNG
 318//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
 319//      deliver high-quality entropy and cannot fail.
 320//      When this option is used, the token passed to `std::random_device`'s
 321//      constructor *must* be "/dev/urandom" -- anything else is an error.
 322//
 323// _LIBCPP_USING_NACL_RANDOM
 324//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
 325//      including accesses to the special files under `/dev`. This implementation
 326//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
 327//      When this option is used, the token passed to `std::random_device`'s
 328//      constructor *must* be "/dev/urandom" -- anything else is an error.
 329//
 330// _LIBCPP_USING_WIN32_RANDOM
 331//      Use rand_s(), for use on Windows.
 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#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
 335      defined(__DragonFly__)
 336#    define _LIBCPP_USING_ARC4_RANDOM
 337#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
 338#    define _LIBCPP_USING_GETENTROPY
 339#  elif defined(__Fuchsia__)
 340#    define _LIBCPP_USING_FUCHSIA_CPRNG
 341#  elif defined(__native_client__)
 342#    define _LIBCPP_USING_NACL_RANDOM
 343#  elif defined(_LIBCPP_WIN32API)
 344#    define _LIBCPP_USING_WIN32_RANDOM
 345#  else
 346#    define _LIBCPP_USING_DEV_RANDOM
 347#  endif
 348
 349#  ifndef _LIBCPP_CXX03_LANG
 350
 351#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
 352#    define _ALIGNAS_TYPE(x) alignas(x)
 353#    define _ALIGNAS(x) alignas(x)
 354#    define _NOEXCEPT noexcept
 355#    define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
 356#    define _LIBCPP_CONSTEXPR constexpr
 357
 358#  else
 359
 360#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
 361#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
 362#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
 363#    define nullptr __nullptr
 364#    define _NOEXCEPT throw()
 365#    define _NOEXCEPT_(...)
 366#    define static_assert(...) _Static_assert(__VA_ARGS__)
 367#    define decltype(...) __decltype(__VA_ARGS__)
 368#    define _LIBCPP_CONSTEXPR
 369
 370typedef __char16_t char16_t;
 371typedef __char32_t char32_t;
 372
 373#  endif
 374
 375#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
 376
 377#  if __has_extension(blocks) && defined(__APPLE__)
 378#    define _LIBCPP_HAS_BLOCKS_RUNTIME 1
 379#  else
 380#    define _LIBCPP_HAS_BLOCKS_RUNTIME 0
 381#  endif
 382
 383#  define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
 384
 385#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
 386
 387#    ifdef _DLL
 388#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
 389#    else
 390#      define _LIBCPP_CRT_FUNC
 391#    endif
 392
 393#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
 394#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
 395#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
 396#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
 397#      define _LIBCPP_EXPORTED_FROM_ABI
 398#    elif defined(_LIBCPP_BUILDING_LIBRARY)
 399#      if defined(__MINGW32__)
 400#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport)
 401#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
 402#      else
 403#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
 404#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport)
 405#      endif
 406#      define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport)
 407#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
 408#    else
 409#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport)
 410#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
 411#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
 412#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
 413#    endif
 414
 415#    define _LIBCPP_HIDDEN
 416#    define _LIBCPP_TEMPLATE_DATA_VIS
 417#    define _LIBCPP_NAMESPACE_VISIBILITY
 418
 419#  else
 420
 421#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 422#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
 423#    else
 424#      define _LIBCPP_VISIBILITY(vis)
 425#    endif
 426
 427#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
 428#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
 429#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
 430#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
 431#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
 432
 433// TODO: Make this a proper customization point or remove the option to override it.
 434#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
 435#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
 436#    endif
 437
 438#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
 439#      define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
 440#    elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 441#      define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
 442#    else
 443#      define _LIBCPP_NAMESPACE_VISIBILITY
 444#    endif
 445
 446#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
 447
 448#  if __has_attribute(exclude_from_explicit_instantiation)
 449#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
 450#  else
 451// Try to approximate the effect of exclude_from_explicit_instantiation
 452// (which is that entities are not assumed to be provided by explicit
 453// template instantiations in the dylib) by always inlining those entities.
 454#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
 455#  endif
 456
 457#  ifdef _LIBCPP_COMPILER_CLANG_BASED
 458#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
 459#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
 460#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
 461#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
 462#  elif defined(_LIBCPP_COMPILER_GCC)
 463#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
 464#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
 465#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
 466#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
 467#  else
 468#    define _LIBCPP_DIAGNOSTIC_PUSH
 469#    define _LIBCPP_DIAGNOSTIC_POP
 470#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
 471#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
 472#  endif
 473
 474#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
 475#    define _LIBCPP_HARDENING_SIG f
 476#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
 477#    define _LIBCPP_HARDENING_SIG s
 478#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 479#    define _LIBCPP_HARDENING_SIG d
 480#  else
 481#    define _LIBCPP_HARDENING_SIG n // "none"
 482#  endif
 483
 484#  if !_LIBCPP_HAS_EXCEPTIONS
 485#    define _LIBCPP_EXCEPTIONS_SIG n
 486#  else
 487#    define _LIBCPP_EXCEPTIONS_SIG e
 488#  endif
 489
 490#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
 491    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
 492
 493// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
 494// on two levels:
 495// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
 496//    symbols from their dynamic library by means of using the libc++ headers. This ensures
 497//    that those symbols stay private to the dynamic library in which it is defined.
 498//
 499// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
 500//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
 501//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
 502//    program contains two definitions of a function, the ODR requires them to be token-by-token
 503//    equivalent, and the linker is allowed to pick either definition and discard the other one.
 504//
 505//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
 506//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
 507//    compiled with different settings), the two definitions are both visible by the linker and they
 508//    have the same name, but they have a meaningfully different implementation (one throws an exception
 509//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
 510//    practice what will happen is that the linker will pick one of the definitions at random and will
 511//    discard the other one. This can quite clearly lead to incorrect program behavior.
 512//
 513//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
 514//    property that causes the code of a function to differ from the code in another configuration
 515//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
 516//    tag, but we encode the ones that we think are most important: library version, exceptions, and
 517//    hardening mode.
 518//
 519//    Note that historically, solving this problem has been achieved in various ways, including
 520//    force-inlining all functions or giving internal linkage to all functions. Both these previous
 521//    solutions suffer from drawbacks that lead notably to code bloat.
 522//
 523// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
 524// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
 525//
 526// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
 527// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
 528// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
 529// the virtual function pointer in the vtable based on the mangled name of the function. Since
 530// we use an ABI tag that changes with each released version, the mangled name of the virtual
 531// function would change, which is incorrect. Note that it doesn't make much sense to change
 532// the implementation of a virtual function in an ABI-incompatible way in the first place,
 533// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
 534//
 535// The macro can be applied to record and enum types. When the tagged type is nested in
 536// a record this "parent" record needs to have the macro too. Another use case for applying
 537// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
 538// This can be useful for inline variables that are implementation details which are expected
 539// to change in the future.
 540//
 541// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
 542//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
 543//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
 544#  ifndef _LIBCPP_NO_ABI_TAG
 545#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
 546      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
 547      __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
 548#  else
 549#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
 550#  endif
 551#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
 552
 553#  ifdef _LIBCPP_BUILDING_LIBRARY
 554#    if _LIBCPP_ABI_VERSION > 1
 555#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
 556#    else
 557#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
 558#    endif
 559#  else
 560#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
 561#  endif
 562
 563// Clang modules take a significant compile time hit when pushing and popping diagnostics.
 564// Since all the headers are marked as system headers unless _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER is defined, we can
 565// simply disable this pushing and popping when _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER isn't defined.
 566#  ifdef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 567#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS                                                                         \
 568      _LIBCPP_DIAGNOSTIC_PUSH                                                                                          \
 569      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions")                                                           \
 570      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                           \
 571      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                           \
 572      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                           \
 573      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")                                                           \
 574      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                             \
 575      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                             \
 576      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                             \
 577      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
 578#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
 579#  else
 580#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
 581#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
 582#  endif
 583
 584// clang-format off
 585
 586// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There
 587// are two main categories where that's the case:
 588// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++
 589//   and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore.
 590// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know
 591//   their mangling without the appropriate declaration in some cases.
 592// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
 593// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
 594#  define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD                                                                      \
 595    _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
 596
 597#  define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
 598
 599#  define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
 600#  define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 601
 602// TODO: This should really be in the versioned namespace
 603#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental {
 604#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
 605
 606#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
 607#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
 608
 609#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
 610#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
 611
 612#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
 613#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
 614#  define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
 615#else
 616#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
 617                                             inline namespace __fs { namespace filesystem {
 618
 619#  define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
 620#endif
 621
 622// clang-format on
 623
 624#  if __has_attribute(__enable_if__)
 625#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
 626#  endif
 627
 628#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
 629#    define _LIBCPP_HAS_INT128 0
 630#  else
 631#    define _LIBCPP_HAS_INT128 1
 632#  endif
 633
 634#  ifdef _LIBCPP_CXX03_LANG
 635#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
 636      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
 637        enum __lx
 638// clang-format off
 639#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
 640      __lx __v_;                                                                                                       \
 641      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
 642      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
 643      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
 644      };
 645// clang-format on
 646
 647#  else // _LIBCPP_CXX03_LANG
 648#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
 649#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
 650#  endif // _LIBCPP_CXX03_LANG
 651
 652#  ifdef __FreeBSD__
 653#    define _DECLARE_C99_LDBL_MATH 1
 654#  endif
 655
 656/* zig patch: compiler defines _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION in some cases */
 657#  if !defined(_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION)
 658// If we are getting operator new from the MSVC CRT, then allocation overloads
 659// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
 660#    if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
 661#      define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
 662#    elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
 663// We're deferring to Microsoft's STL to provide aligned new et al. We don't
 664// have it unless the language feature test macro is defined.
 665#      define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
 666#    elif defined(__MVS__)
 667#      define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
 668#    else
 669#      define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
 670#    endif
 671
 672#    if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
 673#      define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
 674#    else
 675#      define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
 676#    endif
 677#  endif
 678
 679// It is not yet possible to use aligned_alloc() on all Apple platforms since
 680// 10.15 was the first version to ship an implementation of aligned_alloc().
 681#  if defined(__APPLE__)
 682#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
 683         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) ||                                                    \
 684        (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) &&                                                    \
 685         __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) ||                                                   \
 686        (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) &&                                                     \
 687         __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) ||                                                     \
 688        (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000)
 689#      define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
 690#    else
 691#      define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
 692#    endif
 693#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
 694// Android only provides aligned_alloc when targeting API 28 or higher.
 695#    define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
 696#  else
 697#    define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
 698#  endif
 699
 700#  if defined(__APPLE__) || defined(__FreeBSD__)
 701#    define _LIBCPP_WCTYPE_IS_MASK
 702#  endif
 703
 704#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
 705#    define _LIBCPP_HAS_CHAR8_T 0
 706#  else
 707#    define _LIBCPP_HAS_CHAR8_T 1
 708#  endif
 709
 710// Deprecation macros.
 711//
 712// Deprecations warnings are always enabled, except when users explicitly opt-out
 713// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
 714#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
 715#    if __has_attribute(__deprecated__)
 716#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
 717#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
 718#    elif _LIBCPP_STD_VER >= 14
 719#      define _LIBCPP_DEPRECATED [[deprecated]]
 720#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
 721#    else
 722#      define _LIBCPP_DEPRECATED
 723#      define _LIBCPP_DEPRECATED_(m)
 724#    endif
 725#  else
 726#    define _LIBCPP_DEPRECATED
 727#    define _LIBCPP_DEPRECATED_(m)
 728#  endif
 729
 730#  if !defined(_LIBCPP_CXX03_LANG)
 731#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
 732#  else
 733#    define _LIBCPP_DEPRECATED_IN_CXX11
 734#  endif
 735
 736#  if _LIBCPP_STD_VER >= 14
 737#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
 738#  else
 739#    define _LIBCPP_DEPRECATED_IN_CXX14
 740#  endif
 741
 742#  if _LIBCPP_STD_VER >= 17
 743#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
 744#  else
 745#    define _LIBCPP_DEPRECATED_IN_CXX17
 746#  endif
 747
 748#  if _LIBCPP_STD_VER >= 20
 749#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
 750#  else
 751#    define _LIBCPP_DEPRECATED_IN_CXX20
 752#  endif
 753
 754#  if _LIBCPP_STD_VER >= 23
 755#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
 756#  else
 757#    define _LIBCPP_DEPRECATED_IN_CXX23
 758#  endif
 759
 760#  if _LIBCPP_STD_VER >= 26
 761#    define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
 762#    define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m)
 763#  else
 764#    define _LIBCPP_DEPRECATED_IN_CXX26
 765#    define _LIBCPP_DEPRECATED_IN_CXX26_(m)
 766#  endif
 767
 768#  if _LIBCPP_HAS_CHAR8_T
 769#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
 770#  else
 771#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
 772#  endif
 773
 774// Macros to enter and leave a state where deprecation warnings are suppressed.
 775#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
 776#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
 777      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
 778          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
 779#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
 780#  else
 781#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 782#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
 783#  endif
 784
 785#  if _LIBCPP_STD_VER <= 11
 786#    define _LIBCPP_EXPLICIT_SINCE_CXX14
 787#  else
 788#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
 789#  endif
 790
 791#  if _LIBCPP_STD_VER >= 23
 792#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
 793#  else
 794#    define _LIBCPP_EXPLICIT_SINCE_CXX23
 795#  endif
 796
 797#  if _LIBCPP_STD_VER >= 14
 798#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
 799#  else
 800#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
 801#  endif
 802
 803#  if _LIBCPP_STD_VER >= 17
 804#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
 805#  else
 806#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
 807#  endif
 808
 809#  if _LIBCPP_STD_VER >= 20
 810#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
 811#  else
 812#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
 813#  endif
 814
 815#  if _LIBCPP_STD_VER >= 23
 816#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
 817#  else
 818#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
 819#  endif
 820
 821#  if _LIBCPP_STD_VER >= 26
 822#    define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
 823#  else
 824#    define _LIBCPP_CONSTEXPR_SINCE_CXX26
 825#  endif
 826
 827#  ifndef _LIBCPP_WEAK
 828#    define _LIBCPP_WEAK __attribute__((__weak__))
 829#  endif
 830
 831// Thread API
 832// clang-format off
 833#  if _LIBCPP_HAS_THREADS &&                                                                                           \
 834      !_LIBCPP_HAS_THREAD_API_PTHREAD &&                                                                               \
 835      !_LIBCPP_HAS_THREAD_API_WIN32 &&                                                                                 \
 836      !_LIBCPP_HAS_THREAD_API_EXTERNAL
 837
 838#    if defined(__FreeBSD__) ||                                                                                        \
 839        defined(__wasi__) ||                                                                                           \
 840        defined(__NetBSD__) ||                                                                                         \
 841        defined(__OpenBSD__) ||                                                                                        \
 842        defined(__NuttX__) ||                                                                                          \
 843        defined(__linux__) ||                                                                                          \
 844        defined(__GNU__) ||                                                                                            \
 845        defined(__APPLE__) ||                                                                                          \
 846        defined(__MVS__) ||                                                                                            \
 847        defined(_AIX) ||                                                                                               \
 848        defined(__EMSCRIPTEN__)
 849// clang-format on
 850#      undef _LIBCPP_HAS_THREAD_API_PTHREAD
 851#      define _LIBCPP_HAS_THREAD_API_PTHREAD 1
 852#    elif defined(__Fuchsia__)
 853// TODO(44575): Switch to C11 thread API when possible.
 854#      undef _LIBCPP_HAS_THREAD_API_PTHREAD
 855#      define _LIBCPP_HAS_THREAD_API_PTHREAD 1
 856#    elif defined(_LIBCPP_WIN32API)
 857#      undef _LIBCPP_HAS_THREAD_API_WIN32
 858#      define _LIBCPP_HAS_THREAD_API_WIN32 1
 859#    else
 860#      error "No thread API"
 861#    endif // _LIBCPP_HAS_THREAD_API
 862#  endif   // _LIBCPP_HAS_THREADS
 863
 864#  if _LIBCPP_HAS_THREAD_API_PTHREAD
 865#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
 866#      define _LIBCPP_HAS_COND_CLOCKWAIT 1
 867#    elif defined(_LIBCPP_GLIBC_PREREQ)
 868#      if _LIBCPP_GLIBC_PREREQ(2, 30)
 869#        define _LIBCPP_HAS_COND_CLOCKWAIT 1
 870#      else
 871#        define _LIBCPP_HAS_COND_CLOCKWAIT 0
 872#      endif
 873#    else
 874#      define _LIBCPP_HAS_COND_CLOCKWAIT 0
 875#    endif
 876#  else
 877#    define _LIBCPP_HAS_COND_CLOCKWAIT 0
 878#  endif
 879
 880#  if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
 881#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
 882#  endif
 883
 884#  if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
 885#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
 886#  endif
 887
 888#  if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
 889#    error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
 890#  endif
 891
 892#  if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
 893#    define __STDCPP_THREADS__ 1
 894#  endif
 895
 896// The glibc and Bionic implementation of pthreads implements
 897// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
 898// mutexes have no destroy mechanism.
 899//
 900// This optimization can't be performed on Apple platforms, where
 901// pthread_mutex_destroy can allow the kernel to release resources.
 902// See https://llvm.org/D64298 for details.
 903//
 904// TODO(EricWF): Enable this optimization on Bionic after speaking to their
 905//               respective stakeholders.
 906// clang-format off
 907#  if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) ||                                                        \
 908      (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) ||                                                          \
 909       _LIBCPP_HAS_THREAD_API_WIN32
 910// clang-format on
 911#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
 912#  else
 913#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
 914#  endif
 915
 916// Destroying a condvar is a nop on Windows.
 917//
 918// This optimization can't be performed on Apple platforms, where
 919// pthread_cond_destroy can allow the kernel to release resources.
 920// See https://llvm.org/D64298 for details.
 921//
 922// TODO(EricWF): This is potentially true for some pthread implementations
 923// as well.
 924#  if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
 925#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
 926#  else
 927#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
 928#  endif
 929
 930#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
 931      _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
 932#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
 933#  endif
 934
 935#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
 936#    define _LIBCPP_HAS_C_ATOMIC_IMP 1
 937#    define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
 938#    define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
 939#  elif defined(_LIBCPP_COMPILER_GCC)
 940#    define _LIBCPP_HAS_C_ATOMIC_IMP 0
 941#    define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
 942#    define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
 943#  endif
 944
 945#  if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
 946#    define _LIBCPP_HAS_ATOMIC_HEADER 0
 947#  else
 948#    define _LIBCPP_HAS_ATOMIC_HEADER 1
 949#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
 950#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
 951#    endif
 952#  endif
 953
 954#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
 955#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
 956#  else
 957#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
 958#  endif
 959
 960#  if _LIBCPP_STD_VER >= 20
 961#    define _LIBCPP_CONSTINIT constinit
 962#  elif __has_attribute(__require_constant_initialization__)
 963#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
 964#  else
 965#    define _LIBCPP_CONSTINIT
 966#  endif
 967
 968#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
 969// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
 970// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
 971// when compiling for CUDA we use the non-underscored version of the noinline
 972// attribute.
 973//
 974// This is a temporary workaround and we still expect the CUDA SDK team to solve
 975// this issue properly in the SDK headers.
 976//
 977// See https://github.com/llvm/llvm-project/pull/73838 for more details.
 978#    define _LIBCPP_NOINLINE __attribute__((noinline))
 979#  elif __has_attribute(__noinline__)
 980#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
 981#  else
 982#    define _LIBCPP_NOINLINE
 983#  endif
 984
 985// We often repeat things just for handling wide characters in the library.
 986// When wide characters are disabled, it can be useful to have a quick way of
 987// disabling it without having to resort to #if-#endif, which has a larger
 988// impact on readability.
 989#  if !_LIBCPP_HAS_WIDE_CHARACTERS
 990#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
 991#  else
 992#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
 993#  endif
 994
 995// clang-format off
 996#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
 997#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
 998// clang-format on
 999
1000#  ifndef _LIBCPP_NO_AUTO_LINK
1001#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1002#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1003#        pragma comment(lib, "c++.lib")
1004#      else
1005#        pragma comment(lib, "libc++.lib")
1006#      endif
1007#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1008#  endif   // _LIBCPP_NO_AUTO_LINK
1009
1010// Configures the fopen close-on-exec mode character, if any. This string will
1011// be appended to any mode string used by fstream for fopen/fdopen.
1012//
1013// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1014// do.
1015#  if defined(__BIONIC__)
1016#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1017#  else
1018#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1019#  endif
1020
1021#  if __has_cpp_attribute(msvc::no_unique_address)
1022// MSVC implements [[no_unique_address]] as a silent no-op currently.
1023// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1024// However, MSVC implements [[msvc::no_unique_address]] which does what
1025// [[no_unique_address]] is supposed to do, in general.
1026#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1027#  else
1028#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1029#  endif
1030
1031// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1032// functions is gradually being added to existing C libraries. The conditions
1033// below check for known C library versions and conditions under which these
1034// functions are declared by the C library.
1035//
1036// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1037// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1038// the latter depends on internal GNU libc details that are not appropriate
1039// to depend on here, so any declarations present when __cpp_char8_t is not
1040// defined are ignored.
1041#  if defined(_LIBCPP_GLIBC_PREREQ)
1042#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1043#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1044#    else
1045#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1046#    endif
1047#  else
1048#    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1049#  endif
1050
1051// There are a handful of public standard library types that are intended to
1052// support CTAD but don't need any explicit deduction guides to do so. This
1053// macro is used to mark them as such, which suppresses the
1054// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1055// with these classes.
1056#  if _LIBCPP_STD_VER >= 17
1057#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1058#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1059        template <class... _Tag>                                                                                       \
1060        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1061#    else
1062#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
1063        template <class... _Tag>                                                                                       \
1064        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1065#    endif
1066#  else
1067#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1068#  endif
1069
1070// TODO(LLVM 22): Remove the workaround
1071#  if defined(__OBJC__) && (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER < 2001)
1072#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1073#  endif
1074
1075#  define _PSTL_PRAGMA(x) _Pragma(#x)
1076
1077// Enable SIMD for compilers that support OpenMP 4.0
1078#  if (defined(_OPENMP) && _OPENMP >= 201307)
1079
1080#    define _PSTL_UDR_PRESENT
1081#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1082#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1083#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1084#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1085#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1086#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1087
1088// Declaration of reduction functor, where
1089// NAME - the name of the functor
1090// OP - type of the callable object with the reduction operation
1091// omp_in - refers to the local partial result
1092// omp_out - refers to the final value of the combiner operator
1093// omp_priv - refers to the private copy of the initial value
1094// omp_orig - refers to the original variable to be reduced
1095#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
1096      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1097
1098#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1099
1100#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1101#    define _PSTL_PRAGMA_DECLARE_SIMD
1102#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1103#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1104#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1105#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1106#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1107
1108#  else // (defined(_OPENMP) && _OPENMP >= 201307)
1109
1110#    define _PSTL_PRAGMA_SIMD
1111#    define _PSTL_PRAGMA_DECLARE_SIMD
1112#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1113#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1114#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1115#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1116#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1117
1118#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
1119
1120#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1121
1122// Optional attributes - these are useful for a better QoI, but not required to be available
1123
1124#  define _LIBCPP_NOALIAS __attribute__((__malloc__))
1125#  define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1126#  define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1127#  define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1128#  define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                             \
1129    __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1130#  define _LIBCPP_PACKED __attribute__((__packed__))
1131
1132#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1133#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1134#  else
1135#    define _LIBCPP_NO_CFI
1136#  endif
1137
1138#  if __has_attribute(__using_if_exists__)
1139#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1140#  else
1141#    define _LIBCPP_USING_IF_EXISTS
1142#  endif
1143
1144#  if __has_cpp_attribute(_Clang::__no_destroy__)
1145#    define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]]
1146#  else
1147#    define _LIBCPP_NO_DESTROY
1148#  endif
1149
1150#  if __has_attribute(__diagnose_if__)
1151#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1152#  else
1153#    define _LIBCPP_DIAGNOSE_WARNING(...)
1154#  endif
1155
1156#  if __has_cpp_attribute(_Clang::__lifetimebound__)
1157#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1158#  else
1159#    define _LIBCPP_LIFETIMEBOUND
1160#  endif
1161
1162#  if __has_cpp_attribute(_Clang::__noescape__)
1163#    define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
1164#  else
1165#    define _LIBCPP_NOESCAPE
1166#  endif
1167
1168#  if __has_cpp_attribute(_Clang::__no_specializations__)
1169#    define _LIBCPP_NO_SPECIALIZATIONS                                                                                 \
1170      [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
1171#  else
1172#    define _LIBCPP_NO_SPECIALIZATIONS
1173#  endif
1174
1175#  if __has_cpp_attribute(_Clang::__standalone_debug__)
1176#    define _LIBCPP_STANDALONE_DEBUG [[_Clang::__standalone_debug__]]
1177#  else
1178#    define _LIBCPP_STANDALONE_DEBUG
1179#  endif
1180
1181#  if __has_cpp_attribute(_Clang::__preferred_name__)
1182#    define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]]
1183#  else
1184#    define _LIBCPP_PREFERRED_NAME(x)
1185#  endif
1186
1187#  if __has_cpp_attribute(_Clang::__scoped_lockable__)
1188#    define _LIBCPP_SCOPED_LOCKABLE [[_Clang::__scoped_lockable__]]
1189#  else
1190#    define _LIBCPP_SCOPED_LOCKABLE
1191#  endif
1192
1193#  if __has_cpp_attribute(_Clang::__capability__)
1194#    define _LIBCPP_CAPABILITY(...) [[_Clang::__capability__(__VA_ARGS__)]]
1195#  else
1196#    define _LIBCPP_CAPABILITY(...)
1197#  endif
1198
1199#  if __has_attribute(__acquire_capability__)
1200#    define _LIBCPP_ACQUIRE_CAPABILITY(...) __attribute__((__acquire_capability__(__VA_ARGS__)))
1201#  else
1202#    define _LIBCPP_ACQUIRE_CAPABILITY(...)
1203#  endif
1204
1205#  if __has_cpp_attribute(_Clang::__try_acquire_capability__)
1206#    define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...) [[_Clang::__try_acquire_capability__(__VA_ARGS__)]]
1207#  else
1208#    define _LIBCPP_TRY_ACQUIRE_CAPABILITY(...)
1209#  endif
1210
1211#  if __has_cpp_attribute(_Clang::__acquire_shared_capability__)
1212#    define _LIBCPP_ACQUIRE_SHARED_CAPABILITY [[_Clang::__acquire_shared_capability__]]
1213#  else
1214#    define _LIBCPP_ACQUIRE_SHARED_CAPABILITY
1215#  endif
1216
1217#  if __has_cpp_attribute(_Clang::__try_acquire_shared_capability__)
1218#    define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...) [[_Clang::__try_acquire_shared_capability__(__VA_ARGS__)]]
1219#  else
1220#    define _LIBCPP_TRY_ACQUIRE_SHARED_CAPABILITY(...)
1221#  endif
1222
1223#  if __has_cpp_attribute(_Clang::__release_capability__)
1224#    define _LIBCPP_RELEASE_CAPABILITY [[_Clang::__release_capability__]]
1225#  else
1226#    define _LIBCPP_RELEASE_CAPABILITY
1227#  endif
1228
1229#  if __has_cpp_attribute(_Clang::__release_shared_capability__)
1230#    define _LIBCPP_RELEASE_SHARED_CAPABILITY [[_Clang::__release_shared_capability__]]
1231#  else
1232#    define _LIBCPP_RELEASE_SHARED_CAPABILITY
1233#  endif
1234
1235#  if __has_attribute(__requires_capability__)
1236#    define _LIBCPP_REQUIRES_CAPABILITY(...) __attribute__((__requires_capability__(__VA_ARGS__)))
1237#  else
1238#    define _LIBCPP_REQUIRES_CAPABILITY(...)
1239#  endif
1240
1241#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1242#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1243#  else
1244#    define _LIBCPP_DECLSPEC_EMPTY_BASES
1245#  endif
1246
1247// Allow for build-time disabling of unsigned integer sanitization
1248#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1249#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1250#  else
1251#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1252#  endif
1253
1254#  if __has_feature(nullability)
1255#    define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull
1256#  else
1257#    define _LIBCPP_DIAGNOSE_NULLPTR
1258#  endif
1259
1260// TODO(LLVM 22): Remove this macro once LLVM19 support ends. __cpp_explicit_this_parameter has been set in LLVM20.
1261// Clang-18 has support for deducing this, but it does not set the FTM.
1262#  if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1263#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
1264#  else
1265#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
1266#  endif
1267
1268#endif // __cplusplus
1269
1270#endif // _LIBCPP___CONFIG