xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision 647cbc5de815c5651677bf8582797f716ec7b48d)
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#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16#  pragma GCC system_header
17#endif
18
19#if defined(__apple_build_version__)
20// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
21#  define _LIBCPP_COMPILER_CLANG_BASED
22#  define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
23#elif defined(__clang__)
24#  define _LIBCPP_COMPILER_CLANG_BASED
25#  define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
26#elif defined(__GNUC__)
27#  define _LIBCPP_COMPILER_GCC
28#  define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
29#endif
30
31#ifdef __cplusplus
32
33// Warn if a compiler version is used that is not supported anymore
34// LLVM RELEASE Update the minimum compiler versions
35#  if defined(_LIBCPP_CLANG_VER)
36#    if _LIBCPP_CLANG_VER < 1600
37#      warning "Libc++ only supports Clang 16 and later"
38#    endif
39#  elif defined(_LIBCPP_APPLE_CLANG_VER)
40#    if _LIBCPP_APPLE_CLANG_VER < 1500
41#      warning "Libc++ only supports AppleClang 15 and later"
42#    endif
43#  elif defined(_LIBCPP_GCC_VER)
44#    if _LIBCPP_GCC_VER < 1300
45#      warning "Libc++ only supports GCC 13 and later"
46#    endif
47#  endif
48
49// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
50
51// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
52// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
53// defined to XXYYZZ.
54#  define _LIBCPP_VERSION 180000
55
56#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
57#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
58
59#  if __STDC_HOSTED__ == 0
60#    define _LIBCPP_FREESTANDING
61#  endif
62
63// NOLINTBEGIN(libcpp-cpp-version-check)
64#  ifndef _LIBCPP_STD_VER
65#    if __cplusplus <= 201103L
66#      define _LIBCPP_STD_VER 11
67#    elif __cplusplus <= 201402L
68#      define _LIBCPP_STD_VER 14
69#    elif __cplusplus <= 201703L
70#      define _LIBCPP_STD_VER 17
71#    elif __cplusplus <= 202002L
72#      define _LIBCPP_STD_VER 20
73#    elif __cplusplus <= 202302L
74#      define _LIBCPP_STD_VER 23
75#    else
76// Expected release year of the next C++ standard
77#      define _LIBCPP_STD_VER 26
78#    endif
79#  endif // _LIBCPP_STD_VER
80// NOLINTEND(libcpp-cpp-version-check)
81
82#  if defined(__ELF__)
83#    define _LIBCPP_OBJECT_FORMAT_ELF 1
84#  elif defined(__MACH__)
85#    define _LIBCPP_OBJECT_FORMAT_MACHO 1
86#  elif defined(_WIN32)
87#    define _LIBCPP_OBJECT_FORMAT_COFF 1
88#  elif defined(__wasm__)
89#    define _LIBCPP_OBJECT_FORMAT_WASM 1
90#  elif defined(_AIX)
91#    define _LIBCPP_OBJECT_FORMAT_XCOFF 1
92#  else
93// ... add new file formats here ...
94#  endif
95
96// ABI {
97
98#  if _LIBCPP_ABI_VERSION >= 2
99// Change short string representation so that string data starts at offset 0,
100// improving its alignment in some cases.
101#    define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
102// Fix deque iterator type in order to support incomplete types.
103#    define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
104// Fix undefined behavior in how std::list stores its linked nodes.
105#    define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
106// Fix undefined behavior in  how __tree stores its end and parent nodes.
107#    define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
108// Fix undefined behavior in how __hash_table stores its pointer types.
109#    define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
110#    define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
111#    define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
112// Define a key function for `bad_function_call` in the library, to centralize
113// its vtable and typeinfo to libc++ rather than having all other libraries
114// using that class define their own copies.
115#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
116// Override the default return value of exception::what() for
117// bad_function_call::what() with a string that is specific to
118// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
119// because it changes the vtable layout of bad_function_call.
120#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
121// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
122#    define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
123// Give reverse_iterator<T> one data member of type T, not two.
124// Also, in C++17 and later, don't derive iterator types from std::iterator.
125#    define _LIBCPP_ABI_NO_ITERATOR_BASES
126// Use the smallest possible integer type to represent the index of the variant.
127// Previously libc++ used "unsigned int" exclusively.
128#    define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
129// Unstable attempt to provide a more optimized std::function
130#    define _LIBCPP_ABI_OPTIMIZED_FUNCTION
131// All the regex constants must be distinct and nonzero.
132#    define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
133// Re-worked external template instantiations for std::string with a focus on
134// performance and fast-path inlining.
135#    define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
136// Enable clang::trivial_abi on std::unique_ptr.
137#    define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
138// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
139#    define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
140// std::random_device holds some state when it uses an implementation that gets
141// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
142// implementation to another one on a platform that has already shipped
143// std::random_device, one needs to retain the same object layout to remain ABI
144// compatible. This switch removes these workarounds for platforms that don't care
145// about ABI compatibility.
146#    define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
147// Don't export the legacy __basic_string_common class and its methods from the built library.
148#    define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
149// Don't export the legacy __vector_base_common class and its methods from the built library.
150#    define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
151// According to the Standard, `bitset::operator[] const` returns bool
152#    define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
153// Fix the implementation of CityHash used for std::hash<fundamental-type>.
154// This is an ABI break because `std::hash` will return a different result,
155// which means that hashing the same object in translation units built against
156// different versions of libc++ can return inconsistent results. This is especially
157// tricky since std::hash is used in the implementation of unordered containers.
158//
159// The incorrect implementation of CityHash has the problem that it drops some
160// bits on the floor.
161#    define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
162// Remove the base 10 implementation of std::to_chars from the dylib.
163// The implementation moved to the header, but we still export the symbols from
164// the dylib for backwards compatibility.
165#    define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
166// Save memory by providing the allocator more freedom to allocate the most
167// efficient size class by dropping the alignment requirements for std::string's
168// pointer from 16 to 8. This changes the output of std::string::max_size,
169// which makes it ABI breaking
170#    define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
171#  elif _LIBCPP_ABI_VERSION == 1
172#    if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
173// Enable compiling copies of now inline methods into the dylib to support
174// applications compiled against older libraries. This is unnecessary with
175// COFF dllexport semantics, since dllexport forces a non-inline definition
176// of inline functions to be emitted anyway. Our own non-inline copy would
177// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
178// the linker will take issue with the symbols in the shared object if the
179// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
180// so disable it.
181#      define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
182#    endif
183// Feature macros for disabling pre ABI v1 features. All of these options
184// are deprecated.
185#    if defined(__FreeBSD__) && __FreeBSD__ < 14
186#      define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
187#    endif
188// For XCOFF linkers, we have problems if we see a weak hidden version of a symbol
189// in user code (like you get with -fvisibility-inlines-hidden) and then a strong def
190// in the library, so we need to always rely on the library version.
191#    if defined(_AIX)
192#      define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
193#    endif
194#  endif
195
196#  if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
197// Define a key function for `bad_function_call` in the library, to centralize
198// its vtable and typeinfo to libc++ rather than having all other libraries
199// using that class define their own copies.
200#    define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
201#  endif
202
203// We had some bugs where we use [[no_unique_address]] together with construct_at,
204// which causes UB as the call on construct_at could write to overlapping subobjects
205//
206// https://github.com/llvm/llvm-project/issues/70506
207// https://github.com/llvm/llvm-project/issues/70494
208//
209// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions.
210// The below macro is used for all classes whose ABI have changed as part of fixing these bugs.
211#  define _LIBCPP_ABI_2023_OVERLAPPING_SUBOBJECT_FIX_TAG __attribute__((__abi_tag__("subobj_fix_2023")))
212
213// Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
214// within the bounds of the original container and asserts it on every dereference.
215//
216// ABI impact: changes the iterator type of the relevant containers.
217//
218// Supported containers:
219// - `span`;
220// - `string_view`;
221// - `array`.
222// #define _LIBCPP_ABI_BOUNDED_ITERATORS
223
224// } ABI
225
226// HARDENING {
227
228// TODO(hardening): deprecate this in LLVM 19.
229// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
230// equivalent to setting the extensive mode.
231#  ifdef _LIBCPP_ENABLE_ASSERTIONS
232#    if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
233#      error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
234#    endif
235#    if _LIBCPP_ENABLE_ASSERTIONS
236#      define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
237#    endif
238#  endif
239
240// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
241//
242// - `_LIBCPP_HARDENING_MODE_NONE`;
243// - `_LIBCPP_HARDENING_MODE_FAST`;
244// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
245// - `_LIBCPP_HARDENING_MODE_DEBUG`.
246//
247// These values have the following effects:
248//
249// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
250//
251// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
252//   that can be done with relatively little runtime overhead in constant time;
253//
254// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
255//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
256//   but are not necessarily security-critical;
257//
258// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
259//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
260//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
261
262// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
263// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
264//
265// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
266//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
267//   - the sentinel is reachable from the begin iterator;
268//   - TODO(hardening): both iterators refer to the same container.
269//
270// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
271//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
272//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
273//   `optional` and `function` are considered one-element containers for the purposes of this check.
274//
275// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
276//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
277//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
278//   compiler optimizations).
279//
280// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
281//   given ranges do not overlap.
282//
283// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
284//   the containers have compatible allocators.
285//
286// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
287//   user input.
288//
289// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
290
291// clang-format off
292#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
293#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
294#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
295#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
296// clang-format on
297
298#  ifndef _LIBCPP_HARDENING_MODE
299#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
300#  endif
301
302#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
303      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
304      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
305      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
306#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
307_LIBCPP_HARDENING_MODE_NONE, \
308_LIBCPP_HARDENING_MODE_FAST, \
309_LIBCPP_HARDENING_MODE_EXTENSIVE, \
310_LIBCPP_HARDENING_MODE_DEBUG
311#  endif
312
313// clang-format off
314// Fast hardening mode checks.
315
316#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
317
318// Enabled checks.
319#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
320#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
321// Disabled checks.
322// On most modern platforms, dereferencing a null pointer does not lead to an actual memory access.
323#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSUME(expression)
324// Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
325// vulnerability.
326#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSUME(expression)
327#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSUME(expression)
328#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
329#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSUME(expression)
330
331// Extensive hardening mode checks.
332
333#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
334
335// Enabled checks.
336#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)        _LIBCPP_ASSERT(expression, message)
337#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)     _LIBCPP_ASSERT(expression, message)
338#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                 _LIBCPP_ASSERT(expression, message)
339#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)   _LIBCPP_ASSERT(expression, message)
340#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)     _LIBCPP_ASSERT(expression, message)
341#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)            _LIBCPP_ASSERT(expression, message)
342// Disabled checks.
343#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                 _LIBCPP_ASSUME(expression)
344
345// Debug hardening mode checks.
346
347#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
348
349// All checks enabled.
350#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSERT(expression, message)
351#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSERT(expression, message)
352#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSERT(expression, message)
353#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSERT(expression, message)
354#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSERT(expression, message)
355#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSERT(expression, message)
356#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSERT(expression, message)
357
358// Disable all checks if hardening is not enabled.
359
360#  else
361
362// All checks disabled.
363#    define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message)         _LIBCPP_ASSUME(expression)
364#    define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message)      _LIBCPP_ASSUME(expression)
365#    define _LIBCPP_ASSERT_NON_NULL(expression, message)                  _LIBCPP_ASSUME(expression)
366#    define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message)    _LIBCPP_ASSUME(expression)
367#    define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message)      _LIBCPP_ASSUME(expression)
368#    define _LIBCPP_ASSERT_INTERNAL(expression, message)                  _LIBCPP_ASSUME(expression)
369#    define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message)             _LIBCPP_ASSUME(expression)
370
371#  endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
372// clang-format on
373
374// } HARDENING
375
376#  define _LIBCPP_TOSTRING2(x) #x
377#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
378
379// NOLINTNEXTLINE(libcpp-cpp-version-check)
380#  if __cplusplus < 201103L
381#    define _LIBCPP_CXX03_LANG
382#  endif
383
384#  ifndef __has_attribute
385#    define __has_attribute(__x) 0
386#  endif
387
388#  ifndef __has_builtin
389#    define __has_builtin(__x) 0
390#  endif
391
392#  ifndef __has_extension
393#    define __has_extension(__x) 0
394#  endif
395
396#  ifndef __has_feature
397#    define __has_feature(__x) 0
398#  endif
399
400#  ifndef __has_cpp_attribute
401#    define __has_cpp_attribute(__x) 0
402#  endif
403
404#  ifndef __has_constexpr_builtin
405#    define __has_constexpr_builtin(x) 0
406#  endif
407
408// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
409// the compiler and '1' otherwise.
410#  ifndef __is_identifier
411#    define __is_identifier(__x) 1
412#  endif
413
414#  ifndef __has_declspec_attribute
415#    define __has_declspec_attribute(__x) 0
416#  endif
417
418#  define __has_keyword(__x) !(__is_identifier(__x))
419
420#  ifndef __has_include
421#    define __has_include(...) 0
422#  endif
423
424#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
425#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
426#  endif
427
428// FIXME: ABI detection should be done via compiler builtin macros. This
429// is just a placeholder until Clang implements such macros. For now assume
430// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
431// and allow the user to explicitly specify the ABI to handle cases where this
432// heuristic falls short.
433#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
434#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
435#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
436#    define _LIBCPP_ABI_ITANIUM
437#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
438#    define _LIBCPP_ABI_MICROSOFT
439#  else
440#    if defined(_WIN32) && defined(_MSC_VER)
441#      define _LIBCPP_ABI_MICROSOFT
442#    else
443#      define _LIBCPP_ABI_ITANIUM
444#    endif
445#  endif
446
447#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
448#    define _LIBCPP_ABI_VCRUNTIME
449#  endif
450
451#  if __has_feature(experimental_library)
452#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
453#      define _LIBCPP_ENABLE_EXPERIMENTAL
454#    endif
455#  endif
456
457// Incomplete features get their own specific disabling flags. This makes it
458// easier to grep for target specific flags once the feature is complete.
459#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
460#    define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
461#    define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
462#    define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
463#    define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
464#  endif
465
466// Need to detect which libc we're using if we're on Linux.
467#  if defined(__linux__)
468#    include <features.h>
469#    if defined(__GLIBC_PREREQ)
470#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
471#    else
472#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
473#    endif // defined(__GLIBC_PREREQ)
474#  endif   // defined(__linux__)
475
476#  if defined(__MVS__)
477#    include <features.h> // for __NATIVE_ASCII_F
478#  endif
479
480#  ifndef __BYTE_ORDER__
481#    error                                                                                                             \
482        "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
483#  endif
484
485#  if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
486#    define _LIBCPP_LITTLE_ENDIAN
487#  elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
488#    define _LIBCPP_BIG_ENDIAN
489#  endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
490
491#  if defined(_WIN32)
492#    define _LIBCPP_WIN32API
493#    define _LIBCPP_SHORT_WCHAR 1
494// Both MinGW and native MSVC provide a "MSVC"-like environment
495#    define _LIBCPP_MSVCRT_LIKE
496// If mingw not explicitly detected, assume using MS C runtime only if
497// a MS compatibility version is specified.
498#    if defined(_MSC_VER) && !defined(__MINGW32__)
499#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
500#    endif
501#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
502#      define _LIBCPP_HAS_BITSCAN64
503#    endif
504#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
505#  endif // defined(_WIN32)
506
507#  if defined(_AIX) && !defined(__64BIT__)
508// The size of wchar is 2 byte on 32-bit mode on AIX.
509#    define _LIBCPP_SHORT_WCHAR 1
510#  endif
511
512// Libc++ supports various implementations of std::random_device.
513//
514// _LIBCPP_USING_DEV_RANDOM
515//      Read entropy from the given file, by default `/dev/urandom`.
516//      If a token is provided, it is assumed to be the path to a file
517//      to read entropy from. This is the default behavior if nothing
518//      else is specified. This implementation requires storing state
519//      inside `std::random_device`.
520//
521// _LIBCPP_USING_ARC4_RANDOM
522//      Use arc4random(). This allows obtaining random data even when
523//      using sandboxing mechanisms. On some platforms like Apple, this
524//      is the recommended source of entropy for user-space programs.
525//      When this option is used, the token passed to `std::random_device`'s
526//      constructor *must* be "/dev/urandom" -- anything else is an error.
527//
528// _LIBCPP_USING_GETENTROPY
529//      Use getentropy().
530//      When this option is used, the token passed to `std::random_device`'s
531//      constructor *must* be "/dev/urandom" -- anything else is an error.
532//
533// _LIBCPP_USING_FUCHSIA_CPRNG
534//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
535//      deliver high-quality entropy and cannot fail.
536//      When this option is used, the token passed to `std::random_device`'s
537//      constructor *must* be "/dev/urandom" -- anything else is an error.
538//
539// _LIBCPP_USING_NACL_RANDOM
540//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
541//      including accesses to the special files under `/dev`. This implementation
542//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
543//      When this option is used, the token passed to `std::random_device`'s
544//      constructor *must* be "/dev/urandom" -- anything else is an error.
545//
546// _LIBCPP_USING_WIN32_RANDOM
547//      Use rand_s(), for use on Windows.
548//      When this option is used, the token passed to `std::random_device`'s
549//      constructor *must* be "/dev/urandom" -- anything else is an error.
550#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
551      defined(__DragonFly__)
552#    define _LIBCPP_USING_ARC4_RANDOM
553#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
554#    define _LIBCPP_USING_GETENTROPY
555#  elif defined(__Fuchsia__)
556#    define _LIBCPP_USING_FUCHSIA_CPRNG
557#  elif defined(__native_client__)
558#    define _LIBCPP_USING_NACL_RANDOM
559#  elif defined(_LIBCPP_WIN32API)
560#    define _LIBCPP_USING_WIN32_RANDOM
561#  else
562#    define _LIBCPP_USING_DEV_RANDOM
563#  endif
564
565#  ifndef _LIBCPP_CXX03_LANG
566
567#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
568#    define _ALIGNAS_TYPE(x) alignas(x)
569#    define _ALIGNAS(x) alignas(x)
570#    define _LIBCPP_NORETURN [[noreturn]]
571#    define _NOEXCEPT noexcept
572#    define _NOEXCEPT_(x) noexcept(x)
573#    define _LIBCPP_CONSTEXPR constexpr
574
575#  else
576
577#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
578#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
579#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
580#    define _LIBCPP_NORETURN __attribute__((__noreturn__))
581#    define _LIBCPP_HAS_NO_NOEXCEPT
582#    define nullptr __nullptr
583#    define _NOEXCEPT throw()
584#    define _NOEXCEPT_(x)
585#    define static_assert(...) _Static_assert(__VA_ARGS__)
586#    define decltype(...) __decltype(__VA_ARGS__)
587#    define _LIBCPP_CONSTEXPR
588
589typedef __char16_t char16_t;
590typedef __char32_t char32_t;
591
592#  endif
593
594#  if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
595#    define _LIBCPP_HAS_NO_EXCEPTIONS
596#  endif
597
598#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
599
600#  if defined(_LIBCPP_COMPILER_CLANG_BASED)
601
602#    if defined(__APPLE__)
603#      if defined(__i386__) || defined(__x86_64__)
604// use old string layout on x86_64 and i386
605#      elif defined(__arm__)
606// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
607#        if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
608#          define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
609#        endif
610#      else
611#        define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
612#      endif
613#    endif
614
615// Objective-C++ features (opt-in)
616#    if __has_feature(objc_arc)
617#      define _LIBCPP_HAS_OBJC_ARC
618#    endif
619
620#    if __has_feature(objc_arc_weak)
621#      define _LIBCPP_HAS_OBJC_ARC_WEAK
622#    endif
623
624#    if __has_extension(blocks)
625#      define _LIBCPP_HAS_EXTENSION_BLOCKS
626#    endif
627
628#    if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
629#      define _LIBCPP_HAS_BLOCKS_RUNTIME
630#    endif
631
632#    if !__has_feature(address_sanitizer)
633#      define _LIBCPP_HAS_NO_ASAN
634#    endif
635
636#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
637
638#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
639
640#  elif defined(_LIBCPP_COMPILER_GCC)
641
642#    if !defined(__SANITIZE_ADDRESS__)
643#      define _LIBCPP_HAS_NO_ASAN
644#    endif
645
646#    define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
647
648#    define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
649
650#  endif // _LIBCPP_COMPILER_[CLANG|GCC]
651
652#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
653
654#    ifdef _DLL
655#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
656#    else
657#      define _LIBCPP_CRT_FUNC
658#    endif
659
660#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
661#      define _LIBCPP_DLL_VIS
662#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
663#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
664#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
665#      define _LIBCPP_EXPORTED_FROM_ABI
666#    elif defined(_LIBCPP_BUILDING_LIBRARY)
667#      define _LIBCPP_DLL_VIS __declspec(dllexport)
668#      if defined(__MINGW32__)
669#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
670#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
671#      else
672#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
673#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
674#      endif
675#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
676#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
677#    else
678#      define _LIBCPP_DLL_VIS __declspec(dllimport)
679#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
680#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
681#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
682#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
683#    endif
684
685#    define _LIBCPP_HIDDEN
686#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
687#    define _LIBCPP_TEMPLATE_VIS
688#    define _LIBCPP_TEMPLATE_DATA_VIS
689#    define _LIBCPP_TYPE_VISIBILITY_DEFAULT
690
691#  else
692
693#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
694#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
695#    else
696#      define _LIBCPP_VISIBILITY(vis)
697#    endif
698
699#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
700#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
701#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
702#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
703#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
704
705// TODO: Make this a proper customization point or remove the option to override it.
706#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
707#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
708#    endif
709
710#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
711// The inline should be removed once PR32114 is resolved
712#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
713#    else
714#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
715#    endif
716
717// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
718#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
719#      define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
720#    else
721#      define _LIBCPP_TEMPLATE_VIS
722#    endif
723
724#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
725#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
726#    else
727#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT
728#    endif
729
730#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
731
732#  if __has_attribute(exclude_from_explicit_instantiation)
733#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
734#  else
735// Try to approximate the effect of exclude_from_explicit_instantiation
736// (which is that entities are not assumed to be provided by explicit
737// template instantiations in the dylib) by always inlining those entities.
738#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
739#  endif
740
741#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
742#    define _LIBCPP_HARDENING_SIG f
743#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
744#    define _LIBCPP_HARDENING_SIG s
745#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
746#    define _LIBCPP_HARDENING_SIG d
747#  else
748#    define _LIBCPP_HARDENING_SIG n // "none"
749#  endif
750
751#  ifdef _LIBCPP_HAS_NO_EXCEPTIONS
752#    define _LIBCPP_EXCEPTIONS_SIG n
753#  else
754#    define _LIBCPP_EXCEPTIONS_SIG e
755#  endif
756
757#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
758    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
759
760// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
761// on two levels:
762// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
763//    symbols from their dynamic library by means of using the libc++ headers. This ensures
764//    that those symbols stay private to the dynamic library in which it is defined.
765//
766// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
767//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
768//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
769//    program contains two definitions of a function, the ODR requires them to be token-by-token
770//    equivalent, and the linker is allowed to pick either definition and discard the other one.
771//
772//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
773//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
774//    compiled with different settings), the two definitions are both visible by the linker and they
775//    have the same name, but they have a meaningfully different implementation (one throws an exception
776//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
777//    practice what will happen is that the linker will pick one of the definitions at random and will
778//    discard the other one. This can quite clearly lead to incorrect program behavior.
779//
780//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
781//    property that causes the code of a function to differ from the code in another configuration
782//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
783//    tag, but we encode the ones that we think are most important: library version, exceptions, and
784//    hardening mode.
785//
786//    Note that historically, solving this problem has been achieved in various ways, including
787//    force-inlining all functions or giving internal linkage to all functions. Both these previous
788//    solutions suffer from drawbacks that lead notably to code bloat.
789//
790// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
791// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
792//
793// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
794// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
795// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
796// the virtual function pointer in the vtable based on the mangled name of the function. Since
797// we use an ABI tag that changes with each released version, the mangled name of the virtual
798// function would change, which is incorrect. Note that it doesn't make much sense to change
799// the implementation of a virtual function in an ABI-incompatible way in the first place,
800// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
801//
802// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
803//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
804//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
805#  ifndef _LIBCPP_NO_ABI_TAG
806#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
807      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
808          __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
809#  else
810#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
811#  endif
812#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
813
814// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
815// "C" function, as those lack mangling.
816#  define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
817
818#  ifdef _LIBCPP_BUILDING_LIBRARY
819#    if _LIBCPP_ABI_VERSION > 1
820#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
821#    else
822#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
823#    endif
824#  else
825#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
826#  endif
827
828// TODO(LLVM-19): Remove _LIBCPP_INLINE_VISIBILITY and _VSTD, which we're keeping around
829//                only to ease the renaming for downstreams.
830#  define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
831#  define _VSTD std
832
833// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
834// clang-format off
835#  define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {                                  \
836                               inline namespace _LIBCPP_ABI_NAMESPACE {
837#  define _LIBCPP_END_NAMESPACE_STD }}
838
839#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
840                                             inline namespace __fs { namespace filesystem {
841
842#  define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
843// clang-format on
844
845#  if __has_attribute(__enable_if__)
846#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
847#  endif
848
849#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
850#    define _LIBCPP_HAS_NO_INT128
851#  endif
852
853#  ifdef _LIBCPP_CXX03_LANG
854#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
855      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
856        enum __lx
857// clang-format off
858#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
859      __lx __v_;                                                                                                       \
860      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
861      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
862      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
863      };
864// clang-format on
865
866#  else // _LIBCPP_CXX03_LANG
867#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
868#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
869#  endif // _LIBCPP_CXX03_LANG
870
871#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
872#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
873#  endif
874
875#  ifdef __FreeBSD__
876#    define _DECLARE_C99_LDBL_MATH 1
877#  endif
878
879// If we are getting operator new from the MSVC CRT, then allocation overloads
880// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
881#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
882#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
883#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
884// We're deferring to Microsoft's STL to provide aligned new et al. We don't
885// have it unless the language feature test macro is defined.
886#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
887#  elif defined(__MVS__)
888#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
889#  endif
890
891#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
892#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
893#  endif
894
895// It is not yet possible to use aligned_alloc() on all Apple platforms since
896// 10.15 was the first version to ship an implementation of aligned_alloc().
897#  if defined(__APPLE__)
898#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
899         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
900#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
901#    endif
902#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
903// Android only provides aligned_alloc when targeting API 28 or higher.
904#    define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
905#  endif
906
907#  if defined(__APPLE__) || defined(__FreeBSD__)
908#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
909#  endif
910
911#  if defined(__APPLE__) || defined(__FreeBSD__)
912#    define _LIBCPP_WCTYPE_IS_MASK
913#  endif
914
915#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
916#    define _LIBCPP_HAS_NO_CHAR8_T
917#  endif
918
919// Deprecation macros.
920//
921// Deprecations warnings are always enabled, except when users explicitly opt-out
922// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
923#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
924#    if __has_attribute(__deprecated__)
925#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
926#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
927#    elif _LIBCPP_STD_VER >= 14
928#      define _LIBCPP_DEPRECATED [[deprecated]]
929#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
930#    else
931#      define _LIBCPP_DEPRECATED
932#      define _LIBCPP_DEPRECATED_(m)
933#    endif
934#  else
935#    define _LIBCPP_DEPRECATED
936#    define _LIBCPP_DEPRECATED_(m)
937#  endif
938
939#  if !defined(_LIBCPP_CXX03_LANG)
940#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
941#  else
942#    define _LIBCPP_DEPRECATED_IN_CXX11
943#  endif
944
945#  if _LIBCPP_STD_VER >= 14
946#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
947#  else
948#    define _LIBCPP_DEPRECATED_IN_CXX14
949#  endif
950
951#  if _LIBCPP_STD_VER >= 17
952#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
953#  else
954#    define _LIBCPP_DEPRECATED_IN_CXX17
955#  endif
956
957#  if _LIBCPP_STD_VER >= 20
958#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
959#  else
960#    define _LIBCPP_DEPRECATED_IN_CXX20
961#  endif
962
963#  if _LIBCPP_STD_VER >= 23
964#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
965#  else
966#    define _LIBCPP_DEPRECATED_IN_CXX23
967#  endif
968
969#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
970#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
971#  else
972#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
973#  endif
974
975// Macros to enter and leave a state where deprecation warnings are suppressed.
976#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
977#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
978      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
979          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
980#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
981#  else
982#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
983#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
984#  endif
985
986#  if _LIBCPP_STD_VER <= 11
987#    define _LIBCPP_EXPLICIT_SINCE_CXX14
988#  else
989#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
990#  endif
991
992#  if _LIBCPP_STD_VER >= 23
993#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
994#  else
995#    define _LIBCPP_EXPLICIT_SINCE_CXX23
996#  endif
997
998#  if _LIBCPP_STD_VER >= 14
999#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
1000#  else
1001#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
1002#  endif
1003
1004#  if _LIBCPP_STD_VER >= 17
1005#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
1006#  else
1007#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
1008#  endif
1009
1010#  if _LIBCPP_STD_VER >= 20
1011#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
1012#  else
1013#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
1014#  endif
1015
1016#  if _LIBCPP_STD_VER >= 23
1017#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
1018#  else
1019#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
1020#  endif
1021
1022#  ifndef _LIBCPP_HAS_NO_ASAN
1023extern "C" _LIBCPP_EXPORTED_FROM_ABI void
1024__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
1025extern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
1026    const void*, const void*, const void*, const void*, const void*, const void*);
1027extern "C" _LIBCPP_EXPORTED_FROM_ABI int
1028__sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
1029#  endif
1030
1031// Try to find out if RTTI is disabled.
1032#  if !defined(__cpp_rtti) || __cpp_rtti < 199711L
1033#    define _LIBCPP_HAS_NO_RTTI
1034#  endif
1035
1036#  ifndef _LIBCPP_WEAK
1037#    define _LIBCPP_WEAK __attribute__((__weak__))
1038#  endif
1039
1040// Thread API
1041// clang-format off
1042#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
1043      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
1044      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
1045      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1046
1047#    if defined(__FreeBSD__) ||                                                                                        \
1048        defined(__wasi__) ||                                                                                           \
1049        defined(__NetBSD__) ||                                                                                         \
1050        defined(__OpenBSD__) ||                                                                                        \
1051        defined(__NuttX__) ||                                                                                          \
1052        defined(__linux__) ||                                                                                          \
1053        defined(__GNU__) ||                                                                                            \
1054        defined(__APPLE__) ||                                                                                          \
1055        defined(__MVS__) ||                                                                                            \
1056        defined(_AIX) ||                                                                                               \
1057        defined(__EMSCRIPTEN__)
1058// clang-format on
1059#      define _LIBCPP_HAS_THREAD_API_PTHREAD
1060#    elif defined(__Fuchsia__)
1061// TODO(44575): Switch to C11 thread API when possible.
1062#      define _LIBCPP_HAS_THREAD_API_PTHREAD
1063#    elif defined(_LIBCPP_WIN32API)
1064#      define _LIBCPP_HAS_THREAD_API_WIN32
1065#    else
1066#      error "No thread API"
1067#    endif // _LIBCPP_HAS_THREAD_API
1068#  endif   // _LIBCPP_HAS_NO_THREADS
1069
1070#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1071#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
1072#      define _LIBCPP_HAS_COND_CLOCKWAIT
1073#    elif defined(_LIBCPP_GLIBC_PREREQ)
1074#      if _LIBCPP_GLIBC_PREREQ(2, 30)
1075#        define _LIBCPP_HAS_COND_CLOCKWAIT
1076#      endif
1077#    endif
1078#  endif
1079
1080#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1081#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1082       _LIBCPP_HAS_NO_THREADS is not defined.
1083#  endif
1084
1085#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
1086#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1087       _LIBCPP_HAS_NO_THREADS is defined.
1088#  endif
1089
1090#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
1091#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1092       _LIBCPP_HAS_NO_THREADS is defined.
1093#  endif
1094
1095#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1096#    define __STDCPP_THREADS__ 1
1097#  endif
1098
1099// The glibc and Bionic implementation of pthreads implements
1100// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1101// mutexes have no destroy mechanism.
1102//
1103// This optimization can't be performed on Apple platforms, where
1104// pthread_mutex_destroy can allow the kernel to release resources.
1105// See https://llvm.org/D64298 for details.
1106//
1107// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1108//               respective stakeholders.
1109// clang-format off
1110#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
1111      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
1112       defined(_LIBCPP_HAS_THREAD_API_WIN32)
1113// clang-format on
1114#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1115#  endif
1116
1117// Destroying a condvar is a nop on Windows.
1118//
1119// This optimization can't be performed on Apple platforms, where
1120// pthread_cond_destroy can allow the kernel to release resources.
1121// See https://llvm.org/D64298 for details.
1122//
1123// TODO(EricWF): This is potentially true for some pthread implementations
1124// as well.
1125#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
1126#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1127#  endif
1128
1129// Some systems do not provide gets() in their C library, for security reasons.
1130#  if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
1131#    define _LIBCPP_C_HAS_NO_GETS
1132#  endif
1133
1134#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
1135      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
1136#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1137#  endif
1138
1139#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
1140#    define _LIBCPP_HAS_C_ATOMIC_IMP
1141#  elif defined(_LIBCPP_COMPILER_GCC)
1142#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
1143#  endif
1144
1145#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
1146      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
1147#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
1148#  else
1149#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1150#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
1151#    endif
1152#    ifdef _LIBCPP_FREESTANDING
1153#      define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1154#    endif
1155#  endif
1156
1157#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
1158#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
1159#  else
1160#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
1161#  endif
1162
1163#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
1164#    if defined(__clang__) && __has_attribute(acquire_capability)
1165// Work around the attribute handling in clang.  When both __declspec and
1166// __attribute__ are present, the processing goes awry preventing the definition
1167// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1168// combining the two does work.
1169#      if !defined(_MSC_VER)
1170#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1171#      endif
1172#    endif
1173#  endif
1174
1175#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1176#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1177#  else
1178#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1179#  endif
1180
1181#  if _LIBCPP_STD_VER >= 20
1182#    define _LIBCPP_CONSTINIT constinit
1183#  elif __has_attribute(__require_constant_initialization__)
1184#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
1185#  else
1186#    define _LIBCPP_CONSTINIT
1187#  endif
1188
1189#  if __has_attribute(__noinline__)
1190#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
1191#  else
1192#    define _LIBCPP_NOINLINE
1193#  endif
1194
1195// We often repeat things just for handling wide characters in the library.
1196// When wide characters are disabled, it can be useful to have a quick way of
1197// disabling it without having to resort to #if-#endif, which has a larger
1198// impact on readability.
1199#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1200#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
1201#  else
1202#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1203#  endif
1204
1205#  if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
1206#    define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1207#    define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
1208#    define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1209#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1210#    define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
1211#  endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1212
1213#  if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1214#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
1215#    define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
1216#    define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
1217#    define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1218#    define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
1219#    define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
1220#  endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1221
1222// clang-format off
1223#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh()\")") _Pragma("push_macro(\"move(int, int)\")") _Pragma("push_macro(\"erase()\")")
1224#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh()\")") _Pragma("pop_macro(\"move(int, int)\")") _Pragma("pop_macro(\"erase()\")")
1225// clang-format on
1226
1227#  ifndef _LIBCPP_NO_AUTO_LINK
1228#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1229#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
1230#        pragma comment(lib, "c++.lib")
1231#      else
1232#        pragma comment(lib, "libc++.lib")
1233#      endif
1234#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1235#  endif   // _LIBCPP_NO_AUTO_LINK
1236
1237// Configures the fopen close-on-exec mode character, if any. This string will
1238// be appended to any mode string used by fstream for fopen/fdopen.
1239//
1240// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1241// do.
1242#  if defined(__BIONIC__)
1243#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1244#  else
1245#    define _LIBCPP_FOPEN_CLOEXEC_MODE
1246#  endif
1247
1248#  if __has_cpp_attribute(msvc::no_unique_address)
1249// MSVC implements [[no_unique_address]] as a silent no-op currently.
1250// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1251// However, MSVC implements [[msvc::no_unique_address]] which does what
1252// [[no_unique_address]] is supposed to do, in general.
1253
1254// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
1255// [[msvc::no_unique_address]] though. If/when it does implement
1256// [[msvc::no_unique_address]], this should be preferred though.
1257#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
1258#  elif __has_cpp_attribute(no_unique_address)
1259#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
1260#  else
1261#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
1262// Note that this can be replaced by #error as soon as clang-cl
1263// implements msvc::no_unique_address, since there should be no C++20
1264// compiler that doesn't support one of the two attributes at that point.
1265// We generally don't want to use this macro outside of C++20-only code,
1266// because using it conditionally in one language version only would make
1267// the ABI inconsistent.
1268#  endif
1269
1270#  ifdef _LIBCPP_COMPILER_CLANG_BASED
1271#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1272#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1273#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
1274#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1275#  elif defined(_LIBCPP_COMPILER_GCC)
1276#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1277#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1278#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1279#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
1280#  else
1281#    define _LIBCPP_DIAGNOSTIC_PUSH
1282#    define _LIBCPP_DIAGNOSTIC_POP
1283#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
1284#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
1285#  endif
1286
1287// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1288// functions is gradually being added to existing C libraries. The conditions
1289// below check for known C library versions and conditions under which these
1290// functions are declared by the C library.
1291#  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1292// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
1293// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1294// the latter depends on internal GNU libc details that are not appropriate
1295// to depend on here, so any declarations present when __cpp_char8_t is not
1296// defined are ignored.
1297#  if defined(_LIBCPP_GLIBC_PREREQ)
1298#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1299#      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1300#    endif
1301#  endif
1302
1303// There are a handful of public standard library types that are intended to
1304// support CTAD but don't need any explicit deduction guides to do so. This
1305// macro is used to mark them as such, which suppresses the
1306// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1307// with these classes.
1308#  if _LIBCPP_STD_VER >= 17
1309#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1310#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1311        template <class... _Tag>                                                                                       \
1312        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1313#    else
1314#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
1315        template <class... _Tag>                                                                                       \
1316        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1317#    endif
1318#  else
1319#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1320#  endif
1321
1322// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1323// compiler intrinsics in the Objective-C++ mode.
1324#  ifdef __OBJC__
1325#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1326#  endif
1327
1328#  define _PSTL_PRAGMA(x) _Pragma(#x)
1329
1330// Enable SIMD for compilers that support OpenMP 4.0
1331#  if (defined(_OPENMP) && _OPENMP >= 201307)
1332
1333#    define _PSTL_UDR_PRESENT
1334#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1335#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1336#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1337#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1338#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1339#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
1340
1341// Declaration of reduction functor, where
1342// NAME - the name of the functor
1343// OP - type of the callable object with the reduction operation
1344// omp_in - refers to the local partial result
1345// omp_out - refers to the final value of the combiner operator
1346// omp_priv - refers to the private copy of the initial value
1347// omp_orig - refers to the original variable to be reduced
1348#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
1349      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
1350
1351#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1352
1353#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1354#    define _PSTL_PRAGMA_DECLARE_SIMD
1355#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1356#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1357#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1358#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1359#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1360
1361#  else // (defined(_OPENMP) && _OPENMP >= 201307)
1362
1363#    define _PSTL_PRAGMA_SIMD
1364#    define _PSTL_PRAGMA_DECLARE_SIMD
1365#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1366#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1367#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1368#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1369#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1370
1371#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
1372
1373#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
1374
1375// Optional attributes - these are useful for a better QoI, but not required to be available
1376
1377#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1378#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1379#  else
1380#    define _LIBCPP_NO_CFI
1381#  endif
1382
1383#  if __has_attribute(__malloc__)
1384#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
1385#  else
1386#    define _LIBCPP_NOALIAS
1387#  endif
1388
1389#  if __has_attribute(__using_if_exists__)
1390#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1391#  else
1392#    define _LIBCPP_USING_IF_EXISTS
1393#  endif
1394
1395#  if __has_cpp_attribute(nodiscard)
1396#    define _LIBCPP_NODISCARD [[__nodiscard__]]
1397#  else
1398// We can't use GCC's [[gnu::warn_unused_result]] and
1399// __attribute__((warn_unused_result)), because GCC does not silence them via
1400// (void) cast.
1401#    define _LIBCPP_NODISCARD
1402#  endif
1403
1404// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1405// specified as such as an extension.
1406#  if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1407#    define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
1408#  else
1409#    define _LIBCPP_NODISCARD_EXT
1410#  endif
1411
1412#  if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1413#    define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
1414#  else
1415#    define _LIBCPP_NODISCARD_AFTER_CXX17
1416#  endif
1417
1418#  if __has_attribute(__no_destroy__)
1419#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1420#  else
1421#    define _LIBCPP_NO_DESTROY
1422#  endif
1423
1424#  if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1425#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1426#  else
1427#    define _LIBCPP_DIAGNOSE_WARNING(...)
1428#  endif
1429
1430// Use a function like macro to imply that it must be followed by a semicolon
1431#  if __has_cpp_attribute(fallthrough)
1432#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1433#  elif __has_attribute(__fallthrough__)
1434#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1435#  else
1436#    define _LIBCPP_FALLTHROUGH() ((void)0)
1437#  endif
1438
1439#  if __has_cpp_attribute(_Clang::__lifetimebound__)
1440#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1441#  else
1442#    define _LIBCPP_LIFETIMEBOUND
1443#  endif
1444
1445#  if __has_attribute(__nodebug__)
1446#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1447#  else
1448#    define _LIBCPP_NODEBUG
1449#  endif
1450
1451#  if __has_attribute(__standalone_debug__)
1452#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1453#  else
1454#    define _LIBCPP_STANDALONE_DEBUG
1455#  endif
1456
1457#  if __has_attribute(__preferred_name__)
1458#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1459#  else
1460#    define _LIBCPP_PREFERRED_NAME(x)
1461#  endif
1462
1463#  if __has_attribute(__no_sanitize__)
1464#    define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1465#  else
1466#    define _LIBCPP_NO_SANITIZE(...)
1467#  endif
1468
1469#  if __has_attribute(__init_priority__)
1470#    define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1471#  else
1472#    define _LIBCPP_INIT_PRIORITY_MAX
1473#  endif
1474
1475#  if __has_attribute(__format__)
1476// The attribute uses 1-based indices for ordinary and static member functions.
1477// The attribute uses 2-based indices for non-static member functions.
1478#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
1479      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1480#  else
1481#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1482#  endif
1483
1484#  if __has_attribute(__packed__)
1485#    define _LIBCPP_PACKED __attribute__((__packed__))
1486#  else
1487#    define _LIBCPP_PACKED
1488#  endif
1489
1490#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1491#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1492#  else
1493#    define _LIBCPP_DECLSPEC_EMPTY_BASES
1494#  endif
1495
1496// Allow for build-time disabling of unsigned integer sanitization
1497#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1498#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1499#  else
1500#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1501#  endif
1502
1503#endif // __cplusplus
1504
1505#endif // _LIBCPP___CONFIG
1506