Debian Codegraph @

llvm-project/libcxx/include/__config

raw
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef _LIBCPP___CONFIG
11 #define _LIBCPP___CONFIG
12
13 #include <__config_site>
14
15 #if defined(_MSC_VER) && !defined(__clang__)
16 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
18 # endif
19 #endif
20
21 #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
22 # pragma GCC system_header
23 #endif
24
25 #if defined(__apple_build_version__)
26 // Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
27 # define _LIBCPP_COMPILER_CLANG_BASED
28 # define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
29 #elif defined(__clang__)
30 # define _LIBCPP_COMPILER_CLANG_BASED
31 # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
32 #elif defined(__GNUC__)
33 # define _LIBCPP_COMPILER_GCC
34 #endif
35
36 #ifdef __cplusplus
37
38 // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
39 // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 16.0.1 == 16.00.01), _LIBCPP_VERSION is
40 // defined to XXYYZZ.
41 # define _LIBCPP_VERSION 160006
42
43 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
44 # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
45
46 // Valid C++ identifier that revs with every libc++ version. This can be used to
47 // generate identifiers that must be unique for every released libc++ version.
48 # define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION)
49
50 # if __STDC_HOSTED__ == 0
51 # define _LIBCPP_FREESTANDING
52 # endif
53
54 # ifndef _LIBCPP_STD_VER
55 # if __cplusplus <= 201103L
56 # define _LIBCPP_STD_VER 11
57 # elif __cplusplus <= 201402L
58 # define _LIBCPP_STD_VER 14
59 # elif __cplusplus <= 201703L
60 # define _LIBCPP_STD_VER 17
61 # elif __cplusplus <= 202002L
62 # define _LIBCPP_STD_VER 20
63 # else
64 // Expected release year of the next C++ standard
65 # define _LIBCPP_STD_VER 23
66 # endif
67 # endif // _LIBCPP_STD_VER
68
69 # if defined(__ELF__)
70 # define _LIBCPP_OBJECT_FORMAT_ELF 1
71 # elif defined(__MACH__)
72 # define _LIBCPP_OBJECT_FORMAT_MACHO 1
73 # elif defined(_WIN32)
74 # define _LIBCPP_OBJECT_FORMAT_COFF 1
75 # elif defined(__wasm__)
76 # define _LIBCPP_OBJECT_FORMAT_WASM 1
77 # elif defined(_AIX)
78 # define _LIBCPP_OBJECT_FORMAT_XCOFF 1
79 # else
80 // ... add new file formats here ...
81 # endif
82
83 # if _LIBCPP_ABI_VERSION >= 2
84 // Change short string representation so that string data starts at offset 0,
85 // improving its alignment in some cases.
86 # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
87 // Fix deque iterator type in order to support incomplete types.
88 # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
89 // Fix undefined behavior in how std::list stores its linked nodes.
90 # define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
91 // Fix undefined behavior in how __tree stores its end and parent nodes.
92 # define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
93 // Fix undefined behavior in how __hash_table stores its pointer types.
94 # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
95 # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
96 # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
97 // Define a key function for `bad_function_call` in the library, to centralize
98 // its vtable and typeinfo to libc++ rather than having all other libraries
99 // using that class define their own copies.
100 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
101 // Override the default return value of exception::what() for
102 // bad_function_call::what() with a string that is specific to
103 // bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
104 // because it changes the vtable layout of bad_function_call.
105 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
106 // Enable optimized version of __do_get_(un)signed which avoids redundant copies.
107 # define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
108 // Give reverse_iterator<T> one data member of type T, not two.
109 // Also, in C++17 and later, don't derive iterator types from std::iterator.
110 # define _LIBCPP_ABI_NO_ITERATOR_BASES
111 // Use the smallest possible integer type to represent the index of the variant.
112 // Previously libc++ used "unsigned int" exclusively.
113 # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
114 // Unstable attempt to provide a more optimized std::function
115 # define _LIBCPP_ABI_OPTIMIZED_FUNCTION
116 // All the regex constants must be distinct and nonzero.
117 # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
118 // Re-worked external template instantiations for std::string with a focus on
119 // performance and fast-path inlining.
120 # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
121 // Enable clang::trivial_abi on std::unique_ptr.
122 # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
123 // Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
124 # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
125 // std::random_device holds some state when it uses an implementation that gets
126 // entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
127 // implementation to another one on a platform that has already shipped
128 // std::random_device, one needs to retain the same object layout to remain ABI
129 // compatible. This switch removes these workarounds for platforms that don't care
130 // about ABI compatibility.
131 # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
132 // Don't export the legacy __basic_string_common class and its methods from the built library.
133 # define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
134 // Don't export the legacy __vector_base_common class and its methods from the built library.
135 # define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
136 // According to the Standard, `bitset::operator[] const` returns bool
137 # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
138 // Fix the implementation of CityHash used for std::hash<fundamental-type>.
139 // This is an ABI break because `std::hash` will return a different result,
140 // which means that hashing the same object in translation units built against
141 // different versions of libc++ can return inconsistent results. This is especially
142 // tricky since std::hash is used in the implementation of unordered containers.
143 //
144 // The incorrect implementation of CityHash has the problem that it drops some
145 // bits on the floor.
146 # define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
147 // Remove the base 10 implementation of std::to_chars from the dylib.
148 // The implementation moved to the header, but we still export the symbols from
149 // the dylib for backwards compatibility.
150 # define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
151 # elif _LIBCPP_ABI_VERSION == 1
152 # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
153 // Enable compiling copies of now inline methods into the dylib to support
154 // applications compiled against older libraries. This is unnecessary with
155 // COFF dllexport semantics, since dllexport forces a non-inline definition
156 // of inline functions to be emitted anyway. Our own non-inline copy would
157 // conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
158 // the linker will take issue with the symbols in the shared object if the
159 // weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
160 // so disable it.
161 # define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
162 # endif
163 // Feature macros for disabling pre ABI v1 features. All of these options
164 // are deprecated.
165 # if defined(__FreeBSD__)
166 # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
167 # endif
168 # endif
169
170 # if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
171 // Enable additional explicit instantiations of iostreams components. This
172 // reduces the number of weak definitions generated in programs that use
173 // iostreams by providing a single strong definition in the shared library.
174 # define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
175
176 // Define a key function for `bad_function_call` in the library, to centralize
177 // its vtable and typeinfo to libc++ rather than having all other libraries
178 // using that class define their own copies.
179 # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
180 # endif
181
182 # define _LIBCPP_TOSTRING2(x) #x
183 # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
184
185 # if __cplusplus < 201103L
186 # define _LIBCPP_CXX03_LANG
187 # endif
188
189 # ifndef __has_attribute
190 # define __has_attribute(__x) 0
191 # endif
192
193 # ifndef __has_builtin
194 # define __has_builtin(__x) 0
195 # endif
196
197 # ifndef __has_extension
198 # define __has_extension(__x) 0
199 # endif
200
201 # ifndef __has_feature
202 # define __has_feature(__x) 0
203 # endif
204
205 # ifndef __has_cpp_attribute
206 # define __has_cpp_attribute(__x) 0
207 # endif
208
209 # ifndef __has_constexpr_builtin
210 # define __has_constexpr_builtin(x) 0
211 # endif
212
213 // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
214 // the compiler and '1' otherwise.
215 # ifndef __is_identifier
216 # define __is_identifier(__x) 1
217 # endif
218
219 # ifndef __has_declspec_attribute
220 # define __has_declspec_attribute(__x) 0
221 # endif
222
223 # define __has_keyword(__x) !(__is_identifier(__x))
224
225 # ifndef __has_include
226 # define __has_include(...) 0
227 # endif
228
229 # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
230 # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
231 # endif
232
233 // FIXME: ABI detection should be done via compiler builtin macros. This
234 // is just a placeholder until Clang implements such macros. For now assume
235 // that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
236 // and allow the user to explicitly specify the ABI to handle cases where this
237 // heuristic falls short.
238 # if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
239 # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
240 # elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
241 # define _LIBCPP_ABI_ITANIUM
242 # elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
243 # define _LIBCPP_ABI_MICROSOFT
244 # else
245 # if defined(_WIN32) && defined(_MSC_VER)
246 # define _LIBCPP_ABI_MICROSOFT
247 # else
248 # define _LIBCPP_ABI_ITANIUM
249 # endif
250 # endif
251
252 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
253 # define _LIBCPP_ABI_VCRUNTIME
254 # endif
255
256 # if __has_feature(experimental_library)
257 # ifndef _LIBCPP_ENABLE_EXPERIMENTAL
258 # define _LIBCPP_ENABLE_EXPERIMENTAL
259 # endif
260 # endif
261
262 // Incomplete features get their own specific disabling flags. This makes it
263 // easier to grep for target specific flags once the feature is complete.
264 # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
265 # define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT
266 # endif
267
268 // Need to detect which libc we're using if we're on Linux.
269 # if defined(__linux__)
270 # include <features.h>
271 # if defined(__GLIBC_PREREQ)
272 # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
273 # else
274 # define _LIBCPP_GLIBC_PREREQ(a, b) 0
275 # endif // defined(__GLIBC_PREREQ)
276 # endif // defined(__linux__)
277
278 # if defined(__MVS__)
279 # include <features.h> // for __NATIVE_ASCII_F
280 # endif
281
282 # ifdef __LITTLE_ENDIAN__
283 # if __LITTLE_ENDIAN__
284 # define _LIBCPP_LITTLE_ENDIAN
285 # endif // __LITTLE_ENDIAN__
286 # endif // __LITTLE_ENDIAN__
287
288 # ifdef __BIG_ENDIAN__
289 # if __BIG_ENDIAN__
290 # define _LIBCPP_BIG_ENDIAN
291 # endif // __BIG_ENDIAN__
292 # endif // __BIG_ENDIAN__
293
294 # ifdef __BYTE_ORDER__
295 # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
296 # define _LIBCPP_LITTLE_ENDIAN
297 # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
298 # define _LIBCPP_BIG_ENDIAN
299 # endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
300 # endif // __BYTE_ORDER__
301
302 # ifdef __FreeBSD__
303 # include <sys/endian.h>
304 # include <osreldate.h>
305 # if _BYTE_ORDER == _LITTLE_ENDIAN
306 # define _LIBCPP_LITTLE_ENDIAN
307 # else // _BYTE_ORDER == _LITTLE_ENDIAN
308 # define _LIBCPP_BIG_ENDIAN
309 # endif // _BYTE_ORDER == _LITTLE_ENDIAN
310 # endif // __FreeBSD__
311
312 # if defined(__NetBSD__) || defined(__OpenBSD__)
313 # include <sys/endian.h>
314 # if _BYTE_ORDER == _LITTLE_ENDIAN
315 # define _LIBCPP_LITTLE_ENDIAN
316 # else // _BYTE_ORDER == _LITTLE_ENDIAN
317 # define _LIBCPP_BIG_ENDIAN
318 # endif // _BYTE_ORDER == _LITTLE_ENDIAN
319 # endif // defined(__NetBSD__) || defined(__OpenBSD__)
320
321 # if defined(_WIN32)
322 # define _LIBCPP_WIN32API
323 # define _LIBCPP_LITTLE_ENDIAN
324 # define _LIBCPP_SHORT_WCHAR 1
325 // Both MinGW and native MSVC provide a "MSVC"-like environment
326 # define _LIBCPP_MSVCRT_LIKE
327 // If mingw not explicitly detected, assume using MS C runtime only if
328 // a MS compatibility version is specified.
329 # if defined(_MSC_VER) && !defined(__MINGW32__)
330 # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
331 # endif
332 # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
333 # define _LIBCPP_HAS_BITSCAN64
334 # endif
335 # define _LIBCPP_HAS_OPEN_WITH_WCHAR
336 # endif // defined(_WIN32)
337
338 # ifdef __sun__
339 # include <sys/isa_defs.h>
340 # ifdef _LITTLE_ENDIAN
341 # define _LIBCPP_LITTLE_ENDIAN
342 # else
343 # define _LIBCPP_BIG_ENDIAN
344 # endif
345 # endif // __sun__
346
347 # if defined(_AIX) && !defined(__64BIT__)
348 // The size of wchar is 2 byte on 32-bit mode on AIX.
349 # define _LIBCPP_SHORT_WCHAR 1
350 # endif
351
352 // Libc++ supports various implementations of std::random_device.
353 //
354 // _LIBCPP_USING_DEV_RANDOM
355 // Read entropy from the given file, by default `/dev/urandom`.
356 // If a token is provided, it is assumed to be the path to a file
357 // to read entropy from. This is the default behavior if nothing
358 // else is specified. This implementation requires storing state
359 // inside `std::random_device`.
360 //
361 // _LIBCPP_USING_ARC4_RANDOM
362 // Use arc4random(). This allows obtaining random data even when
363 // using sandboxing mechanisms. On some platforms like Apple, this
364 // is the recommended source of entropy for user-space programs.
365 // When this option is used, the token passed to `std::random_device`'s
366 // constructor *must* be "/dev/urandom" -- anything else is an error.
367 //
368 // _LIBCPP_USING_GETENTROPY
369 // Use getentropy().
370 // When this option is used, the token passed to `std::random_device`'s
371 // constructor *must* be "/dev/urandom" -- anything else is an error.
372 //
373 // _LIBCPP_USING_FUCHSIA_CPRNG
374 // Use Fuchsia's zx_cprng_draw() system call, which is specified to
375 // deliver high-quality entropy and cannot fail.
376 // When this option is used, the token passed to `std::random_device`'s
377 // constructor *must* be "/dev/urandom" -- anything else is an error.
378 //
379 // _LIBCPP_USING_NACL_RANDOM
380 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
381 // including accesses to the special files under `/dev`. This implementation
382 // uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
383 // When this option is used, the token passed to `std::random_device`'s
384 // constructor *must* be "/dev/urandom" -- anything else is an error.
385 //
386 // _LIBCPP_USING_WIN32_RANDOM
387 // Use rand_s(), for use on Windows.
388 // When this option is used, the token passed to `std::random_device`'s
389 // constructor *must* be "/dev/urandom" -- anything else is an error.
390 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
391 defined(__DragonFly__) || defined(__sun__)
392 # define _LIBCPP_USING_ARC4_RANDOM
393 # elif defined(__wasi__) || defined(__EMSCRIPTEN__)
394 # define _LIBCPP_USING_GETENTROPY
395 # elif defined(__Fuchsia__)
396 # define _LIBCPP_USING_FUCHSIA_CPRNG
397 # elif defined(__native_client__)
398 # define _LIBCPP_USING_NACL_RANDOM
399 # elif defined(_LIBCPP_WIN32API)
400 # define _LIBCPP_USING_WIN32_RANDOM
401 # else
402 # define _LIBCPP_USING_DEV_RANDOM
403 # endif
404
405 # if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
406 # include <endian.h>
407 # if __BYTE_ORDER == __LITTLE_ENDIAN
408 # define _LIBCPP_LITTLE_ENDIAN
409 # elif __BYTE_ORDER == __BIG_ENDIAN
410 # define _LIBCPP_BIG_ENDIAN
411 # else // __BYTE_ORDER == __BIG_ENDIAN
412 # error unable to determine endian
413 # endif
414 # endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
415
416 # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
417 # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
418 # else
419 # define _LIBCPP_NO_CFI
420 # endif
421
422 # ifndef _LIBCPP_CXX03_LANG
423
424 # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
425 # define _ALIGNAS_TYPE(x) alignas(x)
426 # define _ALIGNAS(x) alignas(x)
427 # define _LIBCPP_NORETURN [[noreturn]]
428 # define _NOEXCEPT noexcept
429 # define _NOEXCEPT_(x) noexcept(x)
430 # define _LIBCPP_CONSTEXPR constexpr
431
432 # else
433
434 # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
435 # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
436 # define _ALIGNAS(x) __attribute__((__aligned__(x)))
437 # define _LIBCPP_NORETURN __attribute__((__noreturn__))
438 # define _LIBCPP_HAS_NO_NOEXCEPT
439 # define nullptr __nullptr
440 # define _NOEXCEPT throw()
441 # define _NOEXCEPT_(x)
442 # define static_assert(...) _Static_assert(__VA_ARGS__)
443 # define decltype(...) __decltype(__VA_ARGS__)
444 # define _LIBCPP_CONSTEXPR
445
446 typedef __char16_t char16_t;
447 typedef __char32_t char32_t;
448
449 # endif
450
451 # if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
452 # define _LIBCPP_NO_EXCEPTIONS
453 # endif
454
455 # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
456
457 # if defined(_LIBCPP_COMPILER_CLANG_BASED)
458
459 # if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
460 # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
461 # endif
462
463 // Objective-C++ features (opt-in)
464 # if __has_feature(objc_arc)
465 # define _LIBCPP_HAS_OBJC_ARC
466 # endif
467
468 # if __has_feature(objc_arc_weak)
469 # define _LIBCPP_HAS_OBJC_ARC_WEAK
470 # endif
471
472 # if __has_extension(blocks)
473 # define _LIBCPP_HAS_EXTENSION_BLOCKS
474 # endif
475
476 # if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
477 # define _LIBCPP_HAS_BLOCKS_RUNTIME
478 # endif
479
480 # if !__has_feature(address_sanitizer)
481 # define _LIBCPP_HAS_NO_ASAN
482 # endif
483
484 // Allow for build-time disabling of unsigned integer sanitization
485 # if __has_attribute(no_sanitize)
486 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
487 # endif
488
489 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
490
491 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
492
493 # elif defined(_LIBCPP_COMPILER_GCC)
494
495 # if !defined(__SANITIZE_ADDRESS__)
496 # define _LIBCPP_HAS_NO_ASAN
497 # endif
498
499 # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
500
501 # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
502
503 # endif // _LIBCPP_COMPILER_[CLANG|GCC]
504
505 # if defined(_LIBCPP_OBJECT_FORMAT_COFF)
506
507 # ifdef _DLL
508 # define _LIBCPP_CRT_FUNC __declspec(dllimport)
509 # else
510 # define _LIBCPP_CRT_FUNC
511 # endif
512
513 # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
514 # define _LIBCPP_DLL_VIS
515 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
516 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
517 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
518 # define _LIBCPP_EXPORTED_FROM_ABI
519 # elif defined(_LIBCPP_BUILDING_LIBRARY)
520 # define _LIBCPP_DLL_VIS __declspec(dllexport)
521 # if defined(__MINGW32__)
522 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
523 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
524 # else
525 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
526 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
527 # endif
528 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
529 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
530 # else
531 # define _LIBCPP_DLL_VIS __declspec(dllimport)
532 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
533 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
534 # define _LIBCPP_OVERRIDABLE_FUNC_VIS
535 # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
536 # endif
537
538 # define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
539 # define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
540 # define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
541 # define _LIBCPP_HIDDEN
542 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
543 # define _LIBCPP_TEMPLATE_VIS
544 # define _LIBCPP_TEMPLATE_DATA_VIS
545 # define _LIBCPP_ENUM_VIS
546
547 # else
548
549 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
550 # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
551 # else
552 # define _LIBCPP_VISIBILITY(vis)
553 # endif
554
555 # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
556 # define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default")
557 # define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default")
558 # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
559 # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
560 # define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default")
561 # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
562 # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
563
564 // TODO: Make this a proper customization point or remove the option to override it.
565 # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
566 # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
567 # endif
568
569 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
570 // The inline should be removed once PR32114 is resolved
571 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
572 # else
573 # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
574 # endif
575
576 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
577 # if __has_attribute(__type_visibility__)
578 # define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default")))
579 # else
580 # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
581 # endif
582 # else
583 # define _LIBCPP_TEMPLATE_VIS
584 # endif
585
586 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
587 # define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default")))
588 # else
589 # define _LIBCPP_ENUM_VIS
590 # endif
591
592 # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
593
594 # if __has_attribute(exclude_from_explicit_instantiation)
595 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
596 # else
597 // Try to approximate the effect of exclude_from_explicit_instantiation
598 // (which is that entities are not assumed to be provided by explicit
599 // template instantiations in the dylib) by always inlining those entities.
600 # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
601 # endif
602
603 // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
604 // on two levels:
605 // 1. The symbol is given hidden visibility, which ensures that users won't start exporting
606 // symbols from their dynamic library by means of using the libc++ headers. This ensures
607 // that those symbols stay private to the dynamic library in which it is defined.
608 //
609 // 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures
610 // that no ODR violation can arise from mixing two TUs compiled with different versions
611 // of libc++ where we would have changed the definition of a symbol. If the symbols shared
612 // the same name, the ODR would require that their definitions be token-by-token equivalent,
613 // which basically prevents us from being able to make any change to any function in our
614 // headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at
615 // each release, which lets us change the definition of these symbols at our leisure.
616 // Note that historically, this has been achieved in various ways, including force-inlining
617 // all functions or giving internal linkage to all functions. Both these (previous) solutions
618 // suffer from drawbacks that lead notably to code bloat.
619 //
620 // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
621 // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
622 //
623 // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
624 // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
625 // name of a virtual function is part of its ABI, since some architectures like arm64e can sign
626 // the virtual function pointer in the vtable based on the mangled name of the function. Since
627 // we use an ABI tag that changes with each released version, the mangled name of the virtual
628 // function would change, which is incorrect. Note that it doesn't make much sense to change
629 // the implementation of a virtual function in an ABI-incompatible way in the first place,
630 // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
631 //
632 // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
633 // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
634 // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
635 # ifndef _LIBCPP_NO_ABI_TAG
636 # define _LIBCPP_HIDE_FROM_ABI \
637 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
638 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
639 # else
640 # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
641 # endif
642 # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
643
644 // This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
645 // "C" function, as those lack mangling.
646 # define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
647
648 # ifdef _LIBCPP_BUILDING_LIBRARY
649 # if _LIBCPP_ABI_VERSION > 1
650 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
651 # else
652 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
653 # endif
654 # else
655 # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
656 # endif
657
658 // Just so we can migrate to the new macros gradually.
659 # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
660
661 // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
662 // clang-format off
663 # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
664 # define _LIBCPP_END_NAMESPACE_STD }}
665 # define _VSTD std
666
667 _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
668
669 # if _LIBCPP_STD_VER > 14
670 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
671 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
672 # else
673 # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
674 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
675 # endif
676
677 # define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
678 // clang-format on
679
680 # define _VSTD_FS std::__fs::filesystem
681
682 # if __has_attribute(__enable_if__)
683 # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
684 # endif
685
686 # ifndef __SIZEOF_INT128__
687 # define _LIBCPP_HAS_NO_INT128
688 # endif
689
690 # ifndef __cpp_consteval
691 # define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
692 # else
693 # define _LIBCPP_CONSTEVAL consteval
694 # endif
695
696 # if __has_attribute(__malloc__)
697 # define _LIBCPP_NOALIAS __attribute__((__malloc__))
698 # else
699 # define _LIBCPP_NOALIAS
700 # endif
701
702 # if __has_attribute(__using_if_exists__)
703 # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
704 # else
705 # define _LIBCPP_USING_IF_EXISTS
706 # endif
707
708 # ifdef _LIBCPP_CXX03_LANG
709 # define _LIBCPP_DECLARE_STRONG_ENUM(x) \
710 struct _LIBCPP_TYPE_VIS x { \
711 enum __lx
712 // clang-format off
713 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
714 __lx __v_; \
715 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
716 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
717 _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \
718 };
719 // clang-format on
720
721 # else // _LIBCPP_CXX03_LANG
722 # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
723 # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
724 # endif // _LIBCPP_CXX03_LANG
725
726 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \
727 defined(__NetBSD__)
728 # define _LIBCPP_LOCALE__L_EXTENSIONS 1
729 # endif
730
731 # ifdef __FreeBSD__
732 # define _DECLARE_C99_LDBL_MATH 1
733 # endif
734
735 // If we are getting operator new from the MSVC CRT, then allocation overloads
736 // for align_val_t were added in 19.12, aka VS 2017 version 15.3.
737 # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
738 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
739 # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
740 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
741 // have it unless the language feature test macro is defined.
742 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
743 # elif defined(__MVS__)
744 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
745 # endif
746
747 # if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
748 # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
749 # endif
750
751 // It is not yet possible to use aligned_alloc() on all Apple platforms since
752 // 10.15 was the first version to ship an implementation of aligned_alloc().
753 # if defined(__APPLE__)
754 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
755 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
756 # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
757 # endif
758 # elif defined(__ANDROID__) && __ANDROID_API__ < 28
759 // Android only provides aligned_alloc when targeting API 28 or higher.
760 # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
761 # endif
762
763 # if defined(__APPLE__) || defined(__FreeBSD__)
764 # define _LIBCPP_HAS_DEFAULTRUNELOCALE
765 # endif
766
767 # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
768 # define _LIBCPP_WCTYPE_IS_MASK
769 # endif
770
771 # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
772 # define _LIBCPP_HAS_NO_CHAR8_T
773 # endif
774
775 // Deprecation macros.
776 //
777 // Deprecations warnings are always enabled, except when users explicitly opt-out
778 // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
779 # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
780 # if __has_attribute(deprecated)
781 # define _LIBCPP_DEPRECATED __attribute__((deprecated))
782 # define _LIBCPP_DEPRECATED_(m) __attribute__((deprecated(m)))
783 # elif _LIBCPP_STD_VER > 11
784 # define _LIBCPP_DEPRECATED [[deprecated]]
785 # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
786 # else
787 # define _LIBCPP_DEPRECATED
788 # define _LIBCPP_DEPRECATED_(m)
789 # endif
790 # else
791 # define _LIBCPP_DEPRECATED
792 # define _LIBCPP_DEPRECATED_(m)
793 # endif
794
795 # if !defined(_LIBCPP_CXX03_LANG)
796 # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
797 # else
798 # define _LIBCPP_DEPRECATED_IN_CXX11
799 # endif
800
801 # if _LIBCPP_STD_VER > 11
802 # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
803 # else
804 # define _LIBCPP_DEPRECATED_IN_CXX14
805 # endif
806
807 # if _LIBCPP_STD_VER > 14
808 # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
809 # else
810 # define _LIBCPP_DEPRECATED_IN_CXX17
811 # endif
812
813 # if _LIBCPP_STD_VER > 17
814 # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
815 # else
816 # define _LIBCPP_DEPRECATED_IN_CXX20
817 # endif
818
819 #if _LIBCPP_STD_VER >= 23
820 # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
821 #else
822 # define _LIBCPP_DEPRECATED_IN_CXX23
823 #endif
824
825 # if !defined(_LIBCPP_HAS_NO_CHAR8_T)
826 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
827 # else
828 # define _LIBCPP_DEPRECATED_WITH_CHAR8_T
829 # endif
830
831 // Macros to enter and leave a state where deprecation warnings are suppressed.
832 # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
833 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
834 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
835 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
836 # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
837 # else
838 # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
839 # define _LIBCPP_SUPPRESS_DEPRECATED_POP
840 # endif
841
842 # if _LIBCPP_STD_VER <= 11
843 # define _LIBCPP_EXPLICIT_AFTER_CXX11
844 # else
845 # define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
846 # endif
847
848 # if _LIBCPP_STD_VER > 11
849 # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
850 # else
851 # define _LIBCPP_CONSTEXPR_SINCE_CXX14
852 # endif
853
854 # if _LIBCPP_STD_VER > 14
855 # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
856 # else
857 # define _LIBCPP_CONSTEXPR_SINCE_CXX17
858 # endif
859
860 # if _LIBCPP_STD_VER > 17
861 # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
862 # else
863 # define _LIBCPP_CONSTEXPR_SINCE_CXX20
864 # endif
865
866 # if _LIBCPP_STD_VER > 20
867 # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
868 # else
869 # define _LIBCPP_CONSTEXPR_SINCE_CXX23
870 # endif
871
872 # if __has_cpp_attribute(nodiscard)
873 # define _LIBCPP_NODISCARD [[nodiscard]]
874 # else
875 // We can't use GCC's [[gnu::warn_unused_result]] and
876 // __attribute__((warn_unused_result)), because GCC does not silence them via
877 // (void) cast.
878 # define _LIBCPP_NODISCARD
879 # endif
880
881 // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
882 // specified as such as an extension.
883 # if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
884 # define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
885 # else
886 # define _LIBCPP_NODISCARD_EXT
887 # endif
888
889 # if _LIBCPP_STD_VER > 17 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
890 # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
891 # else
892 # define _LIBCPP_NODISCARD_AFTER_CXX17
893 # endif
894
895 # if __has_attribute(__no_destroy__)
896 # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
897 # else
898 # define _LIBCPP_NO_DESTROY
899 # endif
900
901 # ifndef _LIBCPP_HAS_NO_ASAN
902 extern "C" _LIBCPP_FUNC_VIS void
903 __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
904 # endif
905
906 // Try to find out if RTTI is disabled.
907 # if !defined(__cpp_rtti) || __cpp_rtti < 199711L
908 # define _LIBCPP_HAS_NO_RTTI
909 # endif
910
911 # ifndef _LIBCPP_WEAK
912 # define _LIBCPP_WEAK __attribute__((__weak__))
913 # endif
914
915 // Thread API
916 // clang-format off
917 # if !defined(_LIBCPP_HAS_NO_THREADS) && \
918 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
919 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
920 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
921
922 # if defined(__FreeBSD__) || \
923 defined(__wasi__) || \
924 defined(__NetBSD__) || \
925 defined(__OpenBSD__) || \
926 defined(__NuttX__) || \
927 defined(__linux__) || \
928 defined(__GNU__) || \
929 defined(__APPLE__) || \
930 defined(__sun__) || \
931 defined(__MVS__) || \
932 defined(_AIX) || \
933 defined(__EMSCRIPTEN__)
934 // clang-format on
935 # define _LIBCPP_HAS_THREAD_API_PTHREAD
936 # elif defined(__Fuchsia__)
937 // TODO(44575): Switch to C11 thread API when possible.
938 # define _LIBCPP_HAS_THREAD_API_PTHREAD
939 # elif defined(_LIBCPP_WIN32API)
940 # define _LIBCPP_HAS_THREAD_API_WIN32
941 # else
942 # error "No thread API"
943 # endif // _LIBCPP_HAS_THREAD_API
944 # endif // _LIBCPP_HAS_NO_THREADS
945
946 # if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
947 # if defined(__ANDROID__) && __ANDROID_API__ >= 30
948 # define _LIBCPP_HAS_COND_CLOCKWAIT
949 # elif defined(_LIBCPP_GLIBC_PREREQ)
950 # if _LIBCPP_GLIBC_PREREQ(2, 30)
951 # define _LIBCPP_HAS_COND_CLOCKWAIT
952 # endif
953 # endif
954 # endif
955
956 # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
957 # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
958 _LIBCPP_HAS_NO_THREADS is not defined.
959 # endif
960
961 # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
962 # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
963 _LIBCPP_HAS_NO_THREADS is defined.
964 # endif
965
966 # if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
967 # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
968 _LIBCPP_HAS_NO_THREADS is defined.
969 # endif
970
971 # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
972 # define __STDCPP_THREADS__ 1
973 # endif
974
975 // The glibc and Bionic implementation of pthreads implements
976 // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
977 // mutexes have no destroy mechanism.
978 //
979 // This optimization can't be performed on Apple platforms, where
980 // pthread_mutex_destroy can allow the kernel to release resources.
981 // See https://llvm.org/D64298 for details.
982 //
983 // TODO(EricWF): Enable this optimization on Bionic after speaking to their
984 // respective stakeholders.
985 // clang-format off
986 # if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
987 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
988 defined(_LIBCPP_HAS_THREAD_API_WIN32)
989 // clang-format on
990 # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
991 # endif
992
993 // Destroying a condvar is a nop on Windows.
994 //
995 // This optimization can't be performed on Apple platforms, where
996 // pthread_cond_destroy can allow the kernel to release resources.
997 // See https://llvm.org/D64298 for details.
998 //
999 // TODO(EricWF): This is potentially true for some pthread implementations
1000 // as well.
1001 # if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1002 # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1003 # endif
1004
1005 // Some systems do not provide gets() in their C library, for security reasons.
1006 # if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
1007 # define _LIBCPP_C_HAS_NO_GETS
1008 # endif
1009
1010 # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
1011 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1012 # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1013 # endif
1014
1015 # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1016 # define _LIBCPP_HAS_C_ATOMIC_IMP
1017 # elif defined(_LIBCPP_COMPILER_GCC)
1018 # define _LIBCPP_HAS_GCC_ATOMIC_IMP
1019 # endif
1020
1021 # if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1022 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1023 # define _LIBCPP_HAS_NO_ATOMIC_HEADER
1024 # else
1025 # ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1026 # define _LIBCPP_ATOMIC_FLAG_TYPE bool
1027 # endif
1028 # ifdef _LIBCPP_FREESTANDING
1029 # define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1030 # endif
1031 # endif
1032
1033 # ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1034 # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1035 # endif
1036
1037 # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1038 # if defined(__clang__) && __has_attribute(acquire_capability)
1039 // Work around the attribute handling in clang. When both __declspec and
1040 // __attribute__ are present, the processing goes awry preventing the definition
1041 // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1042 // combining the two does work.
1043 # if !defined(_MSC_VER)
1044 # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1045 # endif
1046 # endif
1047 # endif
1048
1049 # ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1050 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1051 # else
1052 # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1053 # endif
1054
1055 # if _LIBCPP_STD_VER > 17
1056 # define _LIBCPP_CONSTINIT constinit
1057 # elif __has_attribute(__require_constant_initialization__)
1058 # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1059 # else
1060 # define _LIBCPP_CONSTINIT
1061 # endif
1062
1063 # if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1064 # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1065 # else
1066 # define _LIBCPP_DIAGNOSE_WARNING(...)
1067 # endif
1068
1069 // Use a function like macro to imply that it must be followed by a semicolon
1070 # if __has_cpp_attribute(fallthrough)
1071 # define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1072 # elif __has_attribute(__fallthrough__)
1073 # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1074 # else
1075 # define _LIBCPP_FALLTHROUGH() ((void)0)
1076 # endif
1077
1078 # if __has_cpp_attribute(_Clang::__lifetimebound__)
1079 # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1080 # else
1081 # define _LIBCPP_LIFETIMEBOUND
1082 # endif
1083
1084 # if __has_attribute(__nodebug__)
1085 # define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1086 # else
1087 # define _LIBCPP_NODEBUG
1088 # endif
1089
1090 # if __has_attribute(__standalone_debug__)
1091 # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1092 # else
1093 # define _LIBCPP_STANDALONE_DEBUG
1094 # endif
1095
1096 # if __has_attribute(__preferred_name__)
1097 # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1098 # else
1099 # define _LIBCPP_PREFERRED_NAME(x)
1100 # endif
1101
1102 // We often repeat things just for handling wide characters in the library.
1103 // When wide characters are disabled, it can be useful to have a quick way of
1104 // disabling it without having to resort to #if-#endif, which has a larger
1105 // impact on readability.
1106 # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1107 # define _LIBCPP_IF_WIDE_CHARACTERS(...)
1108 # else
1109 # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1110 # endif
1111
1112 # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1113 # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1114 # else
1115 # define _LIBCPP_DECLSPEC_EMPTY_BASES
1116 # endif
1117
1118 # if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1119 # define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1120 # define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1121 # define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1122 # define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1123 # define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1124 # endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1125
1126 # if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1127 # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1128 # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1129 # define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1130 # define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1131 # define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1132 # define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1133 # endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1134
1135 # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")")
1136 # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")")
1137
1138 # ifndef _LIBCPP_NO_AUTO_LINK
1139 # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1140 # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1141 # pragma comment(lib, "c++.lib")
1142 # else
1143 # pragma comment(lib, "libc++.lib")
1144 # endif
1145 # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1146 # endif // _LIBCPP_NO_AUTO_LINK
1147
1148 // Configures the fopen close-on-exec mode character, if any. This string will
1149 // be appended to any mode string used by fstream for fopen/fdopen.
1150 //
1151 // Not all platforms support this, but it helps avoid fd-leaks on platforms that
1152 // do.
1153 # if defined(__BIONIC__)
1154 # define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1155 # else
1156 # define _LIBCPP_FOPEN_CLOEXEC_MODE
1157 # endif
1158
1159 // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1160 // of functions used in cstdio may not be available for low API levels when
1161 // using 64-bit file offsets on LP32.
1162 # if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1163 # define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1164 # endif
1165
1166 # if __has_attribute(__init_priority__)
1167 # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1168 # else
1169 # define _LIBCPP_INIT_PRIORITY_MAX
1170 # endif
1171
1172 # if __has_attribute(__format__)
1173 // The attribute uses 1-based indices for ordinary and static member functions.
1174 // The attribute uses 2-based indices for non-static member functions.
1175 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1176 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1177 # else
1178 # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1179 # endif
1180
1181 # if __has_cpp_attribute(msvc::no_unique_address)
1182 // MSVC implements [[no_unique_address]] as a silent no-op currently.
1183 // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1184 // However, MSVC implements [[msvc::no_unique_address]] which does what
1185 // [[no_unique_address]] is supposed to do, in general.
1186
1187 // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1188 // [[msvc::no_unique_address]] though. If/when it does implement
1189 // [[msvc::no_unique_address]], this should be preferred though.
1190 # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1191 # elif __has_cpp_attribute(no_unique_address)
1192 # define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]]
1193 # else
1194 # define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1195 // Note that this can be replaced by #error as soon as clang-cl
1196 // implements msvc::no_unique_address, since there should be no C++20
1197 // compiler that doesn't support one of the two attributes at that point.
1198 // We generally don't want to use this macro outside of C++20-only code,
1199 // because using it conditionally in one language version only would make
1200 // the ABI inconsistent.
1201 # endif
1202
1203 # ifdef _LIBCPP_COMPILER_CLANG_BASED
1204 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1205 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1206 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1207 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1208 # elif defined(_LIBCPP_COMPILER_GCC)
1209 # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1210 # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1211 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1212 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1213 # else
1214 # define _LIBCPP_DIAGNOSTIC_PUSH
1215 # define _LIBCPP_DIAGNOSTIC_POP
1216 # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1217 # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1218 # endif
1219
1220 # if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
1221 # define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
1222 # define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
1223 # else
1224 # define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */
1225 # define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
1226 # endif
1227
1228 # if __has_attribute(__packed__)
1229 # define _LIBCPP_PACKED __attribute__((__packed__))
1230 # else
1231 # define _LIBCPP_PACKED
1232 # endif
1233
1234 // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1235 // functions is gradually being added to existing C libraries. The conditions
1236 // below check for known C library versions and conditions under which these
1237 // functions are declared by the C library.
1238 # define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1239 // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1240 // __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1241 // the latter depends on internal GNU libc details that are not appropriate
1242 // to depend on here, so any declarations present when __cpp_char8_t is not
1243 // defined are ignored.
1244 # if defined(_LIBCPP_GLIBC_PREREQ)
1245 # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1246 # undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1247 # endif
1248 # endif
1249
1250 // There are a handful of public standard library types that are intended to
1251 // support CTAD but don't need any explicit deduction guides to do so. This
1252 // macro is used to mark them as such, which suppresses the
1253 // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1254 // with these classes.
1255 #if _LIBCPP_STD_VER >= 17
1256 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1257 template <class ..._Tag> \
1258 _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...>
1259 #else
1260 # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1261 #endif
1262
1263 // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1264 // compiler intrinsics in the Objective-C++ mode.
1265 # ifdef __OBJC__
1266 # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1267 # endif
1268
1269 #endif // __cplusplus
1270
1271 #endif // _LIBCPP___CONFIG