blob: b0a5dda147a6ae38012973739bc231313562715c [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>
17#include <__configuration/platform.h>
Louis Dionnec06a8f92020-06-26 16:08:5918
Eric Fiselier60506cb2015-11-06 06:30:1219#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
Arthur O'Dwyerfa6b9e42022-02-02 01:16:4020# pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:1021#endif
Howard Hinnant3e519522010-05-11 19:42:1622
Eric Fiselier60506cb2015-11-06 06:30:1223#ifdef __cplusplus
24
Nikolas Klauser7949ee02023-06-07 20:33:0225// The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
26
Louis Dionnead0dfb42022-09-19 15:27:5027// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
Tom Stellard603c2862023-01-25 06:55:5328// 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:1829// defined to XXYYZZ.
Tobias Hieta8f701b52024-07-23 08:50:3630# define _LIBCPP_VERSION 200000
Howard Hinnant3e519522010-05-11 19:42:1631
Louis Dionned2e86862022-07-07 18:07:3732# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
33# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
34
Nikolas Klauserac251722022-06-13 15:25:2335# if __STDC_HOSTED__ == 0
36# define _LIBCPP_FREESTANDING
Eric Fiselier998a5c82018-07-27 03:07:0937# endif
Eric Fiselier998a5c82018-07-27 03:07:0938
varconstd1367ca2023-07-12 17:12:5139// HARDENING {
40
varconstf0dfe682023-07-14 23:58:1541// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
Louis Dionne9bd575d2024-07-12 20:07:1242// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20.
varconstf0dfe682023-07-14 23:58:1543# ifdef _LIBCPP_ENABLE_ASSERTIONS
Louis Dionne9bd575d2024-07-12 20:07:1244# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead"
varconstf0dfe682023-07-14 23:58:1545# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
46# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
47# endif
48# if _LIBCPP_ENABLE_ASSERTIONS
Konstantin Varlamov64d413e2023-11-08 19:10:0049# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE
varconstf0dfe682023-07-14 23:58:1550# endif
51# endif
52
Konstantin Varlamov64d413e2023-11-08 19:10:0053// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
varconstd1367ca2023-07-12 17:12:5154//
Konstantin Varlamov64d413e2023-11-08 19:10:0055// - `_LIBCPP_HARDENING_MODE_NONE`;
56// - `_LIBCPP_HARDENING_MODE_FAST`;
57// - `_LIBCPP_HARDENING_MODE_EXTENSIVE`;
58// - `_LIBCPP_HARDENING_MODE_DEBUG`.
Konstantin Varlamovb85e1862023-09-12 19:01:3659//
Konstantin Varlamov64d413e2023-11-08 19:10:0060// These values have the following effects:
varconstd1367ca2023-07-12 17:12:5161//
Konstantin Varlamov64d413e2023-11-08 19:10:0062// - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks;
63//
64// - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks
65// that can be done with relatively little runtime overhead in constant time;
66//
67// - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of
68// the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors
69// but are not necessarily security-critical;
70//
71// - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive
72// mode and enables all checks available in the library, including internal assertions. Checks that are part of the
73// 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:5174
varconst4122db12023-07-20 17:13:5475// Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
76// macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
77//
78// - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
79// a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
80// - the sentinel is reachable from the begin iterator;
varconst4122db12023-07-20 17:13:5481// - TODO(hardening): both iterators refer to the same container.
82//
83// - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
84// the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
85// a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
86// `optional` and `function` are considered one-element containers for the purposes of this check.
87//
Konstantin Varlamovb85fdc42023-11-08 02:12:1588// - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero
89// address does not refer to an actual location in memory, so a null pointer dereference would not compromize the
90// memory security of a program (however, it is still undefined behavior that can result in strange errors due to
91// compiler optimizations).
92//
varconst4a652e42023-07-24 21:56:4493// - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
94// given ranges do not overlap.
95//
Konstantin Varlamov60824782024-01-23 02:12:5896// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object
97// was allocated by the given allocator). Violating this category typically results in a memory leak.
98//
99// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in
100// an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like
101// attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category
102// (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or
103// otherwise create an immediate security issue.
104//
varconst4122db12023-07-20 17:13:54105// - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
106// the containers have compatible allocators.
107//
Konstantin Varlamovdc577522024-01-21 07:38:02108// - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments
109// for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the
110// original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g.
111// a string view where only a subset of elements is possible to access). This category is for assertions violating
112// which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the
113// user code.
114//
Konstantin Varlamov4f215fd2024-01-06 00:29:23115// - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to
116// be benign in our implementation.
117//
Konstantin Varlamov8938bc02024-01-23 07:31:58118// - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed
119// by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied;
120// thus, this would often be a heuristic check and it might be quite expensive.
121//
varconst4122db12023-07-20 17:13:54122// - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
123// user input.
124//
125// - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
varconstd1367ca2023-07-12 17:12:51126
Konstantin Varlamov64d413e2023-11-08 19:10:00127// clang-format off
128# define _LIBCPP_HARDENING_MODE_NONE (1 << 1)
129# define _LIBCPP_HARDENING_MODE_FAST (1 << 2)
130# define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered.
131# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3)
132// clang-format on
133
134# ifndef _LIBCPP_HARDENING_MODE
Konstantin Varlamov091fc812024-02-06 21:45:31135
136# ifndef _LIBCPP_HARDENING_MODE_DEFAULT
137# error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
138`__config_site` header, please make sure your installation of libc++ is not broken.
139# endif
140
Konstantin Varlamov64d413e2023-11-08 19:10:00141# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
varconstd1367ca2023-07-12 17:12:51142# endif
143
Konstantin Varlamov64d413e2023-11-08 19:10:00144# if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \
145 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
146 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
147 _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
148# error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
149_LIBCPP_HARDENING_MODE_NONE, \
150_LIBCPP_HARDENING_MODE_FAST, \
151_LIBCPP_HARDENING_MODE_EXTENSIVE, \
152_LIBCPP_HARDENING_MODE_DEBUG
varconstd1367ca2023-07-12 17:12:51153# endif
154
varconstd1367ca2023-07-12 17:12:51155// } HARDENING
156
Nikolas Klauserf02120f2022-08-13 11:52:35157# define _LIBCPP_TOSTRING2(x) #x
Nikolas Klauserac251722022-06-13 15:25:23158# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
Nikolas Klausera7c2a622022-02-14 17:52:28159
Nikolas Klauser07efa282023-02-17 13:01:19160// NOLINTNEXTLINE(libcpp-cpp-version-check)
Nikolas Klauserac251722022-06-13 15:25:23161# if __cplusplus < 201103L
162# define _LIBCPP_CXX03_LANG
163# endif
Eric Fiseliere825d8b2015-07-10 20:26:38164
Marek Kurdej7223bcf2022-12-15 01:19:59165# ifndef __has_constexpr_builtin
166# define __has_constexpr_builtin(x) 0
167# endif
168
Nikolas Klauser15300342024-02-28 20:14:35169// This checks wheter a Clang module is built
170# ifndef __building_module
171# define __building_module(...) 0
172# endif
173
Eric Fiseliere825d8b2015-07-10 20:26:38174// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
175// the compiler and '1' otherwise.
Nikolas Klauserac251722022-06-13 15:25:23176# ifndef __is_identifier
177# define __is_identifier(__x) 1
178# endif
Logan Chien2b772b92018-02-24 07:57:32179
Nikolas Klauserac251722022-06-13 15:25:23180# ifndef __has_declspec_attribute
181# define __has_declspec_attribute(__x) 0
182# endif
Eric Fiseliere825d8b2015-07-10 20:26:38183
Xing Xue7f302f22023-09-07 18:48:45184# define __has_keyword(__x) !(__is_identifier(__x))
185
Nikolas Klauser4d323e42024-03-09 00:09:28186# ifndef __has_warning
187# define __has_warning(...) 0
188# endif
189
Nikolas Klauser929d5de2022-06-17 11:58:22190# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
191# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
Nikolas Klauserac251722022-06-13 15:25:23192# endif
Eric Fiselier5de7cac2019-06-13 00:37:25193
Eric Fiselier330fe012017-01-07 02:43:58194// FIXME: ABI detection should be done via compiler builtin macros. This
195// is just a placeholder until Clang implements such macros. For now assume
Shoaib Meenaid4563852017-10-04 23:44:38196// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
197// and allow the user to explicitly specify the ABI to handle cases where this
198// heuristic falls short.
Nikolas Klauserac251722022-06-13 15:25:23199# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
200# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
201# elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
202# define _LIBCPP_ABI_ITANIUM
203# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
Logan Chien2b772b92018-02-24 07:57:32204# define _LIBCPP_ABI_MICROSOFT
205# else
Nikolas Klauserac251722022-06-13 15:25:23206# if defined(_WIN32) && defined(_MSC_VER)
207# define _LIBCPP_ABI_MICROSOFT
208# else
209# define _LIBCPP_ABI_ITANIUM
210# endif
Logan Chien2b772b92018-02-24 07:57:32211# endif
Eric Fiselier330fe012017-01-07 02:43:58212
Nikolas Klauserac251722022-06-13 15:25:23213# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
214# define _LIBCPP_ABI_VCRUNTIME
215# endif
Eric Fiseliere69290d2019-03-05 01:57:01216
Louis Dionnedeb3b552022-07-20 14:42:04217# if __has_feature(experimental_library)
218# ifndef _LIBCPP_ENABLE_EXPERIMENTAL
219# define _LIBCPP_ENABLE_EXPERIMENTAL
220# endif
221# endif
222
Louis Dionne8711fca2022-06-30 15:57:52223// Incomplete features get their own specific disabling flags. This makes it
224// easier to grep for target specific flags once the feature is complete.
225# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
Nikolas Klausere7e37112023-05-05 15:41:13226# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
Hui477f6bc2023-07-10 14:55:55227# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
Mark de Wevera4422a52024-04-20 10:09:13228# define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB
Mark de Wever7cc72a02023-09-05 18:10:38229# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM
Hui477f6bc2023-07-10 14:55:55230# endif
231
Nikolas Klauserac251722022-06-13 15:25:23232# if defined(__MVS__)
233# include <features.h> // for __NATIVE_ASCII_F
234# endif
Muiez Ahmeda1da7392022-01-14 16:35:53235
Nikolas Klauserac251722022-06-13 15:25:23236# if defined(_WIN32)
237# define _LIBCPP_WIN32API
Nikolas Klauserac251722022-06-13 15:25:23238# define _LIBCPP_SHORT_WCHAR 1
Louis Dionne77bca6d2019-03-20 17:05:52239// Both MinGW and native MSVC provide a "MSVC"-like environment
Nikolas Klauserac251722022-06-13 15:25:23240# define _LIBCPP_MSVCRT_LIKE
Bruno Cardoso Lopese59dd002017-07-17 21:52:31241// If mingw not explicitly detected, assume using MS C runtime only if
242// a MS compatibility version is specified.
Nikolas Klauserac251722022-06-13 15:25:23243# if defined(_MSC_VER) && !defined(__MINGW32__)
244# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
245# endif
246# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
247# define _LIBCPP_HAS_BITSCAN64
248# endif
249# define _LIBCPP_HAS_OPEN_WITH_WCHAR
250# endif // defined(_WIN32)
Howard Hinnant3e714642011-05-13 17:16:06251
Nikolas Klauserac251722022-06-13 15:25:23252# if defined(_AIX) && !defined(__64BIT__)
253// The size of wchar is 2 byte on 32-bit mode on AIX.
254# define _LIBCPP_SHORT_WCHAR 1
255# endif
Xing Xuef53fafb2021-09-09 20:20:36256
Louis Dionnebeff7152021-12-21 21:50:34257// Libc++ supports various implementations of std::random_device.
258//
259// _LIBCPP_USING_DEV_RANDOM
260// Read entropy from the given file, by default `/dev/urandom`.
261// If a token is provided, it is assumed to be the path to a file
262// to read entropy from. This is the default behavior if nothing
263// else is specified. This implementation requires storing state
264// inside `std::random_device`.
265//
266// _LIBCPP_USING_ARC4_RANDOM
267// Use arc4random(). This allows obtaining random data even when
268// using sandboxing mechanisms. On some platforms like Apple, this
269// is the recommended source of entropy for user-space programs.
270// When this option is used, the token passed to `std::random_device`'s
271// constructor *must* be "/dev/urandom" -- anything else is an error.
272//
273// _LIBCPP_USING_GETENTROPY
274// Use getentropy().
275// When this option is used, the token passed to `std::random_device`'s
276// constructor *must* be "/dev/urandom" -- anything else is an error.
277//
Roland McGrath3064dd82022-01-02 19:53:53278// _LIBCPP_USING_FUCHSIA_CPRNG
279// Use Fuchsia's zx_cprng_draw() system call, which is specified to
280// deliver high-quality entropy and cannot fail.
281// When this option is used, the token passed to `std::random_device`'s
282// constructor *must* be "/dev/urandom" -- anything else is an error.
283//
Louis Dionnebeff7152021-12-21 21:50:34284// _LIBCPP_USING_NACL_RANDOM
285// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
286// including accesses to the special files under `/dev`. This implementation
287// uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
288// When this option is used, the token passed to `std::random_device`'s
289// constructor *must* be "/dev/urandom" -- anything else is an error.
290//
291// _LIBCPP_USING_WIN32_RANDOM
292// Use rand_s(), for use on Windows.
293// When this option is used, the token passed to `std::random_device`'s
294// constructor *must* be "/dev/urandom" -- anything else is an error.
Nikolas Klauserac251722022-06-13 15:25:23295# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
Louis Dionne3b6bc8752022-11-24 18:02:58296 defined(__DragonFly__)
Nikolas Klauserac251722022-06-13 15:25:23297# define _LIBCPP_USING_ARC4_RANDOM
298# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
299# define _LIBCPP_USING_GETENTROPY
300# elif defined(__Fuchsia__)
301# define _LIBCPP_USING_FUCHSIA_CPRNG
302# elif defined(__native_client__)
303# define _LIBCPP_USING_NACL_RANDOM
304# elif defined(_LIBCPP_WIN32API)
305# define _LIBCPP_USING_WIN32_RANDOM
306# else
307# define _LIBCPP_USING_DEV_RANDOM
Logan Chien2b772b92018-02-24 07:57:32308# endif
Howard Hinnant3e519522010-05-11 19:42:16309
Nikolas Klauserac251722022-06-13 15:25:23310# ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser929d5de2022-06-17 11:58:22311
Nikolas Klauserac251722022-06-13 15:25:23312# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
Nikolas Klauser929d5de2022-06-17 11:58:22313# define _ALIGNAS_TYPE(x) alignas(x)
314# define _ALIGNAS(x) alignas(x)
Nikolas Klauser929d5de2022-06-17 11:58:22315# define _NOEXCEPT noexcept
Louis Dionnef89d7072024-01-30 13:33:48316# define _NOEXCEPT_(...) noexcept(__VA_ARGS__)
Nikolas Klauserae87a3b2022-08-09 11:22:25317# define _LIBCPP_CONSTEXPR constexpr
Nikolas Klauser929d5de2022-06-17 11:58:22318
Nikolas Klauserac251722022-06-13 15:25:23319# else
Nikolas Klauser929d5de2022-06-17 11:58:22320
321# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
322# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
323# define _ALIGNAS(x) __attribute__((__aligned__(x)))
Nikolas Klauser929d5de2022-06-17 11:58:22324# define _LIBCPP_HAS_NO_NOEXCEPT
325# define nullptr __nullptr
326# define _NOEXCEPT throw()
Louis Dionnef89d7072024-01-30 13:33:48327# define _NOEXCEPT_(...)
Nikolas Klauserae87a3b2022-08-09 11:22:25328# define static_assert(...) _Static_assert(__VA_ARGS__)
329# define decltype(...) __decltype(__VA_ARGS__)
330# define _LIBCPP_CONSTEXPR
Nikolas Klauser929d5de2022-06-17 11:58:22331
332typedef __char16_t char16_t;
333typedef __char32_t char32_t;
334
335# endif
336
Nikolas Klauserac251722022-06-13 15:25:23337# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
Howard Hinnanteb269252010-08-10 20:48:29338
Douglas Gregor64ec1012011-06-22 22:17:44339// Objective-C++ features (opt-in)
Nikolas Klauser69fecaa2024-07-13 07:41:36340# if __has_feature(objc_arc)
341# define _LIBCPP_HAS_OBJC_ARC
342# endif
Douglas Gregor64ec1012011-06-22 22:17:44343
Nikolas Klauser69fecaa2024-07-13 07:41:36344# if __has_feature(objc_arc_weak)
345# define _LIBCPP_HAS_OBJC_ARC_WEAK
346# endif
Douglas Gregor64ec1012011-06-22 22:17:44347
Nikolas Klauser69fecaa2024-07-13 07:41:36348# if __has_extension(blocks)
349# define _LIBCPP_HAS_EXTENSION_BLOCKS
350# endif
Louis Dionne8ae404a2020-01-21 20:39:43351
Nikolas Klauser69fecaa2024-07-13 07:41:36352# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
353# define _LIBCPP_HAS_BLOCKS_RUNTIME
354# endif
Louis Dionnef76c4242020-04-23 20:47:52355
Nikolas Klauser69fecaa2024-07-13 07:41:36356# if !__has_feature(address_sanitizer)
357# define _LIBCPP_HAS_NO_ASAN
358# endif
Marshall Clow91c71dd2014-04-14 15:44:57359
Nikolas Klauser69fecaa2024-07-13 07:41:36360# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
Louis Dionnecb3eb302018-07-27 12:46:03361
Nikolas Klauser69fecaa2024-07-13 07:41:36362# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
Howard Hinnant3e519522010-05-11 19:42:16363
Nikolas Klauserac251722022-06-13 15:25:23364# if defined(_LIBCPP_OBJECT_FORMAT_COFF)
Logan Chien2b772b92018-02-24 07:57:32365
Nikolas Klauserac251722022-06-13 15:25:23366# ifdef _DLL
367# define _LIBCPP_CRT_FUNC __declspec(dllimport)
Shoaib Meenaibda3c7d2017-03-02 03:22:18368# else
Nikolas Klauserac251722022-06-13 15:25:23369# define _LIBCPP_CRT_FUNC
370# endif
371
372# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
373# define _LIBCPP_DLL_VIS
374# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
375# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
376# define _LIBCPP_OVERRIDABLE_FUNC_VIS
377# define _LIBCPP_EXPORTED_FROM_ABI
378# elif defined(_LIBCPP_BUILDING_LIBRARY)
379# define _LIBCPP_DLL_VIS __declspec(dllexport)
380# if defined(__MINGW32__)
381# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
382# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
383# else
384# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
385# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
386# endif
387# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
388# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
389# else
390# define _LIBCPP_DLL_VIS __declspec(dllimport)
391# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
392# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
393# define _LIBCPP_OVERRIDABLE_FUNC_VIS
394# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
395# endif
396
Nikolas Klauserac251722022-06-13 15:25:23397# define _LIBCPP_HIDDEN
398# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
399# define _LIBCPP_TEMPLATE_VIS
400# define _LIBCPP_TEMPLATE_DATA_VIS
Nikolas Klauser3583bf32023-08-19 22:15:47401# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
Nikolas Klauserac251722022-06-13 15:25:23402
Nikolas Klauser758504b2022-06-22 09:14:04403# else
Nikolas Klauserac251722022-06-13 15:25:23404
Nikolas Klauserac251722022-06-13 15:25:23405# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Nikolas Klauser758504b2022-06-22 09:14:04406# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
Nikolas Klauserac251722022-06-13 15:25:23407# else
Nikolas Klauser758504b2022-06-22 09:14:04408# define _LIBCPP_VISIBILITY(vis)
Nikolas Klauserac251722022-06-13 15:25:23409# endif
Nikolas Klauserac251722022-06-13 15:25:23410
Nikolas Klauser758504b2022-06-22 09:14:04411# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
Nikolas Klauser758504b2022-06-22 09:14:04412# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
413# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
Nikolas Klauser758504b2022-06-22 09:14:04414# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
415# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
416
Nikolas Klauser0f050522022-07-14 13:04:36417// TODO: Make this a proper customization point or remove the option to override it.
418# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
419# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
420# endif
421
Nikolas Klauserac251722022-06-13 15:25:23422# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
423// The inline should be removed once PR32114 is resolved
424# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
425# else
426# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
427# endif
Nikolas Klauserac251722022-06-13 15:25:23428
Nikolas Klauser3583bf32023-08-19 22:15:47429// GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
430# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
431# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
Nikolas Klauserac251722022-06-13 15:25:23432# else
433# define _LIBCPP_TEMPLATE_VIS
434# endif
Nikolas Klauserac251722022-06-13 15:25:23435
Nikolas Klauserac251722022-06-13 15:25:23436# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
Nikolas Klauser3583bf32023-08-19 22:15:47437# define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
Nikolas Klauserac251722022-06-13 15:25:23438# else
Nikolas Klauser3583bf32023-08-19 22:15:47439# define _LIBCPP_TYPE_VISIBILITY_DEFAULT
Nikolas Klauserac251722022-06-13 15:25:23440# endif
Nikolas Klauserac251722022-06-13 15:25:23441
Nikolas Klauser758504b2022-06-22 09:14:04442# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
Nikolas Klauserac251722022-06-13 15:25:23443
Nikolas Klauser140c3752023-05-24 15:46:13444# if __has_attribute(exclude_from_explicit_instantiation)
Nikolas Klauserac251722022-06-13 15:25:23445# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
446# else
447// Try to approximate the effect of exclude_from_explicit_instantiation
448// (which is that entities are not assumed to be provided by explicit
449// template instantiations in the dylib) by always inlining those entities.
450# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
451# endif
452
Nikolas Klauser4d323e42024-03-09 00:09:28453# ifdef _LIBCPP_COMPILER_CLANG_BASED
454# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
455# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
456# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
457# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
458# elif defined(_LIBCPP_COMPILER_GCC)
459# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
460# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
461# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
462# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
463# else
464# define _LIBCPP_DIAGNOSTIC_PUSH
465# define _LIBCPP_DIAGNOSTIC_POP
466# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
467# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
468# endif
469
Konstantin Varlamov64d413e2023-11-08 19:10:00470# if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST
471# define _LIBCPP_HARDENING_SIG f
472# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE
Louis Dionnebc792a22023-10-26 13:05:16473# define _LIBCPP_HARDENING_SIG s
Konstantin Varlamov64d413e2023-11-08 19:10:00474# elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
Louis Dionnebc792a22023-10-26 13:05:16475# define _LIBCPP_HARDENING_SIG d
476# else
Konstantin Varlamov64d413e2023-11-08 19:10:00477# define _LIBCPP_HARDENING_SIG n // "none"
Louis Dionnebc792a22023-10-26 13:05:16478# endif
479
480# ifdef _LIBCPP_HAS_NO_EXCEPTIONS
481# define _LIBCPP_EXCEPTIONS_SIG n
482# else
483# define _LIBCPP_EXCEPTIONS_SIG e
484# endif
485
486# define _LIBCPP_ODR_SIGNATURE \
487 _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION)
488
Louis Dionned2e86862022-07-07 18:07:37489// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
490// on two levels:
491// 1. The symbol is given hidden visibility, which ensures that users won't start exporting
492// symbols from their dynamic library by means of using the libc++ headers. This ensures
493// that those symbols stay private to the dynamic library in which it is defined.
494//
Louis Dionnebc792a22023-10-26 13:05:16495// 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library.
496// This ensures that no ODR violation can arise from mixing two TUs compiled with different
497// versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the
498// program contains two definitions of a function, the ODR requires them to be token-by-token
499// equivalent, and the linker is allowed to pick either definition and discard the other one.
500//
501// For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled
502// *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs
503// compiled with different settings), the two definitions are both visible by the linker and they
504// have the same name, but they have a meaningfully different implementation (one throws an exception
505// and the other aborts the program). This violates the ODR and makes the program ill-formed, and in
506// practice what will happen is that the linker will pick one of the definitions at random and will
507// discard the other one. This can quite clearly lead to incorrect program behavior.
508//
509// A similar reasoning holds for many other properties that are ODR-affecting. Essentially any
510// property that causes the code of a function to differ from the code in another configuration
511// can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI
512// tag, but we encode the ones that we think are most important: library version, exceptions, and
513// hardening mode.
514//
515// Note that historically, solving this problem has been achieved in various ways, including
516// force-inlining all functions or giving internal linkage to all functions. Both these previous
517// solutions suffer from drawbacks that lead notably to code bloat.
Louis Dionned2e86862022-07-07 18:07:37518//
Nikolas Klauser140c3752023-05-24 15:46:13519// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
520// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
521//
Louis Dionne5efc8112022-12-21 15:08:54522// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
523// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
524// name of a virtual function is part of its ABI, since some architectures like arm64e can sign
525// the virtual function pointer in the vtable based on the mangled name of the function. Since
526// we use an ABI tag that changes with each released version, the mangled name of the virtual
527// function would change, which is incorrect. Note that it doesn't make much sense to change
528// the implementation of a virtual function in an ABI-incompatible way in the first place,
529// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
530//
Mark de Weverd1791762024-03-25 17:33:30531// The macro can be applied to record and enum types. When the tagged type is nested in
532// a record this "parent" record needs to have the macro too. Another use case for applying
533// this macro to records and unions is to apply an ABI tag to inline constexpr variables.
534// This can be useful for inline variables that are implementation details which are expected
535// to change in the future.
536//
Louis Dionned2e86862022-07-07 18:07:37537// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
538// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
539// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
540# ifndef _LIBCPP_NO_ABI_TAG
541# define _LIBCPP_HIDE_FROM_ABI \
Nikolas Klauser140c3752023-05-24 15:46:13542 _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
Louis Dionnee2c2ffb2024-06-18 13:13:45543 __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE))))
Louis Dionned2e86862022-07-07 18:07:37544# else
Nikolas Klauser140c3752023-05-24 15:46:13545# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Nikolas Klauserac251722022-06-13 15:25:23546# endif
Nikolas Klauser140c3752023-05-24 15:46:13547# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Arsen Arsenović21d92822023-01-25 07:34:55548
Nikolas Klauserac251722022-06-13 15:25:23549# ifdef _LIBCPP_BUILDING_LIBRARY
550# if _LIBCPP_ABI_VERSION > 1
Nikolas Klauser140c3752023-05-24 15:46:13551# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Nikolas Klauserac251722022-06-13 15:25:23552# else
553# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Shoaib Meenaibda3c7d2017-03-02 03:22:18554# endif
555# else
Nikolas Klauser140c3752023-05-24 15:46:13556# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Logan Chien2b772b92018-02-24 07:57:32557# endif
Eric Fiselierf8f31c42016-09-16 00:00:48558
Nikolas Klauser4d323e42024-03-09 00:09:28559// TODO: Remove this workaround once we drop support for Clang 16
Louis Dionnee2c2ffb2024-06-18 13:13:45560# if __has_warning("-Wc++23-extensions")
561# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
562# else
563# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions")
564# endif
Nikolas Klauser4d323e42024-03-09 00:09:28565
Nikolas Klauserf886dfe2024-03-23 12:54:35566// Clang modules take a significant compile time hit when pushing and popping diagnostics.
567// Since all the headers are marked as system headers in the modulemap, we can simply disable this
568// pushing and popping when building with clang modules.
569# if !__has_feature(modules)
570# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
571 _LIBCPP_DIAGNOSTIC_PUSH \
572 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \
573 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
574 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
575 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
576 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \
577 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \
578 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \
579 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \
580 _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions")
581# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP
582# else
583# define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS
584# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
585# endif
586
Eric Fiselier2f3e8b32018-10-30 02:02:00587// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
Nikolas Klauserac251722022-06-13 15:25:23588// clang-format off
Nikolas Klauserf886dfe2024-03-23 12:54:35589# define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
Nikolas Klauser4d323e42024-03-09 00:09:28590 namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
Nikolas Klauser3583bf32023-08-19 22:15:47591 inline namespace _LIBCPP_ABI_NAMESPACE {
Nikolas Klauserf886dfe2024-03-23 12:54:35592# define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
Nikolas Klauserac251722022-06-13 15:25:23593
Nikolas Klauser5d313602024-06-01 06:37:49594#ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
595# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem {
596# define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD
597#else
Louis Dionneac8c9f12023-11-28 23:41:59598# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \
599 inline namespace __fs { namespace filesystem {
Eric Fiselier2f3e8b32018-10-30 02:02:00600
Nikolas Klauser4d323e42024-03-09 00:09:28601# define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD
Nikolas Klauser5d313602024-06-01 06:37:49602#endif
603
Nikolas Klauserac251722022-06-13 15:25:23604// clang-format on
Eric Fiselier2f3e8b32018-10-30 02:02:00605
Nikolas Klauserac251722022-06-13 15:25:23606# if __has_attribute(__enable_if__)
607# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
608# endif
Eric Fiselier49e29672016-09-15 22:27:07609
Louis Dionne5a6e6ad2023-06-16 18:32:08610# if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
Nikolas Klauserac251722022-06-13 15:25:23611# define _LIBCPP_HAS_NO_INT128
612# endif
Stephan Tolksdorfe180eca2014-03-26 19:45:52613
Nikolas Klauserac251722022-06-13 15:25:23614# ifdef _LIBCPP_CXX03_LANG
615# define _LIBCPP_DECLARE_STRONG_ENUM(x) \
Louis Dionne5a6e6ad2023-06-16 18:32:08616 struct _LIBCPP_EXPORTED_FROM_ABI x { \
Nikolas Klauserac251722022-06-13 15:25:23617 enum __lx
618// clang-format off
619# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
620 __lx __v_; \
Louis Dionne4c198542023-12-04 15:25:14621 _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \
622 _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
623 _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \
Nikolas Klauserac251722022-06-13 15:25:23624 };
625// clang-format on
Howard Hinnant75689c12011-12-02 19:36:40626
Nikolas Klauserac251722022-06-13 15:25:23627# else // _LIBCPP_CXX03_LANG
Nikolas Klauser3583bf32023-08-19 22:15:47628# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
Nikolas Klauserac251722022-06-13 15:25:23629# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
630# endif // _LIBCPP_CXX03_LANG
Yaron Keren21a697b82013-12-20 13:19:45631
Louis Dionne3b6bc8752022-11-24 18:02:58632# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
Nikolas Klauserac251722022-06-13 15:25:23633# define _LIBCPP_LOCALE__L_EXTENSIONS 1
634# endif
635
636# ifdef __FreeBSD__
637# define _DECLARE_C99_LDBL_MATH 1
638# endif
Alexis Hunt4084c9e2011-07-15 05:40:33639
Reid Kleckner6a2a5e02018-04-19 22:12:10640// If we are getting operator new from the MSVC CRT, then allocation overloads
641// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
Nikolas Klauserac251722022-06-13 15:25:23642# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
643# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
644# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
645// We're deferring to Microsoft's STL to provide aligned new et al. We don't
646// have it unless the language feature test macro is defined.
647# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
648# elif defined(__MVS__)
649# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
650# endif
Reid Kleckner6a2a5e02018-04-19 22:12:10651
Nikolas Klauserac251722022-06-13 15:25:23652# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
653# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
654# endif
Eric Fiselierf2918d12018-03-22 04:42:56655
Alex Richardsoneb6fbad2022-11-17 10:19:28656// It is not yet possible to use aligned_alloc() on all Apple platforms since
657// 10.15 was the first version to ship an implementation of aligned_alloc().
658# if defined(__APPLE__)
659# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
660 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
661# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
662# endif
Shoaib Meenai49c8f902023-01-07 07:35:15663# elif defined(__ANDROID__) && __ANDROID_API__ < 28
664// Android only provides aligned_alloc when targeting API 28 or higher.
665# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
Alex Richardsoneb6fbad2022-11-17 10:19:28666# endif
667
Nikolas Klauserac251722022-06-13 15:25:23668# if defined(__APPLE__) || defined(__FreeBSD__)
669# define _LIBCPP_HAS_DEFAULTRUNELOCALE
670# endif
Alexis Huntf0235192011-07-09 01:09:31671
Louis Dionne3b6bc8752022-11-24 18:02:58672# if defined(__APPLE__) || defined(__FreeBSD__)
Nikolas Klauserac251722022-06-13 15:25:23673# define _LIBCPP_WCTYPE_IS_MASK
674# endif
Alexis Hunt00818922011-07-09 03:40:04675
Nikolas Klauserac251722022-06-13 15:25:23676# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
677# define _LIBCPP_HAS_NO_CHAR8_T
678# endif
Marshall Clow7dad0bd2018-12-11 04:35:44679
Louis Dionneea5cd3b2018-09-23 18:35:00680// Deprecation macros.
Louis Dionnea470a132019-03-12 20:10:06681//
682// Deprecations warnings are always enabled, except when users explicitly opt-out
683// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
Nikolas Klauserac251722022-06-13 15:25:23684# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Nikolas Klauserc8eff952023-01-10 00:56:53685# if __has_attribute(__deprecated__)
686# define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
687# define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
Nikolas Klauser4f152672023-02-13 23:56:09688# elif _LIBCPP_STD_VER >= 14
Nikolas Klauserac251722022-06-13 15:25:23689# define _LIBCPP_DEPRECATED [[deprecated]]
Nikolas Klauser971e9c82022-06-17 14:02:53690# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
Nikolas Klauserac251722022-06-13 15:25:23691# else
692# define _LIBCPP_DEPRECATED
Nikolas Klauser971e9c82022-06-17 14:02:53693# define _LIBCPP_DEPRECATED_(m)
Nikolas Klauserac251722022-06-13 15:25:23694# endif
Louis Dionneea5cd3b2018-09-23 18:35:00695# else
696# define _LIBCPP_DEPRECATED
Nikolas Klauser971e9c82022-06-17 14:02:53697# define _LIBCPP_DEPRECATED_(m)
Louis Dionneea5cd3b2018-09-23 18:35:00698# endif
Marshall Clow8392ab22013-09-28 18:35:31699
Nikolas Klauserac251722022-06-13 15:25:23700# if !defined(_LIBCPP_CXX03_LANG)
701# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
702# else
703# define _LIBCPP_DEPRECATED_IN_CXX11
704# endif
Louis Dionneea5cd3b2018-09-23 18:35:00705
Nikolas Klauser4f152672023-02-13 23:56:09706# if _LIBCPP_STD_VER >= 14
Nikolas Klauserac251722022-06-13 15:25:23707# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
708# else
709# define _LIBCPP_DEPRECATED_IN_CXX14
710# endif
Louis Dionneea5cd3b2018-09-23 18:35:00711
Nikolas Klauser4f152672023-02-13 23:56:09712# if _LIBCPP_STD_VER >= 17
Nikolas Klauserac251722022-06-13 15:25:23713# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
714# else
715# define _LIBCPP_DEPRECATED_IN_CXX17
716# endif
Louis Dionneea5cd3b2018-09-23 18:35:00717
Nikolas Klauser4f152672023-02-13 23:56:09718# if _LIBCPP_STD_VER >= 20
Nikolas Klauserac251722022-06-13 15:25:23719# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
720# else
721# define _LIBCPP_DEPRECATED_IN_CXX20
722# endif
Marek Kurdej841132e2020-11-26 09:07:16723
Louis Dionne5a6e6ad2023-06-16 18:32:08724# if _LIBCPP_STD_VER >= 23
725# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
726# else
727# define _LIBCPP_DEPRECATED_IN_CXX23
728# endif
Nikolas Klauser987f08f2022-12-11 01:10:31729
Hristo Hristov27e67cd2024-01-29 18:57:12730# if _LIBCPP_STD_VER >= 26
731# define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
732# else
733# define _LIBCPP_DEPRECATED_IN_CXX26
734# endif
735
Nikolas Klauserac251722022-06-13 15:25:23736# if !defined(_LIBCPP_HAS_NO_CHAR8_T)
737# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
738# else
739# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
740# endif
Martin Storsjö6be11e32020-10-26 11:18:46741
Richard Smitha9727032019-10-19 00:06:00742// Macros to enter and leave a state where deprecation warnings are suppressed.
Nikolas Klauserac251722022-06-13 15:25:23743# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
744# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
745 _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
746 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
747# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
748# else
749# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
750# define _LIBCPP_SUPPRESS_DEPRECATED_POP
751# endif
Richard Smitha9727032019-10-19 00:06:00752
Nikolas Klauserac251722022-06-13 15:25:23753# if _LIBCPP_STD_VER <= 11
Nikolas Klauser3c7a7a72023-02-02 11:12:28754# define _LIBCPP_EXPLICIT_SINCE_CXX14
Nikolas Klauserac251722022-06-13 15:25:23755# else
Nikolas Klauser3c7a7a72023-02-02 11:12:28756# define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
Nikolas Klauserac251722022-06-13 15:25:23757# endif
Marshall Clowf20d2672013-07-15 14:57:19758
Hristo Hristov40aaa272023-03-22 21:24:22759# if _LIBCPP_STD_VER >= 23
760# define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
761# else
762# define _LIBCPP_EXPLICIT_SINCE_CXX23
763# endif
764
Nikolas Klauser4f152672023-02-13 23:56:09765# if _LIBCPP_STD_VER >= 14
Nikolas Klauser5146b572022-08-19 11:08:01766# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
Nikolas Klauserac251722022-06-13 15:25:23767# else
Nikolas Klauser5146b572022-08-19 11:08:01768# define _LIBCPP_CONSTEXPR_SINCE_CXX14
Nikolas Klauserac251722022-06-13 15:25:23769# endif
Eric Fiselier371aac12014-07-17 05:16:18770
Nikolas Klauser4f152672023-02-13 23:56:09771# if _LIBCPP_STD_VER >= 17
Nikolas Klauser5146b572022-08-19 11:08:01772# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
Nikolas Klauserac251722022-06-13 15:25:23773# else
Nikolas Klauser5146b572022-08-19 11:08:01774# define _LIBCPP_CONSTEXPR_SINCE_CXX17
Nikolas Klauserac251722022-06-13 15:25:23775# endif
Eric Fiseliera58d4302016-03-17 03:30:56776
Nikolas Klauser4f152672023-02-13 23:56:09777# if _LIBCPP_STD_VER >= 20
Nikolas Klauser5146b572022-08-19 11:08:01778# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
Nikolas Klauserac251722022-06-13 15:25:23779# else
Nikolas Klauser5146b572022-08-19 11:08:01780# define _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauserac251722022-06-13 15:25:23781# endif
Marshall Clow1644c12e2017-11-14 22:26:50782
Nikolas Klauser4f152672023-02-13 23:56:09783# if _LIBCPP_STD_VER >= 23
Nikolas Klauser5146b572022-08-19 11:08:01784# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
Nikolas Klauserf02120f2022-08-13 11:52:35785# else
Nikolas Klauser5146b572022-08-19 11:08:01786# define _LIBCPP_CONSTEXPR_SINCE_CXX23
Nikolas Klauserf02120f2022-08-13 11:52:35787# endif
788
A. Jiang78085412024-08-28 13:35:57789# if _LIBCPP_STD_VER >= 26
790# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr
791# else
792# define _LIBCPP_CONSTEXPR_SINCE_CXX26
793# endif
794
Nikolas Klauserac251722022-06-13 15:25:23795# ifndef _LIBCPP_WEAK
796# define _LIBCPP_WEAK __attribute__((__weak__))
797# endif
Howard Hinnanta942f2f2013-10-04 23:56:37798
Asiri Rathnayakec7e42392016-05-06 14:06:29799// Thread API
Nikolas Klauserac251722022-06-13 15:25:23800// clang-format off
801# if !defined(_LIBCPP_HAS_NO_THREADS) && \
802 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
803 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
804 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Asiri Rathnayakec7e42392016-05-06 14:06:29805
Nikolas Klauserac251722022-06-13 15:25:23806# if defined(__FreeBSD__) || \
807 defined(__wasi__) || \
808 defined(__NetBSD__) || \
809 defined(__OpenBSD__) || \
810 defined(__NuttX__) || \
811 defined(__linux__) || \
812 defined(__GNU__) || \
813 defined(__APPLE__) || \
Nikolas Klauserac251722022-06-13 15:25:23814 defined(__MVS__) || \
815 defined(_AIX) || \
816 defined(__EMSCRIPTEN__)
817// clang-format on
818# define _LIBCPP_HAS_THREAD_API_PTHREAD
819# elif defined(__Fuchsia__)
820// TODO(44575): Switch to C11 thread API when possible.
821# define _LIBCPP_HAS_THREAD_API_PTHREAD
822# elif defined(_LIBCPP_WIN32API)
823# define _LIBCPP_HAS_THREAD_API_WIN32
824# else
825# error "No thread API"
826# endif // _LIBCPP_HAS_THREAD_API
827# endif // _LIBCPP_HAS_NO_THREADS
Dan Albert85e26f52019-09-18 18:13:32828
Nikolas Klauserac251722022-06-13 15:25:23829# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
830# if defined(__ANDROID__) && __ANDROID_API__ >= 30
831# define _LIBCPP_HAS_COND_CLOCKWAIT
832# elif defined(_LIBCPP_GLIBC_PREREQ)
833# if _LIBCPP_GLIBC_PREREQ(2, 30)
834# define _LIBCPP_HAS_COND_CLOCKWAIT
835# endif
836# endif
837# endif
838
839# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
840# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
Logan Chien2b772b92018-02-24 07:57:32841 _LIBCPP_HAS_NO_THREADS is not defined.
Nikolas Klauserac251722022-06-13 15:25:23842# endif
Asiri Rathnayakec7e42392016-05-06 14:06:29843
Nikolas Klauserac251722022-06-13 15:25:23844# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
845# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
Logan Chien2b772b92018-02-24 07:57:32846 _LIBCPP_HAS_NO_THREADS is defined.
Nikolas Klauserac251722022-06-13 15:25:23847# endif
Asiri Rathnayake8c2bf452016-09-11 21:46:40848
Nikolas Klauserac251722022-06-13 15:25:23849# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
850# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
Logan Chien2b772b92018-02-24 07:57:32851 _LIBCPP_HAS_NO_THREADS is defined.
Nikolas Klauserac251722022-06-13 15:25:23852# endif
Eric Fiselier2050bed2014-12-06 20:09:11853
Nikolas Klauserac251722022-06-13 15:25:23854# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
855# define __STDCPP_THREADS__ 1
856# endif
Nico Weber9aae5392019-07-30 14:32:47857
Louis Dionne568bb7e2019-07-25 20:29:20858// The glibc and Bionic implementation of pthreads implements
Eric Fiselier8cedf042019-07-07 17:24:03859// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
860// mutexes have no destroy mechanism.
Louis Dionne568bb7e2019-07-25 20:29:20861//
862// This optimization can't be performed on Apple platforms, where
863// pthread_mutex_destroy can allow the kernel to release resources.
864// See https://llvm.org/D64298 for details.
865//
866// TODO(EricWF): Enable this optimization on Bionic after speaking to their
867// respective stakeholders.
Nikolas Klauserac251722022-06-13 15:25:23868// clang-format off
869# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
870 (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
871 defined(_LIBCPP_HAS_THREAD_API_WIN32)
872// clang-format on
873# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
874# endif
Eric Fiselier8baf8382019-07-07 01:20:54875
Eric Fiselier8cedf042019-07-07 17:24:03876// Destroying a condvar is a nop on Windows.
Louis Dionne568bb7e2019-07-25 20:29:20877//
878// This optimization can't be performed on Apple platforms, where
879// pthread_cond_destroy can allow the kernel to release resources.
880// See https://llvm.org/D64298 for details.
881//
Eric Fiselier8cedf042019-07-07 17:24:03882// TODO(EricWF): This is potentially true for some pthread implementations
883// as well.
Nikolas Klauserac251722022-06-13 15:25:23884# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
885# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
886# endif
Eric Fiselier8cedf042019-07-07 17:24:03887
Nikolas Klauserac251722022-06-13 15:25:23888# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
Joseph Huber38dbcbd2024-08-31 12:07:52889 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
Nikolas Klauserac251722022-06-13 15:25:23890# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
Davide Italiano6de760a2019-03-05 18:40:49891# endif
Eric Fiselier749adeb2015-08-19 17:21:46892
Xing Xue7f302f22023-09-07 18:48:45893# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
Nikolas Klauserac251722022-06-13 15:25:23894# define _LIBCPP_HAS_C_ATOMIC_IMP
895# elif defined(_LIBCPP_COMPILER_GCC)
896# define _LIBCPP_HAS_GCC_ATOMIC_IMP
897# endif
Eric Fiselierfcd02212016-02-11 11:59:44898
Nikolas Klauserac251722022-06-13 15:25:23899# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
900 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
901# define _LIBCPP_HAS_NO_ATOMIC_HEADER
902# else
903# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
904# define _LIBCPP_ATOMIC_FLAG_TYPE bool
905# endif
Nikolas Klauserac251722022-06-13 15:25:23906# endif
907
Louis Dionne71f95ec2023-07-04 22:11:16908# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
909# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
910# else
911# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
912# endif
913
Nikolas Klauserac251722022-06-13 15:25:23914# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
915# if defined(__clang__) && __has_attribute(acquire_capability)
Saleem Abdulrasool3444e9f2017-02-13 15:26:51916// Work around the attribute handling in clang. When both __declspec and
917// __attribute__ are present, the processing goes awry preventing the definition
Martin Storsjöde5d38e2022-01-11 09:23:39918// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
919// combining the two does work.
Nikolas Klauserac251722022-06-13 15:25:23920# if !defined(_MSC_VER)
921# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
922# endif
Logan Chien2b772b92018-02-24 07:57:32923# endif
924# endif
Eric Fiselier7865b2e2016-03-16 02:30:06925
Nikolas Klauserac251722022-06-13 15:25:23926# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
927# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
928# else
929# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
930# endif
Eric Fiselierfda38252019-12-13 20:42:07931
Nikolas Klauser8b73be52023-11-13 12:06:06932# if _LIBCPP_STD_VER >= 20
933# define _LIBCPP_CONSTINIT constinit
934# elif __has_attribute(__require_constant_initialization__)
935# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
936# else
937# define _LIBCPP_CONSTINIT
938# endif
939
Dmitri Gribenko7378fb32024-01-22 18:12:05940# if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__)
941// The CUDA SDK contains an unfortunate definition for the __noinline__ macro,
942// which breaks the regular __attribute__((__noinline__)) syntax. Therefore,
943// when compiling for CUDA we use the non-underscored version of the noinline
944// attribute.
945//
946// This is a temporary workaround and we still expect the CUDA SDK team to solve
947// this issue properly in the SDK headers.
948//
949// See https://github.com/llvm/llvm-project/pull/73838 for more details.
950# define _LIBCPP_NOINLINE __attribute__((noinline))
951# elif __has_attribute(__noinline__)
952# define _LIBCPP_NOINLINE __attribute__((__noinline__))
953# else
954# define _LIBCPP_NOINLINE
955# endif
956
Louis Dionnef4c12582021-08-23 19:32:36957// We often repeat things just for handling wide characters in the library.
958// When wide characters are disabled, it can be useful to have a quick way of
959// disabling it without having to resort to #if-#endif, which has a larger
960// impact on readability.
Nikolas Klauserac251722022-06-13 15:25:23961# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
962# define _LIBCPP_IF_WIDE_CHARACTERS(...)
963# else
964# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
965# endif
Louis Dionnef4c12582021-08-23 19:32:36966
Nicole Rabjohn92e4d672023-07-06 17:12:05967// clang-format off
Louis Dionne7b462252024-01-25 20:48:46968# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")")
969# 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:05970// clang-format on
Eric Fiseliera016efb2017-05-31 22:07:49971
Nikolas Klauserac251722022-06-13 15:25:23972# ifndef _LIBCPP_NO_AUTO_LINK
973# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
974# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
975# pragma comment(lib, "c++.lib")
976# else
977# pragma comment(lib, "libc++.lib")
978# endif
979# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
980# endif // _LIBCPP_NO_AUTO_LINK
Eric Fiselier56312f52017-06-16 01:57:41981
Dan Alberta7e90592019-09-16 19:26:41982// Configures the fopen close-on-exec mode character, if any. This string will
983// be appended to any mode string used by fstream for fopen/fdopen.
984//
985// Not all platforms support this, but it helps avoid fd-leaks on platforms that
986// do.
Nikolas Klauserac251722022-06-13 15:25:23987# if defined(__BIONIC__)
988# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
989# else
990# define _LIBCPP_FOPEN_CLOEXEC_MODE
991# endif
Dan Alberta7e90592019-09-16 19:26:41992
Nikolas Klauserac251722022-06-13 15:25:23993# if __has_cpp_attribute(msvc::no_unique_address)
994// MSVC implements [[no_unique_address]] as a silent no-op currently.
995// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
996// However, MSVC implements [[msvc::no_unique_address]] which does what
997// [[no_unique_address]] is supposed to do, in general.
Nikolas Klauserac251722022-06-13 15:25:23998# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
Nikolas Klauserac251722022-06-13 15:25:23999# else
Nikolas Klauser42f52772024-09-03 17:46:081000# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
Nikolas Klauserac251722022-06-13 15:25:231001# endif
Martin Storsjö8a0a7062022-02-10 11:23:401002
Tom Honermann7e7013c2022-09-10 14:16:201003// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
1004// functions is gradually being added to existing C libraries. The conditions
1005// below check for known C library versions and conditions under which these
1006// functions are declared by the C library.
1007# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1008// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
Tom Honermanncf93a3d2023-01-25 22:57:151009// __cpp_char8_t is defined or if C2X extensions are enabled. Determining
1010// the latter depends on internal GNU libc details that are not appropriate
1011// to depend on here, so any declarations present when __cpp_char8_t is not
1012// defined are ignored.
1013# if defined(_LIBCPP_GLIBC_PREREQ)
1014# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
Tom Honermann7e7013c2022-09-10 14:16:201015# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
1016# endif
1017# endif
1018
Mark de Wever261b5ab2022-10-05 17:54:441019// There are a handful of public standard library types that are intended to
1020// support CTAD but don't need any explicit deduction guides to do so. This
1021// macro is used to mark them as such, which suppresses the
1022// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
1023// with these classes.
Nikolas Klausere65cd4c2023-02-23 20:17:111024# if _LIBCPP_STD_VER >= 17
1025# ifdef _LIBCPP_COMPILER_CLANG_BASED
1026# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
1027 template <class... _Tag> \
1028 [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
1029# else
1030# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
1031 template <class... _Tag> \
1032 ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
1033# endif
1034# else
1035# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
1036# endif
Louis Dionnec2df7072022-09-08 21:36:111037
Konstantin Varlamov87cf39a2023-03-03 01:35:031038// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
1039// compiler intrinsics in the Objective-C++ mode.
1040# ifdef __OBJC__
1041# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
1042# endif
1043
Louis Dionne5a6e6ad2023-06-16 18:32:081044# define _PSTL_PRAGMA(x) _Pragma(#x)
Nikolas Klauserf041b342023-05-09 18:51:401045
1046// Enable SIMD for compilers that support OpenMP 4.0
Louis Dionne5a6e6ad2023-06-16 18:32:081047# if (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401048
Louis Dionne5a6e6ad2023-06-16 18:32:081049# define _PSTL_UDR_PRESENT
1050# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
1051# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
1052# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
1053# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
1054# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
1055# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
Nikolas Klauserf041b342023-05-09 18:51:401056
1057// Declaration of reduction functor, where
1058// NAME - the name of the functor
1059// OP - type of the callable object with the reduction operation
1060// omp_in - refers to the local partial result
1061// omp_out - refers to the final value of the combiner operator
1062// omp_priv - refers to the private copy of the initial value
1063// omp_orig - refers to the original variable to be reduced
Louis Dionne5a6e6ad2023-06-16 18:32:081064# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
1065 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
Nikolas Klauserf041b342023-05-09 18:51:401066
Nikolas Klauser15941dd2023-08-01 01:43:501067# elif defined(_LIBCPP_COMPILER_CLANG_BASED)
1068
1069# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
1070# define _PSTL_PRAGMA_DECLARE_SIMD
1071# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1072# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
1073# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1074# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1075# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
1076
Louis Dionne5a6e6ad2023-06-16 18:32:081077# else // (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401078
Louis Dionne5a6e6ad2023-06-16 18:32:081079# define _PSTL_PRAGMA_SIMD
1080# define _PSTL_PRAGMA_DECLARE_SIMD
1081# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
1082# define _PSTL_PRAGMA_SIMD_SCAN(PRM)
1083# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
1084# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
1085# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
Nikolas Klauserf041b342023-05-09 18:51:401086
Louis Dionne5a6e6ad2023-06-16 18:32:081087# endif // (defined(_OPENMP) && _OPENMP >= 201307)
Nikolas Klauserf041b342023-05-09 18:51:401088
Louis Dionne5a6e6ad2023-06-16 18:32:081089# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
Nikolas Klauserf041b342023-05-09 18:51:401090
philnik777e90845f2023-11-23 21:15:061091// Optional attributes - these are useful for a better QoI, but not required to be available
1092
1093# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1094# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1095# else
1096# define _LIBCPP_NO_CFI
1097# endif
1098
1099# if __has_attribute(__malloc__)
1100# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1101# else
1102# define _LIBCPP_NOALIAS
1103# endif
1104
1105# if __has_attribute(__using_if_exists__)
1106# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1107# else
1108# define _LIBCPP_USING_IF_EXISTS
1109# endif
1110
Nikolas Klauser83bc7b52024-04-22 20:13:581111# if __has_cpp_attribute(__nodiscard__)
philnik777e90845f2023-11-23 21:15:061112# define _LIBCPP_NODISCARD [[__nodiscard__]]
1113# else
1114// We can't use GCC's [[gnu::warn_unused_result]] and
1115// __attribute__((warn_unused_result)), because GCC does not silence them via
1116// (void) cast.
1117# define _LIBCPP_NODISCARD
1118# endif
1119
philnik777e90845f2023-11-23 21:15:061120# if __has_attribute(__no_destroy__)
1121# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1122# else
1123# define _LIBCPP_NO_DESTROY
1124# endif
1125
Louis Dionnea00bbcb2024-05-01 16:26:381126# if __has_attribute(__diagnose_if__)
philnik777e90845f2023-11-23 21:15:061127# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1128# else
1129# define _LIBCPP_DIAGNOSE_WARNING(...)
1130# endif
1131
1132// Use a function like macro to imply that it must be followed by a semicolon
1133# if __has_cpp_attribute(fallthrough)
1134# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1135# elif __has_attribute(__fallthrough__)
1136# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1137# else
1138# define _LIBCPP_FALLTHROUGH() ((void)0)
1139# endif
1140
1141# if __has_cpp_attribute(_Clang::__lifetimebound__)
1142# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1143# else
1144# define _LIBCPP_LIFETIMEBOUND
1145# endif
1146
1147# if __has_attribute(__nodebug__)
1148# define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1149# else
1150# define _LIBCPP_NODEBUG
1151# endif
1152
1153# if __has_attribute(__standalone_debug__)
1154# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1155# else
1156# define _LIBCPP_STANDALONE_DEBUG
1157# endif
1158
1159# if __has_attribute(__preferred_name__)
1160# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1161# else
1162# define _LIBCPP_PREFERRED_NAME(x)
1163# endif
1164
1165# if __has_attribute(__no_sanitize__)
1166# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1167# else
1168# define _LIBCPP_NO_SANITIZE(...)
1169# endif
1170
1171# if __has_attribute(__init_priority__)
1172# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1173# else
1174# define _LIBCPP_INIT_PRIORITY_MAX
1175# endif
1176
1177# if __has_attribute(__format__)
1178// The attribute uses 1-based indices for ordinary and static member functions.
1179// The attribute uses 2-based indices for non-static member functions.
1180# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1181 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1182# else
1183# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1184# endif
1185
1186# if __has_attribute(__packed__)
1187# define _LIBCPP_PACKED __attribute__((__packed__))
1188# else
1189# define _LIBCPP_PACKED
1190# endif
1191
1192# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1193# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1194# else
1195# define _LIBCPP_DECLSPEC_EMPTY_BASES
1196# endif
1197
1198// Allow for build-time disabling of unsigned integer sanitization
1199# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1200# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1201# else
1202# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1203# endif
1204
Hristo Hristov3412bc72024-01-21 05:16:511205// Clang-18 has support for deducing this, but it does not set the FTM.
1206# if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800)
1207# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER
1208# endif
1209
Eric Fiselier56312f52017-06-16 01:57:411210#endif // __cplusplus
1211
Louis Dionnecc82a1b2022-03-23 17:11:041212#endif // _LIBCPP___CONFIG