xref: /freebsd/contrib/llvm-project/libcxx/include/__config (revision 36b606ae6aa4b24061096ba18582e0a08ccd5dba)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
1081ad6265SDimitry Andric#ifndef _LIBCPP___CONFIG
1181ad6265SDimitry Andric#define _LIBCPP___CONFIG
120b57cec5SDimitry Andric
13fe6060f1SDimitry Andric#include <__config_site>
140fca6ea1SDimitry Andric#include <__configuration/abi.h>
150fca6ea1SDimitry Andric#include <__configuration/availability.h>
160fca6ea1SDimitry Andric#include <__configuration/compiler.h>
170fca6ea1SDimitry Andric#include <__configuration/platform.h>
18fe6060f1SDimitry Andric
190b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
200b57cec5SDimitry Andric#  pragma GCC system_header
210b57cec5SDimitry Andric#endif
220b57cec5SDimitry Andric
230b57cec5SDimitry Andric#ifdef __cplusplus
240b57cec5SDimitry Andric
2506c3fb27SDimitry Andric// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
2606c3fb27SDimitry Andric
27bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
2806c3fb27SDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
29bdd1243dSDimitry Andric// defined to XXYYZZ.
30*36b606aeSDimitry Andric#  define _LIBCPP_VERSION 190100
310b57cec5SDimitry Andric
32753f127fSDimitry Andric#  define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
33753f127fSDimitry Andric#  define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
34753f127fSDimitry Andric
35e8d8bef9SDimitry Andric#  if __STDC_HOSTED__ == 0
360b57cec5SDimitry Andric#    define _LIBCPP_FREESTANDING
370b57cec5SDimitry Andric#  endif
380b57cec5SDimitry Andric
3906c3fb27SDimitry Andric// HARDENING {
4006c3fb27SDimitry Andric
415f757f3fSDimitry Andric// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
420fca6ea1SDimitry Andric// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20.
435f757f3fSDimitry Andric#  ifdef _LIBCPP_ENABLE_ASSERTIONS
440fca6ea1SDimitry Andric#    warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead"
4506c3fb27SDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
4606c3fb27SDimitry Andric#      error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
4706c3fb27SDimitry Andric#    endif
485f757f3fSDimitry Andric#    if _LIBCPP_ENABLE_ASSERTIONS
495f757f3fSDimitry Andric#      define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
505f757f3fSDimitry Andric#    endif
515f757f3fSDimitry Andric#  endif
5206c3fb27SDimitry Andric
535f757f3fSDimitry Andric// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
548a4dda33SDimitry Andric//
555f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE`;
565f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST`;
575f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
585f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG`.
5906c3fb27SDimitry Andric//
605f757f3fSDimitry Andric// These values have the following effects:
6106c3fb27SDimitry Andric//
625f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
635f757f3fSDimitry Andric//
645f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
655f757f3fSDimitry Andric//   that can be done with relatively little runtime overhead in constant time;
665f757f3fSDimitry Andric//
675f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
685f757f3fSDimitry Andric//   the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
695f757f3fSDimitry Andric//   but are not necessarily security-critical;
705f757f3fSDimitry Andric//
715f757f3fSDimitry Andric// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
725f757f3fSDimitry Andric//   mode and enables all checks available in the library, including internal assertions. Checks that are part of the
735f757f3fSDimitry Andric//   debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
7406c3fb27SDimitry Andric
7506c3fb27SDimitry Andric// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
7606c3fb27SDimitry Andric// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
7706c3fb27SDimitry Andric//
7806c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
7906c3fb27SDimitry Andric//   a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
8006c3fb27SDimitry Andric//   - the sentinel is reachable from the begin iterator;
8106c3fb27SDimitry Andric//   - TODO(hardening): both iterators refer to the same container.
8206c3fb27SDimitry Andric//
8306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
8406c3fb27SDimitry Andric//   the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
8506c3fb27SDimitry Andric//   a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
8606c3fb27SDimitry Andric//   `optional` and `function` are considered one-element containers for the purposes of this check.
8706c3fb27SDimitry Andric//
885f757f3fSDimitry Andric// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
895f757f3fSDimitry Andric//   address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
905f757f3fSDimitry Andric//   memory security of a program (however, it is still undefined behavior that can result in strange errors due to
915f757f3fSDimitry Andric//   compiler optimizations).
925f757f3fSDimitry Andric//
9306c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
9406c3fb27SDimitry Andric//   given ranges do not overlap.
9506c3fb27SDimitry Andric//
967a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
977a6dacacSDimitry Andric//   was allocated by the given allocator). Violating this category typically results in a memory leak.
987a6dacacSDimitry Andric//
997a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
1007a6dacacSDimitry Andric//   an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
1017a6dacacSDimitry Andric//   attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
1027a6dacacSDimitry Andric//   (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
1037a6dacacSDimitry Andric//   otherwise create an immediate security issue.
1047a6dacacSDimitry Andric//
10506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
10606c3fb27SDimitry Andric//   the containers have compatible allocators.
10706c3fb27SDimitry Andric//
1087a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
1097a6dacacSDimitry Andric//   for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
1107a6dacacSDimitry Andric//   original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
1117a6dacacSDimitry Andric//   a string view where only a subset of elements is possible to access). This category is for assertions violating
1127a6dacacSDimitry Andric//   which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
1137a6dacacSDimitry Andric//   user code.
1147a6dacacSDimitry Andric//
1151db9f3b2SDimitry Andric// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
1161db9f3b2SDimitry Andric//   be benign in our implementation.
1171db9f3b2SDimitry Andric//
1187a6dacacSDimitry Andric// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
1197a6dacacSDimitry Andric//   by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
1207a6dacacSDimitry Andric//   thus, this would often be a heuristic check and it might be quite expensive.
1217a6dacacSDimitry Andric//
12206c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
12306c3fb27SDimitry Andric//   user input.
12406c3fb27SDimitry Andric//
12506c3fb27SDimitry Andric// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
12606c3fb27SDimitry Andric
1275f757f3fSDimitry Andric// clang-format off
1285f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_NONE      (1 << 1)
1295f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_FAST      (1 << 2)
1305f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
1315f757f3fSDimitry Andric#  define _LIBCPP_HARDENING_MODE_DEBUG     (1 << 3)
1325f757f3fSDimitry Andric// clang-format on
1335f757f3fSDimitry Andric
1345f757f3fSDimitry Andric#  ifndef _LIBCPP_HARDENING_MODE
1350fca6ea1SDimitry Andric
1360fca6ea1SDimitry Andric#    ifndef _LIBCPP_HARDENING_MODE_DEFAULT
1370fca6ea1SDimitry Andric#      error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
1380fca6ea1SDimitry Andric`__config_site` header, please make sure your installation of libc++ is not broken.
1390fca6ea1SDimitry Andric#    endif
1400fca6ea1SDimitry Andric
1415f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
14206c3fb27SDimitry Andric#  endif
14306c3fb27SDimitry Andric
1445f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE &&                                                         \
1455f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST &&                                                         \
1465f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE &&                                                    \
1475f757f3fSDimitry Andric      _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
1485f757f3fSDimitry Andric#    error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
1495f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_NONE, \
1505f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_FAST, \
1515f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_EXTENSIVE, \
1525f757f3fSDimitry Andric_LIBCPP_HARDENING_MODE_DEBUG
15306c3fb27SDimitry Andric#  endif
15406c3fb27SDimitry Andric
15506c3fb27SDimitry Andric// } HARDENING
15606c3fb27SDimitry Andric
15781ad6265SDimitry Andric#  define _LIBCPP_TOSTRING2(x) #x
15881ad6265SDimitry Andric#  define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
1590b57cec5SDimitry Andric
16006c3fb27SDimitry Andric// NOLINTNEXTLINE(libcpp-cpp-version-check)
1610b57cec5SDimitry Andric#  if __cplusplus < 201103L
1620b57cec5SDimitry Andric#    define _LIBCPP_CXX03_LANG
1630b57cec5SDimitry Andric#  endif
1640b57cec5SDimitry Andric
165bdd1243dSDimitry Andric#  ifndef __has_constexpr_builtin
166bdd1243dSDimitry Andric#    define __has_constexpr_builtin(x) 0
167bdd1243dSDimitry Andric#  endif
168bdd1243dSDimitry Andric
1690fca6ea1SDimitry Andric// This checks wheter a Clang module is built
1700fca6ea1SDimitry Andric#  ifndef __building_module
1710fca6ea1SDimitry Andric#    define __building_module(...) 0
1720fca6ea1SDimitry Andric#  endif
1730fca6ea1SDimitry Andric
1740b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
1750b57cec5SDimitry Andric// the compiler and '1' otherwise.
1760b57cec5SDimitry Andric#  ifndef __is_identifier
1770b57cec5SDimitry Andric#    define __is_identifier(__x) 1
1780b57cec5SDimitry Andric#  endif
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric#  ifndef __has_declspec_attribute
1810b57cec5SDimitry Andric#    define __has_declspec_attribute(__x) 0
1820b57cec5SDimitry Andric#  endif
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric#  define __has_keyword(__x) !(__is_identifier(__x))
1850b57cec5SDimitry Andric
1860fca6ea1SDimitry Andric#  ifndef __has_warning
1870fca6ea1SDimitry Andric#    define __has_warning(...) 0
1880b57cec5SDimitry Andric#  endif
1890b57cec5SDimitry Andric
19081ad6265SDimitry Andric#  if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
19181ad6265SDimitry Andric#    error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
1920b57cec5SDimitry Andric#  endif
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This
1950b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume
1960b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
1970b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this
1980b57cec5SDimitry Andric// heuristic falls short.
1990b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2000b57cec5SDimitry Andric#    error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
2010b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
2020b57cec5SDimitry Andric#    define _LIBCPP_ABI_ITANIUM
2030b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
2040b57cec5SDimitry Andric#    define _LIBCPP_ABI_MICROSOFT
2050b57cec5SDimitry Andric#  else
2060b57cec5SDimitry Andric#    if defined(_WIN32) && defined(_MSC_VER)
2070b57cec5SDimitry Andric#      define _LIBCPP_ABI_MICROSOFT
2080b57cec5SDimitry Andric#    else
2090b57cec5SDimitry Andric#      define _LIBCPP_ABI_ITANIUM
2100b57cec5SDimitry Andric#    endif
2110b57cec5SDimitry Andric#  endif
2120b57cec5SDimitry Andric
2130b57cec5SDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
2140b57cec5SDimitry Andric#    define _LIBCPP_ABI_VCRUNTIME
2150b57cec5SDimitry Andric#  endif
2160b57cec5SDimitry Andric
217fcaf7f86SDimitry Andric#  if __has_feature(experimental_library)
218fcaf7f86SDimitry Andric#    ifndef _LIBCPP_ENABLE_EXPERIMENTAL
219fcaf7f86SDimitry Andric#      define _LIBCPP_ENABLE_EXPERIMENTAL
220fcaf7f86SDimitry Andric#    endif
221fcaf7f86SDimitry Andric#  endif
222fcaf7f86SDimitry Andric
223fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it
224fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete.
225fcaf7f86SDimitry Andric#  if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
22606c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
22706c3fb27SDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
2280fca6ea1SDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB
2295f757f3fSDimitry Andric#    define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
230fcaf7f86SDimitry Andric#  endif
231fcaf7f86SDimitry Andric
23204eeddc0SDimitry Andric#  if defined(__MVS__)
23304eeddc0SDimitry Andric#    include <features.h> // for __NATIVE_ASCII_F
23404eeddc0SDimitry Andric#  endif
23504eeddc0SDimitry Andric
2360b57cec5SDimitry Andric#  if defined(_WIN32)
2370b57cec5SDimitry Andric#    define _LIBCPP_WIN32API
2380b57cec5SDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
2390b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment
2400b57cec5SDimitry Andric#    define _LIBCPP_MSVCRT_LIKE
2410b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if
2420b57cec5SDimitry Andric// a MS compatibility version is specified.
2430b57cec5SDimitry Andric#    if defined(_MSC_VER) && !defined(__MINGW32__)
2440b57cec5SDimitry Andric#      define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
2450b57cec5SDimitry Andric#    endif
2460b57cec5SDimitry Andric#    if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
2470b57cec5SDimitry Andric#      define _LIBCPP_HAS_BITSCAN64
2480b57cec5SDimitry Andric#    endif
2490b57cec5SDimitry Andric#    define _LIBCPP_HAS_OPEN_WITH_WCHAR
2500b57cec5SDimitry Andric#  endif // defined(_WIN32)
2510b57cec5SDimitry Andric
252349cc55cSDimitry Andric#  if defined(_AIX) && !defined(__64BIT__)
253349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX.
254349cc55cSDimitry Andric#    define _LIBCPP_SHORT_WCHAR 1
255349cc55cSDimitry Andric#  endif
256349cc55cSDimitry Andric
2570eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device.
2580eae32dcSDimitry Andric//
2590eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM
2600eae32dcSDimitry Andric//      Read entropy from the given file, by default `/dev/urandom`.
2610eae32dcSDimitry Andric//      If a token is provided, it is assumed to be the path to a file
2620eae32dcSDimitry Andric//      to read entropy from. This is the default behavior if nothing
2630eae32dcSDimitry Andric//      else is specified. This implementation requires storing state
2640eae32dcSDimitry Andric//      inside `std::random_device`.
2650eae32dcSDimitry Andric//
2660eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM
2670eae32dcSDimitry Andric//      Use arc4random(). This allows obtaining random data even when
2680eae32dcSDimitry Andric//      using sandboxing mechanisms. On some platforms like Apple, this
2690eae32dcSDimitry Andric//      is the recommended source of entropy for user-space programs.
2700eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2710eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
2720eae32dcSDimitry Andric//
2730eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY
2740eae32dcSDimitry Andric//      Use getentropy().
2750eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2760eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
2770eae32dcSDimitry Andric//
27804eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG
27904eeddc0SDimitry Andric//      Use Fuchsia's zx_cprng_draw() system call, which is specified to
28004eeddc0SDimitry Andric//      deliver high-quality entropy and cannot fail.
28104eeddc0SDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
28204eeddc0SDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
28304eeddc0SDimitry Andric//
2840eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM
2850eae32dcSDimitry Andric//      NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
2860eae32dcSDimitry Andric//      including accesses to the special files under `/dev`. This implementation
2870eae32dcSDimitry Andric//      uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
2880eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2890eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
2900eae32dcSDimitry Andric//
2910eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM
2920eae32dcSDimitry Andric//      Use rand_s(), for use on Windows.
2930eae32dcSDimitry Andric//      When this option is used, the token passed to `std::random_device`'s
2940eae32dcSDimitry Andric//      constructor *must* be "/dev/urandom" -- anything else is an error.
29581ad6265SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
29606c3fb27SDimitry Andric      defined(__DragonFly__)
2970b57cec5SDimitry Andric#    define _LIBCPP_USING_ARC4_RANDOM
29881ad6265SDimitry Andric#  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
2990b57cec5SDimitry Andric#    define _LIBCPP_USING_GETENTROPY
30004eeddc0SDimitry Andric#  elif defined(__Fuchsia__)
30104eeddc0SDimitry Andric#    define _LIBCPP_USING_FUCHSIA_CPRNG
3020b57cec5SDimitry Andric#  elif defined(__native_client__)
3030b57cec5SDimitry Andric#    define _LIBCPP_USING_NACL_RANDOM
3040b57cec5SDimitry Andric#  elif defined(_LIBCPP_WIN32API)
3050b57cec5SDimitry Andric#    define _LIBCPP_USING_WIN32_RANDOM
3060b57cec5SDimitry Andric#  else
3070b57cec5SDimitry Andric#    define _LIBCPP_USING_DEV_RANDOM
3080b57cec5SDimitry Andric#  endif
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric#  ifndef _LIBCPP_CXX03_LANG
31181ad6265SDimitry Andric
3120b57cec5SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
31381ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) alignas(x)
31481ad6265SDimitry Andric#    define _ALIGNAS(x) alignas(x)
31581ad6265SDimitry Andric#    define _LIBCPP_NORETURN [[noreturn]]
31681ad6265SDimitry Andric#    define _NOEXCEPT noexcept
3170fca6ea1SDimitry Andric#    define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
318bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR constexpr
31981ad6265SDimitry Andric
3200b57cec5SDimitry Andric#  else
32181ad6265SDimitry Andric
32281ad6265SDimitry Andric#    define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
32381ad6265SDimitry Andric#    define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
32481ad6265SDimitry Andric#    define _ALIGNAS(x) __attribute__((__aligned__(x)))
325bdd1243dSDimitry Andric#    define _LIBCPP_NORETURN __attribute__((__noreturn__))
32681ad6265SDimitry Andric#    define _LIBCPP_HAS_NO_NOEXCEPT
32781ad6265SDimitry Andric#    define nullptr __nullptr
32881ad6265SDimitry Andric#    define _NOEXCEPT throw()
3290fca6ea1SDimitry Andric#    define _NOEXCEPT_(...)
330bdd1243dSDimitry Andric#    define static_assert(...) _Static_assert(__VA_ARGS__)
331bdd1243dSDimitry Andric#    define decltype(...) __decltype(__VA_ARGS__)
332bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR
33381ad6265SDimitry Andric
33481ad6265SDimitry Andrictypedef __char16_t char16_t;
33581ad6265SDimitry Andrictypedef __char32_t char32_t;
33681ad6265SDimitry Andric
33781ad6265SDimitry Andric#  endif
33881ad6265SDimitry Andric
3390b57cec5SDimitry Andric#  define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andric// Objective-C++ features (opt-in)
3420b57cec5SDimitry Andric#  if __has_feature(objc_arc)
3430b57cec5SDimitry Andric#    define _LIBCPP_HAS_OBJC_ARC
3440b57cec5SDimitry Andric#  endif
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andric#  if __has_feature(objc_arc_weak)
3470b57cec5SDimitry Andric#    define _LIBCPP_HAS_OBJC_ARC_WEAK
3480b57cec5SDimitry Andric#  endif
3490b57cec5SDimitry Andric
3505ffd83dbSDimitry Andric#  if __has_extension(blocks)
3515ffd83dbSDimitry Andric#    define _LIBCPP_HAS_EXTENSION_BLOCKS
3525ffd83dbSDimitry Andric#  endif
3535ffd83dbSDimitry Andric
3545ffd83dbSDimitry Andric#  if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
3555ffd83dbSDimitry Andric#    define _LIBCPP_HAS_BLOCKS_RUNTIME
3565ffd83dbSDimitry Andric#  endif
3575ffd83dbSDimitry Andric
358fe6060f1SDimitry Andric#  if !__has_feature(address_sanitizer)
3590b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ASAN
3600b57cec5SDimitry Andric#  endif
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andric#  define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
3630b57cec5SDimitry Andric
364e40139ffSDimitry Andric#  define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
365e40139ffSDimitry Andric
3660b57cec5SDimitry Andric#  if defined(_LIBCPP_OBJECT_FORMAT_COFF)
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andric#    ifdef _DLL
3690b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC __declspec(dllimport)
3700b57cec5SDimitry Andric#    else
3710b57cec5SDimitry Andric#      define _LIBCPP_CRT_FUNC
3720b57cec5SDimitry Andric#    endif
3730b57cec5SDimitry Andric
37481ad6265SDimitry Andric#    if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
3750b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS
3760b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
3770b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
3780b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
3790b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI
3800b57cec5SDimitry Andric#    elif defined(_LIBCPP_BUILDING_LIBRARY)
3810b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllexport)
3820b57cec5SDimitry Andric#      if defined(__MINGW32__)
3830b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
3840b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
3850b57cec5SDimitry Andric#      else
3860b57cec5SDimitry Andric#        define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
3870b57cec5SDimitry Andric#        define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
3880b57cec5SDimitry Andric#      endif
3890b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
3900b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
3910b57cec5SDimitry Andric#    else
3920b57cec5SDimitry Andric#      define _LIBCPP_DLL_VIS __declspec(dllimport)
3930b57cec5SDimitry Andric#      define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
3940b57cec5SDimitry Andric#      define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
3950b57cec5SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS
3960b57cec5SDimitry Andric#      define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
3970b57cec5SDimitry Andric#    endif
3980b57cec5SDimitry Andric
3990b57cec5SDimitry Andric#    define _LIBCPP_HIDDEN
4000b57cec5SDimitry Andric#    define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
4010b57cec5SDimitry Andric#    define _LIBCPP_TEMPLATE_VIS
402fe6060f1SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS
4035f757f3fSDimitry Andric#    define _LIBCPP_TYPE_VISIBILITY_DEFAULT
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric#  else
40681ad6265SDimitry Andric
40781ad6265SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
40881ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
40981ad6265SDimitry Andric#    else
41081ad6265SDimitry Andric#      define _LIBCPP_VISIBILITY(vis)
4110b57cec5SDimitry Andric#    endif
4120b57cec5SDimitry Andric
41381ad6265SDimitry Andric#    define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
41481ad6265SDimitry Andric#    define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
41581ad6265SDimitry Andric#    define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
41681ad6265SDimitry Andric#    define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
41781ad6265SDimitry Andric#    define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
41881ad6265SDimitry Andric
419fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it.
420fcaf7f86SDimitry Andric#    ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
421fcaf7f86SDimitry Andric#      define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
422fcaf7f86SDimitry Andric#    endif
423fcaf7f86SDimitry Andric
4240b57cec5SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
4250b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved
4260b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
4270b57cec5SDimitry Andric#    else
4280b57cec5SDimitry Andric#      define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
4290b57cec5SDimitry Andric#    endif
4300b57cec5SDimitry Andric
4315f757f3fSDimitry Andric// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
4325f757f3fSDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
4330b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
4340b57cec5SDimitry Andric#    else
4350b57cec5SDimitry Andric#      define _LIBCPP_TEMPLATE_VIS
4360b57cec5SDimitry Andric#    endif
4370b57cec5SDimitry Andric
43846c59ea9SDimitry Andric#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) && \
43946c59ea9SDimitry Andric        _LIBCPP_CLANG_VER >= 1500 // FreeBSD customization
4405f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
4410b57cec5SDimitry Andric#    else
4425f757f3fSDimitry Andric#      define _LIBCPP_TYPE_VISIBILITY_DEFAULT
4430b57cec5SDimitry Andric#    endif
4440b57cec5SDimitry Andric
44581ad6265SDimitry Andric#  endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
4460b57cec5SDimitry Andric
4470b57cec5SDimitry Andric#  if __has_attribute(exclude_from_explicit_instantiation)
4480b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
4490b57cec5SDimitry Andric#  else
4500b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation
4510b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit
4520b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities.
4530b57cec5SDimitry Andric#    define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
4540b57cec5SDimitry Andric#  endif
4550b57cec5SDimitry Andric
4560fca6ea1SDimitry Andric#  ifdef _LIBCPP_COMPILER_CLANG_BASED
4570fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
4580fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
4590fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
4600fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
4610fca6ea1SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
4620fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
4630fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
4640fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
4650fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
4660fca6ea1SDimitry Andric#  else
4670fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_PUSH
4680fca6ea1SDimitry Andric#    define _LIBCPP_DIAGNOSTIC_POP
4690fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
4700fca6ea1SDimitry Andric#    define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
4710fca6ea1SDimitry Andric#  endif
4720fca6ea1SDimitry Andric
4735f757f3fSDimitry Andric#  if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
4745f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG f
4755f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
476b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG s
4775f757f3fSDimitry Andric#  elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
478b121cb00SDimitry Andric#    define _LIBCPP_HARDENING_SIG d
479b121cb00SDimitry Andric#  else
4805f757f3fSDimitry Andric#    define _LIBCPP_HARDENING_SIG n // "none"
481b121cb00SDimitry Andric#  endif
482b121cb00SDimitry Andric
483b121cb00SDimitry Andric#  ifdef _LIBCPP_HAS_NO_EXCEPTIONS
484b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG n
485b121cb00SDimitry Andric#  else
486b121cb00SDimitry Andric#    define _LIBCPP_EXCEPTIONS_SIG e
487b121cb00SDimitry Andric#  endif
488b121cb00SDimitry Andric
489b121cb00SDimitry Andric#  define _LIBCPP_ODR_SIGNATURE                                                                                        \
490b121cb00SDimitry Andric    _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
491b121cb00SDimitry Andric
492753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
493753f127fSDimitry Andric// on two levels:
494753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
495753f127fSDimitry Andric//    symbols from their dynamic library by means of using the libc++ headers. This ensures
496753f127fSDimitry Andric//    that those symbols stay private to the dynamic library in which it is defined.
497753f127fSDimitry Andric//
498b121cb00SDimitry Andric// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
499b121cb00SDimitry Andric//    This ensures that no ODR violation can arise from mixing two TUs compiled with different
500b121cb00SDimitry Andric//    versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
501b121cb00SDimitry Andric//    program contains two definitions of a function, the ODR requires them to be token-by-token
502b121cb00SDimitry Andric//    equivalent, and the linker is allowed to pick either definition and discard the other one.
503b121cb00SDimitry Andric//
504b121cb00SDimitry Andric//    For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
505b121cb00SDimitry Andric//    *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
506b121cb00SDimitry Andric//    compiled with different settings), the two definitions are both visible by the linker and they
507b121cb00SDimitry Andric//    have the same name, but they have a meaningfully different implementation (one throws an exception
508b121cb00SDimitry Andric//    and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
509b121cb00SDimitry Andric//    practice what will happen is that the linker will pick one of the definitions at random and will
510b121cb00SDimitry Andric//    discard the other one. This can quite clearly lead to incorrect program behavior.
511b121cb00SDimitry Andric//
512b121cb00SDimitry Andric//    A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
513b121cb00SDimitry Andric//    property that causes the code of a function to differ from the code in another configuration
514b121cb00SDimitry Andric//    can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
515b121cb00SDimitry Andric//    tag, but we encode the ones that we think are most important: library version, exceptions, and
516b121cb00SDimitry Andric//    hardening mode.
517b121cb00SDimitry Andric//
518b121cb00SDimitry Andric//    Note that historically, solving this problem has been achieved in various ways, including
519b121cb00SDimitry Andric//    force-inlining all functions or giving internal linkage to all functions. Both these previous
520b121cb00SDimitry Andric//    solutions suffer from drawbacks that lead notably to code bloat.
521753f127fSDimitry Andric//
522753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
523753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
524753f127fSDimitry Andric//
525bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
526bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
527bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
528bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since
529bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual
530bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change
531bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place,
532bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
533bdd1243dSDimitry Andric//
5340fca6ea1SDimitry Andric// The macro can be applied to record and enum types. When the tagged type is nested in
5350fca6ea1SDimitry Andric// a record this "parent" record needs to have the macro too. Another use case for applying
5360fca6ea1SDimitry Andric// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
5370fca6ea1SDimitry Andric// This can be useful for inline variables that are implementation details which are expected
5380fca6ea1SDimitry Andric// to change in the future.
5390fca6ea1SDimitry Andric//
540753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
541753f127fSDimitry Andric//       the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
542753f127fSDimitry Andric//       use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
543753f127fSDimitry Andric#  ifndef _LIBCPP_NO_ABI_TAG
544753f127fSDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI                                                                                      \
545753f127fSDimitry Andric      _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION                                                       \
546b121cb00SDimitry Andric      __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
5470b57cec5SDimitry Andric#  else
5480b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
5490b57cec5SDimitry Andric#  endif
550bdd1243dSDimitry Andric#  define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric#  ifdef _LIBCPP_BUILDING_LIBRARY
5530b57cec5SDimitry Andric#    if _LIBCPP_ABI_VERSION > 1
5540b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
5550b57cec5SDimitry Andric#    else
5560b57cec5SDimitry Andric#      define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
5570b57cec5SDimitry Andric#    endif
5580b57cec5SDimitry Andric#  else
5590b57cec5SDimitry Andric#    define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
5600b57cec5SDimitry Andric#  endif
5610b57cec5SDimitry Andric
5620fca6ea1SDimitry Andric// TODO: Remove this workaround once we drop support for Clang 16
5630fca6ea1SDimitry Andric#  if __has_warning("-Wc++23-extensions")
5640fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
5650fca6ea1SDimitry Andric#  else
5660fca6ea1SDimitry Andric#    define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
5670fca6ea1SDimitry Andric#  endif
5680fca6ea1SDimitry Andric
5690fca6ea1SDimitry Andric// Clang modules take a significant compile time hit when pushing and popping diagnostics.
5700fca6ea1SDimitry Andric// Since all the headers are marked as system headers in the modulemap, we can simply disable this
5710fca6ea1SDimitry Andric// pushing and popping when building with clang modules.
5720fca6ea1SDimitry Andric#  if !__has_feature(modules)
5730fca6ea1SDimitry Andric#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS                                                                         \
5740fca6ea1SDimitry Andric      _LIBCPP_DIAGNOSTIC_PUSH                                                                                          \
5750fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions")                                                           \
5760fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                           \
5770fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                           \
5780fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                           \
5790fca6ea1SDimitry Andric      _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION                                                                 \
5800fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions")                                                             \
5810fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions")                                                             \
5820fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions")                                                             \
5830fca6ea1SDimitry Andric      _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
5840fca6ea1SDimitry Andric#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
5850fca6ea1SDimitry Andric#  else
5860fca6ea1SDimitry Andric#    define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
5870fca6ea1SDimitry Andric#    define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
5880fca6ea1SDimitry Andric#  endif
5890b57cec5SDimitry Andric
5900b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
59181ad6265SDimitry Andric// clang-format off
5920fca6ea1SDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS                                               \
5930fca6ea1SDimitry Andric                                      namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {                                  \
5945f757f3fSDimitry Andric                               inline namespace _LIBCPP_ABI_NAMESPACE {
5950fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
59681ad6265SDimitry Andric
5970fca6ea1SDimitry Andric#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
5980fca6ea1SDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
5990fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
6000fca6ea1SDimitry Andric#else
6015f757f3fSDimitry Andric#  define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD                                               \
6025f757f3fSDimitry Andric                                             inline namespace __fs { namespace filesystem {
6030b57cec5SDimitry Andric
6040fca6ea1SDimitry Andric#  define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
6050fca6ea1SDimitry Andric#endif
6060fca6ea1SDimitry Andric
60781ad6265SDimitry Andric// clang-format on
6080b57cec5SDimitry Andric
6090b57cec5SDimitry Andric#  if __has_attribute(__enable_if__)
6100b57cec5SDimitry Andric#    define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
6110b57cec5SDimitry Andric#  endif
6120b57cec5SDimitry Andric
61306c3fb27SDimitry Andric#  if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
6140b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_INT128
6150b57cec5SDimitry Andric#  endif
6160b57cec5SDimitry Andric
61781ad6265SDimitry Andric#  ifdef _LIBCPP_CXX03_LANG
61881ad6265SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x)                                                                             \
61906c3fb27SDimitry Andric      struct _LIBCPP_EXPORTED_FROM_ABI x {                                                                             \
62081ad6265SDimitry Andric        enum __lx
62181ad6265SDimitry Andric// clang-format off
6220b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)                                                                      \
6230b57cec5SDimitry Andric      __lx __v_;                                                                                                       \
6245f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {}                                                                 \
6255f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {}                                      \
6265f757f3fSDimitry Andric      _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; }                                                      \
6270b57cec5SDimitry Andric      };
62881ad6265SDimitry Andric// clang-format on
62981ad6265SDimitry Andric
63081ad6265SDimitry Andric#  else // _LIBCPP_CXX03_LANG
6315f757f3fSDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
6320b57cec5SDimitry Andric#    define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
63381ad6265SDimitry Andric#  endif // _LIBCPP_CXX03_LANG
6340b57cec5SDimitry Andric
63506c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
6360b57cec5SDimitry Andric#    define _LIBCPP_LOCALE__L_EXTENSIONS 1
6370b57cec5SDimitry Andric#  endif
6380b57cec5SDimitry Andric
6390b57cec5SDimitry Andric#  ifdef __FreeBSD__
6400b57cec5SDimitry Andric#    define _DECLARE_C99_LDBL_MATH 1
6410b57cec5SDimitry Andric#  endif
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads
6440b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
6450b57cec5SDimitry Andric#  if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
6460b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
6470b57cec5SDimitry Andric#  elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
6480b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't
6490b57cec5SDimitry Andric// have it unless the language feature test macro is defined.
6500b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
651e8d8bef9SDimitry Andric#  elif defined(__MVS__)
652e8d8bef9SDimitry Andric#    define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
6530b57cec5SDimitry Andric#  endif
6540b57cec5SDimitry Andric
65581ad6265SDimitry Andric#  if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
6560b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
6570b57cec5SDimitry Andric#  endif
6580b57cec5SDimitry Andric
659bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since
660bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc().
661bdd1243dSDimitry Andric#  if defined(__APPLE__)
662bdd1243dSDimitry Andric#    if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) &&                                                     \
663bdd1243dSDimitry Andric         __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
664bdd1243dSDimitry Andric#      define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
665bdd1243dSDimitry Andric#    endif
666bdd1243dSDimitry Andric#  elif defined(__ANDROID__) && __ANDROID_API__ < 28
667bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher.
668bdd1243dSDimitry Andric#    define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
669bdd1243dSDimitry Andric#  endif
670bdd1243dSDimitry Andric
6710b57cec5SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
6720b57cec5SDimitry Andric#    define _LIBCPP_HAS_DEFAULTRUNELOCALE
6730b57cec5SDimitry Andric#  endif
6740b57cec5SDimitry Andric
67506c3fb27SDimitry Andric#  if defined(__APPLE__) || defined(__FreeBSD__)
6760b57cec5SDimitry Andric#    define _LIBCPP_WCTYPE_IS_MASK
6770b57cec5SDimitry Andric#  endif
6780b57cec5SDimitry Andric
6790b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
680fe6060f1SDimitry Andric#    define _LIBCPP_HAS_NO_CHAR8_T
6810b57cec5SDimitry Andric#  endif
6820b57cec5SDimitry Andric
6830b57cec5SDimitry Andric// Deprecation macros.
6840b57cec5SDimitry Andric//
6850b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out
6860b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
6870b57cec5SDimitry Andric#  if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
68806c3fb27SDimitry Andric#    if __has_attribute(__deprecated__)
68906c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
69006c3fb27SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
69106c3fb27SDimitry Andric#    elif _LIBCPP_STD_VER >= 14
6920b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED [[deprecated]]
69381ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
6940b57cec5SDimitry Andric#    else
6950b57cec5SDimitry Andric#      define _LIBCPP_DEPRECATED
69681ad6265SDimitry Andric#      define _LIBCPP_DEPRECATED_(m)
6970b57cec5SDimitry Andric#    endif
6980b57cec5SDimitry Andric#  else
6990b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED
70081ad6265SDimitry Andric#    define _LIBCPP_DEPRECATED_(m)
7010b57cec5SDimitry Andric#  endif
7020b57cec5SDimitry Andric
7030fca6ea1SDimitry Andric#  if _LIBCPP_STD_VER < 20
7040fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_ATOMIC_SYNC                                                                             \
7050fca6ea1SDimitry Andric      _LIBCPP_DEPRECATED_("The C++20 synchronization library has been deprecated prior to C++20. Please update to "    \
7060fca6ea1SDimitry Andric                          "using -std=c++20 if you need to use these facilities.")
7070fca6ea1SDimitry Andric#  else
7080fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */
7090fca6ea1SDimitry Andric#  endif
7100fca6ea1SDimitry Andric
7110b57cec5SDimitry Andric#  if !defined(_LIBCPP_CXX03_LANG)
7120b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
7130b57cec5SDimitry Andric#  else
7140b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX11
7150b57cec5SDimitry Andric#  endif
7160b57cec5SDimitry Andric
71706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
7180b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
7190b57cec5SDimitry Andric#  else
7200b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX14
7210b57cec5SDimitry Andric#  endif
7220b57cec5SDimitry Andric
72306c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
7240b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
7250b57cec5SDimitry Andric#  else
7260b57cec5SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX17
7270b57cec5SDimitry Andric#  endif
7280b57cec5SDimitry Andric
72906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
730e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
731e8d8bef9SDimitry Andric#  else
732e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX20
733e8d8bef9SDimitry Andric#  endif
734e8d8bef9SDimitry Andric
735bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 23
736bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
737bdd1243dSDimitry Andric#  else
738bdd1243dSDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX23
739bdd1243dSDimitry Andric#  endif
740bdd1243dSDimitry Andric
7410fca6ea1SDimitry Andric#  if _LIBCPP_STD_VER >= 26
7420fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
7430fca6ea1SDimitry Andric#  else
7440fca6ea1SDimitry Andric#    define _LIBCPP_DEPRECATED_IN_CXX26
7450fca6ea1SDimitry Andric#  endif
7460fca6ea1SDimitry Andric
747fe6060f1SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_CHAR8_T)
748e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
749e8d8bef9SDimitry Andric#  else
750e8d8bef9SDimitry Andric#    define _LIBCPP_DEPRECATED_WITH_CHAR8_T
751e8d8bef9SDimitry Andric#  endif
752e8d8bef9SDimitry Andric
753e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed.
754fe6060f1SDimitry Andric#  if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
755e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH                                                                           \
75681ad6265SDimitry Andric      _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")                                \
757fe6060f1SDimitry Andric          _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
75881ad6265SDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
759fe6060f1SDimitry Andric#  else
760e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
761e40139ffSDimitry Andric#    define _LIBCPP_SUPPRESS_DEPRECATED_POP
762e40139ffSDimitry Andric#  endif
763e40139ffSDimitry Andric
7640b57cec5SDimitry Andric#  if _LIBCPP_STD_VER <= 11
76506c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14
7660b57cec5SDimitry Andric#  else
76706c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
7680b57cec5SDimitry Andric#  endif
7690b57cec5SDimitry Andric
77006c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
77106c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
77206c3fb27SDimitry Andric#  else
77306c3fb27SDimitry Andric#    define _LIBCPP_EXPLICIT_SINCE_CXX23
77406c3fb27SDimitry Andric#  endif
77506c3fb27SDimitry Andric
77606c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
777bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
7780b57cec5SDimitry Andric#  else
779bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX14
7800b57cec5SDimitry Andric#  endif
7810b57cec5SDimitry Andric
78206c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
783bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
7840b57cec5SDimitry Andric#  else
785bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX17
7860b57cec5SDimitry Andric#  endif
7870b57cec5SDimitry Andric
78806c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
789bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
7900b57cec5SDimitry Andric#  else
791bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX20
7920b57cec5SDimitry Andric#  endif
7930b57cec5SDimitry Andric
79406c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 23
795bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
796bdd1243dSDimitry Andric#  else
797bdd1243dSDimitry Andric#    define _LIBCPP_CONSTEXPR_SINCE_CXX23
798bdd1243dSDimitry Andric#  endif
799bdd1243dSDimitry Andric
8000b57cec5SDimitry Andric#  ifndef _LIBCPP_WEAK
8010b57cec5SDimitry Andric#    define _LIBCPP_WEAK __attribute__((__weak__))
8020b57cec5SDimitry Andric#  endif
8030b57cec5SDimitry Andric
8040b57cec5SDimitry Andric// Thread API
80581ad6265SDimitry Andric// clang-format off
8060b57cec5SDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) &&                                                                              \
8070b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) &&                                                                      \
8080b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_WIN32) &&                                                                        \
8090b57cec5SDimitry Andric      !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
81081ad6265SDimitry Andric
8110b57cec5SDimitry Andric#    if defined(__FreeBSD__) ||                                                                                        \
8120b57cec5SDimitry Andric        defined(__wasi__) ||                                                                                           \
8130b57cec5SDimitry Andric        defined(__NetBSD__) ||                                                                                         \
814e8d8bef9SDimitry Andric        defined(__OpenBSD__) ||                                                                                        \
815e8d8bef9SDimitry Andric        defined(__NuttX__) ||                                                                                          \
8160b57cec5SDimitry Andric        defined(__linux__) ||                                                                                          \
8170b57cec5SDimitry Andric        defined(__GNU__) ||                                                                                            \
8180b57cec5SDimitry Andric        defined(__APPLE__) ||                                                                                          \
819e8d8bef9SDimitry Andric        defined(__MVS__) ||                                                                                            \
82081ad6265SDimitry Andric        defined(_AIX) ||                                                                                               \
82181ad6265SDimitry Andric        defined(__EMSCRIPTEN__)
82281ad6265SDimitry Andric// clang-format on
8230b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
824480093f4SDimitry Andric#    elif defined(__Fuchsia__)
8255ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible.
8265ffd83dbSDimitry Andric#      define _LIBCPP_HAS_THREAD_API_PTHREAD
8270b57cec5SDimitry Andric#    elif defined(_LIBCPP_WIN32API)
8280b57cec5SDimitry Andric#      define _LIBCPP_HAS_THREAD_API_WIN32
8290b57cec5SDimitry Andric#    else
8300b57cec5SDimitry Andric#      error "No thread API"
8310b57cec5SDimitry Andric#    endif // _LIBCPP_HAS_THREAD_API
8320b57cec5SDimitry Andric#  endif   // _LIBCPP_HAS_NO_THREADS
8330b57cec5SDimitry Andric
834e40139ffSDimitry Andric#  if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
835e40139ffSDimitry Andric#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
836e40139ffSDimitry Andric#      define _LIBCPP_HAS_COND_CLOCKWAIT
837e40139ffSDimitry Andric#    elif defined(_LIBCPP_GLIBC_PREREQ)
838e40139ffSDimitry Andric#      if _LIBCPP_GLIBC_PREREQ(2, 30)
839e40139ffSDimitry Andric#        define _LIBCPP_HAS_COND_CLOCKWAIT
840e40139ffSDimitry Andric#      endif
841e40139ffSDimitry Andric#    endif
842e40139ffSDimitry Andric#  endif
843e40139ffSDimitry Andric
8440b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
8450b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
8460b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is not defined.
8470b57cec5SDimitry Andric#  endif
8480b57cec5SDimitry Andric
8490b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
8500b57cec5SDimitry Andric#    error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
8510b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
8520b57cec5SDimitry Andric#  endif
8530b57cec5SDimitry Andric
8540b57cec5SDimitry Andric#  if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
8550b57cec5SDimitry Andric#    error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
8560b57cec5SDimitry Andric       _LIBCPP_HAS_NO_THREADS is defined.
8570b57cec5SDimitry Andric#  endif
8580b57cec5SDimitry Andric
859e40139ffSDimitry Andric#  if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
860e40139ffSDimitry Andric#    define __STDCPP_THREADS__ 1
861e40139ffSDimitry Andric#  endif
862e40139ffSDimitry Andric
863e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements
8640b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
8650b57cec5SDimitry Andric// mutexes have no destroy mechanism.
866e40139ffSDimitry Andric//
867e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
868e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources.
869e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
870e40139ffSDimitry Andric//
871e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their
872e40139ffSDimitry Andric//               respective stakeholders.
87381ad6265SDimitry Andric// clang-format off
87481ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) ||                                               \
87581ad6265SDimitry Andric      (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) ||                                                 \
87681ad6265SDimitry Andric       defined(_LIBCPP_HAS_THREAD_API_WIN32)
87781ad6265SDimitry Andric// clang-format on
8780b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
8790b57cec5SDimitry Andric#  endif
8800b57cec5SDimitry Andric
8810b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows.
882e40139ffSDimitry Andric//
883e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where
884e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources.
885e40139ffSDimitry Andric// See https://llvm.org/D64298 for details.
886e40139ffSDimitry Andric//
8870b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations
8880b57cec5SDimitry Andric// as well.
88981ad6265SDimitry Andric#  if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
8900b57cec5SDimitry Andric#    define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
8910b57cec5SDimitry Andric#  endif
8920b57cec5SDimitry Andric
89381ad6265SDimitry Andric#  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
89404eeddc0SDimitry Andric      defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
8950b57cec5SDimitry Andric#    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
8960b57cec5SDimitry Andric#  endif
8970b57cec5SDimitry Andric
8980b57cec5SDimitry Andric#  if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
8990b57cec5SDimitry Andric#    define _LIBCPP_HAS_C_ATOMIC_IMP
9000b57cec5SDimitry Andric#  elif defined(_LIBCPP_COMPILER_GCC)
9010b57cec5SDimitry Andric#    define _LIBCPP_HAS_GCC_ATOMIC_IMP
9020b57cec5SDimitry Andric#  endif
9030b57cec5SDimitry Andric
90481ad6265SDimitry Andric#  if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) &&                                    \
905349cc55cSDimitry Andric      !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
9060b57cec5SDimitry Andric#    define _LIBCPP_HAS_NO_ATOMIC_HEADER
9070b57cec5SDimitry Andric#  else
9080b57cec5SDimitry Andric#    ifndef _LIBCPP_ATOMIC_FLAG_TYPE
9090b57cec5SDimitry Andric#      define _LIBCPP_ATOMIC_FLAG_TYPE bool
9100b57cec5SDimitry Andric#    endif
9110b57cec5SDimitry Andric#  endif
9120b57cec5SDimitry Andric
91306c3fb27SDimitry Andric#  if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
91406c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
91506c3fb27SDimitry Andric#  else
91606c3fb27SDimitry Andric#    define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
91706c3fb27SDimitry Andric#  endif
91806c3fb27SDimitry Andric
9190b57cec5SDimitry Andric#  if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
9200b57cec5SDimitry Andric#    if defined(__clang__) && __has_attribute(acquire_capability)
9210b57cec5SDimitry Andric// Work around the attribute handling in clang.  When both __declspec and
9220b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition
9231fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
9241fd87a68SDimitry Andric// combining the two does work.
9251fd87a68SDimitry Andric#      if !defined(_MSC_VER)
9260b57cec5SDimitry Andric#        define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
9270b57cec5SDimitry Andric#      endif
9280b57cec5SDimitry Andric#    endif
9290b57cec5SDimitry Andric#  endif
9300b57cec5SDimitry Andric
931480093f4SDimitry Andric#  ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
932480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
933480093f4SDimitry Andric#  else
934480093f4SDimitry Andric#    define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
935480093f4SDimitry Andric#  endif
936480093f4SDimitry Andric
93706c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 20
93881ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT constinit
939bdd1243dSDimitry Andric#  elif __has_attribute(__require_constant_initialization__)
94081ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
9410b57cec5SDimitry Andric#  else
94281ad6265SDimitry Andric#    define _LIBCPP_CONSTINIT
9430b57cec5SDimitry Andric#  endif
9440b57cec5SDimitry Andric
9457a6dacacSDimitry Andric#  if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
9467a6dacacSDimitry Andric// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
9477a6dacacSDimitry Andric// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
9487a6dacacSDimitry Andric// when compiling for CUDA we use the non-underscored version of the noinline
9497a6dacacSDimitry Andric// attribute.
9507a6dacacSDimitry Andric//
9517a6dacacSDimitry Andric// This is a temporary workaround and we still expect the CUDA SDK team to solve
9527a6dacacSDimitry Andric// this issue properly in the SDK headers.
9537a6dacacSDimitry Andric//
9547a6dacacSDimitry Andric// See https://github.com/llvm/llvm-project/pull/73838 for more details.
9557a6dacacSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((noinline))
9567a6dacacSDimitry Andric#  elif __has_attribute(__noinline__)
9575f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE __attribute__((__noinline__))
9580b57cec5SDimitry Andric#  else
9595f757f3fSDimitry Andric#    define _LIBCPP_NOINLINE
96006c3fb27SDimitry Andric#  endif
96106c3fb27SDimitry Andric
962349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library.
963349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of
964349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger
965349cc55cSDimitry Andric// impact on readability.
966349cc55cSDimitry Andric#  if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
967349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...)
968349cc55cSDimitry Andric#  else
969349cc55cSDimitry Andric#    define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
970349cc55cSDimitry Andric#  endif
971349cc55cSDimitry Andric
97206c3fb27SDimitry Andric// clang-format off
973b3edf446SDimitry Andric#  define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
974b3edf446SDimitry Andric#  define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
97506c3fb27SDimitry Andric// clang-format on
9760b57cec5SDimitry Andric
9770b57cec5SDimitry Andric#  ifndef _LIBCPP_NO_AUTO_LINK
9780b57cec5SDimitry Andric#    if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
979fe6060f1SDimitry Andric#      if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
9800b57cec5SDimitry Andric#        pragma comment(lib, "c++.lib")
9810b57cec5SDimitry Andric#      else
9820b57cec5SDimitry Andric#        pragma comment(lib, "libc++.lib")
9830b57cec5SDimitry Andric#      endif
9840b57cec5SDimitry Andric#    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
9850b57cec5SDimitry Andric#  endif   // _LIBCPP_NO_AUTO_LINK
9860b57cec5SDimitry Andric
987e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will
988e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen.
989e40139ffSDimitry Andric//
990e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that
991e40139ffSDimitry Andric// do.
992e40139ffSDimitry Andric#  if defined(__BIONIC__)
993e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
994e40139ffSDimitry Andric#  else
995e40139ffSDimitry Andric#    define _LIBCPP_FOPEN_CLOEXEC_MODE
996e40139ffSDimitry Andric#  endif
997e40139ffSDimitry Andric
99881ad6265SDimitry Andric#  if __has_cpp_attribute(msvc::no_unique_address)
99981ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently.
100081ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
100181ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what
100281ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general.
100381ad6265SDimitry Andric
100481ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
100581ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement
100681ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though.
100781ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
100881ad6265SDimitry Andric#  elif __has_cpp_attribute(no_unique_address)
100906c3fb27SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
101081ad6265SDimitry Andric#  else
101181ad6265SDimitry Andric#    define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
101281ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl
101381ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20
101481ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point.
101581ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code,
101681ad6265SDimitry Andric// because using it conditionally in one language version only would make
101781ad6265SDimitry Andric// the ABI inconsistent.
101881ad6265SDimitry Andric#  endif
101981ad6265SDimitry Andric
1020bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1021bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions
1022bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these
1023bdd1243dSDimitry Andric// functions are declared by the C library.
1024bdd1243dSDimitry Andric#  define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1025bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
10261ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
10271ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate
10281ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not
10291ac55f4cSDimitry Andric// defined are ignored.
10301ac55f4cSDimitry Andric#  if defined(_LIBCPP_GLIBC_PREREQ)
10311ac55f4cSDimitry Andric#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
1032bdd1243dSDimitry Andric#      undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1033bdd1243dSDimitry Andric#    endif
1034bdd1243dSDimitry Andric#  endif
1035bdd1243dSDimitry Andric
1036bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to
1037bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This
1038bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the
1039bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1040bdd1243dSDimitry Andric// with these classes.
1041bdd1243dSDimitry Andric#  if _LIBCPP_STD_VER >= 17
104206c3fb27SDimitry Andric#    ifdef _LIBCPP_COMPILER_CLANG_BASED
1043bdd1243dSDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName)                                                              \
1044bdd1243dSDimitry Andric        template <class... _Tag>                                                                                       \
104506c3fb27SDimitry Andric        [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
104606c3fb27SDimitry Andric#    else
104706c3fb27SDimitry Andric#      define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName)                                                               \
104806c3fb27SDimitry Andric        template <class... _Tag>                                                                                       \
104906c3fb27SDimitry Andric        ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
105006c3fb27SDimitry Andric#    endif
1051bdd1243dSDimitry Andric#  else
1052bdd1243dSDimitry Andric#    define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1053bdd1243dSDimitry Andric#  endif
1054bdd1243dSDimitry Andric
10551ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
10561ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode.
10571ac55f4cSDimitry Andric#  ifdef __OBJC__
10581ac55f4cSDimitry Andric#    define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
10591ac55f4cSDimitry Andric#  endif
10601ac55f4cSDimitry Andric
106106c3fb27SDimitry Andric#  define _PSTL_PRAGMA(x) _Pragma(#x)
106206c3fb27SDimitry Andric
106306c3fb27SDimitry Andric// Enable SIMD for compilers that support OpenMP 4.0
106406c3fb27SDimitry Andric#  if (defined(_OPENMP) && _OPENMP >= 201307)
106506c3fb27SDimitry Andric
106606c3fb27SDimitry Andric#    define _PSTL_UDR_PRESENT
106706c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
106806c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
106906c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
107006c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
107106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
107206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
107306c3fb27SDimitry Andric
107406c3fb27SDimitry Andric// Declaration of reduction functor, where
107506c3fb27SDimitry Andric// NAME - the name of the functor
107606c3fb27SDimitry Andric// OP - type of the callable object with the reduction operation
107706c3fb27SDimitry Andric// omp_in - refers to the local partial result
107806c3fb27SDimitry Andric// omp_out - refers to the final value of the combiner operator
107906c3fb27SDimitry Andric// omp_priv - refers to the private copy of the initial value
108006c3fb27SDimitry Andric// omp_orig - refers to the original variable to be reduced
108106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                   \
108206c3fb27SDimitry Andric      _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
108306c3fb27SDimitry Andric
10845f757f3fSDimitry Andric#  elif defined(_LIBCPP_COMPILER_CLANG_BASED)
10855f757f3fSDimitry Andric
10865f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
10875f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
10885f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
10895f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
10905f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
10915f757f3fSDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
10925f757f3fSDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
10935f757f3fSDimitry Andric
109406c3fb27SDimitry Andric#  else // (defined(_OPENMP) && _OPENMP >= 201307)
109506c3fb27SDimitry Andric
109606c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD
109706c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_SIMD
109806c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
109906c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_SCAN(PRM)
110006c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
110106c3fb27SDimitry Andric#    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
110206c3fb27SDimitry Andric#    define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
110306c3fb27SDimitry Andric
110406c3fb27SDimitry Andric#  endif // (defined(_OPENMP) && _OPENMP >= 201307)
110506c3fb27SDimitry Andric
110606c3fb27SDimitry Andric#  define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
110706c3fb27SDimitry Andric
11085f757f3fSDimitry Andric// Optional attributes - these are useful for a better QoI, but not required to be available
11095f757f3fSDimitry Andric
11105f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
11115f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
11125f757f3fSDimitry Andric#  else
11135f757f3fSDimitry Andric#    define _LIBCPP_NO_CFI
11145f757f3fSDimitry Andric#  endif
11155f757f3fSDimitry Andric
11165f757f3fSDimitry Andric#  if __has_attribute(__malloc__)
11175f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS __attribute__((__malloc__))
11185f757f3fSDimitry Andric#  else
11195f757f3fSDimitry Andric#    define _LIBCPP_NOALIAS
11205f757f3fSDimitry Andric#  endif
11215f757f3fSDimitry Andric
11225f757f3fSDimitry Andric#  if __has_attribute(__using_if_exists__)
11235f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
11245f757f3fSDimitry Andric#  else
11255f757f3fSDimitry Andric#    define _LIBCPP_USING_IF_EXISTS
11265f757f3fSDimitry Andric#  endif
11275f757f3fSDimitry Andric
11280fca6ea1SDimitry Andric#  if __has_cpp_attribute(__nodiscard__)
11295f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD [[__nodiscard__]]
11305f757f3fSDimitry Andric#  else
11315f757f3fSDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and
11325f757f3fSDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via
11335f757f3fSDimitry Andric// (void) cast.
11345f757f3fSDimitry Andric#    define _LIBCPP_NODISCARD
11355f757f3fSDimitry Andric#  endif
11365f757f3fSDimitry Andric
11375f757f3fSDimitry Andric#  if __has_attribute(__no_destroy__)
11385f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
11395f757f3fSDimitry Andric#  else
11405f757f3fSDimitry Andric#    define _LIBCPP_NO_DESTROY
11415f757f3fSDimitry Andric#  endif
11425f757f3fSDimitry Andric
11430fca6ea1SDimitry Andric#  if __has_attribute(__diagnose_if__)
11445f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
11455f757f3fSDimitry Andric#  else
11465f757f3fSDimitry Andric#    define _LIBCPP_DIAGNOSE_WARNING(...)
11475f757f3fSDimitry Andric#  endif
11485f757f3fSDimitry Andric
11495f757f3fSDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon
11505f757f3fSDimitry Andric#  if __has_cpp_attribute(fallthrough)
11515f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() [[fallthrough]]
11525f757f3fSDimitry Andric#  elif __has_attribute(__fallthrough__)
11535f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
11545f757f3fSDimitry Andric#  else
11555f757f3fSDimitry Andric#    define _LIBCPP_FALLTHROUGH() ((void)0)
11565f757f3fSDimitry Andric#  endif
11575f757f3fSDimitry Andric
11585f757f3fSDimitry Andric#  if __has_cpp_attribute(_Clang::__lifetimebound__)
11595f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
11605f757f3fSDimitry Andric#  else
11615f757f3fSDimitry Andric#    define _LIBCPP_LIFETIMEBOUND
11625f757f3fSDimitry Andric#  endif
11635f757f3fSDimitry Andric
11645f757f3fSDimitry Andric#  if __has_attribute(__nodebug__)
11655f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG __attribute__((__nodebug__))
11665f757f3fSDimitry Andric#  else
11675f757f3fSDimitry Andric#    define _LIBCPP_NODEBUG
11685f757f3fSDimitry Andric#  endif
11695f757f3fSDimitry Andric
11705f757f3fSDimitry Andric#  if __has_attribute(__standalone_debug__)
11715f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
11725f757f3fSDimitry Andric#  else
11735f757f3fSDimitry Andric#    define _LIBCPP_STANDALONE_DEBUG
11745f757f3fSDimitry Andric#  endif
11755f757f3fSDimitry Andric
11765f757f3fSDimitry Andric#  if __has_attribute(__preferred_name__)
11775f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
11785f757f3fSDimitry Andric#  else
11795f757f3fSDimitry Andric#    define _LIBCPP_PREFERRED_NAME(x)
11805f757f3fSDimitry Andric#  endif
11815f757f3fSDimitry Andric
11825f757f3fSDimitry Andric#  if __has_attribute(__no_sanitize__)
11835f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
11845f757f3fSDimitry Andric#  else
11855f757f3fSDimitry Andric#    define _LIBCPP_NO_SANITIZE(...)
11865f757f3fSDimitry Andric#  endif
11875f757f3fSDimitry Andric
11885f757f3fSDimitry Andric#  if __has_attribute(__init_priority__)
11895f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
11905f757f3fSDimitry Andric#  else
11915f757f3fSDimitry Andric#    define _LIBCPP_INIT_PRIORITY_MAX
11925f757f3fSDimitry Andric#  endif
11935f757f3fSDimitry Andric
11945f757f3fSDimitry Andric#  if __has_attribute(__format__)
11955f757f3fSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions.
11965f757f3fSDimitry Andric// The attribute uses 2-based indices for non-static member functions.
11975f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index)                           \
11985f757f3fSDimitry Andric      __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
11995f757f3fSDimitry Andric#  else
12005f757f3fSDimitry Andric#    define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
12015f757f3fSDimitry Andric#  endif
12025f757f3fSDimitry Andric
12035f757f3fSDimitry Andric#  if __has_attribute(__packed__)
12045f757f3fSDimitry Andric#    define _LIBCPP_PACKED __attribute__((__packed__))
12055f757f3fSDimitry Andric#  else
12065f757f3fSDimitry Andric#    define _LIBCPP_PACKED
12075f757f3fSDimitry Andric#  endif
12085f757f3fSDimitry Andric
12095f757f3fSDimitry Andric#  if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
12105f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
12115f757f3fSDimitry Andric#  else
12125f757f3fSDimitry Andric#    define _LIBCPP_DECLSPEC_EMPTY_BASES
12135f757f3fSDimitry Andric#  endif
12145f757f3fSDimitry Andric
12155f757f3fSDimitry Andric// Allow for build-time disabling of unsigned integer sanitization
12165f757f3fSDimitry Andric#  if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
12175f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
12185f757f3fSDimitry Andric#  else
12195f757f3fSDimitry Andric#    define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
12205f757f3fSDimitry Andric#  endif
12215f757f3fSDimitry Andric
12227a6dacacSDimitry Andric// Clang-18 has support for deducing this, but it does not set the FTM.
12237a6dacacSDimitry Andric#  if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
12247a6dacacSDimitry Andric#    define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
12257a6dacacSDimitry Andric#  endif
12267a6dacacSDimitry Andric
12270b57cec5SDimitry Andric#endif // __cplusplus
12280b57cec5SDimitry Andric
122981ad6265SDimitry Andric#endif // _LIBCPP___CONFIG
1230