Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | eb8650a | 2021-11-17 21:25:01 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Louis Dionne | cc82a1b | 2022-03-23 17:11:04 | [diff] [blame] | 10 | #ifndef _LIBCPP___CONFIG |
| 11 | #define _LIBCPP___CONFIG |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 12 | |
Louis Dionne | c06a8f9 | 2020-06-26 16:08:59 | [diff] [blame] | 13 | #include <__config_site> |
Louis Dionne | 23e1ed6 | 2024-05-28 11:22:06 | [diff] [blame] | 14 | #include <__configuration/abi.h> |
Louis Dionne | 04f01a2 | 2024-05-29 01:29:11 | [diff] [blame] | 15 | #include <__configuration/availability.h> |
Louis Dionne | 23e1ed6 | 2024-05-28 11:22:06 | [diff] [blame] | 16 | #include <__configuration/compiler.h> |
Louis Dionne | 61498a8 | 2024-10-31 15:35:30 | [diff] [blame] | 17 | #include <__configuration/language.h> |
Louis Dionne | 23e1ed6 | 2024-05-28 11:22:06 | [diff] [blame] | 18 | #include <__configuration/platform.h> |
Louis Dionne | c06a8f9 | 2020-06-26 16:08:59 | [diff] [blame] | 19 | |
Eric Fiselier | 60506cb | 2015-11-06 06:30:12 | [diff] [blame] | 20 | #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
Arthur O'Dwyer | fa6b9e4 | 2022-02-02 01:16:40 | [diff] [blame] | 21 | # pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 22 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 23 | |
Eric Fiselier | 60506cb | 2015-11-06 06:30:12 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | |
Nikolas Klauser | 7949ee0 | 2023-06-07 20:33:02 | [diff] [blame] | 26 | // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html |
| 27 | |
Louis Dionne | ad0dfb4 | 2022-09-19 15:27:50 | [diff] [blame] | 28 | // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. |
Tom Stellard | 603c286 | 2023-01-25 06:55:53 | [diff] [blame] | 29 | // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is |
Louis Dionne | b6ff5b4 | 2022-09-19 19:38:18 | [diff] [blame] | 30 | // defined to XXYYZZ. |
Tom Stellard | 3bd3e06 | 2025-01-29 03:48:43 | [diff] [blame] | 31 | # define _LIBCPP_VERSION 210000 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 32 | |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 33 | # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y |
| 34 | # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) |
Nikolas Klauser | 27c8338 | 2024-09-16 09:08:57 | [diff] [blame] | 35 | # define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 36 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 37 | # if __STDC_HOSTED__ == 0 |
| 38 | # define _LIBCPP_FREESTANDING |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 39 | # endif |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 40 | |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 41 | // HARDENING { |
| 42 | |
Louis Dionne | c9d9dc9 | 2024-10-29 14:48:18 | [diff] [blame] | 43 | // TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated. |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 44 | # ifdef _LIBCPP_ENABLE_ASSERTIONS |
Louis Dionne | c9d9dc9 | 2024-10-29 14:48:18 | [diff] [blame] | 45 | # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead" |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 46 | # endif |
| 47 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 48 | // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 49 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 50 | // - `_LIBCPP_HARDENING_MODE_NONE`; |
| 51 | // - `_LIBCPP_HARDENING_MODE_FAST`; |
| 52 | // - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; |
| 53 | // - `_LIBCPP_HARDENING_MODE_DEBUG`. |
Konstantin Varlamov | b85e186 | 2023-09-12 19:01:36 | [diff] [blame] | 54 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 55 | // These values have the following effects: |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 56 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 57 | // - `_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. |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 69 | |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 70 | // 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; |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 76 | // - 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 Varlamov | b85fdc4 | 2023-11-08 02:12:15 | [diff] [blame] | 83 | // - `_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 | // |
varconst | 4a652e4 | 2023-07-24 21:56:44 | [diff] [blame] | 88 | // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the |
| 89 | // given ranges do not overlap. |
| 90 | // |
Konstantin Varlamov | 6082478 | 2024-01-23 02:12:58 | [diff] [blame] | 91 | // - `_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 | // |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 100 | // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure |
| 101 | // the containers have compatible allocators. |
| 102 | // |
Konstantin Varlamov | dc57752 | 2024-01-21 07:38:02 | [diff] [blame] | 103 | // - `_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 Varlamov | 4f215fd | 2024-01-06 00:29:23 | [diff] [blame] | 110 | // - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to |
| 111 | // be benign in our implementation. |
| 112 | // |
Konstantin Varlamov | 8938bc0 | 2024-01-23 07:31:58 | [diff] [blame] | 113 | // - `_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 | // |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 117 | // - `_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. |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 121 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 122 | // 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 Varlamov | 091fc81 | 2024-02-06 21:45:31 | [diff] [blame] | 130 | |
| 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 Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 136 | # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 137 | # endif |
| 138 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 139 | # 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 |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 148 | # endif |
| 149 | |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 150 | // } HARDENING |
| 151 | |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 152 | # define _LIBCPP_TOSTRING2(x) #x |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 153 | # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) |
Nikolas Klauser | a7c2a62 | 2022-02-14 17:52:28 | [diff] [blame] | 154 | |
Nikolas Klauser | 07efa28 | 2023-02-17 13:01:19 | [diff] [blame] | 155 | // NOLINTNEXTLINE(libcpp-cpp-version-check) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 156 | # if __cplusplus < 201103L |
| 157 | # define _LIBCPP_CXX03_LANG |
| 158 | # endif |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 159 | |
Marek Kurdej | 7223bcf | 2022-12-15 01:19:59 | [diff] [blame] | 160 | # ifndef __has_constexpr_builtin |
| 161 | # define __has_constexpr_builtin(x) 0 |
| 162 | # endif |
| 163 | |
Nikolas Klauser | 1530034 | 2024-02-28 20:14:35 | [diff] [blame] | 164 | // This checks wheter a Clang module is built |
| 165 | # ifndef __building_module |
| 166 | # define __building_module(...) 0 |
| 167 | # endif |
| 168 | |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 169 | // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by |
| 170 | // the compiler and '1' otherwise. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 171 | # ifndef __is_identifier |
| 172 | # define __is_identifier(__x) 1 |
| 173 | # endif |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 174 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 175 | # ifndef __has_declspec_attribute |
| 176 | # define __has_declspec_attribute(__x) 0 |
| 177 | # endif |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 178 | |
Xing Xue | 7f302f2 | 2023-09-07 18:48:45 | [diff] [blame] | 179 | # define __has_keyword(__x) !(__is_identifier(__x)) |
| 180 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 181 | # ifndef __has_warning |
| 182 | # define __has_warning(...) 0 |
| 183 | # endif |
| 184 | |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 185 | # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L |
| 186 | # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 187 | # endif |
Eric Fiselier | 5de7cac | 2019-06-13 00:37:25 | [diff] [blame] | 188 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 189 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
| 190 | # define _LIBCPP_ABI_VCRUNTIME |
| 191 | # endif |
Eric Fiselier | e69290d | 2019-03-05 01:57:01 | [diff] [blame] | 192 | |
Louis Dionne | deb3b55 | 2022-07-20 14:42:04 | [diff] [blame] | 193 | # if __has_feature(experimental_library) |
| 194 | # ifndef _LIBCPP_ENABLE_EXPERIMENTAL |
| 195 | # define _LIBCPP_ENABLE_EXPERIMENTAL |
| 196 | # endif |
| 197 | # endif |
| 198 | |
Louis Dionne | 8711fca | 2022-06-30 15:57:52 | [diff] [blame] | 199 | // 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 Klauser | 24e70e3 | 2025-01-24 08:34:42 | [diff] [blame] | 201 | # 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 |
Hui | 477f6bc | 2023-07-10 14:55:55 | [diff] [blame] | 205 | # endif |
| 206 | |
Nikolas Klauser | 24e70e3 | 2025-01-24 08:34:42 | [diff] [blame] | 207 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 211 | # if defined(__MVS__) |
| 212 | # include <features.h> // for __NATIVE_ASCII_F |
| 213 | # endif |
Muiez Ahmed | a1da739 | 2022-01-14 16:35:53 | [diff] [blame] | 214 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 215 | # if defined(_WIN32) |
| 216 | # define _LIBCPP_WIN32API |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 217 | # define _LIBCPP_SHORT_WCHAR 1 |
Louis Dionne | 77bca6d | 2019-03-20 17:05:52 | [diff] [blame] | 218 | // Both MinGW and native MSVC provide a "MSVC"-like environment |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 219 | # define _LIBCPP_MSVCRT_LIKE |
Bruno Cardoso Lopes | e59dd00 | 2017-07-17 21:52:31 | [diff] [blame] | 220 | // If mingw not explicitly detected, assume using MS C runtime only if |
| 221 | // a MS compatibility version is specified. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 222 | # 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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 226 | # define _LIBCPP_HAS_BITSCAN64 1 |
| 227 | # else |
| 228 | # define _LIBCPP_HAS_BITSCAN64 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 229 | # endif |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 230 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 |
| 231 | # else |
| 232 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 |
| 233 | # define _LIBCPP_HAS_BITSCAN64 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 234 | # endif // defined(_WIN32) |
Howard Hinnant | 3e71464 | 2011-05-13 17:16:06 | [diff] [blame] | 235 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 236 | # 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 Xue | f53fafb | 2021-09-09 20:20:36 | [diff] [blame] | 240 | |
Louis Dionne | beff715 | 2021-12-21 21:50:34 | [diff] [blame] | 241 | // 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 McGrath | 3064dd8 | 2022-01-02 19:53:53 | [diff] [blame] | 262 | // _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 Dionne | beff715 | 2021-12-21 21:50:34 | [diff] [blame] | 268 | // _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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 279 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ |
Louis Dionne | 3b6bc875 | 2022-11-24 18:02:58 | [diff] [blame] | 280 | defined(__DragonFly__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 281 | # 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 Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 292 | # endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 293 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 294 | # ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 295 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 296 | # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 297 | # define _ALIGNAS_TYPE(x) alignas(x) |
| 298 | # define _ALIGNAS(x) alignas(x) |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 299 | # define _NOEXCEPT noexcept |
Louis Dionne | f89d707 | 2024-01-30 13:33:48 | [diff] [blame] | 300 | # define _NOEXCEPT_(...) noexcept(__VA_ARGS__) |
Nikolas Klauser | ae87a3b | 2022-08-09 11:22:25 | [diff] [blame] | 301 | # define _LIBCPP_CONSTEXPR constexpr |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 302 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 303 | # else |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 304 | |
| 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 Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 308 | # define nullptr __nullptr |
| 309 | # define _NOEXCEPT throw() |
Louis Dionne | f89d707 | 2024-01-30 13:33:48 | [diff] [blame] | 310 | # define _NOEXCEPT_(...) |
Nikolas Klauser | ae87a3b | 2022-08-09 11:22:25 | [diff] [blame] | 311 | # define static_assert(...) _Static_assert(__VA_ARGS__) |
| 312 | # define decltype(...) __decltype(__VA_ARGS__) |
| 313 | # define _LIBCPP_CONSTEXPR |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 314 | |
| 315 | typedef __char16_t char16_t; |
| 316 | typedef __char32_t char32_t; |
| 317 | |
| 318 | # endif |
| 319 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 320 | # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) |
Howard Hinnant | eb26925 | 2010-08-10 20:48:29 | [diff] [blame] | 321 | |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 322 | // Objective-C++ features (opt-in) |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 323 | # if __has_feature(objc_arc) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 324 | # define _LIBCPP_HAS_OBJC_ARC 1 |
| 325 | # else |
| 326 | # define _LIBCPP_HAS_OBJC_ARC 0 |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 327 | # endif |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 328 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 329 | # if __has_feature(objc_arc_weak) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 330 | # define _LIBCPP_HAS_OBJC_ARC_WEAK 1 |
| 331 | # else |
| 332 | # define _LIBCPP_HAS_OBJC_ARC_WEAK 0 |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 333 | # endif |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 334 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 335 | # if __has_extension(blocks) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 336 | # define _LIBCPP_HAS_EXTENSION_BLOCKS 1 |
| 337 | # else |
| 338 | # define _LIBCPP_HAS_EXTENSION_BLOCKS 0 |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 339 | # endif |
Louis Dionne | 8ae404a | 2020-01-21 20:39:43 | [diff] [blame] | 340 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 341 | # if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__) |
| 342 | # define _LIBCPP_HAS_BLOCKS_RUNTIME 1 |
| 343 | # else |
| 344 | # define _LIBCPP_HAS_BLOCKS_RUNTIME 0 |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 345 | # endif |
Louis Dionne | f76c424 | 2020-04-23 20:47:52 | [diff] [blame] | 346 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 347 | # if __has_feature(address_sanitizer) |
| 348 | # define _LIBCPP_HAS_ASAN 1 |
| 349 | # else |
| 350 | # define _LIBCPP_HAS_ASAN 0 |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 351 | # endif |
Marshall Clow | 91c71dd | 2014-04-14 15:44:57 | [diff] [blame] | 352 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 353 | # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) |
Louis Dionne | cb3eb30 | 2018-07-27 12:46:03 | [diff] [blame] | 354 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 355 | # if defined(_LIBCPP_OBJECT_FORMAT_COFF) |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 356 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 357 | # ifdef _DLL |
| 358 | # define _LIBCPP_CRT_FUNC __declspec(dllimport) |
Shoaib Meenai | bda3c7d | 2017-03-02 03:22:18 | [diff] [blame] | 359 | # else |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 360 | # define _LIBCPP_CRT_FUNC |
| 361 | # endif |
| 362 | |
| 363 | # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 364 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 369 | # if defined(__MINGW32__) |
Nikolas Klauser | faefb70 | 2025-03-30 10:02:27 | [diff] [blame] | 370 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 371 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 372 | # else |
| 373 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
Nikolas Klauser | faefb70 | 2025-03-30 10:02:27 | [diff] [blame] | 374 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 375 | # endif |
Nikolas Klauser | faefb70 | 2025-03-30 10:02:27 | [diff] [blame] | 376 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 377 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) |
| 378 | # else |
Nikolas Klauser | faefb70 | 2025-03-30 10:02:27 | [diff] [blame] | 379 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 380 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 381 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 382 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) |
| 383 | # endif |
| 384 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 385 | # define _LIBCPP_HIDDEN |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 386 | # define _LIBCPP_TEMPLATE_DATA_VIS |
Nikolas Klauser | c59d3a2 | 2025-04-02 20:12:59 | [diff] [blame] | 387 | # define _LIBCPP_NAMESPACE_VISIBILITY |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 388 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 389 | # else |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 390 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 391 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 392 | # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 393 | # else |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 394 | # define _LIBCPP_VISIBILITY(vis) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 395 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 396 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 397 | # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 398 | # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") |
| 399 | # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 400 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") |
| 401 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
Nico Weber | a94cec5 | 2024-11-26 23:45:03 | [diff] [blame] | 402 | |
| 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 Klauser | 0f05052 | 2022-07-14 13:04:36 | [diff] [blame] | 407 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 408 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) |
Nikolas Klauser | c59d3a2 | 2025-04-02 20:12:59 | [diff] [blame] | 409 | # define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__type_visibility__("default"))) |
| 410 | # elif !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 411 | # define _LIBCPP_NAMESPACE_VISIBILITY __attribute__((__visibility__("default"))) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 412 | # else |
Nikolas Klauser | c59d3a2 | 2025-04-02 20:12:59 | [diff] [blame] | 413 | # define _LIBCPP_NAMESPACE_VISIBILITY |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 414 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 415 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 416 | # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 417 | |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 418 | # if __has_attribute(exclude_from_explicit_instantiation) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 419 | # 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 Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 427 | # 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 Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 444 | # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST |
| 445 | # define _LIBCPP_HARDENING_SIG f |
| 446 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 447 | # define _LIBCPP_HARDENING_SIG s |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 448 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 449 | # define _LIBCPP_HARDENING_SIG d |
| 450 | # else |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 451 | # define _LIBCPP_HARDENING_SIG n // "none" |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 452 | # endif |
| 453 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 454 | # if !_LIBCPP_HAS_EXCEPTIONS |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 455 | # 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 Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 463 | // 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 Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 469 | // 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 Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 492 | // |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 493 | // 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 Dionne | 5efc811 | 2022-12-21 15:08:54 | [diff] [blame] | 496 | // 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 Wever | d179176 | 2024-03-25 17:33:30 | [diff] [blame] | 505 | // 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 Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 511 | // 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 Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 516 | _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ |
Louis Dionne | e2c2ffb | 2024-06-18 13:13:45 | [diff] [blame] | 517 | __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 518 | # else |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 519 | # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 520 | # endif |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 521 | # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
Arsen Arsenović | 21d9282 | 2023-01-25 07:34:55 | [diff] [blame] | 522 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 523 | # ifdef _LIBCPP_BUILDING_LIBRARY |
| 524 | # if _LIBCPP_ABI_VERSION > 1 |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 525 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 526 | # else |
| 527 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Shoaib Meenai | bda3c7d | 2017-03-02 03:22:18 | [diff] [blame] | 528 | # endif |
| 529 | # else |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 530 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 531 | # endif |
Eric Fiselier | f8f31c4 | 2016-09-16 00:00:48 | [diff] [blame] | 532 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 533 | // TODO: Remove this workaround once we drop support for Clang 16 |
Louis Dionne | e2c2ffb | 2024-06-18 13:13:45 | [diff] [blame] | 534 | # 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 Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 539 | |
Nikolas Klauser | f886dfe | 2024-03-23 12:54:35 | [diff] [blame] | 540 | // 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 561 | // clang-format off |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 562 | |
Nikolas Klauser | 8abca17 | 2025-03-27 10:34:38 | [diff] [blame] | 563 | // 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 Klauser | c59d3a2 | 2025-04-02 20:12:59 | [diff] [blame] | 572 | _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_NAMESPACE_VISIBILITY std { |
Nikolas Klauser | 8abca17 | 2025-03-27 10:34:38 | [diff] [blame] | 573 | |
| 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 Dionne | 118f120 | 2024-09-11 18:59:43 | [diff] [blame] | 582 | |
| 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 Klauser | 5d31360 | 2024-06-01 06:37:49 | [diff] [blame] | 589 | #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 Dionne | ac8c9f1 | 2023-11-28 23:41:59 | [diff] [blame] | 593 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ |
| 594 | inline namespace __fs { namespace filesystem { |
Eric Fiselier | 2f3e8b3 | 2018-10-30 02:02:00 | [diff] [blame] | 595 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 596 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD |
Nikolas Klauser | 5d31360 | 2024-06-01 06:37:49 | [diff] [blame] | 597 | #endif |
| 598 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 599 | // clang-format on |
Eric Fiselier | 2f3e8b3 | 2018-10-30 02:02:00 | [diff] [blame] | 600 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 601 | # if __has_attribute(__enable_if__) |
| 602 | # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) |
| 603 | # endif |
Eric Fiselier | 49e2967 | 2016-09-15 22:27:07 | [diff] [blame] | 604 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 605 | # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 606 | # define _LIBCPP_HAS_INT128 0 |
| 607 | # else |
| 608 | # define _LIBCPP_HAS_INT128 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 609 | # endif |
Stephan Tolksdorf | e180eca | 2014-03-26 19:45:52 | [diff] [blame] | 610 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 611 | # ifdef _LIBCPP_CXX03_LANG |
| 612 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) \ |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 613 | struct _LIBCPP_EXPORTED_FROM_ABI x { \ |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 614 | enum __lx |
| 615 | // clang-format off |
| 616 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ |
| 617 | __lx __v_; \ |
Louis Dionne | 4c19854 | 2023-12-04 15:25:14 | [diff] [blame] | 618 | _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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 621 | }; |
| 622 | // clang-format on |
Howard Hinnant | 75689c1 | 2011-12-02 19:36:40 | [diff] [blame] | 623 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 624 | # else // _LIBCPP_CXX03_LANG |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 625 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 626 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) |
| 627 | # endif // _LIBCPP_CXX03_LANG |
Yaron Keren | 21a697b8 | 2013-12-20 13:19:45 | [diff] [blame] | 628 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 629 | # ifdef __FreeBSD__ |
| 630 | # define _DECLARE_C99_LDBL_MATH 1 |
| 631 | # endif |
Alexis Hunt | 4084c9e | 2011-07-15 05:40:33 | [diff] [blame] | 632 | |
Reid Kleckner | 6a2a5e0 | 2018-04-19 22:12:10 | [diff] [blame] | 633 | // 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 635 | # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 636 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 637 | # 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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 640 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 641 | # elif defined(__MVS__) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 642 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 |
| 643 | # else |
| 644 | # define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 645 | # endif |
Reid Kleckner | 6a2a5e0 | 2018-04-19 22:12:10 | [diff] [blame] | 646 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 647 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 651 | # endif |
Eric Fiselier | f2918d1 | 2018-03-22 04:42:56 | [diff] [blame] | 652 | |
Alex Richardson | eb6fbad | 2022-11-17 10:19:28 | [diff] [blame] | 653 | // 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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 657 | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ |
| 658 | (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ |
Un1q32 | 949e404 | 2025-02-17 13:55:14 | [diff] [blame] | 659 | __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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 663 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 |
| 664 | # else |
| 665 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 |
Un1q32 | 6389974 | 2024-09-27 20:11:47 | [diff] [blame] | 666 | # endif |
Shoaib Meenai | 49c8f90 | 2023-01-07 07:35:15 | [diff] [blame] | 667 | # elif defined(__ANDROID__) && __ANDROID_API__ < 28 |
| 668 | // Android only provides aligned_alloc when targeting API 28 or higher. |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 669 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 |
| 670 | # else |
| 671 | # define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 |
Alex Richardson | eb6fbad | 2022-11-17 10:19:28 | [diff] [blame] | 672 | # endif |
| 673 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 674 | # if defined(__APPLE__) || defined(__FreeBSD__) |
| 675 | # define _LIBCPP_HAS_DEFAULTRUNELOCALE |
| 676 | # endif |
Alexis Hunt | f023519 | 2011-07-09 01:09:31 | [diff] [blame] | 677 | |
Louis Dionne | 3b6bc875 | 2022-11-24 18:02:58 | [diff] [blame] | 678 | # if defined(__APPLE__) || defined(__FreeBSD__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 679 | # define _LIBCPP_WCTYPE_IS_MASK |
| 680 | # endif |
Alexis Hunt | 0081892 | 2011-07-09 03:40:04 | [diff] [blame] | 681 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 682 | # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 683 | # define _LIBCPP_HAS_CHAR8_T 0 |
| 684 | # else |
| 685 | # define _LIBCPP_HAS_CHAR8_T 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 686 | # endif |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 | [diff] [blame] | 687 | |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 688 | // Deprecation macros. |
Louis Dionne | a470a13 | 2019-03-12 20:10:06 | [diff] [blame] | 689 | // |
| 690 | // Deprecations warnings are always enabled, except when users explicitly opt-out |
| 691 | // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 692 | # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) |
Nikolas Klauser | c8eff95 | 2023-01-10 00:56:53 | [diff] [blame] | 693 | # if __has_attribute(__deprecated__) |
| 694 | # define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) |
| 695 | # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 696 | # elif _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 697 | # define _LIBCPP_DEPRECATED [[deprecated]] |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 698 | # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 699 | # else |
| 700 | # define _LIBCPP_DEPRECATED |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 701 | # define _LIBCPP_DEPRECATED_(m) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 702 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 703 | # else |
| 704 | # define _LIBCPP_DEPRECATED |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 705 | # define _LIBCPP_DEPRECATED_(m) |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 706 | # endif |
Marshall Clow | 8392ab2 | 2013-09-28 18:35:31 | [diff] [blame] | 707 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 708 | # if !defined(_LIBCPP_CXX03_LANG) |
| 709 | # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED |
| 710 | # else |
| 711 | # define _LIBCPP_DEPRECATED_IN_CXX11 |
| 712 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 713 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 714 | # if _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 715 | # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED |
| 716 | # else |
| 717 | # define _LIBCPP_DEPRECATED_IN_CXX14 |
| 718 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 719 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 720 | # if _LIBCPP_STD_VER >= 17 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 721 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED |
| 722 | # else |
| 723 | # define _LIBCPP_DEPRECATED_IN_CXX17 |
| 724 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 725 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 726 | # if _LIBCPP_STD_VER >= 20 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 727 | # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED |
| 728 | # else |
| 729 | # define _LIBCPP_DEPRECATED_IN_CXX20 |
| 730 | # endif |
Marek Kurdej | 841132e | 2020-11-26 09:07:16 | [diff] [blame] | 731 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 732 | # if _LIBCPP_STD_VER >= 23 |
| 733 | # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED |
| 734 | # else |
| 735 | # define _LIBCPP_DEPRECATED_IN_CXX23 |
| 736 | # endif |
Nikolas Klauser | 987f08f | 2022-12-11 01:10:31 | [diff] [blame] | 737 | |
Hristo Hristov | 27e67cd | 2024-01-29 18:57:12 | [diff] [blame] | 738 | # if _LIBCPP_STD_VER >= 26 |
| 739 | # define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED |
A. Jiang | ab95005 | 2025-04-08 23:40:01 | [diff] [blame] | 740 | # define _LIBCPP_DEPRECATED_IN_CXX26_(m) _LIBCPP_DEPRECATED_(m) |
Hristo Hristov | 27e67cd | 2024-01-29 18:57:12 | [diff] [blame] | 741 | # else |
| 742 | # define _LIBCPP_DEPRECATED_IN_CXX26 |
A. Jiang | ab95005 | 2025-04-08 23:40:01 | [diff] [blame] | 743 | # define _LIBCPP_DEPRECATED_IN_CXX26_(m) |
Hristo Hristov | 27e67cd | 2024-01-29 18:57:12 | [diff] [blame] | 744 | # endif |
| 745 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 746 | # if _LIBCPP_HAS_CHAR8_T |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 747 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED |
| 748 | # else |
| 749 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T |
| 750 | # endif |
Martin Storsjö | 6be11e3 | 2020-10-26 11:18:46 | [diff] [blame] | 751 | |
Richard Smith | a972703 | 2019-10-19 00:06:00 | [diff] [blame] | 752 | // Macros to enter and leave a state where deprecation warnings are suppressed. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 753 | # 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 Smith | a972703 | 2019-10-19 00:06:00 | [diff] [blame] | 762 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 763 | # if _LIBCPP_STD_VER <= 11 |
Nikolas Klauser | 3c7a7a7 | 2023-02-02 11:12:28 | [diff] [blame] | 764 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 765 | # else |
Nikolas Klauser | 3c7a7a7 | 2023-02-02 11:12:28 | [diff] [blame] | 766 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 767 | # endif |
Marshall Clow | f20d267 | 2013-07-15 14:57:19 | [diff] [blame] | 768 | |
Hristo Hristov | 40aaa27 | 2023-03-22 21:24:22 | [diff] [blame] | 769 | # if _LIBCPP_STD_VER >= 23 |
| 770 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit |
| 771 | # else |
| 772 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 |
| 773 | # endif |
| 774 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 775 | # if _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 776 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 777 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 778 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 779 | # endif |
Eric Fiselier | 371aac1 | 2014-07-17 05:16:18 | [diff] [blame] | 780 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 781 | # if _LIBCPP_STD_VER >= 17 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 782 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 783 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 784 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 785 | # endif |
Eric Fiselier | a58d430 | 2016-03-17 03:30:56 | [diff] [blame] | 786 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 787 | # if _LIBCPP_STD_VER >= 20 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 788 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 789 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 790 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 791 | # endif |
Marshall Clow | 1644c12e | 2017-11-14 22:26:50 | [diff] [blame] | 792 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 793 | # if _LIBCPP_STD_VER >= 23 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 794 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 795 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 796 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 797 | # endif |
| 798 | |
A. Jiang | 7808541 | 2024-08-28 13:35:57 | [diff] [blame] | 799 | # if _LIBCPP_STD_VER >= 26 |
| 800 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr |
| 801 | # else |
| 802 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 |
| 803 | # endif |
| 804 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 805 | # ifndef _LIBCPP_WEAK |
| 806 | # define _LIBCPP_WEAK __attribute__((__weak__)) |
| 807 | # endif |
Howard Hinnant | a942f2f | 2013-10-04 23:56:37 | [diff] [blame] | 808 | |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 809 | // Thread API |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 810 | // clang-format off |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 811 | # if _LIBCPP_HAS_THREADS && \ |
| 812 | !_LIBCPP_HAS_THREAD_API_PTHREAD && \ |
| 813 | !_LIBCPP_HAS_THREAD_API_WIN32 && \ |
| 814 | !_LIBCPP_HAS_THREAD_API_EXTERNAL |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 815 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 816 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 824 | defined(__MVS__) || \ |
| 825 | defined(_AIX) || \ |
| 826 | defined(__EMSCRIPTEN__) |
| 827 | // clang-format on |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 828 | # undef _LIBCPP_HAS_THREAD_API_PTHREAD |
| 829 | # define _LIBCPP_HAS_THREAD_API_PTHREAD 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 830 | # elif defined(__Fuchsia__) |
| 831 | // TODO(44575): Switch to C11 thread API when possible. |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 832 | # undef _LIBCPP_HAS_THREAD_API_PTHREAD |
| 833 | # define _LIBCPP_HAS_THREAD_API_PTHREAD 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 834 | # elif defined(_LIBCPP_WIN32API) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 835 | # undef _LIBCPP_HAS_THREAD_API_WIN32 |
| 836 | # define _LIBCPP_HAS_THREAD_API_WIN32 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 837 | # else |
| 838 | # error "No thread API" |
| 839 | # endif // _LIBCPP_HAS_THREAD_API |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 840 | # endif // _LIBCPP_HAS_THREADS |
Dan Albert | 85e26f5 | 2019-09-18 18:13:32 | [diff] [blame] | 841 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 842 | # if _LIBCPP_HAS_THREAD_API_PTHREAD |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 843 | # if defined(__ANDROID__) && __ANDROID_API__ >= 30 |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 844 | # define _LIBCPP_HAS_COND_CLOCKWAIT 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 845 | # elif defined(_LIBCPP_GLIBC_PREREQ) |
| 846 | # if _LIBCPP_GLIBC_PREREQ(2, 30) |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 847 | # define _LIBCPP_HAS_COND_CLOCKWAIT 1 |
| 848 | # else |
| 849 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 850 | # endif |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 851 | # else |
| 852 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 853 | # endif |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 854 | # else |
| 855 | # define _LIBCPP_HAS_COND_CLOCKWAIT 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 856 | # endif |
| 857 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 858 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 860 | # endif |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 861 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 862 | # if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL |
Caslyn Tonelli | bbf2ad0 | 2024-11-11 21:58:34 | [diff] [blame] | 863 | # error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 864 | # endif |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 865 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 866 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 868 | # endif |
Eric Fiselier | 2050bed | 2014-12-06 20:09:11 | [diff] [blame] | 869 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 870 | # if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 871 | # define __STDCPP_THREADS__ 1 |
| 872 | # endif |
Nico Weber | 9aae539 | 2019-07-30 14:32:47 | [diff] [blame] | 873 | |
Louis Dionne | 568bb7e | 2019-07-25 20:29:20 | [diff] [blame] | 874 | // The glibc and Bionic implementation of pthreads implements |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 875 | // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 |
| 876 | // mutexes have no destroy mechanism. |
Louis Dionne | 568bb7e | 2019-07-25 20:29:20 | [diff] [blame] | 877 | // |
| 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 884 | // clang-format off |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 885 | # if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \ |
| 886 | (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \ |
| 887 | _LIBCPP_HAS_THREAD_API_WIN32 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 888 | // clang-format on |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 889 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1 |
| 890 | # else |
| 891 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 892 | # endif |
Eric Fiselier | 8baf838 | 2019-07-07 01:20:54 | [diff] [blame] | 893 | |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 894 | // Destroying a condvar is a nop on Windows. |
Louis Dionne | 568bb7e | 2019-07-25 20:29:20 | [diff] [blame] | 895 | // |
| 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 Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 900 | // TODO(EricWF): This is potentially true for some pthread implementations |
| 901 | // as well. |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 902 | # if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32 |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 903 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1 |
| 904 | # else |
| 905 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 906 | # endif |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 907 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 908 | # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 909 | _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 910 | # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE |
Davide Italiano | 6de760a | 2019-03-05 18:40:49 | [diff] [blame] | 911 | # endif |
Eric Fiselier | 749adeb | 2015-08-19 17:21:46 | [diff] [blame] | 912 | |
Xing Xue | 7f302f2 | 2023-09-07 18:48:45 | [diff] [blame] | 913 | # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 914 | # define _LIBCPP_HAS_C_ATOMIC_IMP 1 |
| 915 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 |
| 916 | # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 917 | # elif defined(_LIBCPP_COMPILER_GCC) |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 918 | # define _LIBCPP_HAS_C_ATOMIC_IMP 0 |
| 919 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 |
| 920 | # define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 921 | # endif |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 922 | |
Nikolas Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 923 | # if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 924 | # define _LIBCPP_HAS_ATOMIC_HEADER 0 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 925 | # else |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 926 | # define _LIBCPP_HAS_ATOMIC_HEADER 1 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 927 | # ifndef _LIBCPP_ATOMIC_FLAG_TYPE |
| 928 | # define _LIBCPP_ATOMIC_FLAG_TYPE bool |
| 929 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 930 | # endif |
| 931 | |
Louis Dionne | 71f95ec | 2023-07-04 22:11:16 | [diff] [blame] | 932 | # 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 Abdulrasool | 3444e9f | 2017-02-13 15:26:51 | [diff] [blame] | 938 | // Work around the attribute handling in clang. When both __declspec and |
| 939 | // __attribute__ are present, the processing goes awry preventing the definition |
Martin Storsjö | de5d38e | 2022-01-11 09:23:39 | [diff] [blame] | 940 | // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus |
| 941 | // combining the two does work. |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 942 | # 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 Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 947 | # endif |
Eric Fiselier | 7865b2e | 2016-03-16 02:30:06 | [diff] [blame] | 948 | |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 949 | # if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 950 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) |
| 951 | # else |
| 952 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) |
| 953 | # endif |
Eric Fiselier | fda3825 | 2019-12-13 20:42:07 | [diff] [blame] | 954 | |
Nikolas Klauser | 8b73be5 | 2023-11-13 12:06:06 | [diff] [blame] | 955 | # 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 Gribenko | 7378fb3 | 2024-01-22 18:12:05 | [diff] [blame] | 963 | # 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 Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 980 | // 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 Klauser | c6f3b7b | 2024-11-06 09:39:19 | [diff] [blame] | 984 | # if !_LIBCPP_HAS_WIDE_CHARACTERS |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 985 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) |
| 986 | # else |
| 987 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ |
| 988 | # endif |
Louis Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 989 | |
Nicole Rabjohn | 92e4d67 | 2023-07-06 17:12:05 | [diff] [blame] | 990 | // clang-format off |
Louis Dionne | 7b46225 | 2024-01-25 20:48:46 | [diff] [blame] | 991 | # 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 Rabjohn | 92e4d67 | 2023-07-06 17:12:05 | [diff] [blame] | 993 | // clang-format on |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 994 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 995 | # 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 Fiselier | 56312f5 | 2017-06-16 01:57:41 | [diff] [blame] | 1004 | |
Dan Albert | a7e9059 | 2019-09-16 19:26:41 | [diff] [blame] | 1005 | // 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1010 | # if defined(__BIONIC__) |
| 1011 | # define _LIBCPP_FOPEN_CLOEXEC_MODE "e" |
| 1012 | # else |
| 1013 | # define _LIBCPP_FOPEN_CLOEXEC_MODE |
| 1014 | # endif |
Dan Albert | a7e9059 | 2019-09-16 19:26:41 | [diff] [blame] | 1015 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1016 | # 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 Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1021 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1022 | # else |
Nikolas Klauser | 42f5277 | 2024-09-03 17:46:08 | [diff] [blame] | 1023 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1024 | # endif |
Martin Storsjö | 8a0a706 | 2022-02-10 11:23:40 | [diff] [blame] | 1025 | |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1026 | // 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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 1030 | // |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1031 | // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if |
Tom Honermann | cf93a3d | 2023-01-25 22:57:15 | [diff] [blame] | 1032 | // __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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 1038 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 |
| 1039 | # else |
| 1040 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1041 | # endif |
Nikolas Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 1042 | # else |
| 1043 | # define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1044 | # endif |
| 1045 | |
Mark de Wever | 261b5ab | 2022-10-05 17:54:44 | [diff] [blame] | 1046 | // 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 Klauser | e65cd4c | 2023-02-23 20:17:11 | [diff] [blame] | 1051 | # 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 Dionne | c2df707 | 2022-09-08 21:36:11 | [diff] [blame] | 1064 | |
Nikolas Klauser | 483edfe | 2025-04-08 11:05:24 | [diff] [blame] | 1065 | // TODO(LLVM 22): Remove the workaround |
| 1066 | # if defined(__OBJC__) && (!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER < 2001) |
Konstantin Varlamov | 87cf39a | 2023-03-03 01:35:03 | [diff] [blame] | 1067 | # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS |
| 1068 | # endif |
| 1069 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1070 | # define _PSTL_PRAGMA(x) _Pragma(#x) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1071 | |
| 1072 | // Enable SIMD for compilers that support OpenMP 4.0 |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1073 | # if (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1074 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1075 | # 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 Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1082 | |
| 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 Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1090 | # 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 Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1092 | |
Nikolas Klauser | 15941dd | 2023-08-01 01:43:50 | [diff] [blame] | 1093 | # 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 Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1103 | # else // (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1104 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1105 | # 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 Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1112 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1113 | # endif // (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1114 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1115 | # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1116 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1117 | // Optional attributes - these are useful for a better QoI, but not required to be available |
| 1118 | |
Nikolas Klauser | b101c35 | 2025-02-12 12:48:54 | [diff] [blame] | 1119 | # 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 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1127 | # 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 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1133 | # 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 Klauser | abf9c1a | 2025-03-29 21:54:57 | [diff] [blame] | 1139 | # if __has_cpp_attribute(_Clang::__no_destroy__) |
| 1140 | # define _LIBCPP_NO_DESTROY [[_Clang::__no_destroy__]] |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1141 | # else |
| 1142 | # define _LIBCPP_NO_DESTROY |
| 1143 | # endif |
| 1144 | |
Louis Dionne | a00bbcb | 2024-05-01 16:26:38 | [diff] [blame] | 1145 | # if __has_attribute(__diagnose_if__) |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1146 | # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) |
| 1147 | # else |
| 1148 | # define _LIBCPP_DIAGNOSE_WARNING(...) |
| 1149 | # endif |
| 1150 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1151 | # if __has_cpp_attribute(_Clang::__lifetimebound__) |
| 1152 | # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] |
| 1153 | # else |
| 1154 | # define _LIBCPP_LIFETIMEBOUND |
| 1155 | # endif |
| 1156 | |
A. Jiang | 08159e6 | 2024-10-25 01:04:42 | [diff] [blame] | 1157 | # if __has_cpp_attribute(_Clang::__noescape__) |
| 1158 | # define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] |
| 1159 | # else |
| 1160 | # define _LIBCPP_NOESCAPE |
| 1161 | # endif |
| 1162 | |
Nikolas Klauser | 6f68481 | 2025-01-23 12:18:54 | [diff] [blame] | 1163 | # 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 Klauser | abf9c1a | 2025-03-29 21:54:57 | [diff] [blame] | 1170 | # if __has_cpp_attribute(_Clang::__standalone_debug__) |
| 1171 | # define _LIBCPP_STANDALONE_DEBUG [[_Clang::__standalone_debug__]] |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1172 | # else |
| 1173 | # define _LIBCPP_STANDALONE_DEBUG |
| 1174 | # endif |
| 1175 | |
Nikolas Klauser | abf9c1a | 2025-03-29 21:54:57 | [diff] [blame] | 1176 | # if __has_cpp_attribute(_Clang::__preferred_name__) |
| 1177 | # define _LIBCPP_PREFERRED_NAME(x) [[_Clang::__preferred_name__(x)]] |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1178 | # else |
| 1179 | # define _LIBCPP_PREFERRED_NAME(x) |
| 1180 | # endif |
| 1181 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1182 | # 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 Klauser | f896bd3 | 2025-02-27 21:57:19 | [diff] [blame] | 1195 | # if __has_feature(nullability) |
| 1196 | # define _LIBCPP_DIAGNOSE_NULLPTR _Nonnull |
| 1197 | # else |
| 1198 | # define _LIBCPP_DIAGNOSE_NULLPTR |
| 1199 | # endif |
| 1200 | |
Hristo Hristov | e52ad49 | 2025-02-14 14:02:13 | [diff] [blame] | 1201 | // TODO(LLVM 22): Remove this macro once LLVM19 support ends. __cpp_explicit_this_parameter has been set in LLVM20. |
Hristo Hristov | 3412bc7 | 2024-01-21 05:16:51 | [diff] [blame] | 1202 | // 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 Klauser | ba87515 | 2024-10-12 07:49:52 | [diff] [blame] | 1204 | # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1 |
| 1205 | # else |
| 1206 | # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0 |
Hristo Hristov | 3412bc7 | 2024-01-21 05:16:51 | [diff] [blame] | 1207 | # endif |
| 1208 | |
Eric Fiselier | 56312f5 | 2017-06-16 01:57:41 | [diff] [blame] | 1209 | #endif // __cplusplus |
| 1210 | |
Louis Dionne | cc82a1b | 2022-03-23 17:11:04 | [diff] [blame] | 1211 | #endif // _LIBCPP___CONFIG |