blob: e14632f65b877cef33d56fa111bb259b63ba535e [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:161// -*- C++ -*-
Louis Dionneeb8650a2021-11-17 21:25:012//===----------------------------------------------------------------------===//
Howard Hinnant3e519522010-05-11 19:42:163//
Chandler Carruth57b08b02019-01-19 10:56:404// 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
Howard Hinnant3e519522010-05-11 19:42:167//
8//===----------------------------------------------------------------------===//
9
Louis Dionnecc82a1b2022-03-23 17:11:0410#ifndef _LIBCPP___CONFIG
11#define _LIBCPP___CONFIG
Howard Hinnant3e519522010-05-11 19:42:1612
Louis Dionnec06a8f92020-06-26 16:08:5913#include <__config_site>
Louis Dionne23e1ed62024-05-28 11:22:0614#include <__configuration/abi.h>
Louis Dionne04f01a22024-05-29 01:29:1115#include <__configuration/availability.h>
Louis Dionne23e1ed62024-05-28 11:22:0616#include <__configuration/compiler.h>
Louis Dionne61498a82024-10-31 15:35:3017#include <__configuration/language.h>
Louis Dionne23e1ed62024-05-28 11:22:0618#include <__configuration/platform.h>
Louis Dionnec06a8f92020-06-26 16:08:5919
Eric Fiselier60506cb2015-11-06 06:30:1220#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
Arthur O'Dwyerfa6b9e42022-02-02 01:16:4021# pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:1022#endif
Howard Hinnant3e519522010-05-11 19:42:1623
Eric Fiselier60506cb2015-11-06 06:30:1224#ifdef __cplusplus
25
Nikolas Klauser7949ee02023-06-07 20:33:0226// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
27
Louis Dionnead0dfb42022-09-19 15:27:5028// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
Tom Stellard603c2862023-01-25 06:55:5329// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
Louis Dionneb6ff5b42022-09-19 19:38:1830// defined to XXYYZZ.
Tom Stellard3bd3e062025-01-29 03:48:4331# define _LIBCPP_VERSION 210000
Howard Hinnant3e519522010-05-11 19:42:1632
Louis Dionned2e86862022-07-07 18:07:3733# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
34# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
Nikolas Klauser27c83382024-09-16 09:08:5735# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z))
Louis Dionned2e86862022-07-07 18:07:3736
Nikolas Klauserac251722022-06-13 15:25:2337# if __STDC_HOSTED__ == 0
38# define _LIBCPP_FREESTANDING
Eric Fiselier998a5c82018-07-27 03:07:0939# endif
Eric Fiselier998a5c82018-07-27 03:07:0940
varconstd1367ca2023-07-12 17:12:5141// HARDENING {
42
Louis Dionnec9d9dc92024-10-29 14:48:1843// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated.
varconstf0dfe682023-07-14 23:58:1544# ifdef _LIBCPP_ENABLE_ASSERTIONS
Louis Dionnec9d9dc92024-10-29 14:48:1845# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead"
varconstf0dfe682023-07-14 23:58:1546# endif
47
Konstantin Varlamov64d413e2023-11-08 19:10:0048// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
varconstd1367ca2023-07-12 17:12:5149//
Konstantin Varlamov64d413e2023-11-08 19:10:0050// - `_LIBCPP_HARDENING_MODE_NONE`;
51// - `_LIBCPP_HARDENING_MODE_FAST`;
52// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
53// - `_LIBCPP_HARDENING_MODE_DEBUG`.
Konstantin Varlamovb85e1862023-09-12 19:01:3654//
Konstantin Varlamov64d413e2023-11-08 19:10:0055// These values have the following effects:
varconstd1367ca2023-07-12 17:12:5156//
Konstantin Varlamov64d413e2023-11-08 19:10:0057// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
58//
59// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
60// that can be done with relatively little runtime overhead in constant time;
61//
62// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
63// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
64// but are not necessarily security-critical;
65//
66// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
67// mode and enables all checks available in the library, including internal assertions. Checks that are part of the
68// debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production.
varconstd1367ca2023-07-12 17:12:5169
varconst4122db12023-07-20 17:13:5470// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
71// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
72//
73// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
74// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
75// - the sentinel is reachable from the begin iterator;
varconst4122db12023-07-20 17:13:5476// - TODO(hardening): both iterators refer to the same container.
77//
78// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
79// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
80// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
81// `optional` and `function` are considered one-element containers for the purposes of this check.
82//
Konstantin Varlamovb85fdc42023-11-08 02:12:1583// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
84// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
85// memory security of a program (however, it is still undefined behavior that can result in strange errors due to
86// compiler optimizations).
87//
varconst4a652e42023-07-24 21:56:4488// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
89// given ranges do not overlap.
90//
Konstantin Varlamov60824782024-01-23 02:12:5891// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
92// was allocated by the given allocator). Violating this category typically results in a memory leak.
93//
94// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
95// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
96// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
97// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
98// otherwise create an immediate security issue.
99//
varconst4122db12023-07-20 17:13:54100// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
101// the containers have compatible allocators.
102//
Konstantin Varlamovdc577522024-01-21 07:38:02103// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
104// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
105// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
106// a string view where only a subset of elements is possible to access). This category is for assertions violating
107// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
108// user code.
109//
Konstantin Varlamov4f215fd2024-01-06 00:29:23110// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
111// be benign in our implementation.
112//
Konstantin Varlamov8938bc02024-01-23 07:31:58113// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
114// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
115// thus, this would often be a heuristic check and it might be quite expensive.
116//
varconst4122db12023-07-20 17:13:54117// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
118// user input.
119//
120// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
varconstd1367ca2023-07-12 17:12:51121
Konstantin Varlamov64d413e2023-11-08 19:10:00122// clang-format off
123# define _LIBCPP_HARDENING_MODE_NONE (1 << 1)
124# define _LIBCPP_HARDENING_MODE_FAST (1 << 2)
125# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
126# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3)
127// clang-format on
128
129# ifndef _LIBCPP_HARDENING_MODE
Konstantin Varlamov091fc812024-02-06 21:45:31130
131# ifndef _LIBCPP_HARDENING_MODE_DEFAULT
132# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
133`__config_site` header, please make sure your installation of libc++ is not broken.
134# endif
135
Konstantin Varlamov64d413e2023-11-08 19:10:00136# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
varconstd1367ca2023-07-12 17:12:51137# endif
138
Konstantin Varlamov64d413e2023-11-08 19:10:00139# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \
140 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
141 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
142 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
143# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
144_LIBCPP_HARDENING_MODE_NONE, \
145_LIBCPP_HARDENING_MODE_FAST, \
146_LIBCPP_HARDENING_MODE_EXTENSIVE, \
147_LIBCPP_HARDENING_MODE_DEBUG
varconstd1367ca2023-07-12 17:12:51148# endif
149
varconstd1367ca2023-07-12 17:12:51150// } HARDENING
151
Nikolas Klauserf02120f2022-08-13 11:52:35152# define _LIBCPP_TOSTRING2(x) #x
Nikolas Klauserac251722022-06-13 15:25:23153# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
Nikolas Klausera7c2a622022-02-14 17:52:28154
Nikolas Klauser07efa282023-02-17 13:01:19155// NOLINTNEXTLINE(libcpp-cpp-version-check)
Nikolas Klauserac251722022-06-13 15:25:23156# if __cplusplus < 201103L
157# define _LIBCPP_CXX03_LANG
158# endif
Eric Fiseliere825d8b2015-07-10 20:26:38159
Marek Kurdej7223bcf2022-12-15 01:19:59160# ifndef __has_constexpr_builtin
161# define __has_constexpr_builtin(x) 0
162# endif
163
Nikolas Klauser15300342024-02-28 20:14:35164// This checks wheter a Clang module is built
165# ifndef __building_module
166# define __building_module(...) 0
167# endif
168
Eric Fiseliere825d8b2015-07-10 20:26:38169// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
170// the compiler and '1' otherwise.
Nikolas Klauserac251722022-06-13 15:25:23171# ifndef __is_identifier
172# define __is_identifier(__x) 1
173# endif
Logan Chien2b772b92018-02-24 07:57:32174
Nikolas Klauserac251722022-06-13 15:25:23175# ifndef __has_declspec_attribute
176# define __has_declspec_attribute(__x) 0
177# endif
Eric Fiseliere825d8b2015-07-10 20:26:38178
Xing Xue7f302f22023-09-07 18:48:45179# define __has_keyword(__x) !(__is_identifier(__x))
180
Nikolas Klauser4d323e42024-03-09 00:09:28181# ifndef __has_warning
182# define __has_warning(...) 0
183# endif
184
Nikolas Klauser929d5de2022-06-17 11:58:22185# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
186# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
Nikolas Klauserac251722022-06-13 15:25:23187# endif
Eric Fiselier5de7cac2019-06-13 00:37:25188
Nikolas Klauserac251722022-06-13 15:25:23189# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
190# define _LIBCPP_ABI_VCRUNTIME
191# endif
Eric Fiseliere69290d2019-03-05 01:57:01192
Louis Dionnedeb3b552022-07-20 14:42:04193# if __has_feature(experimental_library)
194# ifndef _LIBCPP_ENABLE_EXPERIMENTAL
195# define _LIBCPP_ENABLE_EXPERIMENTAL
196# endif
197# endif
198
Louis Dionne8711fca2022-06-30 15:57:52199// Incomplete features get their own specific disabling flags. This makes it
200// easier to grep for target specific flags once the feature is complete.
Nikolas Klauser24e70e32025-01-24 08:34:42201# if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY)
202# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1
203# else
204# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0
Hui477f6bc2023-07-10 14:55:55205# endif
206
Nikolas Klauser24e70e32025-01-24 08:34:42207# define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
208# define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
209# define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY
210
Nikolas Klauserac251722022-06-13 15:25:23211# if defined(__MVS__)
212# include <features.h> // for __NATIVE_ASCII_F
213# endif
Muiez Ahmeda1da7392022-01-14 16:35:53214
Nikolas Klauserac251722022-06-13 15:25:23215# if defined(_WIN32)
216# define _LIBCPP_WIN32API
Nikolas Klauserac251722022-06-13 15:25:23217# define _LIBCPP_SHORT_WCHAR 1
Louis Dionne77bca6d2019-03-20 17:05:52218// Both MinGW and native MSVC provide a "MSVC"-like environment
Nikolas Klauserac251722022-06-13 15:25:23219# define _LIBCPP_MSVCRT_LIKE
Bruno Cardoso Lopese59dd002017-07-17 21:52:31220// If mingw not explicitly detected, assume using MS C runtime only if
221// a MS compatibility version is specified.
Nikolas Klauserac251722022-06-13 15:25:23222# if defined(_MSC_VER) && !defined(__MINGW32__)
223# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
224# endif
225# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
Nikolas Klauserba875152024-10-12 07:49:52226# define _LIBCPP_HAS_BITSCAN64 1
227# else
228# define _LIBCPP_HAS_BITSCAN64 0
Nikolas Klauserac251722022-06-13 15:25:23229# endif
Nikolas Klauserba875152024-10-12 07:49:52230# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1
231# else
232# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0
233# define _LIBCPP_HAS_BITSCAN64 0
Nikolas Klauserac251722022-06-13 15:25:23234# endif // defined(_WIN32)
Howard Hinnant3e714642011-05-13 17:16:06235
Nikolas Klauserac251722022-06-13 15:25:23236# if defined(_AIX) && !defined(__64BIT__)
237// The size of wchar is 2 byte on 32-bit mode on AIX.
238# define _LIBCPP_SHORT_WCHAR 1
239# endif
Xing Xuef53fafb2021-09-09 20:20:36240
Louis Dionnebeff7152021-12-21 21:50:34241// Libc++ supports various implementations of std::random_device.
242//
243// _LIBCPP_USING_DEV_RANDOM
244// Read entropy from the given file, by default `/dev/urandom`.
245// If a token is provided, it is assumed to be the path to a file
246// to read entropy from. This is the default behavior if nothing
247// else is specified. This implementation requires storing state
248// inside `std::random_device`.
249//
250// _LIBCPP_USING_ARC4_RANDOM
251// Use arc4random(). This allows obtaining random data even when
252// using sandboxing mechanisms. On some platforms like Apple, this
253// is the recommended source of entropy for user-space programs.
254// When this option is used, the token passed to `std::random_device`'s
255// constructor *must* be "/dev/urandom" -- anything else is an error.
256//
257// _LIBCPP_USING_GETENTROPY
258// Use getentropy().
259// When this option is used, the token passed to `std::random_device`'s
260// constructor *must* be "/dev/urandom" -- anything else is an error.
261//
Roland McGrath3064dd82022-01-02 19:53:53262// _LIBCPP_USING_FUCHSIA_CPRNG
263// Use Fuchsia's zx_cprng_draw() system call, which is specified to
264// deliver high-quality entropy and cannot fail.
265// When this option is used, the token passed to `std::random_device`'s
266// constructor *must* be "/dev/urandom" -- anything else is an error.
267//
Louis Dionnebeff7152021-12-21 21:50:34268// _LIBCPP_USING_NACL_RANDOM
269// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
270// including accesses to the special files under `/dev`. This implementation
271// uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
272// When this option is used, the token passed to `std::random_device`'s
273// constructor *must* be "/dev/urandom" -- anything else is an error.
274//
275// _LIBCPP_USING_WIN32_RANDOM
276// Use rand_s(), for use on Windows.
277// When this option is used, the token passed to `std::random_device`'s
278// constructor *must* be "/dev/urandom" -- anything else is an error.
Nikolas Klauserac251722022-06-13 15:25:23279# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
Louis Dionne3b6bc8752022-11-24 18:02:58280 defined(__DragonFly__)
Nikolas Klauserac251722022-06-13 15:25:23281# define _LIBCPP_USING_ARC4_RANDOM
282# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
283# define _LIBCPP_USING_GETENTROPY
284# elif defined(__Fuchsia__)
285# define _LIBCPP_USING_FUCHSIA_CPRNG
286# elif defined(__native_client__)
287# define _LIBCPP_USING_NACL_RANDOM
288# elif defined(_LIBCPP_WIN32API)
289# define _LIBCPP_USING_WIN32_RANDOM
290# else
291# define _LIBCPP_USING_DEV_RANDOM
Logan Chien2b772b92018-02-24 07:57:32292# endif
Howard Hinnant3e519522010-05-11 19:42:16293
Nikolas Klauserac251722022-06-13 15:25:23294# ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser929d5de2022-06-17 11:58:22295
Nikolas Klauserac251722022-06-13 15:25:23296# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
Nikolas Klauser929d5de2022-06-17 11:58:22297# define _ALIGNAS_TYPE(x) alignas(x)
298# define _ALIGNAS(x) alignas(x)
Nikolas Klauser929d5de2022-06-17 11:58:22299# define _NOEXCEPT noexcept
Louis Dionnef89d7072024-01-30 13:33:48300# define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
Nikolas Klauserae87a3b2022-08-09 11:22:25301# define _LIBCPP_CONSTEXPR constexpr
Nikolas Klauser929d5de2022-06-17 11:58:22302
Nikolas Klauserac251722022-06-13 15:25:23303# else
Nikolas Klauser929d5de2022-06-17 11:58:22304
305# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
306# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
307# define _ALIGNAS(x) __attribute__((__aligned__(x)))
Nikolas Klauser929d5de2022-06-17 11:58:22308# define nullptr __nullptr
309# define _NOEXCEPT throw()
Louis Dionnef89d7072024-01-30 13:33:48310# define _NOEXCEPT_(...)
Nikolas Klauserae87a3b2022-08-09 11:22:25311# define static_assert(...) _Static_assert(__VA_ARGS__)
312# define decltype(...) __decltype(__VA_ARGS__)
313# define _LIBCPP_CONSTEXPR
Nikolas Klauser929d5de2022-06-17 11:58:22314
315typedef __char16_t char16_t;
316typedef __char32_t char32_t;
317
318# endif
319
Nikolas Klauserac251722022-06-13 15:25:23320# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
Howard Hinnanteb269252010-08-10 20:48:29321
Douglas Gregor64ec1012011-06-22 22:17:44322// Objective-C++ features (opt-in)
Nikolas Klauser69fecaa2024-07-13 07:41:36323# if __has_feature(objc_arc)
Nikolas Klauserba875152024-10-12 07:49:52324# define _LIBCPP_HAS_OBJC_ARC 1
325# else
326# define _LIBCPP_HAS_OBJC_ARC 0
Nikolas Klauser69fecaa2024-07-13 07:41:36327# endif
Douglas Gregor64ec1012011-06-22 22:17:44328
Nikolas Klauser69fecaa2024-07-13 07:41:36329# if __has_feature(objc_arc_weak)
Nikolas Klauserba875152024-10-12 07:49:52330# define _LIBCPP_HAS_OBJC_ARC_WEAK 1
331# else
332# define _LIBCPP_HAS_OBJC_ARC_WEAK 0
Nikolas Klauser69fecaa2024-07-13 07:41:36333# endif
Douglas Gregor64ec1012011-06-22 22:17:44334
Nikolas Klauser69fecaa2024-07-13 07:41:36335# if __has_extension(blocks)
Nikolas Klauserba875152024-10-12 07:49:52336# define _LIBCPP_HAS_EXTENSION_BLOCKS 1
337# else
338# define _LIBCPP_HAS_EXTENSION_BLOCKS 0
Nikolas Klauser69fecaa2024-07-13 07:41:36339# endif
Louis Dionne8ae404a2020-01-21 20:39:43340
Nikolas Klauserba875152024-10-12 07:49:52341# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__)
342# define _LIBCPP_HAS_BLOCKS_RUNTIME 1
343# else
344# define _LIBCPP_HAS_BLOCKS_RUNTIME 0
Nikolas Klauser69fecaa2024-07-13 07:41:36345# endif
Louis Dionnef76c4242020-04-23 20:47:52346
Nikolas Klauserba875152024-10-12 07:49:52347# if __has_feature(address_sanitizer)
348# define _LIBCPP_HAS_ASAN 1
349# else
350# define _LIBCPP_HAS_ASAN 0
Nikolas Klauser69fecaa2024-07-13 07:41:36351# endif
Marshall Clow91c71dd2014-04-14 15:44:57352
Nikolas Klauser69fecaa2024-07-13 07:41:36353# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
Louis Dionnecb3eb302018-07-27 12:46:03354
Nikolas Klauserac251722022-06-13 15:25:23355# if defined(_LIBCPP_OBJECT_FORMAT_COFF)
Logan Chien2b772b92018-02-24 07:57:32356
Nikolas Klauserac251722022-06-13 15:25:23357# ifdef _DLL
358# define _LIBCPP_CRT_FUNC __declspec(dllimport)
Shoaib Meenaibda3c7d2017-03-02 03:22:18359# else
Nikolas Klauserac251722022-06-13 15:25:23360# define _LIBCPP_CRT_FUNC
361# endif
362
363# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
Nikolas Klauserac251722022-06-13 15:25:23364# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
365# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
366# define _LIBCPP_OVERRIDABLE_FUNC_VIS
367# define _LIBCPP_EXPORTED_FROM_ABI
368# elif defined(_LIBCPP_BUILDING_LIBRARY)
Nikolas Klauserac251722022-06-13 15:25:23369# if defined(__MINGW32__)
Nikolas Klauserfaefb702025-03-30 10:02:27370# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport)
Nikolas Klauserac251722022-06-13 15:25:23371# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
372# else
373# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
Nikolas Klauserfaefb702025-03-30 10:02:27374# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport)
Nikolas Klauserac251722022-06-13 15:25:23375# endif
Nikolas Klauserfaefb702025-03-30 10:02:27376# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport)
Nikolas Klauserac251722022-06-13 15:25:23377# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
378# else
Nikolas Klauserfaefb702025-03-30 10:02:27379# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport)
Nikolas Klauserac251722022-06-13 15:25:23380# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
381# define _LIBCPP_OVERRIDABLE_FUNC_VIS
382# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
383# endif
384
Nikolas Klauserac251722022-06-13 15:25:23385# define _LIBCPP_HIDDEN
Nikolas Klauserac251722022-06-13 15:25:23386# define _LIBCPP_TEMPLATE_DATA_VIS
Nikolas Klauserc59d3a22025-04-02 20:12:59387# define _LIBCPP_NAMESPACE_VISIBILITY
Nikolas Klauserac251722022-06-13 15:25:23388
Nikolas Klauser758504b2022-06-22 09:14:04389# else
Nikolas Klauserac251722022-06-13 15:25:23390
Nikolas Klauserac251722022-06-13 15:25:23391# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Nikolas Klauser758504b2022-06-22 09:14:04392# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
Nikolas Klauserac251722022-06-13 15:25:23393# else
Nikolas Klauser758504b2022-06-22 09:14:04394# define _LIBCPP_VISIBILITY(vis)
Nikolas Klauserac251722022-06-13 15:25:23395# endif
Nikolas Klauserac251722022-06-13 15:25:23396
Nikolas Klauser758504b2022-06-22 09:14:04397# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
Nikolas Klauser758504b2022-06-22 09:14:04398# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
399# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
Nikolas Klauser758504b2022-06-22 09:14:04400# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
401# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Nico Webera94cec52024-11-26 23:45:03402
403// TODO: Make this a proper customization point or remove the option to override it.
404# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
405# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
406# endif
Nikolas Klauser0f050522022-07-14 13:04:36407
Nikolas Klauserac251722022-06-13 15:25:23408# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
Nikolas Klauserc59d3a22025-04-02 20:12:59409# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default")))
410# elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
411# define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default")))
Nikolas Klauserac251722022-06-13 15:25:23412# else
Nikolas Klauserc59d3a22025-04-02 20:12:59413# define _LIBCPP_NAMESPACE_VISIBILITY
Nikolas Klauserac251722022-06-13 15:25:23414# endif
Nikolas Klauserac251722022-06-13 15:25:23415
Nikolas Klauser758504b2022-06-22 09:14:04416# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
Nikolas Klauserac251722022-06-13 15:25:23417
Nikolas Klauser140c3752023-05-24 15:46:13418# if __has_attribute(exclude_from_explicit_instantiation)
Nikolas Klauserac251722022-06-13 15:25:23419# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
420# else
421// Try to approximate the effect of exclude_from_explicit_instantiation
422// (which is that entities are not assumed to be provided by explicit
423// template instantiations in the dylib) by always inlining those entities.
424# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
425# endif
426
Nikolas Klauser4d323e42024-03-09 00:09:28427# ifdef _LIBCPP_COMPILER_CLANG_BASED
428# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
429# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
430# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
431# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
432# elif defined(_LIBCPP_COMPILER_GCC)
433# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
434# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
435# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
436# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
437# else
438# define _LIBCPP_DIAGNOSTIC_PUSH
439# define _LIBCPP_DIAGNOSTIC_POP
440# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
441# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
442# endif
443
Konstantin Varlamov64d413e2023-11-08 19:10:00444# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
445# define _LIBCPP_HARDENING_SIG f
446# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
Louis Dionnebc792a22023-10-26 13:05:16447# define _LIBCPP_HARDENING_SIG s
Konstantin Varlamov64d413e2023-11-08 19:10:00448# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
Louis Dionnebc792a22023-10-26 13:05:16449# define _LIBCPP_HARDENING_SIG d
450# else
Konstantin Varlamov64d413e2023-11-08 19:10:00451# define _LIBCPP_HARDENING_SIG n // "none"
Louis Dionnebc792a22023-10-26 13:05:16452# endif
453
Nikolas Klauserba875152024-10-12 07:49:52454# if !_LIBCPP_HAS_EXCEPTIONS
Louis Dionnebc792a22023-10-26 13:05:16455# define _LIBCPP_EXCEPTIONS_SIG n
456# else
457# define _LIBCPP_EXCEPTIONS_SIG e
458# endif
459
460# define _LIBCPP_ODR_SIGNATURE \
461 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
462
Louis Dionned2e86862022-07-07 18:07:37463// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
464// on two levels:
465// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
466// symbols from their dynamic library by means of using the libc++ headers. This ensures
467// that those symbols stay private to the dynamic library in which it is defined.
468//
Louis Dionnebc792a22023-10-26 13:05:16469// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
470// This ensures that no ODR violation can arise from mixing two TUs compiled with different
471// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
472// program contains two definitions of a function, the ODR requires them to be token-by-token
473// equivalent, and the linker is allowed to pick either definition and discard the other one.
474//
475// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
476// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
477// compiled with different settings), the two definitions are both visible by the linker and they
478// have the same name, but they have a meaningfully different implementation (one throws an exception
479// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
480// practice what will happen is that the linker will pick one of the definitions at random and will
481// discard the other one. This can quite clearly lead to incorrect program behavior.
482//
483// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
484// property that causes the code of a function to differ from the code in another configuration
485// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
486// tag, but we encode the ones that we think are most important: library version, exceptions, and
487// hardening mode.
488//
489// Note that historically, solving this problem has been achieved in various ways, including
490// force-inlining all functions or giving internal linkage to all functions. Both these previous
491// solutions suffer from drawbacks that lead notably to code bloat.
Louis Dionned2e86862022-07-07 18:07:37492//
Nikolas Klauser140c3752023-05-24 15:46:13493// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
494// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
495//
Louis Dionne5efc8112022-12-21 15:08:54496// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
497// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
498// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
499// the virtual function pointer in the vtable based on the mangled name of the function. Since
500// we use an ABI tag that changes with each released version, the mangled name of the virtual
501// function would change, which is incorrect. Note that it doesn't make much sense to change
502// the implementation of a virtual function in an ABI-incompatible way in the first place,
503// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
504//
Mark de Weverd1791762024-03-25 17:33:30505// The macro can be applied to record and enum types. When the tagged type is nested in
506// a record this "parent" record needs to have the macro too. Another use case for applying
507// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
508// This can be useful for inline variables that are implementation details which are expected
509// to change in the future.
510//
Louis Dionned2e86862022-07-07 18:07:37511// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
512// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
513// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
514# ifndef _LIBCPP_NO_ABI_TAG
515# define _LIBCPP_HIDE_FROM_ABI \
Nikolas Klauser140c3752023-05-24 15:46:13516 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
Louis Dionnee2c2ffb2024-06-18 13:13:45517 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
Louis Dionned2e86862022-07-07 18:07:37518# else
Nikolas Klauser140c3752023-05-24 15:46:13519# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Nikolas Klauserac251722022-06-13 15:25:23520# endif
Nikolas Klauser140c3752023-05-24 15:46:13521# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Arsen Arsenović21d92822023-01-25 07:34:55522
Nikolas Klauserac251722022-06-13 15:25:23523# ifdef _LIBCPP_BUILDING_LIBRARY
524# if _LIBCPP_ABI_VERSION > 1
Nikolas Klauser140c3752023-05-24 15:46:13525# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Nikolas Klauserac251722022-06-13 15:25:23526# else
527# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Shoaib Meenaibda3c7d2017-03-02 03:22:18528# endif
529# else
Nikolas Klauser140c3752023-05-24 15:46:13530# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Logan Chien2b772b92018-02-24 07:57:32531# endif
Eric Fiselierf8f31c42016-09-16 00:00:48532
Nikolas Klauser4d323e42024-03-09 00:09:28533// TODO: Remove this workaround once we drop support for Clang 16
Louis Dionnee2c2ffb2024-06-18 13:13:45534# if __has_warning("-Wc++23-extensions")
535# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
536# else
537# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
538# endif
Nikolas Klauser4d323e42024-03-09 00:09:28539
Nikolas Klauserf886dfe2024-03-23 12:54:35540// Clang modules take a significant compile time hit when pushing and popping diagnostics.
541// Since all the headers are marked as system headers in the modulemap, we can simply disable this
542// pushing and popping when building with clang modules.
543# if !__has_feature(modules)
544# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
545 _LIBCPP_DIAGNOSTIC_PUSH \
546 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
547 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
548 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
549 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
550 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
551 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
552 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
553 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
554 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
555# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
556# else
557# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
558# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
559# endif
560
Nikolas Klauserac251722022-06-13 15:25:23561// clang-format off
Nikolas Klauserac251722022-06-13 15:25:23562
Nikolas Klauser8abca172025-03-27 10:34:38563// The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There
564// are two main categories where that's the case:
565// - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++
566// and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore.
567// - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know
568// their mangling without the appropriate declaration in some cases.
569// If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
570// namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
571# define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
Nikolas Klauserc59d3a22025-04-02 20:12:59572 _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std {
Nikolas Klauser8abca172025-03-27 10:34:38573
574# define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
575
576# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
577# define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
578
579// TODO: This should really be in the versioned namespace
580#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental {
581#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
Louis Dionne118f1202024-09-11 18:59:43582
583#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
584#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
585
586#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
587#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
588
Nikolas Klauser5d313602024-06-01 06:37:49589#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
590# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
591# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
592#else
Louis Dionneac8c9f12023-11-28 23:41:59593# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
594 inline namespace __fs { namespace filesystem {
Eric Fiselier2f3e8b32018-10-30 02:02:00595
Nikolas Klauser4d323e42024-03-09 00:09:28596# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
Nikolas Klauser5d313602024-06-01 06:37:49597#endif
598
Nikolas Klauserac251722022-06-13 15:25:23599// clang-format on
Eric Fiselier2f3e8b32018-10-30 02:02:00600
Nikolas Klauserac251722022-06-13 15:25:23601# if __has_attribute(__enable_if__)
602# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
603# endif
Eric Fiselier49e29672016-09-15 22:27:07604
Louis Dionne5a6e6ad2023-06-16 18:32:08605# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
Nikolas Klauserba875152024-10-12 07:49:52606# define _LIBCPP_HAS_INT128 0
607# else
608# define _LIBCPP_HAS_INT128 1
Nikolas Klauserac251722022-06-13 15:25:23609# endif
Stephan Tolksdorfe180eca2014-03-26 19:45:52610
Nikolas Klauserac251722022-06-13 15:25:23611# ifdef _LIBCPP_CXX03_LANG
612# define _LIBCPP_DECLARE_STRONG_ENUM(x) \
Louis Dionne5a6e6ad2023-06-16 18:32:08613 struct _LIBCPP_EXPORTED_FROM_ABI x { \
Nikolas Klauserac251722022-06-13 15:25:23614 enum __lx
615// clang-format off
616# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
617 __lx __v_; \
Louis Dionne4c198542023-12-04 15:25:14618 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \
619 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
620 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \
Nikolas Klauserac251722022-06-13 15:25:23621 };
622// clang-format on
Howard Hinnant75689c12011-12-02 19:36:40623
Nikolas Klauserac251722022-06-13 15:25:23624# else // _LIBCPP_CXX03_LANG
Nikolas Klauser3583bf32023-08-19 22:15:47625# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
Nikolas Klauserac251722022-06-13 15:25:23626# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
627# endif // _LIBCPP_CXX03_LANG
Yaron Keren21a697b82013-12-20 13:19:45628
Nikolas Klauserac251722022-06-13 15:25:23629# ifdef __FreeBSD__
630# define _DECLARE_C99_LDBL_MATH 1
631# endif
Alexis Hunt4084c9e2011-07-15 05:40:33632
Reid Kleckner6a2a5e02018-04-19 22:12:10633// If we are getting operator new from the MSVC CRT, then allocation overloads
634// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
Nikolas Klauserac251722022-06-13 15:25:23635# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
Nikolas Klauserba875152024-10-12 07:49:52636# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
Nikolas Klauserac251722022-06-13 15:25:23637# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
638// We're deferring to Microsoft's STL to provide aligned new et al. We don't
639// have it unless the language feature test macro is defined.
Nikolas Klauserba875152024-10-12 07:49:52640# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
Nikolas Klauserac251722022-06-13 15:25:23641# elif defined(__MVS__)
Nikolas Klauserba875152024-10-12 07:49:52642# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0
643# else
644# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1
Nikolas Klauserac251722022-06-13 15:25:23645# endif
Reid Kleckner6a2a5e02018-04-19 22:12:10646
Nikolas Klauserba875152024-10-12 07:49:52647# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
648# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0
649# else
650# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
Nikolas Klauserac251722022-06-13 15:25:23651# endif
Eric Fiselierf2918d12018-03-22 04:42:56652
Alex Richardsoneb6fbad2022-11-17 10:19:28653// It is not yet possible to use aligned_alloc() on all Apple platforms since
654// 10.15 was the first version to ship an implementation of aligned_alloc().
655# if defined(__APPLE__)
656# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
Nikolas Klauserba875152024-10-12 07:49:52657 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
658 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
Un1q32949e4042025-02-17 13:55:14659 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
660 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
661 __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) || \
662 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000)
Nikolas Klauserba875152024-10-12 07:49:52663# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
664# else
665# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
Un1q3263899742024-09-27 20:11:47666# endif
Shoaib Meenai49c8f902023-01-07 07:35:15667# elif defined(__ANDROID__) && __ANDROID_API__ < 28
668// Android only provides aligned_alloc when targeting API 28 or higher.
Nikolas Klauserba875152024-10-12 07:49:52669# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
670# else
671# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
Alex Richardsoneb6fbad2022-11-17 10:19:28672# endif
673
Nikolas Klauserac251722022-06-13 15:25:23674# if defined(__APPLE__) || defined(__FreeBSD__)
675# define _LIBCPP_HAS_DEFAULTRUNELOCALE
676# endif
Alexis Huntf0235192011-07-09 01:09:31677
Louis Dionne3b6bc8752022-11-24 18:02:58678# if defined(__APPLE__) || defined(__FreeBSD__)
Nikolas Klauserac251722022-06-13 15:25:23679# define _LIBCPP_WCTYPE_IS_MASK
680# endif
Alexis Hunt00818922011-07-09 03:40:04681
Nikolas Klauserac251722022-06-13 15:25:23682# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
Nikolas Klauserba875152024-10-12 07:49:52683# define _LIBCPP_HAS_CHAR8_T 0
684# else
685# define _LIBCPP_HAS_CHAR8_T 1
Nikolas Klauserac251722022-06-13 15:25:23686# endif
Marshall Clow7dad0bd2018-12-11 04:35:44687
Louis Dionneea5cd3b2018-09-23 18:35:00688// Deprecation macros.
Louis Dionnea470a132019-03-12 20:10:06689//
690// Deprecations warnings are always enabled, except when users explicitly opt-out
691// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
Nikolas Klauserac251722022-06-13 15:25:23692# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Nikolas Klauserc8eff952023-01-10 00:56:53693# if __has_attribute(__deprecated__)
694# define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
695# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
Nikolas Klauser4f152672023-02-13 23:56:09696# elif _LIBCPP_STD_VER >= 14
Nikolas Klauserac251722022-06-13 15:25:23697# define _LIBCPP_DEPRECATED [[deprecated]]
Nikolas Klauser971e9c82022-06-17 14:02:53698# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
Nikolas Klauserac251722022-06-13 15:25:23699# else
700# define _LIBCPP_DEPRECATED
Nikolas Klauser971e9c82022-06-17 14:02:53701# define _LIBCPP_DEPRECATED_(m)
Nikolas Klauserac251722022-06-13 15:25:23702# endif
Louis Dionneea5cd3b2018-09-23 18:35:00703# else
704# define _LIBCPP_DEPRECATED
Nikolas Klauser971e9c82022-06-17 14:02:53705# define _LIBCPP_DEPRECATED_(m)
Louis Dionneea5cd3b2018-09-23 18:35:00706# endif
Marshall Clow8392ab22013-09-28 18:35:31707
Nikolas Klauserac251722022-06-13 15:25:23708# if !defined(_LIBCPP_CXX03_LANG)
709# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
710# else
711# define _LIBCPP_DEPRECATED_IN_CXX11
712# endif
Louis Dionneea5cd3b2018-09-23 18:35:00713
Nikolas Klauser4f152672023-02-13 23:56:09714# if _LIBCPP_STD_VER >= 14
Nikolas Klauserac251722022-06-13 15:25:23715# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
716# else
717# define _LIBCPP_DEPRECATED_IN_CXX14
718# endif
Louis Dionneea5cd3b2018-09-23 18:35:00719
Nikolas Klauser4f152672023-02-13 23:56:09720# if _LIBCPP_STD_VER >= 17
Nikolas Klauserac251722022-06-13 15:25:23721# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
722# else
723# define _LIBCPP_DEPRECATED_IN_CXX17
724# endif
Louis Dionneea5cd3b2018-09-23 18:35:00725
Nikolas Klauser4f152672023-02-13 23:56:09726# if _LIBCPP_STD_VER >= 20
Nikolas Klauserac251722022-06-13 15:25:23727# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
728# else
729# define _LIBCPP_DEPRECATED_IN_CXX20
730# endif
Marek Kurdej841132e2020-11-26 09:07:16731
Louis Dionne5a6e6ad2023-06-16 18:32:08732# if _LIBCPP_STD_VER >= 23
733# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
734# else
735# define _LIBCPP_DEPRECATED_IN_CXX23
736# endif
Nikolas Klauser987f08f2022-12-11 01:10:31737
Hristo Hristov27e67cd2024-01-29 18:57:12738# if _LIBCPP_STD_VER >= 26
739# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
A. Jiangab950052025-04-08 23:40:01740# define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m)
Hristo Hristov27e67cd2024-01-29 18:57:12741# else
742# define _LIBCPP_DEPRECATED_IN_CXX26
A. Jiangab950052025-04-08 23:40:01743# define _LIBCPP_DEPRECATED_IN_CXX26_(m)
Hristo Hristov27e67cd2024-01-29 18:57:12744# endif
745
Nikolas Klauserba875152024-10-12 07:49:52746# if _LIBCPP_HAS_CHAR8_T
Nikolas Klauserac251722022-06-13 15:25:23747# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
748# else
749# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
750# endif
Martin Storsjö6be11e32020-10-26 11:18:46751
Richard Smitha9727032019-10-19 00:06:00752// Macros to enter and leave a state where deprecation warnings are suppressed.
Nikolas Klauserac251722022-06-13 15:25:23753# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
754# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
755 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
756 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
757# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
758# else
759# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
760# define _LIBCPP_SUPPRESS_DEPRECATED_POP
761# endif
Richard Smitha9727032019-10-19 00:06:00762
Nikolas Klauserac251722022-06-13 15:25:23763# if _LIBCPP_STD_VER <= 11
Nikolas Klauser3c7a7a72023-02-02 11:12:28764# define _LIBCPP_EXPLICIT_SINCE_CXX14
Nikolas Klauserac251722022-06-13 15:25:23765# else
Nikolas Klauser3c7a7a72023-02-02 11:12:28766# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
Nikolas Klauserac251722022-06-13 15:25:23767# endif
Marshall Clowf20d2672013-07-15 14:57:19768
Hristo Hristov40aaa272023-03-22 21:24:22769# if _LIBCPP_STD_VER >= 23
770# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
771# else
772# define _LIBCPP_EXPLICIT_SINCE_CXX23
773# endif
774
Nikolas Klauser4f152672023-02-13 23:56:09775# if _LIBCPP_STD_VER >= 14
Nikolas Klauser5146b572022-08-19 11:08:01776# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
Nikolas Klauserac251722022-06-13 15:25:23777# else
Nikolas Klauser5146b572022-08-19 11:08:01778# define _LIBCPP_CONSTEXPR_SINCE_CXX14
Nikolas Klauserac251722022-06-13 15:25:23779# endif
Eric Fiselier371aac12014-07-17 05:16:18780
Nikolas Klauser4f152672023-02-13 23:56:09781# if _LIBCPP_STD_VER >= 17
Nikolas Klauser5146b572022-08-19 11:08:01782# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
Nikolas Klauserac251722022-06-13 15:25:23783# else
Nikolas Klauser5146b572022-08-19 11:08:01784# define _LIBCPP_CONSTEXPR_SINCE_CXX17
Nikolas Klauserac251722022-06-13 15:25:23785# endif
Eric Fiseliera58d4302016-03-17 03:30:56786
Nikolas Klauser4f152672023-02-13 23:56:09787# if _LIBCPP_STD_VER >= 20
Nikolas Klauser5146b572022-08-19 11:08:01788# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
Nikolas Klauserac251722022-06-13 15:25:23789# else
Nikolas Klauser5146b572022-08-19 11:08:01790# define _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauserac251722022-06-13 15:25:23791# endif
Marshall Clow1644c12e2017-11-14 22:26:50792
Nikolas Klauser4f152672023-02-13 23:56:09793# if _LIBCPP_STD_VER >= 23
Nikolas Klauser5146b572022-08-19 11:08:01794# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
Nikolas Klauserf02120f2022-08-13 11:52:35795# else
Nikolas Klauser5146b572022-08-19 11:08:01796# define _LIBCPP_CONSTEXPR_SINCE_CXX23
Nikolas Klauserf02120f2022-08-13 11:52:35797# endif
798
A. Jiang78085412024-08-28 13:35:57799# if _LIBCPP_STD_VER >= 26
800# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
801# else
802# define _LIBCPP_CONSTEXPR_SINCE_CXX26
803# endif
804
Nikolas Klauserac251722022-06-13 15:25:23805# ifndef _LIBCPP_WEAK
806# define _LIBCPP_WEAK __attribute__((__weak__))
807# endif
Howard Hinnanta942f2f2013-10-04 23:56:37808
Asiri Rathnayakec7e42392016-05-06 14:06:29809// Thread API
Nikolas Klauserac251722022-06-13 15:25:23810// clang-format off
Nikolas Klauserc6f3b7b2024-11-06 09:39:19811# if _LIBCPP_HAS_THREADS && \
812 !_LIBCPP_HAS_THREAD_API_PTHREAD && \
813 !_LIBCPP_HAS_THREAD_API_WIN32 && \
814 !_LIBCPP_HAS_THREAD_API_EXTERNAL
Asiri Rathnayakec7e42392016-05-06 14:06:29815
Nikolas Klauserac251722022-06-13 15:25:23816# if defined(__FreeBSD__) || \
817 defined(__wasi__) || \
818 defined(__NetBSD__) || \
819 defined(__OpenBSD__) || \
820 defined(__NuttX__) || \
821 defined(__linux__) || \
822 defined(__GNU__) || \
823 defined(__APPLE__) || \
Nikolas Klauserac251722022-06-13 15:25:23824 defined(__MVS__) || \
825 defined(_AIX) || \
826 defined(__EMSCRIPTEN__)
827// clang-format on
Nikolas Klauserc6f3b7b2024-11-06 09:39:19828# undef _LIBCPP_HAS_THREAD_API_PTHREAD
829# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
Nikolas Klauserac251722022-06-13 15:25:23830# elif defined(__Fuchsia__)
831// TODO(44575): Switch to C11 thread API when possible.
Nikolas Klauserc6f3b7b2024-11-06 09:39:19832# undef _LIBCPP_HAS_THREAD_API_PTHREAD
833# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
Nikolas Klauserac251722022-06-13 15:25:23834# elif defined(_LIBCPP_WIN32API)
Nikolas Klauserc6f3b7b2024-11-06 09:39:19835# undef _LIBCPP_HAS_THREAD_API_WIN32
836# define _LIBCPP_HAS_THREAD_API_WIN32 1
Nikolas Klauserac251722022-06-13 15:25:23837# else
838# error "No thread API"
839# endif // _LIBCPP_HAS_THREAD_API
Nikolas Klauserc6f3b7b2024-11-06 09:39:19840# endif // _LIBCPP_HAS_THREADS
Dan Albert85e26f52019-09-18 18:13:32841
Nikolas Klauserc6f3b7b2024-11-06 09:39:19842# if _LIBCPP_HAS_THREAD_API_PTHREAD
Nikolas Klauserac251722022-06-13 15:25:23843# if defined(__ANDROID__) && __ANDROID_API__ >= 30
Nikolas Klauserba875152024-10-12 07:49:52844# define _LIBCPP_HAS_COND_CLOCKWAIT 1
Nikolas Klauserac251722022-06-13 15:25:23845# elif defined(_LIBCPP_GLIBC_PREREQ)
846# if _LIBCPP_GLIBC_PREREQ(2, 30)
Nikolas Klauserba875152024-10-12 07:49:52847# define _LIBCPP_HAS_COND_CLOCKWAIT 1
848# else
849# define _LIBCPP_HAS_COND_CLOCKWAIT 0
Nikolas Klauserac251722022-06-13 15:25:23850# endif
Nikolas Klauserba875152024-10-12 07:49:52851# else
852# define _LIBCPP_HAS_COND_CLOCKWAIT 0
Nikolas Klauserac251722022-06-13 15:25:23853# endif
Nikolas Klauserba875152024-10-12 07:49:52854# else
855# define _LIBCPP_HAS_COND_CLOCKWAIT 0
Nikolas Klauserac251722022-06-13 15:25:23856# endif
857
Nikolas Klauserc6f3b7b2024-11-06 09:39:19858# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
859# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
Nikolas Klauserac251722022-06-13 15:25:23860# endif
Asiri Rathnayakec7e42392016-05-06 14:06:29861
Nikolas Klauserc6f3b7b2024-11-06 09:39:19862# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
Caslyn Tonellibbf2ad02024-11-11 21:58:34863# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
Nikolas Klauserac251722022-06-13 15:25:23864# endif
Asiri Rathnayake8c2bf452016-09-11 21:46:40865
Nikolas Klauserc6f3b7b2024-11-06 09:39:19866# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
867# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
Nikolas Klauserac251722022-06-13 15:25:23868# endif
Eric Fiselier2050bed2014-12-06 20:09:11869
Nikolas Klauserc6f3b7b2024-11-06 09:39:19870# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
Nikolas Klauserac251722022-06-13 15:25:23871# define __STDCPP_THREADS__ 1
872# endif
Nico Weber9aae5392019-07-30 14:32:47873
Louis Dionne568bb7e2019-07-25 20:29:20874// The glibc and Bionic implementation of pthreads implements
Eric Fiselier8cedf042019-07-07 17:24:03875// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
876// mutexes have no destroy mechanism.
Louis Dionne568bb7e2019-07-25 20:29:20877//
878// This optimization can't be performed on Apple platforms, where
879// pthread_mutex_destroy can allow the kernel to release resources.
880// See https://llvm.org/D64298 for details.
881//
882// TODO(EricWF): Enable this optimization on Bionic after speaking to their
883// respective stakeholders.
Nikolas Klauserac251722022-06-13 15:25:23884// clang-format off
Nikolas Klauserc6f3b7b2024-11-06 09:39:19885# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
886 (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
887 _LIBCPP_HAS_THREAD_API_WIN32
Nikolas Klauserac251722022-06-13 15:25:23888// clang-format on
Nikolas Klauserba875152024-10-12 07:49:52889# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
890# else
891# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
Nikolas Klauserac251722022-06-13 15:25:23892# endif
Eric Fiselier8baf8382019-07-07 01:20:54893
Eric Fiselier8cedf042019-07-07 17:24:03894// Destroying a condvar is a nop on Windows.
Louis Dionne568bb7e2019-07-25 20:29:20895//
896// This optimization can't be performed on Apple platforms, where
897// pthread_cond_destroy can allow the kernel to release resources.
898// See https://llvm.org/D64298 for details.
899//
Eric Fiselier8cedf042019-07-07 17:24:03900// TODO(EricWF): This is potentially true for some pthread implementations
901// as well.
Nikolas Klauserc6f3b7b2024-11-06 09:39:19902# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
Nikolas Klauserba875152024-10-12 07:49:52903# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
904# else
905# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
Nikolas Klauserac251722022-06-13 15:25:23906# endif
Eric Fiselier8cedf042019-07-07 17:24:03907
Nikolas Klauserac251722022-06-13 15:25:23908# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
Nikolas Klauserc6f3b7b2024-11-06 09:39:19909 _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
Nikolas Klauserac251722022-06-13 15:25:23910# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
Davide Italiano6de760a2019-03-05 18:40:49911# endif
Eric Fiselier749adeb2015-08-19 17:21:46912
Xing Xue7f302f22023-09-07 18:48:45913# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
Nikolas Klauserc6f3b7b2024-11-06 09:39:19914# define _LIBCPP_HAS_C_ATOMIC_IMP 1
915# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0
916# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
Nikolas Klauserac251722022-06-13 15:25:23917# elif defined(_LIBCPP_COMPILER_GCC)
Nikolas Klauserc6f3b7b2024-11-06 09:39:19918# define _LIBCPP_HAS_C_ATOMIC_IMP 0
919# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1
920# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0
Nikolas Klauserac251722022-06-13 15:25:23921# endif
Eric Fiselierfcd02212016-02-11 11:59:44922
Nikolas Klauserc6f3b7b2024-11-06 09:39:19923# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP
Nikolas Klauserba875152024-10-12 07:49:52924# define _LIBCPP_HAS_ATOMIC_HEADER 0
Nikolas Klauserac251722022-06-13 15:25:23925# else
Nikolas Klauserba875152024-10-12 07:49:52926# define _LIBCPP_HAS_ATOMIC_HEADER 1
Nikolas Klauserac251722022-06-13 15:25:23927# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
928# define _LIBCPP_ATOMIC_FLAG_TYPE bool
929# endif
Nikolas Klauserac251722022-06-13 15:25:23930# endif
931
Louis Dionne71f95ec2023-07-04 22:11:16932# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
933# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
934# else
935# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
936# endif
937
Saleem Abdulrasool3444e9f2017-02-13 15:26:51938// Work around the attribute handling in clang. When both __declspec and
939// __attribute__ are present, the processing goes awry preventing the definition
Martin Storsjöde5d38e2022-01-11 09:23:39940// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
941// combining the two does work.
Nikolas Klauserba875152024-10-12 07:49:52942# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \
943 __has_attribute(acquire_capability) && !defined(_MSC_VER)
944# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1
945# else
946# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0
Logan Chien2b772b92018-02-24 07:57:32947# endif
Eric Fiselier7865b2e2016-03-16 02:30:06948
Nikolas Klauserba875152024-10-12 07:49:52949# if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
Nikolas Klauserac251722022-06-13 15:25:23950# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
951# else
952# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
953# endif
Eric Fiselierfda38252019-12-13 20:42:07954
Nikolas Klauser8b73be52023-11-13 12:06:06955# if _LIBCPP_STD_VER >= 20
956# define _LIBCPP_CONSTINIT constinit
957# elif __has_attribute(__require_constant_initialization__)
958# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
959# else
960# define _LIBCPP_CONSTINIT
961# endif
962
Dmitri Gribenko7378fb32024-01-22 18:12:05963# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
964// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
965// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
966// when compiling for CUDA we use the non-underscored version of the noinline
967// attribute.
968//
969// This is a temporary workaround and we still expect the CUDA SDK team to solve
970// this issue properly in the SDK headers.
971//
972// See https://github.com/llvm/llvm-project/pull/73838 for more details.
973# define _LIBCPP_NOINLINE __attribute__((noinline))
974# elif __has_attribute(__noinline__)
975# define _LIBCPP_NOINLINE __attribute__((__noinline__))
976# else
977# define _LIBCPP_NOINLINE
978# endif
979
Louis Dionnef4c12582021-08-23 19:32:36980// We often repeat things just for handling wide characters in the library.
981// When wide characters are disabled, it can be useful to have a quick way of
982// disabling it without having to resort to #if-#endif, which has a larger
983// impact on readability.
Nikolas Klauserc6f3b7b2024-11-06 09:39:19984# if !_LIBCPP_HAS_WIDE_CHARACTERS
Nikolas Klauserac251722022-06-13 15:25:23985# define _LIBCPP_IF_WIDE_CHARACTERS(...)
986# else
987# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
988# endif
Louis Dionnef4c12582021-08-23 19:32:36989
Nicole Rabjohn92e4d672023-07-06 17:12:05990// clang-format off
Louis Dionne7b462252024-01-25 20:48:46991# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
992# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")")
Nicole Rabjohn92e4d672023-07-06 17:12:05993// clang-format on
Eric Fiseliera016efb2017-05-31 22:07:49994
Nikolas Klauserac251722022-06-13 15:25:23995# ifndef _LIBCPP_NO_AUTO_LINK
996# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
997# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
998# pragma comment(lib, "c++.lib")
999# else
1000# pragma comment(lib, "libc++.lib")
1001# endif
1002# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
1003# endif // _LIBCPP_NO_AUTO_LINK
Eric Fiselier56312f52017-06-16 01:57:411004
Dan Alberta7e90592019-09-16 19:26:411005// Configures the fopen close-on-exec mode character, if any. This string will
1006// be appended to any mode string used by fstream for fopen/fdopen.
1007//
1008// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1009// do.
Nikolas Klauserac251722022-06-13 15:25:231010# if defined(__BIONIC__)
1011# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1012# else
1013# define _LIBCPP_FOPEN_CLOEXEC_MODE
1014# endif
Dan Alberta7e90592019-09-16 19:26:411015
Nikolas Klauserac251722022-06-13 15:25:231016# if __has_cpp_attribute(msvc::no_unique_address)
1017// MSVC implements [[no_unique_address]] as a silent no-op currently.
1018// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
1019// However, MSVC implements [[msvc::no_unique_address]] which does what
1020// [[no_unique_address]] is supposed to do, in general.
Nikolas Klauserac251722022-06-13 15:25:231021# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
Nikolas Klauserac251722022-06-13 15:25:231022# else
Nikolas Klauser42f52772024-09-03 17:46:081023# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
Nikolas Klauserac251722022-06-13 15:25:231024# endif
Martin Storsjö8a0a7062022-02-10 11:23:401025
Tom Honermann7e7013c2022-09-10 14:16:201026// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1027// functions is gradually being added to existing C libraries. The conditions
1028// below check for known C library versions and conditions under which these
1029// functions are declared by the C library.
Nikolas Klauserba875152024-10-12 07:49:521030//
Tom Honermann7e7013c2022-09-10 14:16:201031// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
Tom Honermanncf93a3d2023-01-25 22:57:151032// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1033// the latter depends on internal GNU libc details that are not appropriate
1034// to depend on here, so any declarations present when __cpp_char8_t is not
1035// defined are ignored.
1036# if defined(_LIBCPP_GLIBC_PREREQ)
1037# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
Nikolas Klauserba875152024-10-12 07:49:521038# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
1039# else
1040# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
Tom Honermann7e7013c2022-09-10 14:16:201041# endif
Nikolas Klauserba875152024-10-12 07:49:521042# else
1043# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
Tom Honermann7e7013c2022-09-10 14:16:201044# endif
1045
Mark de Wever261b5ab2022-10-05 17:54:441046// There are a handful of public standard library types that are intended to
1047// support CTAD but don't need any explicit deduction guides to do so. This
1048// macro is used to mark them as such, which suppresses the
1049// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1050// with these classes.
Nikolas Klausere65cd4c2023-02-23 20:17:111051# if _LIBCPP_STD_VER >= 17
1052# ifdef _LIBCPP_COMPILER_CLANG_BASED
1053# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1054 template <class... _Tag> \
1055 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1056# else
1057# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
1058 template <class... _Tag> \
1059 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1060# endif
1061# else
1062# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1063# endif
Louis Dionnec2df7072022-09-08 21:36:111064
Nikolas Klauser483edfe2025-04-08 11:05:241065// TODO(LLVM 22): Remove the workaround
1066# if defined(__OBJC__) && (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER < 2001)
Konstantin Varlamov87cf39a2023-03-03 01:35:031067# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1068# endif
1069
Louis Dionne5a6e6ad2023-06-16 18:32:081070# define _PSTL_PRAGMA(x) _Pragma(#x)
Nikolas Klauserf041b342023-05-09 18:51:401071
1072// Enable SIMD for compilers that support OpenMP 4.0
Louis Dionne5a6e6ad2023-06-16 18:32:081073# if (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401074
Louis Dionne5a6e6ad2023-06-16 18:32:081075# define _PSTL_UDR_PRESENT
1076# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1077# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1078# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1079# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1080# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1081# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
Nikolas Klauserf041b342023-05-09 18:51:401082
1083// Declaration of reduction functor, where
1084// NAME - the name of the functor
1085// OP - type of the callable object with the reduction operation
1086// omp_in - refers to the local partial result
1087// omp_out - refers to the final value of the combiner operator
1088// omp_priv - refers to the private copy of the initial value
1089// omp_orig - refers to the original variable to be reduced
Louis Dionne5a6e6ad2023-06-16 18:32:081090# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
1091 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
Nikolas Klauserf041b342023-05-09 18:51:401092
Nikolas Klauser15941dd2023-08-01 01:43:501093# elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1094
1095# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1096# define _PSTL_PRAGMA_DECLARE_SIMD
1097# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1098# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1099# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1100# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1101# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1102
Louis Dionne5a6e6ad2023-06-16 18:32:081103# else // (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401104
Louis Dionne5a6e6ad2023-06-16 18:32:081105# define _PSTL_PRAGMA_SIMD
1106# define _PSTL_PRAGMA_DECLARE_SIMD
1107# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1108# define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1109# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1110# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1111# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
Nikolas Klauserf041b342023-05-09 18:51:401112
Louis Dionne5a6e6ad2023-06-16 18:32:081113# endif // (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401114
Louis Dionne5a6e6ad2023-06-16 18:32:081115# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
Nikolas Klauserf041b342023-05-09 18:51:401116
philnik777e90845f2023-11-23 21:15:061117// Optional attributes - these are useful for a better QoI, but not required to be available
1118
Nikolas Klauserb101c352025-02-12 12:48:541119# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1120# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1121# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1122# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1123# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1124 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1125# define _LIBCPP_PACKED __attribute__((__packed__))
1126
philnik777e90845f2023-11-23 21:15:061127# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1128# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1129# else
1130# define _LIBCPP_NO_CFI
1131# endif
1132
philnik777e90845f2023-11-23 21:15:061133# if __has_attribute(__using_if_exists__)
1134# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1135# else
1136# define _LIBCPP_USING_IF_EXISTS
1137# endif
1138
Nikolas Klauserabf9c1a2025-03-29 21:54:571139# if __has_cpp_attribute(_Clang::__no_destroy__)
1140# define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]]
philnik777e90845f2023-11-23 21:15:061141# else
1142# define _LIBCPP_NO_DESTROY
1143# endif
1144
Louis Dionnea00bbcb2024-05-01 16:26:381145# if __has_attribute(__diagnose_if__)
philnik777e90845f2023-11-23 21:15:061146# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1147# else
1148# define _LIBCPP_DIAGNOSE_WARNING(...)
1149# endif
1150
philnik777e90845f2023-11-23 21:15:061151# if __has_cpp_attribute(_Clang::__lifetimebound__)
1152# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1153# else
1154# define _LIBCPP_LIFETIMEBOUND
1155# endif
1156
A. Jiang08159e62024-10-25 01:04:421157# if __has_cpp_attribute(_Clang::__noescape__)
1158# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]]
1159# else
1160# define _LIBCPP_NOESCAPE
1161# endif
1162
Nikolas Klauser6f684812025-01-23 12:18:541163# if __has_cpp_attribute(_Clang::__no_specializations__)
1164# define _LIBCPP_NO_SPECIALIZATIONS \
1165 [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
1166# else
1167# define _LIBCPP_NO_SPECIALIZATIONS
1168# endif
1169
Nikolas Klauserabf9c1a2025-03-29 21:54:571170# if __has_cpp_attribute(_Clang::__standalone_debug__)
1171# define _LIBCPP_STANDALONE_DEBUG [[_Clang::__standalone_debug__]]
philnik777e90845f2023-11-23 21:15:061172# else
1173# define _LIBCPP_STANDALONE_DEBUG
1174# endif
1175
Nikolas Klauserabf9c1a2025-03-29 21:54:571176# if __has_cpp_attribute(_Clang::__preferred_name__)
1177# define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]]
philnik777e90845f2023-11-23 21:15:061178# else
1179# define _LIBCPP_PREFERRED_NAME(x)
1180# endif
1181
philnik777e90845f2023-11-23 21:15:061182# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1183# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1184# else
1185# define _LIBCPP_DECLSPEC_EMPTY_BASES
1186# endif
1187
1188// Allow for build-time disabling of unsigned integer sanitization
1189# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1190# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1191# else
1192# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1193# endif
1194
Nikolas Klauserf896bd32025-02-27 21:57:191195# if __has_feature(nullability)
1196# define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull
1197# else
1198# define _LIBCPP_DIAGNOSE_NULLPTR
1199# endif
1200
Hristo Hristove52ad492025-02-14 14:02:131201// TODO(LLVM 22): Remove this macro once LLVM19 support ends. __cpp_explicit_this_parameter has been set in LLVM20.
Hristo Hristov3412bc72024-01-21 05:16:511202// Clang-18 has support for deducing this, but it does not set the FTM.
1203# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
Nikolas Klauserba875152024-10-12 07:49:521204# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1
1205# else
1206# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
Hristo Hristov3412bc72024-01-21 05:16:511207# endif
1208
Eric Fiselier56312f52017-06-16 01:57:411209#endif // __cplusplus
1210
Louis Dionnecc82a1b2022-03-23 17:11:041211#endif // _LIBCPP___CONFIG