2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___CONFIG
11 #define _LIBCPP___CONFIG
13 #include <__config_site>
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>
20 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
21 # pragma GCC system_header
26 // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
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
31 # define _LIBCPP_VERSION 200000
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))
37 # if __STDC_HOSTED__ == 0
38 # define _LIBCPP_FREESTANDING
43 // TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
44 # ifdef _LIBCPP_ENABLE_ASSERTIONS
45 # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
48 // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
50 // - `_LIBCPP_HARDENING_MODE_NONE`;
51 // - `_LIBCPP_HARDENING_MODE_FAST`;
52 // - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
53 // - `_LIBCPP_HARDENING_MODE_DEBUG`.
55 // These values have the following effects:
57 // - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
59 // - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
60 // that can be done with relatively little runtime overhead in constant time;
62 // - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
63 // the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
64 // but are not necessarily security-critical;
66 // - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
67 // mode and enables all checks available in the library, including internal assertions. Checks that are part of the
68 // debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
70 // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
71 // macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
73 // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
74 // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
75 // - the sentinel is reachable from the begin iterator;
76 // - TODO(hardening): both iterators refer to the same container.
78 // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
79 // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
80 // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
81 // `optional` and `function` are considered one-element containers for the purposes of this check.
83 // - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
84 // address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
85 // memory security of a program (however, it is still undefined behavior that can result in strange errors due to
86 // compiler optimizations).
88 // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
89 // given ranges do not overlap.
91 // - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
92 // was allocated by the given allocator). Violating this category typically results in a memory leak.
94 // - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
95 // an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
96 // attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
97 // (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
98 // otherwise create an immediate security issue.
100 // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
101 // the containers have compatible allocators.
103 // - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
104 // for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
105 // original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
106 // a string view where only a subset of elements is possible to access). This category is for assertions violating
107 // which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
110 // - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
111 // be benign in our implementation.
113 // - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
114 // by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
115 // thus, this would often be a heuristic check and it might be quite expensive.
117 // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
120 // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
123 # define _LIBCPP_HARDENING_MODE_NONE (1 << 1)
124 # define _LIBCPP_HARDENING_MODE_FAST (1 << 2)
125 # define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
126 # define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3)
129 # ifndef _LIBCPP_HARDENING_MODE
131 # ifndef _LIBCPP_HARDENING_MODE_DEFAULT
132 # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
133 `__config_site` header, please make sure your installation of libc++ is not broken.
136 # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
139 # if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \
140 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
141 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
142 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
143 # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
144 _LIBCPP_HARDENING_MODE_NONE, \
145 _LIBCPP_HARDENING_MODE_FAST, \
146 _LIBCPP_HARDENING_MODE_EXTENSIVE, \
147 _LIBCPP_HARDENING_MODE_DEBUG
152 # define _LIBCPP_TOSTRING2(x) #x
153 # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
155 // NOLINTNEXTLINE(libcpp-cpp-version-check)
156 # if __cplusplus < 201103L
157 # define _LIBCPP_CXX03_LANG
160 # ifndef __has_constexpr_builtin
161 # define __has_constexpr_builtin(x) 0
164 // This checks wheter a Clang module is built
165 # ifndef __building_module
166 # define __building_module(...) 0
169 // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
170 // the compiler and '1' otherwise.
171 # ifndef __is_identifier
172 # define __is_identifier(__x) 1
175 # ifndef __has_declspec_attribute
176 # define __has_declspec_attribute(__x) 0
179 # define __has_keyword(__x) !(__is_identifier(__x))
181 # ifndef __has_warning
182 # define __has_warning(...) 0
185 # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
186 # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
189 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
190 # define _LIBCPP_ABI_VCRUNTIME
193 # if __has_feature(experimental_library)
194 # ifndef _LIBCPP_ENABLE_EXPERIMENTAL
195 # define _LIBCPP_ENABLE_EXPERIMENTAL
199 // Incomplete features get their own specific disabling flags. This makes it
200 // easier to grep for target specific flags once the feature is complete.
201 # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
202 # define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
203 # define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB
204 # define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
207 # if defined(__MVS__)
208 # include <features.h> // for __NATIVE_ASCII_F
212 # define _LIBCPP_WIN32API
213 # define _LIBCPP_SHORT_WCHAR 1
214 // Both MinGW and native MSVC provide a "MSVC"-like environment
215 # define _LIBCPP_MSVCRT_LIKE
216 // If mingw not explicitly detected, assume using MS C runtime only if
217 // a MS compatibility version is specified.
218 # if defined(_MSC_VER) && !defined(__MINGW32__)
219 # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
221 # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
222 # define _LIBCPP_HAS_BITSCAN64 1
224 # define _LIBCPP_HAS_BITSCAN64 0
226 # define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
228 # define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
229 # define _LIBCPP_HAS_BITSCAN64 0
230 # endif // defined(_WIN32)
232 # if defined(_AIX) && !defined(__64BIT__)
233 // The size of wchar is 2 byte on 32-bit mode on AIX.
234 # define _LIBCPP_SHORT_WCHAR 1
237 // Libc++ supports various implementations of std::random_device.
239 // _LIBCPP_USING_DEV_RANDOM
240 // Read entropy from the given file, by default `/dev/urandom`.
241 // If a token is provided, it is assumed to be the path to a file
242 // to read entropy from. This is the default behavior if nothing
243 // else is specified. This implementation requires storing state
244 // inside `std::random_device`.
246 // _LIBCPP_USING_ARC4_RANDOM
247 // Use arc4random(). This allows obtaining random data even when
248 // using sandboxing mechanisms. On some platforms like Apple, this
249 // is the recommended source of entropy for user-space programs.
250 // When this option is used, the token passed to `std::random_device`'s
251 // constructor *must* be "/dev/urandom" -- anything else is an error.
253 // _LIBCPP_USING_GETENTROPY
255 // When this option is used, the token passed to `std::random_device`'s
256 // constructor *must* be "/dev/urandom" -- anything else is an error.
258 // _LIBCPP_USING_FUCHSIA_CPRNG
259 // Use Fuchsia's zx_cprng_draw() system call, which is specified to
260 // deliver high-quality entropy and cannot fail.
261 // When this option is used, the token passed to `std::random_device`'s
262 // constructor *must* be "/dev/urandom" -- anything else is an error.
264 // _LIBCPP_USING_NACL_RANDOM
265 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
266 // including accesses to the special files under `/dev`. This implementation
267 // uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
268 // When this option is used, the token passed to `std::random_device`'s
269 // constructor *must* be "/dev/urandom" -- anything else is an error.
271 // _LIBCPP_USING_WIN32_RANDOM
272 // Use rand_s(), for use on Windows.
273 // When this option is used, the token passed to `std::random_device`'s
274 // constructor *must* be "/dev/urandom" -- anything else is an error.
275 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
276 defined(__DragonFly__)
277 # define _LIBCPP_USING_ARC4_RANDOM
278 # elif defined(__wasi__) || defined(__EMSCRIPTEN__)
279 # define _LIBCPP_USING_GETENTROPY
280 # elif defined(__Fuchsia__)
281 # define _LIBCPP_USING_FUCHSIA_CPRNG
282 # elif defined(__native_client__)
283 # define _LIBCPP_USING_NACL_RANDOM
284 # elif defined(_LIBCPP_WIN32API)
285 # define _LIBCPP_USING_WIN32_RANDOM
287 # define _LIBCPP_USING_DEV_RANDOM
290 # ifndef _LIBCPP_CXX03_LANG
292 # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
293 # define _ALIGNAS_TYPE(x) alignas(x)
294 # define _ALIGNAS(x) alignas(x)
295 # define _NOEXCEPT noexcept
296 # define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
297 # define _LIBCPP_CONSTEXPR constexpr
301 # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
302 # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
303 # define _ALIGNAS(x) __attribute__((__aligned__(x)))
304 # define nullptr __nullptr
305 # define _NOEXCEPT throw()
306 # define _NOEXCEPT_(...)
307 # define static_assert(...) _Static_assert(__VA_ARGS__)
308 # define decltype(...) __decltype(__VA_ARGS__)
309 # define _LIBCPP_CONSTEXPR
311 typedef __char16_t char16_t;
312 typedef __char32_t char32_t;
316 # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
318 // Objective-C++ features (opt-in)
319 # if __has_feature(objc_arc)
320 # define _LIBCPP_HAS_OBJC_ARC 1
322 # define _LIBCPP_HAS_OBJC_ARC 0
325 # if __has_feature(objc_arc_weak)
326 # define _LIBCPP_HAS_OBJC_ARC_WEAK 1
328 # define _LIBCPP_HAS_OBJC_ARC_WEAK 0
331 # if __has_extension(blocks)
332 # define _LIBCPP_HAS_EXTENSION_BLOCKS 1
334 # define _LIBCPP_HAS_EXTENSION_BLOCKS 0
337 # if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
338 # define _LIBCPP_HAS_BLOCKS_RUNTIME 1
340 # define _LIBCPP_HAS_BLOCKS_RUNTIME 0
343 # if __has_feature(address_sanitizer)
344 # define _LIBCPP_HAS_ASAN 1
346 # define _LIBCPP_HAS_ASAN 0
349 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
351 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
353 # if defined(_LIBCPP_OBJECT_FORMAT_COFF)
356 # define _LIBCPP_CRT_FUNC __declspec(dllimport)
358 # define _LIBCPP_CRT_FUNC
361 # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
362 # define _LIBCPP_DLL_VIS
363 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
364 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
365 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
366 # define _LIBCPP_EXPORTED_FROM_ABI
367 # elif defined(_LIBCPP_BUILDING_LIBRARY)
368 # define _LIBCPP_DLL_VIS __declspec(dllexport)
369 # if defined(__MINGW32__)
370 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
371 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
373 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
374 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
376 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
377 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
379 # define _LIBCPP_DLL_VIS __declspec(dllimport)
380 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
381 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
382 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
383 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
386 # define _LIBCPP_HIDDEN
387 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
388 # define _LIBCPP_TEMPLATE_VIS
389 # define _LIBCPP_TEMPLATE_DATA_VIS
390 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
394 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
395 # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
397 # define _LIBCPP_VISIBILITY(vis)
400 # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
401 # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
402 # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
403 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
404 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
405 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
407 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
408 // The inline should be removed once PR32114 is resolved
409 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
411 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
414 // GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
415 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
416 # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
418 # define _LIBCPP_TEMPLATE_VIS
421 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
422 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
424 # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
427 # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
429 # if __has_attribute(exclude_from_explicit_instantiation)
430 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
432 // Try to approximate the effect of exclude_from_explicit_instantiation
433 // (which is that entities are not assumed to be provided by explicit
434 // template instantiations in the dylib) by always inlining those entities.
435 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
438 # ifdef _LIBCPP_COMPILER_CLANG_BASED
439 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
440 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
441 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
442 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
443 # elif defined(_LIBCPP_COMPILER_GCC)
444 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
445 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
446 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
447 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
449 # define _LIBCPP_DIAGNOSTIC_PUSH
450 # define _LIBCPP_DIAGNOSTIC_POP
451 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
452 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
455 # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
456 # define _LIBCPP_HARDENING_SIG f
457 # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
458 # define _LIBCPP_HARDENING_SIG s
459 # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
460 # define _LIBCPP_HARDENING_SIG d
462 # define _LIBCPP_HARDENING_SIG n // "none"
465 # if !_LIBCPP_HAS_EXCEPTIONS
466 # define _LIBCPP_EXCEPTIONS_SIG n
468 # define _LIBCPP_EXCEPTIONS_SIG e
471 # define _LIBCPP_ODR_SIGNATURE \
472 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
474 // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
476 // 1. The symbol is given hidden visibility, which ensures that users won't start exporting
477 // symbols from their dynamic library by means of using the libc++ headers. This ensures
478 // that those symbols stay private to the dynamic library in which it is defined.
480 // 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
481 // This ensures that no ODR violation can arise from mixing two TUs compiled with different
482 // versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
483 // program contains two definitions of a function, the ODR requires them to be token-by-token
484 // equivalent, and the linker is allowed to pick either definition and discard the other one.
486 // For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
487 // *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
488 // compiled with different settings), the two definitions are both visible by the linker and they
489 // have the same name, but they have a meaningfully different implementation (one throws an exception
490 // and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
491 // practice what will happen is that the linker will pick one of the definitions at random and will
492 // discard the other one. This can quite clearly lead to incorrect program behavior.
494 // A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
495 // property that causes the code of a function to differ from the code in another configuration
496 // can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
497 // tag, but we encode the ones that we think are most important: library version, exceptions, and
500 // Note that historically, solving this problem has been achieved in various ways, including
501 // force-inlining all functions or giving internal linkage to all functions. Both these previous
502 // solutions suffer from drawbacks that lead notably to code bloat.
504 // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
505 // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
507 // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
508 // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
509 // name of a virtual function is part of its ABI, since some architectures like arm64e can sign
510 // the virtual function pointer in the vtable based on the mangled name of the function. Since
511 // we use an ABI tag that changes with each released version, the mangled name of the virtual
512 // function would change, which is incorrect. Note that it doesn't make much sense to change
513 // the implementation of a virtual function in an ABI-incompatible way in the first place,
514 // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
516 // The macro can be applied to record and enum types. When the tagged type is nested in
517 // a record this "parent" record needs to have the macro too. Another use case for applying
518 // this macro to records and unions is to apply an ABI tag to inline constexpr variables.
519 // This can be useful for inline variables that are implementation details which are expected
520 // to change in the future.
522 // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
523 // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
524 // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
525 # ifndef _LIBCPP_NO_ABI_TAG
526 # define _LIBCPP_HIDE_FROM_ABI \
527 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
528 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
530 # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
532 # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
534 # ifdef _LIBCPP_BUILDING_LIBRARY
535 # if _LIBCPP_ABI_VERSION > 1
536 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
538 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
541 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
544 // TODO: Remove this workaround once we drop support for Clang 16
545 # if __has_warning("-Wc++23-extensions")
546 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
548 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
551 // Clang modules take a significant compile time hit when pushing and popping diagnostics.
552 // Since all the headers are marked as system headers in the modulemap, we can simply disable this
553 // pushing and popping when building with clang modules.
554 # if !__has_feature(modules)
555 # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
556 _LIBCPP_DIAGNOSTIC_PUSH \
557 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
558 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
559 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
560 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
561 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
562 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
563 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
564 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
565 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
566 # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
568 # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
569 # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
572 // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
574 # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
575 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
576 inline namespace _LIBCPP_ABI_NAMESPACE {
577 # define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
579 #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
580 #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }}
582 #define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
583 #define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
585 #define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
586 #define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
588 #ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
589 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
590 # define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
592 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
593 inline namespace __fs { namespace filesystem {
595 # define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
600 # if __has_attribute(__enable_if__)
601 # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
604 # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
605 # define _LIBCPP_HAS_INT128 0
607 # define _LIBCPP_HAS_INT128 1
610 # ifdef _LIBCPP_CXX03_LANG
611 # define _LIBCPP_DECLARE_STRONG_ENUM(x) \
612 struct _LIBCPP_EXPORTED_FROM_ABI x { \
615 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
617 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \
618 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
619 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \
623 # else // _LIBCPP_CXX03_LANG
624 # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
625 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
626 # endif // _LIBCPP_CXX03_LANG
628 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
629 # define _LIBCPP_LOCALE__L_EXTENSIONS 1
633 # define _DECLARE_C99_LDBL_MATH 1
636 // If we are getting operator new from the MSVC CRT, then allocation overloads
637 // for align_val_t were added in 19.12, aka VS 2017 version 15.3.
638 # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
639 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
640 # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
641 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
642 // have it unless the language feature test macro is defined.
643 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
644 # elif defined(__MVS__)
645 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
647 # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
650 # if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
651 # define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
653 # define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
656 // It is not yet possible to use aligned_alloc() on all Apple platforms since
657 // 10.15 was the first version to ship an implementation of aligned_alloc().
658 # if defined(__APPLE__)
659 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
660 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
661 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
662 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000)
663 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
665 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
667 # elif defined(__ANDROID__) && __ANDROID_API__ < 28
668 // Android only provides aligned_alloc when targeting API 28 or higher.
669 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
671 # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
674 # if defined(__APPLE__) || defined(__FreeBSD__)
675 # define _LIBCPP_HAS_DEFAULTRUNELOCALE
678 # if defined(__APPLE__) || defined(__FreeBSD__)
679 # define _LIBCPP_WCTYPE_IS_MASK
682 # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
683 # define _LIBCPP_HAS_CHAR8_T 0
685 # define _LIBCPP_HAS_CHAR8_T 1
688 // Deprecation macros.
690 // Deprecations warnings are always enabled, except when users explicitly opt-out
691 // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
692 # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
693 # if __has_attribute(__deprecated__)
694 # define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
695 # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
696 # elif _LIBCPP_STD_VER >= 14
697 # define _LIBCPP_DEPRECATED [[deprecated]]
698 # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
700 # define _LIBCPP_DEPRECATED
701 # define _LIBCPP_DEPRECATED_(m)
704 # define _LIBCPP_DEPRECATED
705 # define _LIBCPP_DEPRECATED_(m)
708 # if !defined(_LIBCPP_CXX03_LANG)
709 # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
711 # define _LIBCPP_DEPRECATED_IN_CXX11
714 # if _LIBCPP_STD_VER >= 14
715 # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
717 # define _LIBCPP_DEPRECATED_IN_CXX14
720 # if _LIBCPP_STD_VER >= 17
721 # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
723 # define _LIBCPP_DEPRECATED_IN_CXX17
726 # if _LIBCPP_STD_VER >= 20
727 # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
729 # define _LIBCPP_DEPRECATED_IN_CXX20
732 # if _LIBCPP_STD_VER >= 23
733 # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
735 # define _LIBCPP_DEPRECATED_IN_CXX23
738 # if _LIBCPP_STD_VER >= 26
739 # define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
741 # define _LIBCPP_DEPRECATED_IN_CXX26
744 # if _LIBCPP_HAS_CHAR8_T
745 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
747 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T
750 // Macros to enter and leave a state where deprecation warnings are suppressed.
751 # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
752 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
753 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
754 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
755 # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
757 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
758 # define _LIBCPP_SUPPRESS_DEPRECATED_POP
761 # if _LIBCPP_STD_VER <= 11
762 # define _LIBCPP_EXPLICIT_SINCE_CXX14
764 # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
767 # if _LIBCPP_STD_VER >= 23
768 # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
770 # define _LIBCPP_EXPLICIT_SINCE_CXX23
773 # if _LIBCPP_STD_VER >= 14
774 # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
776 # define _LIBCPP_CONSTEXPR_SINCE_CXX14
779 # if _LIBCPP_STD_VER >= 17
780 # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
782 # define _LIBCPP_CONSTEXPR_SINCE_CXX17
785 # if _LIBCPP_STD_VER >= 20
786 # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
788 # define _LIBCPP_CONSTEXPR_SINCE_CXX20
791 # if _LIBCPP_STD_VER >= 23
792 # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
794 # define _LIBCPP_CONSTEXPR_SINCE_CXX23
797 # if _LIBCPP_STD_VER >= 26
798 # define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
800 # define _LIBCPP_CONSTEXPR_SINCE_CXX26
803 # ifndef _LIBCPP_WEAK
804 # define _LIBCPP_WEAK __attribute__((__weak__))
809 # if _LIBCPP_HAS_THREADS && \
810 !_LIBCPP_HAS_THREAD_API_PTHREAD && \
811 !_LIBCPP_HAS_THREAD_API_WIN32 && \
812 !_LIBCPP_HAS_THREAD_API_EXTERNAL
814 # if defined(__FreeBSD__) || \
815 defined(__wasi__) || \
816 defined(__NetBSD__) || \
817 defined(__OpenBSD__) || \
818 defined(__NuttX__) || \
819 defined(__linux__) || \
820 defined(__GNU__) || \
821 defined(__APPLE__) || \
822 defined(__MVS__) || \
824 defined(__EMSCRIPTEN__)
826 # undef _LIBCPP_HAS_THREAD_API_PTHREAD
827 # define _LIBCPP_HAS_THREAD_API_PTHREAD 1
828 # elif defined(__Fuchsia__)
829 // TODO(44575): Switch to C11 thread API when possible.
830 # undef _LIBCPP_HAS_THREAD_API_PTHREAD
831 # define _LIBCPP_HAS_THREAD_API_PTHREAD 1
832 # elif defined(_LIBCPP_WIN32API)
833 # undef _LIBCPP_HAS_THREAD_API_WIN32
834 # define _LIBCPP_HAS_THREAD_API_WIN32 1
836 # error "No thread API"
837 # endif // _LIBCPP_HAS_THREAD_API
838 # endif // _LIBCPP_HAS_THREADS
840 # if _LIBCPP_HAS_THREAD_API_PTHREAD
841 # if defined(__ANDROID__) && __ANDROID_API__ >= 30
842 # define _LIBCPP_HAS_COND_CLOCKWAIT 1
843 # elif defined(_LIBCPP_GLIBC_PREREQ)
844 # if _LIBCPP_GLIBC_PREREQ(2, 30)
845 # define _LIBCPP_HAS_COND_CLOCKWAIT 1
847 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
850 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
853 # define _LIBCPP_HAS_COND_CLOCKWAIT 0
856 # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
857 # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
860 # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
861 # error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
864 # if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
865 # error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
868 # if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
869 # define __STDCPP_THREADS__ 1
872 // The glibc and Bionic implementation of pthreads implements
873 // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
874 // mutexes have no destroy mechanism.
876 // This optimization can't be performed on Apple platforms, where
877 // pthread_mutex_destroy can allow the kernel to release resources.
878 // See https://llvm.org/D64298 for details.
880 // TODO(EricWF): Enable this optimization on Bionic after speaking to their
881 // respective stakeholders.
883 # if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
884 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
885 _LIBCPP_HAS_THREAD_API_WIN32
887 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
889 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
892 // Destroying a condvar is a nop on Windows.
894 // This optimization can't be performed on Apple platforms, where
895 // pthread_cond_destroy can allow the kernel to release resources.
896 // See https://llvm.org/D64298 for details.
898 // TODO(EricWF): This is potentially true for some pthread implementations
900 # if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
901 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
903 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
906 # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
907 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
908 # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
911 # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
912 # define _LIBCPP_HAS_C_ATOMIC_IMP 1
913 # define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
914 # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
915 # elif defined(_LIBCPP_COMPILER_GCC)
916 # define _LIBCPP_HAS_C_ATOMIC_IMP 0
917 # define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
918 # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
921 # if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
922 # define _LIBCPP_HAS_ATOMIC_HEADER 0
924 # define _LIBCPP_HAS_ATOMIC_HEADER 1
925 # ifndef _LIBCPP_ATOMIC_FLAG_TYPE
926 # define _LIBCPP_ATOMIC_FLAG_TYPE bool
930 # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
931 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
933 # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
936 // Work around the attribute handling in clang. When both __declspec and
937 // __attribute__ are present, the processing goes awry preventing the definition
938 // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
939 // combining the two does work.
940 # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \
941 __has_attribute(acquire_capability) && !defined(_MSC_VER)
942 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1
944 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0
947 # if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
948 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
950 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
953 # if _LIBCPP_STD_VER >= 20
954 # define _LIBCPP_CONSTINIT constinit
955 # elif __has_attribute(__require_constant_initialization__)
956 # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
958 # define _LIBCPP_CONSTINIT
961 # if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
962 // The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
963 // which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
964 // when compiling for CUDA we use the non-underscored version of the noinline
967 // This is a temporary workaround and we still expect the CUDA SDK team to solve
968 // this issue properly in the SDK headers.
970 // See https://github.com/llvm/llvm-project/pull/73838 for more details.
971 # define _LIBCPP_NOINLINE __attribute__((noinline))
972 # elif __has_attribute(__noinline__)
973 # define _LIBCPP_NOINLINE __attribute__((__noinline__))
975 # define _LIBCPP_NOINLINE
978 // We often repeat things just for handling wide characters in the library.
979 // When wide characters are disabled, it can be useful to have a quick way of
980 // disabling it without having to resort to #if-#endif, which has a larger
981 // impact on readability.
982 # if !_LIBCPP_HAS_WIDE_CHARACTERS
983 # define _LIBCPP_IF_WIDE_CHARACTERS(...)
985 # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
989 # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
990 # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
993 # ifndef _LIBCPP_NO_AUTO_LINK
994 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
995 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
996 # pragma comment(lib, "c++.lib")
998 # pragma comment(lib, "libc++.lib")
1000 # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1001 # endif // _LIBCPP_NO_AUTO_LINK
1003 // Configures the fopen close-on-exec mode character, if any. This string will
1004 // be appended to any mode string used by fstream for fopen/fdopen.
1006 // Not all platforms support this, but it helps avoid fd-leaks on platforms that
1008 # if defined(__BIONIC__)
1009 # define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1011 # define _LIBCPP_FOPEN_CLOEXEC_MODE
1014 # if __has_cpp_attribute(msvc::no_unique_address)
1015 // MSVC implements [[no_unique_address]] as a silent no-op currently.
1016 // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1017 // However, MSVC implements [[msvc::no_unique_address]] which does what
1018 // [[no_unique_address]] is supposed to do, in general.
1019 # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1021 # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1024 // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1025 // functions is gradually being added to existing C libraries. The conditions
1026 // below check for known C library versions and conditions under which these
1027 // functions are declared by the C library.
1029 // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1030 // __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1031 // the latter depends on internal GNU libc details that are not appropriate
1032 // to depend on here, so any declarations present when __cpp_char8_t is not
1033 // defined are ignored.
1034 # if defined(_LIBCPP_GLIBC_PREREQ)
1035 # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1036 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1038 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1041 # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
1044 // There are a handful of public standard library types that are intended to
1045 // support CTAD but don't need any explicit deduction guides to do so. This
1046 // macro is used to mark them as such, which suppresses the
1047 // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1048 // with these classes.
1049 # if _LIBCPP_STD_VER >= 17
1050 # ifdef _LIBCPP_COMPILER_CLANG_BASED
1051 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1052 template <class... _Tag> \
1053 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1055 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
1056 template <class... _Tag> \
1057 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1060 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1063 // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1064 // compiler intrinsics in the Objective-C++ mode.
1066 # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1069 # define _PSTL_PRAGMA(x) _Pragma(#x)
1071 // Enable SIMD for compilers that support OpenMP 4.0
1072 # if (defined(_OPENMP) && _OPENMP >= 201307)
1074 # define _PSTL_UDR_PRESENT
1075 # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1076 # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1077 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1078 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1079 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1080 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1082 // Declaration of reduction functor, where
1083 // NAME - the name of the functor
1084 // OP - type of the callable object with the reduction operation
1085 // omp_in - refers to the local partial result
1086 // omp_out - refers to the final value of the combiner operator
1087 // omp_priv - refers to the private copy of the initial value
1088 // omp_orig - refers to the original variable to be reduced
1089 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
1090 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1092 # elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1094 # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1095 # define _PSTL_PRAGMA_DECLARE_SIMD
1096 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1097 # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1098 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1099 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1100 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1102 # else // (defined(_OPENMP) && _OPENMP >= 201307)
1104 # define _PSTL_PRAGMA_SIMD
1105 # define _PSTL_PRAGMA_DECLARE_SIMD
1106 # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1107 # define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1108 # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1109 # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1110 # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1112 # endif // (defined(_OPENMP) && _OPENMP >= 201307)
1114 # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1116 // Optional attributes - these are useful for a better QoI, but not required to be available
1118 # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1119 # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1121 # define _LIBCPP_NO_CFI
1124 # if __has_attribute(__malloc__)
1125 # define _LIBCPP_NOALIAS __attribute__((__malloc__))
1127 # define _LIBCPP_NOALIAS
1130 # if __has_attribute(__using_if_exists__)
1131 # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1133 # define _LIBCPP_USING_IF_EXISTS
1136 # if __has_attribute(__no_destroy__)
1137 # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1139 # define _LIBCPP_NO_DESTROY
1142 # if __has_attribute(__diagnose_if__)
1143 # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1145 # define _LIBCPP_DIAGNOSE_WARNING(...)
1148 // Use a function like macro to imply that it must be followed by a semicolon
1149 # if __has_cpp_attribute(fallthrough)
1150 # define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1151 # elif __has_attribute(__fallthrough__)
1152 # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1154 # define _LIBCPP_FALLTHROUGH() ((void)0)
1157 # if __has_cpp_attribute(_Clang::__lifetimebound__)
1158 # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1160 # define _LIBCPP_LIFETIMEBOUND
1163 # if __has_cpp_attribute(_Clang::__noescape__)
1164 # define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
1166 # define _LIBCPP_NOESCAPE
1169 # if __has_attribute(__nodebug__)
1170 # define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1172 # define _LIBCPP_NODEBUG
1175 # if __has_attribute(__standalone_debug__)
1176 # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1178 # define _LIBCPP_STANDALONE_DEBUG
1181 # if __has_attribute(__preferred_name__)
1182 # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1184 # define _LIBCPP_PREFERRED_NAME(x)
1187 # if __has_attribute(__no_sanitize__)
1188 # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1190 # define _LIBCPP_NO_SANITIZE(...)
1193 # if __has_attribute(__init_priority__)
1194 # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1196 # define _LIBCPP_INIT_PRIORITY_MAX
1199 # if __has_attribute(__format__)
1200 // The attribute uses 1-based indices for ordinary and static member functions.
1201 // The attribute uses 2-based indices for non-static member functions.
1202 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1203 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1205 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1208 # if __has_attribute(__packed__)
1209 # define _LIBCPP_PACKED __attribute__((__packed__))
1211 # define _LIBCPP_PACKED
1214 # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1215 # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1217 # define _LIBCPP_DECLSPEC_EMPTY_BASES
1220 // Allow for build-time disabling of unsigned integer sanitization
1221 # if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1222 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1224 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1227 // Clang-18 has support for deducing this, but it does not set the FTM.
1228 # if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1229 # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
1231 # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
1234 #endif // __cplusplus
1236 #endif // _LIBCPP___CONFIG