Warning, /include/c++/v1/__config is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP___CONFIG
0011 #define _LIBCPP___CONFIG
0012
0013 #include <__config_site>
0014 #include <__configuration/abi.h>
0015 #include <__configuration/availability.h>
0016 #include <__configuration/compiler.h>
0017 #include <__configuration/language.h>
0018 #include <__configuration/platform.h>
0019
0020 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
0021 # pragma GCC system_header
0022 #endif
0023
0024 #ifdef __cplusplus
0025
0026 // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
0027
0028 // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
0029 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
0030 // defined to XXYYZZ.
0031 # define _LIBCPP_VERSION 200100
0032
0033 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
0034 # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
0035 # define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z))
0036
0037 # if __STDC_HOSTED__ == 0
0038 # define _LIBCPP_FREESTANDING
0039 # endif
0040
0041 // HARDENING {
0042
0043 // TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
0044 # ifdef _LIBCPP_ENABLE_ASSERTIONS
0045 # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
0046 # endif
0047
0048 // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
0049 //
0050 // - `_LIBCPP_HARDENING_MODE_NONE`;
0051 // - `_LIBCPP_HARDENING_MODE_FAST`;
0052 // - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
0053 // - `_LIBCPP_HARDENING_MODE_DEBUG`.
0054 //
0055 // These values have the following effects:
0056 //
0057 // - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
0058 //
0059 // - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
0060 // that can be done with relatively little runtime overhead in constant time;
0061 //
0062 // - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
0063 // the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
0064 // but are not necessarily security-critical;
0065 //
0066 // - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
0067 // mode and enables all checks available in the library, including internal assertions. Checks that are part of the
0068 // debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
0069
0070 // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
0071 // macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
0072 //
0073 // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
0074 // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
0075 // - the sentinel is reachable from the begin iterator;
0076 // - TODO(hardening): both iterators refer to the same container.
0077 //
0078 // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
0079 // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
0080 // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
0081 // `optional` and `function` are considered one-element containers for the purposes of this check.
0082 //
0083 // - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
0084 // address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
0085 // memory security of a program (however, it is still undefined behavior that can result in strange errors due to
0086 // compiler optimizations).
0087 //
0088 // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
0089 // given ranges do not overlap.
0090 //
0091 // - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
0092 // was allocated by the given allocator). Violating this category typically results in a memory leak.
0093 //
0094 // - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
0095 // an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
0096 // attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
0097 // (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
0098 // otherwise create an immediate security issue.
0099 //
0100 // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
0101 // the containers have compatible allocators.
0102 //
0103 // - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
0104 // for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
0105 // original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
0106 // a string view where only a subset of elements is possible to access). This category is for assertions violating
0107 // which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
0108 // user code.
0109 //
0110 // - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
0111 // be benign in our implementation.
0112 //
0113 // - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
0114 // by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
0115 // thus, this would often be a heuristic check and it might be quite expensive.
0116 //
0117 // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
0118 // user input.
0119 //
0120 // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
0121
0122 // clang-format off
0123 # define _LIBCPP_HARDENING_MODE_NONE (1 << 1)
0124 # define _LIBCPP_HARDENING_MODE_FAST (1 << 2)
0125 # define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
0126 # define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3)
0127 // clang-format on
0128
0129 # ifndef _LIBCPP_HARDENING_MODE
0130
0131 # ifndef _LIBCPP_HARDENING_MODE_DEFAULT
0132 # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
0133 `__config_site` header, please make sure your installation of libc++ is not broken.
0134 # endif
0135
0136 # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
0137 # endif
0138
0139 # if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \
0140 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
0141 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
0142 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
0143 # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
0144 _LIBCPP_HARDENING_MODE_NONE, \
0145 _LIBCPP_HARDENING_MODE_FAST, \
0146 _LIBCPP_HARDENING_MODE_EXTENSIVE, \
0147 _LIBCPP_HARDENING_MODE_DEBUG
0148 # endif
0149
0150 // } HARDENING
0151
0152 # define _LIBCPP_TOSTRING2(x) #x
0153 # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
0154
0155 // NOLINTNEXTLINE(libcpp-cpp-version-check)
0156 # if __cplusplus < 201103L
0157 # define _LIBCPP_CXX03_LANG
0158 # endif
0159
0160 # ifndef __has_constexpr_builtin
0161 # define __has_constexpr_builtin(x) 0
0162 # endif
0163
0164 // This checks wheter a Clang module is built
0165 # ifndef __building_module
0166 # define __building_module(...) 0
0167 # endif
0168
0169 // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
0170 // the compiler and '1' otherwise.
0171 # ifndef __is_identifier
0172 # define __is_identifier(__x) 1
0173 # endif
0174
0175 # ifndef __has_declspec_attribute
0176 # define __has_declspec_attribute(__x) 0
0177 # endif
0178
0179 # define __has_keyword(__x) !(__is_identifier(__x))
0180
0181 # ifndef __has_warning
0182 # define __has_warning(...) 0
0183 # endif
0184
0185 # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
0186 # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
0187 # endif
0188
0189 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
0190 # define _LIBCPP_ABI_VCRUNTIME
0191 # endif
0192
0193 # if __has_feature(experimental_library)
0194 # ifndef _LIBCPP_ENABLE_EXPERIMENTAL
0195 # define _LIBCPP_ENABLE_EXPERIMENTAL
0196 # endif
0197 # endif
0198
0199 // Incomplete features get their own specific disabling flags. This makes it
0200 // easier to grep for target specific flags once the feature is complete.
0201 # if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY)
0202 # define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1
0203 # else
0204 # define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0
0205 # endif
0206
0207 # define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
0208 # define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
0209 # define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
0210
0211 # if defined(__MVS__)
0212 # include <features.h> // for __NATIVE_ASCII_F
0213 # endif
0214
0215 # if defined(_WIN32)
0216 # define _LIBCPP_WIN32API
0217 # define _LIBCPP_SHORT_WCHAR 1
0218 // Both MinGW and native MSVC provide a "MSVC"-like environment
0219 # define _LIBCPP_MSVCRT_LIKE
0220 // If mingw not explicitly detected, assume using MS C runtime only if
0221 // a MS compatibility version is specified.
0222 # if defined(_MSC_VER) && !defined(__MINGW32__)
0223 # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
0224 # endif
0225 # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
0226 # define _LIBCPP_HAS_BITSCAN64 1
0227 # else
0228 # define _LIBCPP_HAS_BITSCAN64 0
0229 # endif
0230 # define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
0231 # else
0232 # define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
0233 # define _LIBCPP_HAS_BITSCAN64 0
0234 # endif // defined(_WIN32)
0235
0236 # if defined(_AIX) && !defined(__64BIT__)
0237 // The size of wchar is 2 byte on 32-bit mode on AIX.
0238 # define _LIBCPP_SHORT_WCHAR 1
0239 # endif
0240
0241 // Libc++ supports various implementations of std::random_device.
0242 //
0243 // _LIBCPP_USING_DEV_RANDOM
0244 // Read entropy from the given file, by default `/dev/urandom`.
0245 // If a token is provided, it is assumed to be the path to a file
0246 // to read entropy from. This is the default behavior if nothing
0247 // else is specified. This implementation requires storing state
0248 // inside `std::random_device`.
0249 //
0250 // _LIBCPP_USING_ARC4_RANDOM
0251 // Use arc4random(). This allows obtaining random data even when
0252 // using sandboxing mechanisms. On some platforms like Apple, this
0253 // is the recommended source of entropy for user-space programs.
0254 // When this option is used, the token passed to `std::random_device`'s
0255 // constructor *must* be "/dev/urandom" -- anything else is an error.
0256 //
0257 // _LIBCPP_USING_GETENTROPY
0258 // Use getentropy().
0259 // When this option is used, the token passed to `std::random_device`'s
0260 // constructor *must* be "/dev/urandom" -- anything else is an error.
0261 //
0262 // _LIBCPP_USING_FUCHSIA_CPRNG
0263 // Use Fuchsia's zx_cprng_draw() system call, which is specified to
0264 // deliver high-quality entropy and cannot fail.
0265 // When this option is used, the token passed to `std::random_device`'s
0266 // constructor *must* be "/dev/urandom" -- anything else is an error.
0267 //
0268 // _LIBCPP_USING_NACL_RANDOM
0269 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
0270 // including accesses to the special files under `/dev`. This implementation
0271 // uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
0272 // When this option is used, the token passed to `std::random_device`'s
0273 // constructor *must* be "/dev/urandom" -- anything else is an error.
0274 //
0275 // _LIBCPP_USING_WIN32_RANDOM
0276 // Use rand_s(), for use on Windows.
0277 // When this option is used, the token passed to `std::random_device`'s
0278 // constructor *must* be "/dev/urandom" -- anything else is an error.
0279 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
0280 defined(__DragonFly__)
0281 # define _LIBCPP_USING_ARC4_RANDOM
0282 # elif defined(__wasi__) || defined(__EMSCRIPTEN__)
0283 # define _LIBCPP_USING_GETENTROPY
0284 # elif defined(__Fuchsia__)
0285 # define _LIBCPP_USING_FUCHSIA_CPRNG
0286 # elif defined(__native_client__)
0287 # define _LIBCPP_USING_NACL_RANDOM
0288 # elif defined(_LIBCPP_WIN32API)
0289 # define _LIBCPP_USING_WIN32_RANDOM
0290 # else
0291 # define _LIBCPP_USING_DEV_RANDOM
0292 # endif
0293
0294 # ifndef _LIBCPP_CXX03_LANG
0295
0296 # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
0297 # define _ALIGNAS_TYPE(x) alignas(x)
0298 # define _ALIGNAS(x) alignas(x)
0299 # define _NOEXCEPT noexcept
0300 # define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
0301 # define _LIBCPP_CONSTEXPR constexpr
0302
0303 # else
0304
0305 # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
0306 # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
0307 # define _ALIGNAS(x) __attribute__((__aligned__(x)))
0308 # define nullptr __nullptr
0309 # define _NOEXCEPT throw()
0310 # define _NOEXCEPT_(...)
0311 # define static_assert(...) _Static_assert(__VA_ARGS__)
0312 # define decltype(...) __decltype(__VA_ARGS__)
0313 # define _LIBCPP_CONSTEXPR
0314
0315 typedef __char16_t char16_t;
0316 typedef __char32_t char32_t;
0317
0318 # endif
0319
0320 # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
0321
0322 // Objective-C++ features (opt-in)
0323 # if __has_feature(objc_arc)
0324 # define _LIBCPP_HAS_OBJC_ARC 1
0325 # else
0326 # define _LIBCPP_HAS_OBJC_ARC 0
0327 # endif
0328
0329 # if __has_feature(objc_arc_weak)
0330 # define _LIBCPP_HAS_OBJC_ARC_WEAK 1
0331 # else
0332 # define _LIBCPP_HAS_OBJC_ARC_WEAK 0
0333 # endif
0334
0335 # if __has_extension(blocks)
0336 # define _LIBCPP_HAS_EXTENSION_BLOCKS 1
0337 # else
0338 # define _LIBCPP_HAS_EXTENSION_BLOCKS 0
0339 # endif
0340
0341 # if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
0342 # define _LIBCPP_HAS_BLOCKS_RUNTIME 1
0343 # else
0344 # define _LIBCPP_HAS_BLOCKS_RUNTIME 0
0345 # endif
0346
0347 # if __has_feature(address_sanitizer)
0348 # define _LIBCPP_HAS_ASAN 1
0349 # else
0350 # define _LIBCPP_HAS_ASAN 0
0351 # endif
0352
0353 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
0354
0355 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
0356
0357 # if defined(_LIBCPP_OBJECT_FORMAT_COFF)
0358
0359 # ifdef _DLL
0360 # define _LIBCPP_CRT_FUNC __declspec(dllimport)
0361 # else
0362 # define _LIBCPP_CRT_FUNC
0363 # endif
0364
0365 # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
0366 # define _LIBCPP_DLL_VIS
0367 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
0368 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
0369 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
0370 # define _LIBCPP_EXPORTED_FROM_ABI
0371 # elif defined(_LIBCPP_BUILDING_LIBRARY)
0372 # define _LIBCPP_DLL_VIS __declspec(dllexport)
0373 # if defined(__MINGW32__)
0374 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
0375 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
0376 # else
0377 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
0378 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
0379 # endif
0380 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
0381 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
0382 # else
0383 # define _LIBCPP_DLL_VIS __declspec(dllimport)
0384 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
0385 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
0386 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
0387 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
0388 # endif
0389
0390 # define _LIBCPP_HIDDEN
0391 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
0392 # define _LIBCPP_TEMPLATE_VIS
0393 # define _LIBCPP_TEMPLATE_DATA_VIS
0394 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
0395
0396 # else
0397
0398 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
0399 # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
0400 # else
0401 # define _LIBCPP_VISIBILITY(vis)
0402 # endif
0403
0404 # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
0405 # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
0406 # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
0407 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
0408 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
0409
0410 // TODO: Make this a proper customization point or remove the option to override it.
0411 # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
0412 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
0413 # endif
0414
0415 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
0416 // The inline should be removed once PR32114 is resolved
0417 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
0418 # else
0419 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
0420 # endif
0421
0422 // GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
0423 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
0424 # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
0425 # else
0426 # define _LIBCPP_TEMPLATE_VIS
0427 # endif
0428
0429 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
0430 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
0431 # else
0432 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
0433 # endif
0434
0435 # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
0436
0437 # if __has_attribute(exclude_from_explicit_instantiation)
0438 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
0439 # else
0440 // Try to approximate the effect of exclude_from_explicit_instantiation
0441 // (which is that entities are not assumed to be provided by explicit
0442 // template instantiations in the dylib) by always inlining those entities.
0443 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
0444 # endif
0445
0446 # ifdef _LIBCPP_COMPILER_CLANG_BASED
0447 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
0448 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
0449 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
0450 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
0451 # elif defined(_LIBCPP_COMPILER_GCC)
0452 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
0453 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
0454 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
0455 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
0456 # else
0457 # define _LIBCPP_DIAGNOSTIC_PUSH
0458 # define _LIBCPP_DIAGNOSTIC_POP
0459 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
0460 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
0461 # endif
0462
0463 # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
0464 # define _LIBCPP_HARDENING_SIG f
0465 # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
0466 # define _LIBCPP_HARDENING_SIG s
0467 # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
0468 # define _LIBCPP_HARDENING_SIG d
0469 # else
0470 # define _LIBCPP_HARDENING_SIG n // "none"
0471 # endif
0472
0473 # if !_LIBCPP_HAS_EXCEPTIONS
0474 # define _LIBCPP_EXCEPTIONS_SIG n
0475 # else
0476 # define _LIBCPP_EXCEPTIONS_SIG e
0477 # endif
0478
0479 # define _LIBCPP_ODR_SIGNATURE \
0480 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
0481
0482 // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
0483 // on two levels:
0484 // 1. The symbol is given hidden visibility, which ensures that users won't start exporting
0485 // symbols from their dynamic library by means of using the libc++ headers. This ensures
0486 // that those symbols stay private to the dynamic library in which it is defined.
0487 //
0488 // 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
0489 // This ensures that no ODR violation can arise from mixing two TUs compiled with different
0490 // versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
0491 // program contains two definitions of a function, the ODR requires them to be token-by-token
0492 // equivalent, and the linker is allowed to pick either definition and discard the other one.
0493 //
0494 // For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
0495 // *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
0496 // compiled with different settings), the two definitions are both visible by the linker and they
0497 // have the same name, but they have a meaningfully different implementation (one throws an exception
0498 // and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
0499 // practice what will happen is that the linker will pick one of the definitions at random and will
0500 // discard the other one. This can quite clearly lead to incorrect program behavior.
0501 //
0502 // A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
0503 // property that causes the code of a function to differ from the code in another configuration
0504 // can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
0505 // tag, but we encode the ones that we think are most important: library version, exceptions, and
0506 // hardening mode.
0507 //
0508 // Note that historically, solving this problem has been achieved in various ways, including
0509 // force-inlining all functions or giving internal linkage to all functions. Both these previous
0510 // solutions suffer from drawbacks that lead notably to code bloat.
0511 //
0512 // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
0513 // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
0514 //
0515 // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
0516 // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
0517 // name of a virtual function is part of its ABI, since some architectures like arm64e can sign
0518 // the virtual function pointer in the vtable based on the mangled name of the function. Since
0519 // we use an ABI tag that changes with each released version, the mangled name of the virtual
0520 // function would change, which is incorrect. Note that it doesn't make much sense to change
0521 // the implementation of a virtual function in an ABI-incompatible way in the first place,
0522 // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
0523 //
0524 // The macro can be applied to record and enum types. When the tagged type is nested in
0525 // a record this "parent" record needs to have the macro too. Another use case for applying
0526 // this macro to records and unions is to apply an ABI tag to inline constexpr variables.
0527 // This can be useful for inline variables that are implementation details which are expected
0528 // to change in the future.
0529 //
0530 // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
0531 // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
0532 // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
0533 # ifndef _LIBCPP_NO_ABI_TAG
0534 # define _LIBCPP_HIDE_FROM_ABI \
0535 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
0536 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
0537 # else
0538 # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
0539 # endif
0540 # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
0541
0542 # ifdef _LIBCPP_BUILDING_LIBRARY
0543 # if _LIBCPP_ABI_VERSION > 1
0544 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
0545 # else
0546 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
0547 # endif
0548 # else
0549 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
0550 # endif
0551
0552 // TODO: Remove this workaround once we drop support for Clang 16
0553 # if __has_warning("-Wc++23-extensions")
0554 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
0555 # else
0556 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
0557 # endif
0558
0559 // Clang modules take a significant compile time hit when pushing and popping diagnostics.
0560 // Since all the headers are marked as system headers in the modulemap, we can simply disable this
0561 // pushing and popping when building with clang modules.
0562 # if !__has_feature(modules)
0563 # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
0564 _LIBCPP_DIAGNOSTIC_PUSH \
0565 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
0566 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
0567 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
0568 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
0569 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
0570 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
0571 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
0572 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
0573 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
0574 # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
0575 # else
0576 # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
0577 # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
0578 # endif
0579
0580 // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
0581 // clang-format off
0582 # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
0583 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
0584 inline namespace _LIBCPP_ABI_NAMESPACE {
0585 # define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
0586
0587 #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
0588 #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }}
0589
0590 #define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
0591 #define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0592
0593 #define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
0594 #define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0595
0596 #ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
0597 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
0598 # define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
0599 #else
0600 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
0601 inline namespace __fs { namespace filesystem {
0602
0603 # define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
0604 #endif
0605
0606 // clang-format on
0607
0608 # if __has_attribute(__enable_if__)
0609 # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
0610 # endif
0611
0612 # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
0613 # define _LIBCPP_HAS_INT128 0
0614 # else
0615 # define _LIBCPP_HAS_INT128 1
0616 # endif
0617
0618 # ifdef _LIBCPP_CXX03_LANG
0619 # define _LIBCPP_DECLARE_STRONG_ENUM(x) \
0620 struct _LIBCPP_EXPORTED_FROM_ABI x { \
0621 enum __lx
0622 // clang-format off
0623 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
0624 __lx __v_; \
0625 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \
0626 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
0627 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \
0628 };
0629 // clang-format on
0630
0631 # else // _LIBCPP_CXX03_LANG
0632 # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
0633 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
0634 # endif // _LIBCPP_CXX03_LANG
0635
0636 # ifdef __FreeBSD__
0637 # define _DECLARE_C99_LDBL_MATH 1
0638 # endif
0639
0640 // If we are getting operator new from the MSVC CRT, then allocation overloads
0641 // for align_val_t were added in 19.12, aka VS 2017 version 15.3.
0642 # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
0643 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
0644 # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
0645 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
0646 // have it unless the language feature test macro is defined.
0647 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
0648 # elif defined(__MVS__)
0649 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
0650 # else
0651 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
0652 # endif
0653
0654 # if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
0655 # define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
0656 # else
0657 # define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
0658 # endif
0659
0660 // It is not yet possible to use aligned_alloc() on all Apple platforms since
0661 // 10.15 was the first version to ship an implementation of aligned_alloc().
0662 # if defined(__APPLE__)
0663 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
0664 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
0665 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
0666 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000)
0667 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
0668 # else
0669 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
0670 # endif
0671 # elif defined(__ANDROID__) && __ANDROID_API__ < 28
0672 // Android only provides aligned_alloc when targeting API 28 or higher.
0673 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
0674 # else
0675 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
0676 # endif
0677
0678 # if defined(__APPLE__) || defined(__FreeBSD__)
0679 # define _LIBCPP_HAS_DEFAULTRUNELOCALE
0680 # endif
0681
0682 # if defined(__APPLE__) || defined(__FreeBSD__)
0683 # define _LIBCPP_WCTYPE_IS_MASK
0684 # endif
0685
0686 # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
0687 # define _LIBCPP_HAS_CHAR8_T 0
0688 # else
0689 # define _LIBCPP_HAS_CHAR8_T 1
0690 # endif
0691
0692 // Deprecation macros.
0693 //
0694 // Deprecations warnings are always enabled, except when users explicitly opt-out
0695 // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
0696 # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
0697 # if __has_attribute(__deprecated__)
0698 # define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
0699 # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
0700 # elif _LIBCPP_STD_VER >= 14
0701 # define _LIBCPP_DEPRECATED [[deprecated]]
0702 # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
0703 # else
0704 # define _LIBCPP_DEPRECATED
0705 # define _LIBCPP_DEPRECATED_(m)
0706 # endif
0707 # else
0708 # define _LIBCPP_DEPRECATED
0709 # define _LIBCPP_DEPRECATED_(m)
0710 # endif
0711
0712 # if !defined(_LIBCPP_CXX03_LANG)
0713 # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
0714 # else
0715 # define _LIBCPP_DEPRECATED_IN_CXX11
0716 # endif
0717
0718 # if _LIBCPP_STD_VER >= 14
0719 # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
0720 # else
0721 # define _LIBCPP_DEPRECATED_IN_CXX14
0722 # endif
0723
0724 # if _LIBCPP_STD_VER >= 17
0725 # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
0726 # else
0727 # define _LIBCPP_DEPRECATED_IN_CXX17
0728 # endif
0729
0730 # if _LIBCPP_STD_VER >= 20
0731 # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
0732 # else
0733 # define _LIBCPP_DEPRECATED_IN_CXX20
0734 # endif
0735
0736 # if _LIBCPP_STD_VER >= 23
0737 # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
0738 # else
0739 # define _LIBCPP_DEPRECATED_IN_CXX23
0740 # endif
0741
0742 # if _LIBCPP_STD_VER >= 26
0743 # define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
0744 # else
0745 # define _LIBCPP_DEPRECATED_IN_CXX26
0746 # endif
0747
0748 # if _LIBCPP_HAS_CHAR8_T
0749 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
0750 # else
0751 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T
0752 # endif
0753
0754 // Macros to enter and leave a state where deprecation warnings are suppressed.
0755 # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
0756 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
0757 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
0758 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0759 # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
0760 # else
0761 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
0762 # define _LIBCPP_SUPPRESS_DEPRECATED_POP
0763 # endif
0764
0765 # if _LIBCPP_STD_VER <= 11
0766 # define _LIBCPP_EXPLICIT_SINCE_CXX14
0767 # else
0768 # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
0769 # endif
0770
0771 # if _LIBCPP_STD_VER >= 23
0772 # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
0773 # else
0774 # define _LIBCPP_EXPLICIT_SINCE_CXX23
0775 # endif
0776
0777 # if _LIBCPP_STD_VER >= 14
0778 # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
0779 # else
0780 # define _LIBCPP_CONSTEXPR_SINCE_CXX14
0781 # endif
0782
0783 # if _LIBCPP_STD_VER >= 17
0784 # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
0785 # else
0786 # define _LIBCPP_CONSTEXPR_SINCE_CXX17
0787 # endif
0788
0789 # if _LIBCPP_STD_VER >= 20
0790 # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
0791 # else
0792 # define _LIBCPP_CONSTEXPR_SINCE_CXX20
0793 # endif
0794
0795 # if _LIBCPP_STD_VER >= 23
0796 # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
0797 # else
0798 # define _LIBCPP_CONSTEXPR_SINCE_CXX23
0799 # endif
0800
0801 # if _LIBCPP_STD_VER >= 26
0802 # define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
0803 # else
0804 # define _LIBCPP_CONSTEXPR_SINCE_CXX26
0805 # endif
0806
0807 # ifndef _LIBCPP_WEAK
0808 # define _LIBCPP_WEAK __attribute__((__weak__))
0809 # endif
0810
0811 // Thread API
0812 // clang-format off
0813 # if _LIBCPP_HAS_THREADS && \
0814 !_LIBCPP_HAS_THREAD_API_PTHREAD && \
0815 !_LIBCPP_HAS_THREAD_API_WIN32 && \
0816 !_LIBCPP_HAS_THREAD_API_EXTERNAL
0817
0818 # if defined(__FreeBSD__) || \
0819 defined(__wasi__) || \
0820 defined(__NetBSD__) || \
0821 defined(__OpenBSD__) || \
0822 defined(__NuttX__) || \
0823 defined(__linux__) || \
0824 defined(__GNU__) || \
0825 defined(__APPLE__) || \
0826 defined(__MVS__) || \
0827 defined(_AIX) || \
0828 defined(__EMSCRIPTEN__)
0829 // clang-format on
0830 # undef _LIBCPP_HAS_THREAD_API_PTHREAD
0831 # define _LIBCPP_HAS_THREAD_API_PTHREAD 1
0832 # elif defined(__Fuchsia__)
0833 // TODO(44575): Switch to C11 thread API when possible.
0834 # undef _LIBCPP_HAS_THREAD_API_PTHREAD
0835 # define _LIBCPP_HAS_THREAD_API_PTHREAD 1
0836 # elif defined(_LIBCPP_WIN32API)
0837 # undef _LIBCPP_HAS_THREAD_API_WIN32
0838 # define _LIBCPP_HAS_THREAD_API_WIN32 1
0839 # else
0840 # error "No thread API"
0841 # endif // _LIBCPP_HAS_THREAD_API
0842 # endif // _LIBCPP_HAS_THREADS
0843
0844 # if _LIBCPP_HAS_THREAD_API_PTHREAD
0845 # if defined(__ANDROID__) && __ANDROID_API__ >= 30
0846 # define _LIBCPP_HAS_COND_CLOCKWAIT 1
0847 # elif defined(_LIBCPP_GLIBC_PREREQ)
0848 # if _LIBCPP_GLIBC_PREREQ(2, 30)
0849 # define _LIBCPP_HAS_COND_CLOCKWAIT 1
0850 # else
0851 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
0852 # endif
0853 # else
0854 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
0855 # endif
0856 # else
0857 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
0858 # endif
0859
0860 # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
0861 # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
0862 # endif
0863
0864 # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
0865 # error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
0866 # endif
0867
0868 # if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
0869 # error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
0870 # endif
0871
0872 # if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
0873 # define __STDCPP_THREADS__ 1
0874 # endif
0875
0876 // The glibc and Bionic implementation of pthreads implements
0877 // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
0878 // mutexes have no destroy mechanism.
0879 //
0880 // This optimization can't be performed on Apple platforms, where
0881 // pthread_mutex_destroy can allow the kernel to release resources.
0882 // See https://llvm.org/D64298 for details.
0883 //
0884 // TODO(EricWF): Enable this optimization on Bionic after speaking to their
0885 // respective stakeholders.
0886 // clang-format off
0887 # if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
0888 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
0889 _LIBCPP_HAS_THREAD_API_WIN32
0890 // clang-format on
0891 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
0892 # else
0893 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
0894 # endif
0895
0896 // Destroying a condvar is a nop on Windows.
0897 //
0898 // This optimization can't be performed on Apple platforms, where
0899 // pthread_cond_destroy can allow the kernel to release resources.
0900 // See https://llvm.org/D64298 for details.
0901 //
0902 // TODO(EricWF): This is potentially true for some pthread implementations
0903 // as well.
0904 # if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
0905 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
0906 # else
0907 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
0908 # endif
0909
0910 # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
0911 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
0912 # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
0913 # endif
0914
0915 # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
0916 # define _LIBCPP_HAS_C_ATOMIC_IMP 1
0917 # define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
0918 # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
0919 # elif defined(_LIBCPP_COMPILER_GCC)
0920 # define _LIBCPP_HAS_C_ATOMIC_IMP 0
0921 # define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
0922 # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
0923 # endif
0924
0925 # if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
0926 # define _LIBCPP_HAS_ATOMIC_HEADER 0
0927 # else
0928 # define _LIBCPP_HAS_ATOMIC_HEADER 1
0929 # ifndef _LIBCPP_ATOMIC_FLAG_TYPE
0930 # define _LIBCPP_ATOMIC_FLAG_TYPE bool
0931 # endif
0932 # endif
0933
0934 # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
0935 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
0936 # else
0937 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
0938 # endif
0939
0940 // Work around the attribute handling in clang. When both __declspec and
0941 // __attribute__ are present, the processing goes awry preventing the definition
0942 // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
0943 // combining the two does work.
0944 # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \
0945 __has_attribute(acquire_capability) && !defined(_MSC_VER)
0946 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1
0947 # else
0948 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0
0949 # endif
0950
0951 # if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
0952 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
0953 # else
0954 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
0955 # endif
0956
0957 # if _LIBCPP_STD_VER >= 20
0958 # define _LIBCPP_CONSTINIT constinit
0959 # elif __has_attribute(__require_constant_initialization__)
0960 # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
0961 # else
0962 # define _LIBCPP_CONSTINIT
0963 # endif
0964
0965 # if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
0966 // The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
0967 // which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
0968 // when compiling for CUDA we use the non-underscored version of the noinline
0969 // attribute.
0970 //
0971 // This is a temporary workaround and we still expect the CUDA SDK team to solve
0972 // this issue properly in the SDK headers.
0973 //
0974 // See https://github.com/llvm/llvm-project/pull/73838 for more details.
0975 # define _LIBCPP_NOINLINE __attribute__((noinline))
0976 # elif __has_attribute(__noinline__)
0977 # define _LIBCPP_NOINLINE __attribute__((__noinline__))
0978 # else
0979 # define _LIBCPP_NOINLINE
0980 # endif
0981
0982 // We often repeat things just for handling wide characters in the library.
0983 // When wide characters are disabled, it can be useful to have a quick way of
0984 // disabling it without having to resort to #if-#endif, which has a larger
0985 // impact on readability.
0986 # if !_LIBCPP_HAS_WIDE_CHARACTERS
0987 # define _LIBCPP_IF_WIDE_CHARACTERS(...)
0988 # else
0989 # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
0990 # endif
0991
0992 // clang-format off
0993 # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
0994 # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
0995 // clang-format on
0996
0997 # ifndef _LIBCPP_NO_AUTO_LINK
0998 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
0999 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1000 # pragma comment(lib, "c++.lib")
1001 # else
1002 # pragma comment(lib, "libc++.lib")
1003 # endif
1004 # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1005 # endif // _LIBCPP_NO_AUTO_LINK
1006
1007 // Configures the fopen close-on-exec mode character, if any. This string will
1008 // be appended to any mode string used by fstream for fopen/fdopen.
1009 //
1010 // Not all platforms support this, but it helps avoid fd-leaks on platforms that
1011 // do.
1012 # if defined(__BIONIC__)
1013 # define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1014 # else
1015 # define _LIBCPP_FOPEN_CLOEXEC_MODE
1016 # endif
1017
1018 # if __has_cpp_attribute(msvc::no_unique_address)
1019 // MSVC implements [[no_unique_address]] as a silent no-op currently.
1020 // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1021 // However, MSVC implements [[msvc::no_unique_address]] which does what
1022 // [[no_unique_address]] is supposed to do, in general.
1023 # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1024 # else
1025 # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1026 # endif
1027
1028 // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1029 // functions is gradually being added to existing C libraries. The conditions
1030 // below check for known C library versions and conditions under which these
1031 // functions are declared by the C library.
1032 //
1033 // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1034 // __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1035 // the latter depends on internal GNU libc details that are not appropriate
1036 // to depend on here, so any declarations present when __cpp_char8_t is not
1037 // defined are ignored.
1038 # if defined(_LIBCPP_GLIBC_PREREQ)
1039 # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1040 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1041 # else
1042 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1043 # endif
1044 # else
1045 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1046 # endif
1047
1048 // There are a handful of public standard library types that are intended to
1049 // support CTAD but don't need any explicit deduction guides to do so. This
1050 // macro is used to mark them as such, which suppresses the
1051 // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1052 // with these classes.
1053 # if _LIBCPP_STD_VER >= 17
1054 # ifdef _LIBCPP_COMPILER_CLANG_BASED
1055 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1056 template <class... _Tag> \
1057 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1058 # else
1059 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
1060 template <class... _Tag> \
1061 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1062 # endif
1063 # else
1064 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1065 # endif
1066
1067 // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1068 // compiler intrinsics in the Objective-C++ mode.
1069 # ifdef __OBJC__
1070 # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1071 # endif
1072
1073 # define _PSTL_PRAGMA(x) _Pragma(#x)
1074
1075 // Enable SIMD for compilers that support OpenMP 4.0
1076 # if (defined(_OPENMP) && _OPENMP >= 201307)
1077
1078 # define _PSTL_UDR_PRESENT
1079 # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1080 # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1081 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1082 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1083 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1084 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1085
1086 // Declaration of reduction functor, where
1087 // NAME - the name of the functor
1088 // OP - type of the callable object with the reduction operation
1089 // omp_in - refers to the local partial result
1090 // omp_out - refers to the final value of the combiner operator
1091 // omp_priv - refers to the private copy of the initial value
1092 // omp_orig - refers to the original variable to be reduced
1093 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
1094 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1095
1096 # elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1097
1098 # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1099 # define _PSTL_PRAGMA_DECLARE_SIMD
1100 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1101 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1102 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1103 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1104 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1105
1106 # else // (defined(_OPENMP) && _OPENMP >= 201307)
1107
1108 # define _PSTL_PRAGMA_SIMD
1109 # define _PSTL_PRAGMA_DECLARE_SIMD
1110 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1111 # define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1112 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1113 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1114 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1115
1116 # endif // (defined(_OPENMP) && _OPENMP >= 201307)
1117
1118 # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1119
1120 // Optional attributes - these are useful for a better QoI, but not required to be available
1121
1122 # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1123 # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1124 # else
1125 # define _LIBCPP_NO_CFI
1126 # endif
1127
1128 # if __has_attribute(__malloc__)
1129 # define _LIBCPP_NOALIAS __attribute__((__malloc__))
1130 # else
1131 # define _LIBCPP_NOALIAS
1132 # endif
1133
1134 # if __has_attribute(__using_if_exists__)
1135 # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1136 # else
1137 # define _LIBCPP_USING_IF_EXISTS
1138 # endif
1139
1140 # if __has_attribute(__no_destroy__)
1141 # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1142 # else
1143 # define _LIBCPP_NO_DESTROY
1144 # endif
1145
1146 # if __has_attribute(__diagnose_if__)
1147 # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1148 # else
1149 # define _LIBCPP_DIAGNOSE_WARNING(...)
1150 # endif
1151
1152 // Use a function like macro to imply that it must be followed by a semicolon
1153 # if __has_cpp_attribute(fallthrough)
1154 # define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1155 # elif __has_attribute(__fallthrough__)
1156 # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1157 # else
1158 # define _LIBCPP_FALLTHROUGH() ((void)0)
1159 # endif
1160
1161 # if __has_cpp_attribute(_Clang::__lifetimebound__)
1162 # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1163 # else
1164 # define _LIBCPP_LIFETIMEBOUND
1165 # endif
1166
1167 # if __has_cpp_attribute(_Clang::__noescape__)
1168 # define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
1169 # else
1170 # define _LIBCPP_NOESCAPE
1171 # endif
1172
1173 # define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1174
1175 # if __has_cpp_attribute(_Clang::__no_specializations__)
1176 # define _LIBCPP_NO_SPECIALIZATIONS \
1177 [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
1178 # else
1179 # define _LIBCPP_NO_SPECIALIZATIONS
1180 # endif
1181
1182 # if __has_attribute(__standalone_debug__)
1183 # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1184 # else
1185 # define _LIBCPP_STANDALONE_DEBUG
1186 # endif
1187
1188 # if __has_attribute(__preferred_name__)
1189 # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1190 # else
1191 # define _LIBCPP_PREFERRED_NAME(x)
1192 # endif
1193
1194 # if __has_attribute(__no_sanitize__)
1195 # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1196 # else
1197 # define _LIBCPP_NO_SANITIZE(...)
1198 # endif
1199
1200 # if __has_attribute(__init_priority__)
1201 # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1202 # else
1203 # define _LIBCPP_INIT_PRIORITY_MAX
1204 # endif
1205
1206 # if __has_attribute(__format__)
1207 // The attribute uses 1-based indices for ordinary and static member functions.
1208 // The attribute uses 2-based indices for non-static member functions.
1209 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1210 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1211 # else
1212 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1213 # endif
1214
1215 # if __has_attribute(__packed__)
1216 # define _LIBCPP_PACKED __attribute__((__packed__))
1217 # else
1218 # define _LIBCPP_PACKED
1219 # endif
1220
1221 # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1222 # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1223 # else
1224 # define _LIBCPP_DECLSPEC_EMPTY_BASES
1225 # endif
1226
1227 // Allow for build-time disabling of unsigned integer sanitization
1228 # if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1229 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1230 # else
1231 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1232 # endif
1233
1234 // Clang-18 has support for deducing this, but it does not set the FTM.
1235 # if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1236 # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
1237 # else
1238 # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
1239 # endif
1240
1241 #endif // __cplusplus
1242
1243 #endif // _LIBCPP___CONFIG