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> |
| 17 | #include <__configuration/platform.h> |
Louis Dionne | c06a8f9 | 2020-06-26 16:08:59 | [diff] [blame] | 18 | |
Eric Fiselier | 60506cb | 2015-11-06 06:30:12 | [diff] [blame] | 19 | #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
Arthur O'Dwyer | fa6b9e4 | 2022-02-02 01:16:40 | [diff] [blame] | 20 | # pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 21 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 22 | |
Eric Fiselier | 60506cb | 2015-11-06 06:30:12 | [diff] [blame] | 23 | #ifdef __cplusplus |
| 24 | |
Nikolas Klauser | 7949ee0 | 2023-06-07 20:33:02 | [diff] [blame] | 25 | // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html |
| 26 | |
Louis Dionne | ad0dfb4 | 2022-09-19 15:27:50 | [diff] [blame] | 27 | // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. |
Tom Stellard | 603c286 | 2023-01-25 06:55:53 | [diff] [blame] | 28 | // 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] | 29 | // defined to XXYYZZ. |
Tobias Hieta | 8f701b5 | 2024-07-23 08:50:36 | [diff] [blame] | 30 | # define _LIBCPP_VERSION 200000 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 31 | |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 32 | # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y |
| 33 | # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) |
| 34 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 35 | # if __STDC_HOSTED__ == 0 |
| 36 | # define _LIBCPP_FREESTANDING |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 37 | # endif |
Eric Fiselier | 998a5c8 | 2018-07-27 03:07:09 | [diff] [blame] | 38 | |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 39 | // HARDENING { |
| 40 | |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 41 | // This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) |
Louis Dionne | 9bd575d | 2024-07-12 20:07:12 | [diff] [blame] | 42 | // equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20. |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 43 | # ifdef _LIBCPP_ENABLE_ASSERTIONS |
Louis Dionne | 9bd575d | 2024-07-12 20:07:12 | [diff] [blame] | 44 | # warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead" |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 45 | # if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 |
| 46 | # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" |
| 47 | # endif |
| 48 | # if _LIBCPP_ENABLE_ASSERTIONS |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 49 | # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE |
varconst | f0dfe68 | 2023-07-14 23:58:15 | [diff] [blame] | 50 | # endif |
| 51 | # endif |
| 52 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 53 | // 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] | 54 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 55 | // - `_LIBCPP_HARDENING_MODE_NONE`; |
| 56 | // - `_LIBCPP_HARDENING_MODE_FAST`; |
| 57 | // - `_LIBCPP_HARDENING_MODE_EXTENSIVE`; |
| 58 | // - `_LIBCPP_HARDENING_MODE_DEBUG`. |
Konstantin Varlamov | b85e186 | 2023-09-12 19:01:36 | [diff] [blame] | 59 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 60 | // These values have the following effects: |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 61 | // |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 62 | // - `_LIBCPP_HARDENING_MODE_NONE` -- sets the hardening mode to "none" which disables all runtime hardening checks; |
| 63 | // |
| 64 | // - `_LIBCPP_HARDENING_MODE_FAST` -- sets that hardening mode to "fast". The fast mode enables security-critical checks |
| 65 | // that can be done with relatively little runtime overhead in constant time; |
| 66 | // |
| 67 | // - `_LIBCPP_HARDENING_MODE_EXTENSIVE` -- sets the hardening mode to "extensive". The extensive mode is a superset of |
| 68 | // the fast mode that additionally enables checks that are relatively cheap and prevent common types of logic errors |
| 69 | // but are not necessarily security-critical; |
| 70 | // |
| 71 | // - `_LIBCPP_HARDENING_MODE_DEBUG` -- sets the hardening mode to "debug". The debug mode is a superset of the extensive |
| 72 | // mode and enables all checks available in the library, including internal assertions. Checks that are part of the |
| 73 | // debug mode can be very expensive and thus the debug mode is intended to be used for testing, not in production. |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 74 | |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 75 | // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These |
| 76 | // macros are only for internal use -- users should only pick one of the high-level hardening modes described above. |
| 77 | // |
| 78 | // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and |
| 79 | // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid: |
| 80 | // - the sentinel is reachable from the begin iterator; |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 81 | // - TODO(hardening): both iterators refer to the same container. |
| 82 | // |
| 83 | // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through |
| 84 | // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access |
| 85 | // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like |
| 86 | // `optional` and `function` are considered one-element containers for the purposes of this check. |
| 87 | // |
Konstantin Varlamov | b85fdc4 | 2023-11-08 02:12:15 | [diff] [blame] | 88 | // - `_LIBCPP_ASSERT_NON_NULL` -- checks that the pointer being dereferenced is not null. On most modern platforms zero |
| 89 | // address does not refer to an actual location in memory, so a null pointer dereference would not compromize the |
| 90 | // memory security of a program (however, it is still undefined behavior that can result in strange errors due to |
| 91 | // compiler optimizations). |
| 92 | // |
varconst | 4a652e4 | 2023-07-24 21:56:44 | [diff] [blame] | 93 | // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the |
| 94 | // given ranges do not overlap. |
| 95 | // |
Konstantin Varlamov | 6082478 | 2024-01-23 02:12:58 | [diff] [blame] | 96 | // - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to deallocate memory is valid (e.g. the given object |
| 97 | // was allocated by the given allocator). Violating this category typically results in a memory leak. |
| 98 | // |
| 99 | // - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an external API doesn't fail in |
| 100 | // an unexpected manner. This includes triggering documented cases of undefined behavior in an external library (like |
| 101 | // attempting to unlock an unlocked mutex in pthreads). Any API external to the library falls under this category |
| 102 | // (from system calls to compiler intrinsics). We generally don't expect these failures to compromize memory safety or |
| 103 | // otherwise create an immediate security issue. |
| 104 | // |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 105 | // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure |
| 106 | // the containers have compatible allocators. |
| 107 | // |
Konstantin Varlamov | dc57752 | 2024-01-21 07:38:02 | [diff] [blame] | 108 | // - `_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN` -- checks that the given argument is within the domain of valid arguments |
| 109 | // for the function. Violating this typically produces an incorrect result (e.g. the clamp algorithm returns the |
| 110 | // original value without clamping it due to incorrect functors) or puts an object into an invalid state (e.g. |
| 111 | // a string view where only a subset of elements is possible to access). This category is for assertions violating |
| 112 | // which doesn't cause any immediate issues in the library -- whatever the consequences are, they will happen in the |
| 113 | // user code. |
| 114 | // |
Konstantin Varlamov | 4f215fd | 2024-01-06 00:29:23 | [diff] [blame] | 115 | // - `_LIBCPP_ASSERT_PEDANTIC` -- checks prerequisites which are imposed by the Standard, but violating which happens to |
| 116 | // be benign in our implementation. |
| 117 | // |
Konstantin Varlamov | 8938bc0 | 2024-01-23 07:31:58 | [diff] [blame] | 118 | // - `_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT` -- checks that the given argument satisfies the semantic requirements imposed |
| 119 | // by the Standard. Typically, there is no simple way to completely prove that a semantic requirement is satisfied; |
| 120 | // thus, this would often be a heuristic check and it might be quite expensive. |
| 121 | // |
varconst | 4122db1 | 2023-07-20 17:13:54 | [diff] [blame] | 122 | // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on |
| 123 | // user input. |
| 124 | // |
| 125 | // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet. |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 126 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 127 | // clang-format off |
| 128 | # define _LIBCPP_HARDENING_MODE_NONE (1 << 1) |
| 129 | # define _LIBCPP_HARDENING_MODE_FAST (1 << 2) |
| 130 | # define _LIBCPP_HARDENING_MODE_EXTENSIVE (1 << 4) // Deliberately not ordered. |
| 131 | # define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3) |
| 132 | // clang-format on |
| 133 | |
| 134 | # ifndef _LIBCPP_HARDENING_MODE |
Konstantin Varlamov | 091fc81 | 2024-02-06 21:45:31 | [diff] [blame] | 135 | |
| 136 | # ifndef _LIBCPP_HARDENING_MODE_DEFAULT |
| 137 | # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \ |
| 138 | `__config_site` header, please make sure your installation of libc++ is not broken. |
| 139 | # endif |
| 140 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 141 | # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 142 | # endif |
| 143 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 144 | # if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \ |
| 145 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \ |
| 146 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \ |
| 147 | _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG |
| 148 | # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \ |
| 149 | _LIBCPP_HARDENING_MODE_NONE, \ |
| 150 | _LIBCPP_HARDENING_MODE_FAST, \ |
| 151 | _LIBCPP_HARDENING_MODE_EXTENSIVE, \ |
| 152 | _LIBCPP_HARDENING_MODE_DEBUG |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 153 | # endif |
| 154 | |
varconst | d1367ca | 2023-07-12 17:12:51 | [diff] [blame] | 155 | // } HARDENING |
| 156 | |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 157 | # define _LIBCPP_TOSTRING2(x) #x |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 158 | # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) |
Nikolas Klauser | a7c2a62 | 2022-02-14 17:52:28 | [diff] [blame] | 159 | |
Nikolas Klauser | 07efa28 | 2023-02-17 13:01:19 | [diff] [blame] | 160 | // NOLINTNEXTLINE(libcpp-cpp-version-check) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 161 | # if __cplusplus < 201103L |
| 162 | # define _LIBCPP_CXX03_LANG |
| 163 | # endif |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 164 | |
Marek Kurdej | 7223bcf | 2022-12-15 01:19:59 | [diff] [blame] | 165 | # ifndef __has_constexpr_builtin |
| 166 | # define __has_constexpr_builtin(x) 0 |
| 167 | # endif |
| 168 | |
Nikolas Klauser | 1530034 | 2024-02-28 20:14:35 | [diff] [blame] | 169 | // This checks wheter a Clang module is built |
| 170 | # ifndef __building_module |
| 171 | # define __building_module(...) 0 |
| 172 | # endif |
| 173 | |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 174 | // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by |
| 175 | // the compiler and '1' otherwise. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 176 | # ifndef __is_identifier |
| 177 | # define __is_identifier(__x) 1 |
| 178 | # endif |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 179 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 180 | # ifndef __has_declspec_attribute |
| 181 | # define __has_declspec_attribute(__x) 0 |
| 182 | # endif |
Eric Fiselier | e825d8b | 2015-07-10 20:26:38 | [diff] [blame] | 183 | |
Xing Xue | 7f302f2 | 2023-09-07 18:48:45 | [diff] [blame] | 184 | # define __has_keyword(__x) !(__is_identifier(__x)) |
| 185 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 186 | # ifndef __has_warning |
| 187 | # define __has_warning(...) 0 |
| 188 | # endif |
| 189 | |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 190 | # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L |
| 191 | # 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] | 192 | # endif |
Eric Fiselier | 5de7cac | 2019-06-13 00:37:25 | [diff] [blame] | 193 | |
Eric Fiselier | 330fe01 | 2017-01-07 02:43:58 | [diff] [blame] | 194 | // FIXME: ABI detection should be done via compiler builtin macros. This |
| 195 | // is just a placeholder until Clang implements such macros. For now assume |
Shoaib Meenai | d456385 | 2017-10-04 23:44:38 | [diff] [blame] | 196 | // that Windows compilers pretending to be MSVC++ target the Microsoft ABI, |
| 197 | // and allow the user to explicitly specify the ABI to handle cases where this |
| 198 | // heuristic falls short. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 199 | # if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) |
| 200 | # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" |
| 201 | # elif defined(_LIBCPP_ABI_FORCE_ITANIUM) |
| 202 | # define _LIBCPP_ABI_ITANIUM |
| 203 | # elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 204 | # define _LIBCPP_ABI_MICROSOFT |
| 205 | # else |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 206 | # if defined(_WIN32) && defined(_MSC_VER) |
| 207 | # define _LIBCPP_ABI_MICROSOFT |
| 208 | # else |
| 209 | # define _LIBCPP_ABI_ITANIUM |
| 210 | # endif |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 211 | # endif |
Eric Fiselier | 330fe01 | 2017-01-07 02:43:58 | [diff] [blame] | 212 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 213 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
| 214 | # define _LIBCPP_ABI_VCRUNTIME |
| 215 | # endif |
Eric Fiselier | e69290d | 2019-03-05 01:57:01 | [diff] [blame] | 216 | |
Louis Dionne | deb3b55 | 2022-07-20 14:42:04 | [diff] [blame] | 217 | # if __has_feature(experimental_library) |
| 218 | # ifndef _LIBCPP_ENABLE_EXPERIMENTAL |
| 219 | # define _LIBCPP_ENABLE_EXPERIMENTAL |
| 220 | # endif |
| 221 | # endif |
| 222 | |
Louis Dionne | 8711fca | 2022-06-30 15:57:52 | [diff] [blame] | 223 | // Incomplete features get their own specific disabling flags. This makes it |
| 224 | // easier to grep for target specific flags once the feature is complete. |
| 225 | # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | e7e3711 | 2023-05-05 15:41:13 | [diff] [blame] | 226 | # define _LIBCPP_HAS_NO_INCOMPLETE_PSTL |
Hui | 477f6bc | 2023-07-10 14:55:55 | [diff] [blame] | 227 | # define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN |
Mark de Wever | a4422a5 | 2024-04-20 10:09:13 | [diff] [blame] | 228 | # define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB |
Mark de Wever | 7cc72a0 | 2023-09-05 18:10:38 | [diff] [blame] | 229 | # define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM |
Hui | 477f6bc | 2023-07-10 14:55:55 | [diff] [blame] | 230 | # endif |
| 231 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 232 | # if defined(__MVS__) |
| 233 | # include <features.h> // for __NATIVE_ASCII_F |
| 234 | # endif |
Muiez Ahmed | a1da739 | 2022-01-14 16:35:53 | [diff] [blame] | 235 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 236 | # if defined(_WIN32) |
| 237 | # define _LIBCPP_WIN32API |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 238 | # define _LIBCPP_SHORT_WCHAR 1 |
Louis Dionne | 77bca6d | 2019-03-20 17:05:52 | [diff] [blame] | 239 | // Both MinGW and native MSVC provide a "MSVC"-like environment |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 240 | # define _LIBCPP_MSVCRT_LIKE |
Bruno Cardoso Lopes | e59dd00 | 2017-07-17 21:52:31 | [diff] [blame] | 241 | // If mingw not explicitly detected, assume using MS C runtime only if |
| 242 | // a MS compatibility version is specified. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 243 | # if defined(_MSC_VER) && !defined(__MINGW32__) |
| 244 | # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library |
| 245 | # endif |
| 246 | # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) |
| 247 | # define _LIBCPP_HAS_BITSCAN64 |
| 248 | # endif |
| 249 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR |
| 250 | # endif // defined(_WIN32) |
Howard Hinnant | 3e71464 | 2011-05-13 17:16:06 | [diff] [blame] | 251 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 252 | # if defined(_AIX) && !defined(__64BIT__) |
| 253 | // The size of wchar is 2 byte on 32-bit mode on AIX. |
| 254 | # define _LIBCPP_SHORT_WCHAR 1 |
| 255 | # endif |
Xing Xue | f53fafb | 2021-09-09 20:20:36 | [diff] [blame] | 256 | |
Louis Dionne | beff715 | 2021-12-21 21:50:34 | [diff] [blame] | 257 | // Libc++ supports various implementations of std::random_device. |
| 258 | // |
| 259 | // _LIBCPP_USING_DEV_RANDOM |
| 260 | // Read entropy from the given file, by default `/dev/urandom`. |
| 261 | // If a token is provided, it is assumed to be the path to a file |
| 262 | // to read entropy from. This is the default behavior if nothing |
| 263 | // else is specified. This implementation requires storing state |
| 264 | // inside `std::random_device`. |
| 265 | // |
| 266 | // _LIBCPP_USING_ARC4_RANDOM |
| 267 | // Use arc4random(). This allows obtaining random data even when |
| 268 | // using sandboxing mechanisms. On some platforms like Apple, this |
| 269 | // is the recommended source of entropy for user-space programs. |
| 270 | // When this option is used, the token passed to `std::random_device`'s |
| 271 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 272 | // |
| 273 | // _LIBCPP_USING_GETENTROPY |
| 274 | // Use getentropy(). |
| 275 | // When this option is used, the token passed to `std::random_device`'s |
| 276 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 277 | // |
Roland McGrath | 3064dd8 | 2022-01-02 19:53:53 | [diff] [blame] | 278 | // _LIBCPP_USING_FUCHSIA_CPRNG |
| 279 | // Use Fuchsia's zx_cprng_draw() system call, which is specified to |
| 280 | // deliver high-quality entropy and cannot fail. |
| 281 | // When this option is used, the token passed to `std::random_device`'s |
| 282 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 283 | // |
Louis Dionne | beff715 | 2021-12-21 21:50:34 | [diff] [blame] | 284 | // _LIBCPP_USING_NACL_RANDOM |
| 285 | // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, |
| 286 | // including accesses to the special files under `/dev`. This implementation |
| 287 | // uses the NaCL syscall `nacl_secure_random_init()` to get entropy. |
| 288 | // When this option is used, the token passed to `std::random_device`'s |
| 289 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 290 | // |
| 291 | // _LIBCPP_USING_WIN32_RANDOM |
| 292 | // Use rand_s(), for use on Windows. |
| 293 | // When this option is used, the token passed to `std::random_device`'s |
| 294 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 295 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ |
Louis Dionne | 3b6bc875 | 2022-11-24 18:02:58 | [diff] [blame] | 296 | defined(__DragonFly__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 297 | # define _LIBCPP_USING_ARC4_RANDOM |
| 298 | # elif defined(__wasi__) || defined(__EMSCRIPTEN__) |
| 299 | # define _LIBCPP_USING_GETENTROPY |
| 300 | # elif defined(__Fuchsia__) |
| 301 | # define _LIBCPP_USING_FUCHSIA_CPRNG |
| 302 | # elif defined(__native_client__) |
| 303 | # define _LIBCPP_USING_NACL_RANDOM |
| 304 | # elif defined(_LIBCPP_WIN32API) |
| 305 | # define _LIBCPP_USING_WIN32_RANDOM |
| 306 | # else |
| 307 | # define _LIBCPP_USING_DEV_RANDOM |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 308 | # endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 309 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 310 | # ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 311 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 312 | # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 313 | # define _ALIGNAS_TYPE(x) alignas(x) |
| 314 | # define _ALIGNAS(x) alignas(x) |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 315 | # define _NOEXCEPT noexcept |
Louis Dionne | f89d707 | 2024-01-30 13:33:48 | [diff] [blame] | 316 | # define _NOEXCEPT_(...) noexcept(__VA_ARGS__) |
Nikolas Klauser | ae87a3b | 2022-08-09 11:22:25 | [diff] [blame] | 317 | # define _LIBCPP_CONSTEXPR constexpr |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 318 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 319 | # else |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 320 | |
| 321 | # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) |
| 322 | # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) |
| 323 | # define _ALIGNAS(x) __attribute__((__aligned__(x))) |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 324 | # define _LIBCPP_HAS_NO_NOEXCEPT |
| 325 | # define nullptr __nullptr |
| 326 | # define _NOEXCEPT throw() |
Louis Dionne | f89d707 | 2024-01-30 13:33:48 | [diff] [blame] | 327 | # define _NOEXCEPT_(...) |
Nikolas Klauser | ae87a3b | 2022-08-09 11:22:25 | [diff] [blame] | 328 | # define static_assert(...) _Static_assert(__VA_ARGS__) |
| 329 | # define decltype(...) __decltype(__VA_ARGS__) |
| 330 | # define _LIBCPP_CONSTEXPR |
Nikolas Klauser | 929d5de | 2022-06-17 11:58:22 | [diff] [blame] | 331 | |
| 332 | typedef __char16_t char16_t; |
| 333 | typedef __char32_t char32_t; |
| 334 | |
| 335 | # endif |
| 336 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 337 | # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) |
Howard Hinnant | eb26925 | 2010-08-10 20:48:29 | [diff] [blame] | 338 | |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 339 | // Objective-C++ features (opt-in) |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 340 | # if __has_feature(objc_arc) |
| 341 | # define _LIBCPP_HAS_OBJC_ARC |
| 342 | # endif |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 343 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 344 | # if __has_feature(objc_arc_weak) |
| 345 | # define _LIBCPP_HAS_OBJC_ARC_WEAK |
| 346 | # endif |
Douglas Gregor | 64ec101 | 2011-06-22 22:17:44 | [diff] [blame] | 347 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 348 | # if __has_extension(blocks) |
| 349 | # define _LIBCPP_HAS_EXTENSION_BLOCKS |
| 350 | # endif |
Louis Dionne | 8ae404a | 2020-01-21 20:39:43 | [diff] [blame] | 351 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 352 | # if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) |
| 353 | # define _LIBCPP_HAS_BLOCKS_RUNTIME |
| 354 | # endif |
Louis Dionne | f76c424 | 2020-04-23 20:47:52 | [diff] [blame] | 355 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 356 | # if !__has_feature(address_sanitizer) |
| 357 | # define _LIBCPP_HAS_NO_ASAN |
| 358 | # endif |
Marshall Clow | 91c71dd | 2014-04-14 15:44:57 | [diff] [blame] | 359 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 360 | # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) |
Louis Dionne | cb3eb30 | 2018-07-27 12:46:03 | [diff] [blame] | 361 | |
Nikolas Klauser | 69fecaa | 2024-07-13 07:41:36 | [diff] [blame] | 362 | # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 | [diff] [blame] | 363 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 364 | # if defined(_LIBCPP_OBJECT_FORMAT_COFF) |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 365 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 366 | # ifdef _DLL |
| 367 | # define _LIBCPP_CRT_FUNC __declspec(dllimport) |
Shoaib Meenai | bda3c7d | 2017-03-02 03:22:18 | [diff] [blame] | 368 | # else |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 369 | # define _LIBCPP_CRT_FUNC |
| 370 | # endif |
| 371 | |
| 372 | # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) |
| 373 | # define _LIBCPP_DLL_VIS |
| 374 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
| 375 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 376 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 377 | # define _LIBCPP_EXPORTED_FROM_ABI |
| 378 | # elif defined(_LIBCPP_BUILDING_LIBRARY) |
| 379 | # define _LIBCPP_DLL_VIS __declspec(dllexport) |
| 380 | # if defined(__MINGW32__) |
| 381 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS |
| 382 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 383 | # else |
| 384 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
| 385 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS |
| 386 | # endif |
| 387 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS |
| 388 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) |
| 389 | # else |
| 390 | # define _LIBCPP_DLL_VIS __declspec(dllimport) |
| 391 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS |
| 392 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 393 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 394 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) |
| 395 | # endif |
| 396 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 397 | # define _LIBCPP_HIDDEN |
| 398 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
| 399 | # define _LIBCPP_TEMPLATE_VIS |
| 400 | # define _LIBCPP_TEMPLATE_DATA_VIS |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 401 | # define _LIBCPP_TYPE_VISIBILITY_DEFAULT |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 402 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 403 | # else |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 404 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 405 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 406 | # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 407 | # else |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 408 | # define _LIBCPP_VISIBILITY(vis) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 409 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 410 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 411 | # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 412 | # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") |
| 413 | # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 414 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") |
| 415 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 416 | |
Nikolas Klauser | 0f05052 | 2022-07-14 13:04:36 | [diff] [blame] | 417 | // TODO: Make this a proper customization point or remove the option to override it. |
| 418 | # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 419 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") |
| 420 | # endif |
| 421 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 422 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 423 | // The inline should be removed once PR32114 is resolved |
| 424 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN |
| 425 | # else |
| 426 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
| 427 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 428 | |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 429 | // GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates |
| 430 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__) |
| 431 | # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 432 | # else |
| 433 | # define _LIBCPP_TEMPLATE_VIS |
| 434 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 435 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 436 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 437 | # define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default"))) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 438 | # else |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 439 | # define _LIBCPP_TYPE_VISIBILITY_DEFAULT |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 440 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 441 | |
Nikolas Klauser | 758504b | 2022-06-22 09:14:04 | [diff] [blame] | 442 | # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 443 | |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 444 | # if __has_attribute(exclude_from_explicit_instantiation) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 445 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) |
| 446 | # else |
| 447 | // Try to approximate the effect of exclude_from_explicit_instantiation |
| 448 | // (which is that entities are not assumed to be provided by explicit |
| 449 | // template instantiations in the dylib) by always inlining those entities. |
| 450 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE |
| 451 | # endif |
| 452 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 453 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 454 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") |
| 455 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") |
| 456 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) |
| 457 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
| 458 | # elif defined(_LIBCPP_COMPILER_GCC) |
| 459 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") |
| 460 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") |
| 461 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
| 462 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) |
| 463 | # else |
| 464 | # define _LIBCPP_DIAGNOSTIC_PUSH |
| 465 | # define _LIBCPP_DIAGNOSTIC_POP |
| 466 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
| 467 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
| 468 | # endif |
| 469 | |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 470 | # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST |
| 471 | # define _LIBCPP_HARDENING_SIG f |
| 472 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 473 | # define _LIBCPP_HARDENING_SIG s |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 474 | # elif _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 475 | # define _LIBCPP_HARDENING_SIG d |
| 476 | # else |
Konstantin Varlamov | 64d413e | 2023-11-08 19:10:00 | [diff] [blame] | 477 | # define _LIBCPP_HARDENING_SIG n // "none" |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 478 | # endif |
| 479 | |
| 480 | # ifdef _LIBCPP_HAS_NO_EXCEPTIONS |
| 481 | # define _LIBCPP_EXCEPTIONS_SIG n |
| 482 | # else |
| 483 | # define _LIBCPP_EXCEPTIONS_SIG e |
| 484 | # endif |
| 485 | |
| 486 | # define _LIBCPP_ODR_SIGNATURE \ |
| 487 | _LIBCPP_CONCAT(_LIBCPP_CONCAT(_LIBCPP_HARDENING_SIG, _LIBCPP_EXCEPTIONS_SIG), _LIBCPP_VERSION) |
| 488 | |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 489 | // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved |
| 490 | // on two levels: |
| 491 | // 1. The symbol is given hidden visibility, which ensures that users won't start exporting |
| 492 | // symbols from their dynamic library by means of using the libc++ headers. This ensures |
| 493 | // that those symbols stay private to the dynamic library in which it is defined. |
| 494 | // |
Louis Dionne | bc792a2 | 2023-10-26 13:05:16 | [diff] [blame] | 495 | // 2. The symbol is given an ABI tag that encodes the ODR-relevant properties of the library. |
| 496 | // This ensures that no ODR violation can arise from mixing two TUs compiled with different |
| 497 | // versions or configurations of libc++ (such as exceptions vs no-exceptions). Indeed, if the |
| 498 | // program contains two definitions of a function, the ODR requires them to be token-by-token |
| 499 | // equivalent, and the linker is allowed to pick either definition and discard the other one. |
| 500 | // |
| 501 | // For example, if a program contains a copy of `vector::at()` compiled with exceptions enabled |
| 502 | // *and* a copy of `vector::at()` compiled with exceptions disabled (by means of having two TUs |
| 503 | // compiled with different settings), the two definitions are both visible by the linker and they |
| 504 | // have the same name, but they have a meaningfully different implementation (one throws an exception |
| 505 | // and the other aborts the program). This violates the ODR and makes the program ill-formed, and in |
| 506 | // practice what will happen is that the linker will pick one of the definitions at random and will |
| 507 | // discard the other one. This can quite clearly lead to incorrect program behavior. |
| 508 | // |
| 509 | // A similar reasoning holds for many other properties that are ODR-affecting. Essentially any |
| 510 | // property that causes the code of a function to differ from the code in another configuration |
| 511 | // can be considered ODR-affecting. In practice, we don't encode all such properties in the ABI |
| 512 | // tag, but we encode the ones that we think are most important: library version, exceptions, and |
| 513 | // hardening mode. |
| 514 | // |
| 515 | // Note that historically, solving this problem has been achieved in various ways, including |
| 516 | // force-inlining all functions or giving internal linkage to all functions. Both these previous |
| 517 | // solutions suffer from drawbacks that lead notably to code bloat. |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 518 | // |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 519 | // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend |
| 520 | // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. |
| 521 | // |
Louis Dionne | 5efc811 | 2022-12-21 15:08:54 | [diff] [blame] | 522 | // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions |
| 523 | // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled |
| 524 | // name of a virtual function is part of its ABI, since some architectures like arm64e can sign |
| 525 | // the virtual function pointer in the vtable based on the mangled name of the function. Since |
| 526 | // we use an ABI tag that changes with each released version, the mangled name of the virtual |
| 527 | // function would change, which is incorrect. Note that it doesn't make much sense to change |
| 528 | // the implementation of a virtual function in an ABI-incompatible way in the first place, |
| 529 | // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. |
| 530 | // |
Mark de Wever | d179176 | 2024-03-25 17:33:30 | [diff] [blame] | 531 | // The macro can be applied to record and enum types. When the tagged type is nested in |
| 532 | // a record this "parent" record needs to have the macro too. Another use case for applying |
| 533 | // this macro to records and unions is to apply an ABI tag to inline constexpr variables. |
| 534 | // This can be useful for inline variables that are implementation details which are expected |
| 535 | // to change in the future. |
| 536 | // |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 537 | // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing |
| 538 | // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and |
| 539 | // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. |
| 540 | # ifndef _LIBCPP_NO_ABI_TAG |
| 541 | # define _LIBCPP_HIDE_FROM_ABI \ |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 542 | _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ |
Louis Dionne | e2c2ffb | 2024-06-18 13:13:45 | [diff] [blame] | 543 | __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_ODR_SIGNATURE)))) |
Louis Dionne | d2e8686 | 2022-07-07 18:07:37 | [diff] [blame] | 544 | # else |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 545 | # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 546 | # endif |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 547 | # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
Arsen Arsenović | 21d9282 | 2023-01-25 07:34:55 | [diff] [blame] | 548 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 549 | # ifdef _LIBCPP_BUILDING_LIBRARY |
| 550 | # if _LIBCPP_ABI_VERSION > 1 |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 551 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 552 | # else |
| 553 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Shoaib Meenai | bda3c7d | 2017-03-02 03:22:18 | [diff] [blame] | 554 | # endif |
| 555 | # else |
Nikolas Klauser | 140c375 | 2023-05-24 15:46:13 | [diff] [blame] | 556 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 557 | # endif |
Eric Fiselier | f8f31c4 | 2016-09-16 00:00:48 | [diff] [blame] | 558 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 559 | // TODO: Remove this workaround once we drop support for Clang 16 |
Louis Dionne | e2c2ffb | 2024-06-18 13:13:45 | [diff] [blame] | 560 | # if __has_warning("-Wc++23-extensions") |
| 561 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++23-extensions") |
| 562 | # else |
| 563 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++2b-extensions") |
| 564 | # endif |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 565 | |
Nikolas Klauser | f886dfe | 2024-03-23 12:54:35 | [diff] [blame] | 566 | // Clang modules take a significant compile time hit when pushing and popping diagnostics. |
| 567 | // Since all the headers are marked as system headers in the modulemap, we can simply disable this |
| 568 | // pushing and popping when building with clang modules. |
| 569 | # if !__has_feature(modules) |
| 570 | # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ |
| 571 | _LIBCPP_DIAGNOSTIC_PUSH \ |
| 572 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++11-extensions") \ |
| 573 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ |
| 574 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ |
| 575 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ |
| 576 | _LIBCPP_CLANG_DIAGNOSTIC_IGNORED_CXX23_EXTENSION \ |
| 577 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++14-extensions") \ |
| 578 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++17-extensions") \ |
| 579 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") \ |
| 580 | _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++23-extensions") |
| 581 | # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS _LIBCPP_DIAGNOSTIC_POP |
| 582 | # else |
| 583 | # define _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS |
| 584 | # define _LIBCPP_POP_EXTENSION_DIAGNOSTICS |
| 585 | # endif |
| 586 | |
Eric Fiselier | 2f3e8b3 | 2018-10-30 02:02:00 | [diff] [blame] | 587 | // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 588 | // clang-format off |
Nikolas Klauser | f886dfe | 2024-03-23 12:54:35 | [diff] [blame] | 589 | # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \ |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 590 | namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \ |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 591 | inline namespace _LIBCPP_ABI_NAMESPACE { |
Nikolas Klauser | f886dfe | 2024-03-23 12:54:35 | [diff] [blame] | 592 | # define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 593 | |
Nikolas Klauser | 5d31360 | 2024-06-01 06:37:49 | [diff] [blame] | 594 | #ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE |
| 595 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { |
| 596 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD |
| 597 | #else |
Louis Dionne | ac8c9f1 | 2023-11-28 23:41:59 | [diff] [blame] | 598 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD \ |
| 599 | inline namespace __fs { namespace filesystem { |
Eric Fiselier | 2f3e8b3 | 2018-10-30 02:02:00 | [diff] [blame] | 600 | |
Nikolas Klauser | 4d323e4 | 2024-03-09 00:09:28 | [diff] [blame] | 601 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM }} _LIBCPP_END_NAMESPACE_STD |
Nikolas Klauser | 5d31360 | 2024-06-01 06:37:49 | [diff] [blame] | 602 | #endif |
| 603 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 604 | // clang-format on |
Eric Fiselier | 2f3e8b3 | 2018-10-30 02:02:00 | [diff] [blame] | 605 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 606 | # if __has_attribute(__enable_if__) |
| 607 | # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) |
| 608 | # endif |
Eric Fiselier | 49e2967 | 2016-09-15 22:27:07 | [diff] [blame] | 609 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 610 | # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 611 | # define _LIBCPP_HAS_NO_INT128 |
| 612 | # endif |
Stephan Tolksdorf | e180eca | 2014-03-26 19:45:52 | [diff] [blame] | 613 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 614 | # ifdef _LIBCPP_CXX03_LANG |
| 615 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) \ |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 616 | struct _LIBCPP_EXPORTED_FROM_ABI x { \ |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 617 | enum __lx |
| 618 | // clang-format off |
| 619 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ |
| 620 | __lx __v_; \ |
Louis Dionne | 4c19854 | 2023-12-04 15:25:14 | [diff] [blame] | 621 | _LIBCPP_HIDE_FROM_ABI x(__lx __v) : __v_(__v) {} \ |
| 622 | _LIBCPP_HIDE_FROM_ABI explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ |
| 623 | _LIBCPP_HIDE_FROM_ABI operator int() const { return __v_; } \ |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 624 | }; |
| 625 | // clang-format on |
Howard Hinnant | 75689c1 | 2011-12-02 19:36:40 | [diff] [blame] | 626 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 627 | # else // _LIBCPP_CXX03_LANG |
Nikolas Klauser | 3583bf3 | 2023-08-19 22:15:47 | [diff] [blame] | 628 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 629 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) |
| 630 | # endif // _LIBCPP_CXX03_LANG |
Yaron Keren | 21a697b8 | 2013-12-20 13:19:45 | [diff] [blame] | 631 | |
Louis Dionne | 3b6bc875 | 2022-11-24 18:02:58 | [diff] [blame] | 632 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 633 | # define _LIBCPP_LOCALE__L_EXTENSIONS 1 |
| 634 | # endif |
| 635 | |
| 636 | # ifdef __FreeBSD__ |
| 637 | # define _DECLARE_C99_LDBL_MATH 1 |
| 638 | # endif |
Alexis Hunt | 4084c9e | 2011-07-15 05:40:33 | [diff] [blame] | 639 | |
Reid Kleckner | 6a2a5e0 | 2018-04-19 22:12:10 | [diff] [blame] | 640 | // If we are getting operator new from the MSVC CRT, then allocation overloads |
| 641 | // for align_val_t were added in 19.12, aka VS 2017 version 15.3. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 642 | # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 |
| 643 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
| 644 | # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) |
| 645 | // We're deferring to Microsoft's STL to provide aligned new et al. We don't |
| 646 | // have it unless the language feature test macro is defined. |
| 647 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
| 648 | # elif defined(__MVS__) |
| 649 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
| 650 | # endif |
Reid Kleckner | 6a2a5e0 | 2018-04-19 22:12:10 | [diff] [blame] | 651 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 652 | # if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) |
| 653 | # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 654 | # endif |
Eric Fiselier | f2918d1 | 2018-03-22 04:42:56 | [diff] [blame] | 655 | |
Alex Richardson | eb6fbad | 2022-11-17 10:19:28 | [diff] [blame] | 656 | // It is not yet possible to use aligned_alloc() on all Apple platforms since |
| 657 | // 10.15 was the first version to ship an implementation of aligned_alloc(). |
| 658 | # if defined(__APPLE__) |
| 659 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ |
| 660 | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) |
| 661 | # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC |
| 662 | # endif |
Shoaib Meenai | 49c8f90 | 2023-01-07 07:35:15 | [diff] [blame] | 663 | # elif defined(__ANDROID__) && __ANDROID_API__ < 28 |
| 664 | // Android only provides aligned_alloc when targeting API 28 or higher. |
| 665 | # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC |
Alex Richardson | eb6fbad | 2022-11-17 10:19:28 | [diff] [blame] | 666 | # endif |
| 667 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 668 | # if defined(__APPLE__) || defined(__FreeBSD__) |
| 669 | # define _LIBCPP_HAS_DEFAULTRUNELOCALE |
| 670 | # endif |
Alexis Hunt | f023519 | 2011-07-09 01:09:31 | [diff] [blame] | 671 | |
Louis Dionne | 3b6bc875 | 2022-11-24 18:02:58 | [diff] [blame] | 672 | # if defined(__APPLE__) || defined(__FreeBSD__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 673 | # define _LIBCPP_WCTYPE_IS_MASK |
| 674 | # endif |
Alexis Hunt | 0081892 | 2011-07-09 03:40:04 | [diff] [blame] | 675 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 676 | # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) |
| 677 | # define _LIBCPP_HAS_NO_CHAR8_T |
| 678 | # endif |
Marshall Clow | 7dad0bd | 2018-12-11 04:35:44 | [diff] [blame] | 679 | |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 680 | // Deprecation macros. |
Louis Dionne | a470a13 | 2019-03-12 20:10:06 | [diff] [blame] | 681 | // |
| 682 | // Deprecations warnings are always enabled, except when users explicitly opt-out |
| 683 | // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 684 | # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) |
Nikolas Klauser | c8eff95 | 2023-01-10 00:56:53 | [diff] [blame] | 685 | # if __has_attribute(__deprecated__) |
| 686 | # define _LIBCPP_DEPRECATED __attribute__((__deprecated__)) |
| 687 | # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m))) |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 688 | # elif _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 689 | # define _LIBCPP_DEPRECATED [[deprecated]] |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 690 | # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 691 | # else |
| 692 | # define _LIBCPP_DEPRECATED |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 693 | # define _LIBCPP_DEPRECATED_(m) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 694 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 695 | # else |
| 696 | # define _LIBCPP_DEPRECATED |
Nikolas Klauser | 971e9c8 | 2022-06-17 14:02:53 | [diff] [blame] | 697 | # define _LIBCPP_DEPRECATED_(m) |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 698 | # endif |
Marshall Clow | 8392ab2 | 2013-09-28 18:35:31 | [diff] [blame] | 699 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 700 | # if !defined(_LIBCPP_CXX03_LANG) |
| 701 | # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED |
| 702 | # else |
| 703 | # define _LIBCPP_DEPRECATED_IN_CXX11 |
| 704 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 705 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 706 | # if _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 707 | # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED |
| 708 | # else |
| 709 | # define _LIBCPP_DEPRECATED_IN_CXX14 |
| 710 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 711 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 712 | # if _LIBCPP_STD_VER >= 17 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 713 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED |
| 714 | # else |
| 715 | # define _LIBCPP_DEPRECATED_IN_CXX17 |
| 716 | # endif |
Louis Dionne | ea5cd3b | 2018-09-23 18:35:00 | [diff] [blame] | 717 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 718 | # if _LIBCPP_STD_VER >= 20 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 719 | # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED |
| 720 | # else |
| 721 | # define _LIBCPP_DEPRECATED_IN_CXX20 |
| 722 | # endif |
Marek Kurdej | 841132e | 2020-11-26 09:07:16 | [diff] [blame] | 723 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 724 | # if _LIBCPP_STD_VER >= 23 |
| 725 | # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED |
| 726 | # else |
| 727 | # define _LIBCPP_DEPRECATED_IN_CXX23 |
| 728 | # endif |
Nikolas Klauser | 987f08f | 2022-12-11 01:10:31 | [diff] [blame] | 729 | |
Hristo Hristov | 27e67cd | 2024-01-29 18:57:12 | [diff] [blame] | 730 | # if _LIBCPP_STD_VER >= 26 |
| 731 | # define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED |
| 732 | # else |
| 733 | # define _LIBCPP_DEPRECATED_IN_CXX26 |
| 734 | # endif |
| 735 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 736 | # if !defined(_LIBCPP_HAS_NO_CHAR8_T) |
| 737 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED |
| 738 | # else |
| 739 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T |
| 740 | # endif |
Martin Storsjö | 6be11e3 | 2020-10-26 11:18:46 | [diff] [blame] | 741 | |
Richard Smith | a972703 | 2019-10-19 00:06:00 | [diff] [blame] | 742 | // Macros to enter and leave a state where deprecation warnings are suppressed. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 743 | # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) |
| 744 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ |
| 745 | _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ |
| 746 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| 747 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") |
| 748 | # else |
| 749 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 750 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 751 | # endif |
Richard Smith | a972703 | 2019-10-19 00:06:00 | [diff] [blame] | 752 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 753 | # if _LIBCPP_STD_VER <= 11 |
Nikolas Klauser | 3c7a7a7 | 2023-02-02 11:12:28 | [diff] [blame] | 754 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 755 | # else |
Nikolas Klauser | 3c7a7a7 | 2023-02-02 11:12:28 | [diff] [blame] | 756 | # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 757 | # endif |
Marshall Clow | f20d267 | 2013-07-15 14:57:19 | [diff] [blame] | 758 | |
Hristo Hristov | 40aaa27 | 2023-03-22 21:24:22 | [diff] [blame] | 759 | # if _LIBCPP_STD_VER >= 23 |
| 760 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit |
| 761 | # else |
| 762 | # define _LIBCPP_EXPLICIT_SINCE_CXX23 |
| 763 | # endif |
| 764 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 765 | # if _LIBCPP_STD_VER >= 14 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 766 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 767 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 768 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 769 | # endif |
Eric Fiselier | 371aac1 | 2014-07-17 05:16:18 | [diff] [blame] | 770 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 771 | # if _LIBCPP_STD_VER >= 17 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 772 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 773 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 774 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 775 | # endif |
Eric Fiselier | a58d430 | 2016-03-17 03:30:56 | [diff] [blame] | 776 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 777 | # if _LIBCPP_STD_VER >= 20 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 778 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 779 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 780 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 781 | # endif |
Marshall Clow | 1644c12e | 2017-11-14 22:26:50 | [diff] [blame] | 782 | |
Nikolas Klauser | 4f15267 | 2023-02-13 23:56:09 | [diff] [blame] | 783 | # if _LIBCPP_STD_VER >= 23 |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 784 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 785 | # else |
Nikolas Klauser | 5146b57 | 2022-08-19 11:08:01 | [diff] [blame] | 786 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 |
Nikolas Klauser | f02120f | 2022-08-13 11:52:35 | [diff] [blame] | 787 | # endif |
| 788 | |
A. Jiang | 7808541 | 2024-08-28 13:35:57 | [diff] [blame] | 789 | # if _LIBCPP_STD_VER >= 26 |
| 790 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr |
| 791 | # else |
| 792 | # define _LIBCPP_CONSTEXPR_SINCE_CXX26 |
| 793 | # endif |
| 794 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 795 | # ifndef _LIBCPP_WEAK |
| 796 | # define _LIBCPP_WEAK __attribute__((__weak__)) |
| 797 | # endif |
Howard Hinnant | a942f2f | 2013-10-04 23:56:37 | [diff] [blame] | 798 | |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 799 | // Thread API |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 800 | // clang-format off |
| 801 | # if !defined(_LIBCPP_HAS_NO_THREADS) && \ |
| 802 | !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ |
| 803 | !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ |
| 804 | !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 805 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 806 | # if defined(__FreeBSD__) || \ |
| 807 | defined(__wasi__) || \ |
| 808 | defined(__NetBSD__) || \ |
| 809 | defined(__OpenBSD__) || \ |
| 810 | defined(__NuttX__) || \ |
| 811 | defined(__linux__) || \ |
| 812 | defined(__GNU__) || \ |
| 813 | defined(__APPLE__) || \ |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 814 | defined(__MVS__) || \ |
| 815 | defined(_AIX) || \ |
| 816 | defined(__EMSCRIPTEN__) |
| 817 | // clang-format on |
| 818 | # define _LIBCPP_HAS_THREAD_API_PTHREAD |
| 819 | # elif defined(__Fuchsia__) |
| 820 | // TODO(44575): Switch to C11 thread API when possible. |
| 821 | # define _LIBCPP_HAS_THREAD_API_PTHREAD |
| 822 | # elif defined(_LIBCPP_WIN32API) |
| 823 | # define _LIBCPP_HAS_THREAD_API_WIN32 |
| 824 | # else |
| 825 | # error "No thread API" |
| 826 | # endif // _LIBCPP_HAS_THREAD_API |
| 827 | # endif // _LIBCPP_HAS_NO_THREADS |
Dan Albert | 85e26f5 | 2019-09-18 18:13:32 | [diff] [blame] | 828 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 829 | # if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 830 | # if defined(__ANDROID__) && __ANDROID_API__ >= 30 |
| 831 | # define _LIBCPP_HAS_COND_CLOCKWAIT |
| 832 | # elif defined(_LIBCPP_GLIBC_PREREQ) |
| 833 | # if _LIBCPP_GLIBC_PREREQ(2, 30) |
| 834 | # define _LIBCPP_HAS_COND_CLOCKWAIT |
| 835 | # endif |
| 836 | # endif |
| 837 | # endif |
| 838 | |
| 839 | # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 840 | # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 841 | _LIBCPP_HAS_NO_THREADS is not defined. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 842 | # endif |
Asiri Rathnayake | c7e4239 | 2016-05-06 14:06:29 | [diff] [blame] | 843 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 844 | # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 845 | # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 846 | _LIBCPP_HAS_NO_THREADS is defined. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 847 | # endif |
Asiri Rathnayake | 8c2bf45 | 2016-09-11 21:46:40 | [diff] [blame] | 848 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 849 | # if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 850 | # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 851 | _LIBCPP_HAS_NO_THREADS is defined. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 852 | # endif |
Eric Fiselier | 2050bed | 2014-12-06 20:09:11 | [diff] [blame] | 853 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 854 | # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) |
| 855 | # define __STDCPP_THREADS__ 1 |
| 856 | # endif |
Nico Weber | 9aae539 | 2019-07-30 14:32:47 | [diff] [blame] | 857 | |
Louis Dionne | 568bb7e | 2019-07-25 20:29:20 | [diff] [blame] | 858 | // The glibc and Bionic implementation of pthreads implements |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 859 | // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 |
| 860 | // mutexes have no destroy mechanism. |
Louis Dionne | 568bb7e | 2019-07-25 20:29:20 | [diff] [blame] | 861 | // |
| 862 | // This optimization can't be performed on Apple platforms, where |
| 863 | // pthread_mutex_destroy can allow the kernel to release resources. |
| 864 | // See https://llvm.org/D64298 for details. |
| 865 | // |
| 866 | // TODO(EricWF): Enable this optimization on Bionic after speaking to their |
| 867 | // respective stakeholders. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 868 | // clang-format off |
| 869 | # if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ |
| 870 | (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ |
| 871 | defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 872 | // clang-format on |
| 873 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION |
| 874 | # endif |
Eric Fiselier | 8baf838 | 2019-07-07 01:20:54 | [diff] [blame] | 875 | |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 876 | // Destroying a condvar is a nop on Windows. |
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_cond_destroy can allow the kernel to release resources. |
| 880 | // See https://llvm.org/D64298 for details. |
| 881 | // |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 882 | // TODO(EricWF): This is potentially true for some pthread implementations |
| 883 | // as well. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 884 | # if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 885 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION |
| 886 | # endif |
Eric Fiselier | 8cedf04 | 2019-07-07 17:24:03 | [diff] [blame] | 887 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 888 | # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ |
Joseph Huber | 38dbcbd | 2024-08-31 12:07:52 | [diff] [blame] | 889 | defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) || defined(__LLVM_LIBC__) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 890 | # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE |
Davide Italiano | 6de760a | 2019-03-05 18:40:49 | [diff] [blame] | 891 | # endif |
Eric Fiselier | 749adeb | 2015-08-19 17:21:46 | [diff] [blame] | 892 | |
Xing Xue | 7f302f2 | 2023-09-07 18:48:45 | [diff] [blame] | 893 | # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 894 | # define _LIBCPP_HAS_C_ATOMIC_IMP |
| 895 | # elif defined(_LIBCPP_COMPILER_GCC) |
| 896 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP |
| 897 | # endif |
Eric Fiselier | fcd0221 | 2016-02-11 11:59:44 | [diff] [blame] | 898 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 899 | # if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ |
| 900 | !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) |
| 901 | # define _LIBCPP_HAS_NO_ATOMIC_HEADER |
| 902 | # else |
| 903 | # ifndef _LIBCPP_ATOMIC_FLAG_TYPE |
| 904 | # define _LIBCPP_ATOMIC_FLAG_TYPE bool |
| 905 | # endif |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 906 | # endif |
| 907 | |
Louis Dionne | 71f95ec | 2023-07-04 22:11:16 | [diff] [blame] | 908 | # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__) |
| 909 | # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__)) |
| 910 | # else |
| 911 | # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS |
| 912 | # endif |
| 913 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 914 | # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) |
| 915 | # if defined(__clang__) && __has_attribute(acquire_capability) |
Saleem Abdulrasool | 3444e9f | 2017-02-13 15:26:51 | [diff] [blame] | 916 | // Work around the attribute handling in clang. When both __declspec and |
| 917 | // __attribute__ are present, the processing goes awry preventing the definition |
Martin Storsjö | de5d38e | 2022-01-11 09:23:39 | [diff] [blame] | 918 | // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus |
| 919 | // combining the two does work. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 920 | # if !defined(_MSC_VER) |
| 921 | # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
| 922 | # endif |
Logan Chien | 2b772b9 | 2018-02-24 07:57:32 | [diff] [blame] | 923 | # endif |
| 924 | # endif |
Eric Fiselier | 7865b2e | 2016-03-16 02:30:06 | [diff] [blame] | 925 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 926 | # ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
| 927 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) |
| 928 | # else |
| 929 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) |
| 930 | # endif |
Eric Fiselier | fda3825 | 2019-12-13 20:42:07 | [diff] [blame] | 931 | |
Nikolas Klauser | 8b73be5 | 2023-11-13 12:06:06 | [diff] [blame] | 932 | # if _LIBCPP_STD_VER >= 20 |
| 933 | # define _LIBCPP_CONSTINIT constinit |
| 934 | # elif __has_attribute(__require_constant_initialization__) |
| 935 | # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) |
| 936 | # else |
| 937 | # define _LIBCPP_CONSTINIT |
| 938 | # endif |
| 939 | |
Dmitri Gribenko | 7378fb3 | 2024-01-22 18:12:05 | [diff] [blame] | 940 | # if defined(__CUDACC__) || defined(__CUDA_ARCH__) || defined(__CUDA_LIBDEVICE__) |
| 941 | // The CUDA SDK contains an unfortunate definition for the __noinline__ macro, |
| 942 | // which breaks the regular __attribute__((__noinline__)) syntax. Therefore, |
| 943 | // when compiling for CUDA we use the non-underscored version of the noinline |
| 944 | // attribute. |
| 945 | // |
| 946 | // This is a temporary workaround and we still expect the CUDA SDK team to solve |
| 947 | // this issue properly in the SDK headers. |
| 948 | // |
| 949 | // See https://github.com/llvm/llvm-project/pull/73838 for more details. |
| 950 | # define _LIBCPP_NOINLINE __attribute__((noinline)) |
| 951 | # elif __has_attribute(__noinline__) |
| 952 | # define _LIBCPP_NOINLINE __attribute__((__noinline__)) |
| 953 | # else |
| 954 | # define _LIBCPP_NOINLINE |
| 955 | # endif |
| 956 | |
Louis Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 957 | // We often repeat things just for handling wide characters in the library. |
| 958 | // When wide characters are disabled, it can be useful to have a quick way of |
| 959 | // disabling it without having to resort to #if-#endif, which has a larger |
| 960 | // impact on readability. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 961 | # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) |
| 962 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) |
| 963 | # else |
| 964 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ |
| 965 | # endif |
Louis Dionne | f4c1258 | 2021-08-23 19:32:36 | [diff] [blame] | 966 | |
Nicole Rabjohn | 92e4d67 | 2023-07-06 17:12:05 | [diff] [blame] | 967 | // clang-format off |
Louis Dionne | 7b46225 | 2024-01-25 20:48:46 | [diff] [blame] | 968 | # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh\")") _Pragma("push_macro(\"move\")") _Pragma("push_macro(\"erase\")") |
| 969 | # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh\")") _Pragma("pop_macro(\"move\")") _Pragma("pop_macro(\"erase\")") |
Nicole Rabjohn | 92e4d67 | 2023-07-06 17:12:05 | [diff] [blame] | 970 | // clang-format on |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 971 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 972 | # ifndef _LIBCPP_NO_AUTO_LINK |
| 973 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
| 974 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 975 | # pragma comment(lib, "c++.lib") |
| 976 | # else |
| 977 | # pragma comment(lib, "libc++.lib") |
| 978 | # endif |
| 979 | # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
| 980 | # endif // _LIBCPP_NO_AUTO_LINK |
Eric Fiselier | 56312f5 | 2017-06-16 01:57:41 | [diff] [blame] | 981 | |
Dan Albert | a7e9059 | 2019-09-16 19:26:41 | [diff] [blame] | 982 | // Configures the fopen close-on-exec mode character, if any. This string will |
| 983 | // be appended to any mode string used by fstream for fopen/fdopen. |
| 984 | // |
| 985 | // Not all platforms support this, but it helps avoid fd-leaks on platforms that |
| 986 | // do. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 987 | # if defined(__BIONIC__) |
| 988 | # define _LIBCPP_FOPEN_CLOEXEC_MODE "e" |
| 989 | # else |
| 990 | # define _LIBCPP_FOPEN_CLOEXEC_MODE |
| 991 | # endif |
Dan Albert | a7e9059 | 2019-09-16 19:26:41 | [diff] [blame] | 992 | |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 993 | # if __has_cpp_attribute(msvc::no_unique_address) |
| 994 | // MSVC implements [[no_unique_address]] as a silent no-op currently. |
| 995 | // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) |
| 996 | // However, MSVC implements [[msvc::no_unique_address]] which does what |
| 997 | // [[no_unique_address]] is supposed to do, in general. |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 998 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 999 | # else |
Nikolas Klauser | 42f5277 | 2024-09-03 17:46:08 | [diff] [blame] | 1000 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] |
Nikolas Klauser | ac25172 | 2022-06-13 15:25:23 | [diff] [blame] | 1001 | # endif |
Martin Storsjö | 8a0a706 | 2022-02-10 11:23:40 | [diff] [blame] | 1002 | |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1003 | // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these |
| 1004 | // functions is gradually being added to existing C libraries. The conditions |
| 1005 | // below check for known C library versions and conditions under which these |
| 1006 | // functions are declared by the C library. |
| 1007 | # define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 |
| 1008 | // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if |
Tom Honermann | cf93a3d | 2023-01-25 22:57:15 | [diff] [blame] | 1009 | // __cpp_char8_t is defined or if C2X extensions are enabled. Determining |
| 1010 | // the latter depends on internal GNU libc details that are not appropriate |
| 1011 | // to depend on here, so any declarations present when __cpp_char8_t is not |
| 1012 | // defined are ignored. |
| 1013 | # if defined(_LIBCPP_GLIBC_PREREQ) |
| 1014 | # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) |
Tom Honermann | 7e7013c | 2022-09-10 14:16:20 | [diff] [blame] | 1015 | # undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 |
| 1016 | # endif |
| 1017 | # endif |
| 1018 | |
Mark de Wever | 261b5ab | 2022-10-05 17:54:44 | [diff] [blame] | 1019 | // There are a handful of public standard library types that are intended to |
| 1020 | // support CTAD but don't need any explicit deduction guides to do so. This |
| 1021 | // macro is used to mark them as such, which suppresses the |
| 1022 | // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code |
| 1023 | // with these classes. |
Nikolas Klauser | e65cd4c | 2023-02-23 20:17:11 | [diff] [blame] | 1024 | # if _LIBCPP_STD_VER >= 17 |
| 1025 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 1026 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ |
| 1027 | template <class... _Tag> \ |
| 1028 | [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...> |
| 1029 | # else |
| 1030 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \ |
| 1031 | template <class... _Tag> \ |
| 1032 | ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...> |
| 1033 | # endif |
| 1034 | # else |
| 1035 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") |
| 1036 | # endif |
Louis Dionne | c2df707 | 2022-09-08 21:36:11 | [diff] [blame] | 1037 | |
Konstantin Varlamov | 87cf39a | 2023-03-03 01:35:03 | [diff] [blame] | 1038 | // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use |
| 1039 | // compiler intrinsics in the Objective-C++ mode. |
| 1040 | # ifdef __OBJC__ |
| 1041 | # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS |
| 1042 | # endif |
| 1043 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1044 | # define _PSTL_PRAGMA(x) _Pragma(#x) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1045 | |
| 1046 | // Enable SIMD for compilers that support OpenMP 4.0 |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1047 | # if (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1048 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1049 | # define _PSTL_UDR_PRESENT |
| 1050 | # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd) |
| 1051 | # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd) |
| 1052 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM)) |
| 1053 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM)) |
| 1054 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM)) |
| 1055 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM)) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1056 | |
| 1057 | // Declaration of reduction functor, where |
| 1058 | // NAME - the name of the functor |
| 1059 | // OP - type of the callable object with the reduction operation |
| 1060 | // omp_in - refers to the local partial result |
| 1061 | // omp_out - refers to the final value of the combiner operator |
| 1062 | // omp_priv - refers to the private copy of the initial value |
| 1063 | // omp_orig - refers to the original variable to be reduced |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1064 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \ |
| 1065 | _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig)) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1066 | |
Nikolas Klauser | 15941dd | 2023-08-01 01:43:50 | [diff] [blame] | 1067 | # elif defined(_LIBCPP_COMPILER_CLANG_BASED) |
| 1068 | |
| 1069 | # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)") |
| 1070 | # define _PSTL_PRAGMA_DECLARE_SIMD |
| 1071 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") |
| 1072 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)") |
| 1073 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) |
| 1074 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) |
| 1075 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) |
| 1076 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1077 | # else // (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1078 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1079 | # define _PSTL_PRAGMA_SIMD |
| 1080 | # define _PSTL_PRAGMA_DECLARE_SIMD |
| 1081 | # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) |
| 1082 | # define _PSTL_PRAGMA_SIMD_SCAN(PRM) |
| 1083 | # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) |
| 1084 | # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) |
| 1085 | # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1086 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1087 | # endif // (defined(_OPENMP) && _OPENMP >= 201307) |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1088 | |
Louis Dionne | 5a6e6ad | 2023-06-16 18:32:08 | [diff] [blame] | 1089 | # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED |
Nikolas Klauser | f041b34 | 2023-05-09 18:51:40 | [diff] [blame] | 1090 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1091 | // Optional attributes - these are useful for a better QoI, but not required to be available |
| 1092 | |
| 1093 | # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) |
| 1094 | # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) |
| 1095 | # else |
| 1096 | # define _LIBCPP_NO_CFI |
| 1097 | # endif |
| 1098 | |
| 1099 | # if __has_attribute(__malloc__) |
| 1100 | # define _LIBCPP_NOALIAS __attribute__((__malloc__)) |
| 1101 | # else |
| 1102 | # define _LIBCPP_NOALIAS |
| 1103 | # endif |
| 1104 | |
| 1105 | # if __has_attribute(__using_if_exists__) |
| 1106 | # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) |
| 1107 | # else |
| 1108 | # define _LIBCPP_USING_IF_EXISTS |
| 1109 | # endif |
| 1110 | |
Nikolas Klauser | 83bc7b5 | 2024-04-22 20:13:58 | [diff] [blame] | 1111 | # if __has_cpp_attribute(__nodiscard__) |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1112 | # define _LIBCPP_NODISCARD [[__nodiscard__]] |
| 1113 | # else |
| 1114 | // We can't use GCC's [[gnu::warn_unused_result]] and |
| 1115 | // __attribute__((warn_unused_result)), because GCC does not silence them via |
| 1116 | // (void) cast. |
| 1117 | # define _LIBCPP_NODISCARD |
| 1118 | # endif |
| 1119 | |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1120 | # if __has_attribute(__no_destroy__) |
| 1121 | # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) |
| 1122 | # else |
| 1123 | # define _LIBCPP_NO_DESTROY |
| 1124 | # endif |
| 1125 | |
Louis Dionne | a00bbcb | 2024-05-01 16:26:38 | [diff] [blame] | 1126 | # if __has_attribute(__diagnose_if__) |
philnik777 | e90845f | 2023-11-23 21:15:06 | [diff] [blame] | 1127 | # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) |
| 1128 | # else |
| 1129 | # define _LIBCPP_DIAGNOSE_WARNING(...) |
| 1130 | # endif |
| 1131 | |
| 1132 | // Use a function like macro to imply that it must be followed by a semicolon |
| 1133 | # if __has_cpp_attribute(fallthrough) |
| 1134 | # define _LIBCPP_FALLTHROUGH() [[fallthrough]] |
| 1135 | # elif __has_attribute(__fallthrough__) |
| 1136 | # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) |
| 1137 | # else |
| 1138 | # define _LIBCPP_FALLTHROUGH() ((void)0) |
| 1139 | # endif |
| 1140 | |
| 1141 | # if __has_cpp_attribute(_Clang::__lifetimebound__) |
| 1142 | # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] |
| 1143 | # else |
| 1144 | # define _LIBCPP_LIFETIMEBOUND |
| 1145 | # endif |
| 1146 | |
| 1147 | # if __has_attribute(__nodebug__) |
| 1148 | # define _LIBCPP_NODEBUG __attribute__((__nodebug__)) |
| 1149 | # else |
| 1150 | # define _LIBCPP_NODEBUG |
| 1151 | # endif |
| 1152 | |
| 1153 | # if __has_attribute(__standalone_debug__) |
| 1154 | # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) |
| 1155 | # else |
| 1156 | # define _LIBCPP_STANDALONE_DEBUG |
| 1157 | # endif |
| 1158 | |
| 1159 | # if __has_attribute(__preferred_name__) |
| 1160 | # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) |
| 1161 | # else |
| 1162 | # define _LIBCPP_PREFERRED_NAME(x) |
| 1163 | # endif |
| 1164 | |
| 1165 | # if __has_attribute(__no_sanitize__) |
| 1166 | # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__))) |
| 1167 | # else |
| 1168 | # define _LIBCPP_NO_SANITIZE(...) |
| 1169 | # endif |
| 1170 | |
| 1171 | # if __has_attribute(__init_priority__) |
| 1172 | # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) |
| 1173 | # else |
| 1174 | # define _LIBCPP_INIT_PRIORITY_MAX |
| 1175 | # endif |
| 1176 | |
| 1177 | # if __has_attribute(__format__) |
| 1178 | // The attribute uses 1-based indices for ordinary and static member functions. |
| 1179 | // The attribute uses 2-based indices for non-static member functions. |
| 1180 | # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ |
| 1181 | __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) |
| 1182 | # else |
| 1183 | # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ |
| 1184 | # endif |
| 1185 | |
| 1186 | # if __has_attribute(__packed__) |
| 1187 | # define _LIBCPP_PACKED __attribute__((__packed__)) |
| 1188 | # else |
| 1189 | # define _LIBCPP_PACKED |
| 1190 | # endif |
| 1191 | |
| 1192 | # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) |
| 1193 | # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) |
| 1194 | # else |
| 1195 | # define _LIBCPP_DECLSPEC_EMPTY_BASES |
| 1196 | # endif |
| 1197 | |
| 1198 | // Allow for build-time disabling of unsigned integer sanitization |
| 1199 | # if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC) |
| 1200 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) |
| 1201 | # else |
| 1202 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
| 1203 | # endif |
| 1204 | |
Hristo Hristov | 3412bc7 | 2024-01-21 05:16:51 | [diff] [blame] | 1205 | // Clang-18 has support for deducing this, but it does not set the FTM. |
| 1206 | # if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) |
| 1207 | # define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER |
| 1208 | # endif |
| 1209 | |
Eric Fiselier | 56312f5 | 2017-06-16 01:57:41 | [diff] [blame] | 1210 | #endif // __cplusplus |
| 1211 | |
Louis Dionne | cc82a1b | 2022-03-23 17:11:04 | [diff] [blame] | 1212 | #endif // _LIBCPP___CONFIG |