Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1 | // -*- C++ -*- |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 3 | // |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [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 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 10 | #ifndef _LIBCPP___CONFIG |
| 11 | #define _LIBCPP___CONFIG |
| 12 | |
| 13 | #include <__config_site> |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 14 | |
| 15 | #if defined(_MSC_VER) && !defined(__clang__) |
| 16 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 17 | # define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
| 18 | # endif |
| 19 | #endif |
| 20 | |
| 21 | #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 22 | # pragma GCC system_header |
| 23 | #endif |
| 24 | |
| 25 | #if defined(__apple_build_version__) |
| 26 | # define _LIBCPP_COMPILER_CLANG_BASED |
| 27 | # define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) |
| 28 | #elif defined(__clang__) |
| 29 | # define _LIBCPP_COMPILER_CLANG_BASED |
| 30 | # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) |
| 31 | #elif defined(__GNUC__) |
| 32 | # define _LIBCPP_COMPILER_GCC |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 33 | #endif |
| 34 | |
| 35 | #ifdef __cplusplus |
| 36 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 37 | // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. |
Kaido Kert | b108943 | 2024-03-18 19:46:49 -0700 | [diff] [blame^] | 38 | // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 39 | // defined to XXYYZZ. |
Kaido Kert | b108943 | 2024-03-18 19:46:49 -0700 | [diff] [blame^] | 40 | # define _LIBCPP_VERSION 170000 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 41 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 42 | # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y |
| 43 | # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 44 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 45 | // Valid C++ identifier that revs with every libc++ version. This can be used to |
| 46 | // generate identifiers that must be unique for every released libc++ version. |
| 47 | # define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION) |
| 48 | |
| 49 | # if __STDC_HOSTED__ == 0 |
| 50 | # define _LIBCPP_FREESTANDING |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 51 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 52 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 53 | # ifndef _LIBCPP_STD_VER |
| 54 | # if __cplusplus <= 201103L |
| 55 | # define _LIBCPP_STD_VER 11 |
| 56 | # elif __cplusplus <= 201402L |
| 57 | # define _LIBCPP_STD_VER 14 |
| 58 | # elif __cplusplus <= 201703L |
| 59 | # define _LIBCPP_STD_VER 17 |
| 60 | # elif __cplusplus <= 202002L |
| 61 | # define _LIBCPP_STD_VER 20 |
| 62 | # else |
| 63 | // Expected release year of the next C++ standard |
| 64 | # define _LIBCPP_STD_VER 23 |
| 65 | # endif |
| 66 | # endif // _LIBCPP_STD_VER |
| 67 | |
| 68 | # if defined(__ELF__) |
| 69 | # define _LIBCPP_OBJECT_FORMAT_ELF 1 |
| 70 | # elif defined(__MACH__) |
| 71 | # define _LIBCPP_OBJECT_FORMAT_MACHO 1 |
| 72 | # elif defined(_WIN32) |
| 73 | # define _LIBCPP_OBJECT_FORMAT_COFF 1 |
| 74 | # elif defined(__wasm__) |
| 75 | # define _LIBCPP_OBJECT_FORMAT_WASM 1 |
| 76 | # elif defined(_AIX) |
| 77 | # define _LIBCPP_OBJECT_FORMAT_XCOFF 1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 78 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 79 | // ... add new file formats here ... |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 80 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 81 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 82 | # if _LIBCPP_ABI_VERSION >= 2 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 83 | // Change short string representation so that string data starts at offset 0, |
| 84 | // improving its alignment in some cases. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 85 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 86 | // Fix deque iterator type in order to support incomplete types. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 87 | # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 88 | // Fix undefined behavior in how std::list stores its linked nodes. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 89 | # define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 90 | // Fix undefined behavior in how __tree stores its end and parent nodes. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 91 | # define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 92 | // Fix undefined behavior in how __hash_table stores its pointer types. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 93 | # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB |
| 94 | # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB |
| 95 | # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 96 | // Define a key function for `bad_function_call` in the library, to centralize |
| 97 | // its vtable and typeinfo to libc++ rather than having all other libraries |
| 98 | // using that class define their own copies. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 99 | # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION |
| 100 | // Override the default return value of exception::what() for |
| 101 | // bad_function_call::what() with a string that is specific to |
| 102 | // bad_function_call (see http://wg21.link/LWG2233). This is an ABI break |
| 103 | // because it changes the vtable layout of bad_function_call. |
| 104 | # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 105 | // Enable optimized version of __do_get_(un)signed which avoids redundant copies. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 106 | # define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET |
| 107 | // Give reverse_iterator<T> one data member of type T, not two. |
| 108 | // Also, in C++17 and later, don't derive iterator types from std::iterator. |
| 109 | # define _LIBCPP_ABI_NO_ITERATOR_BASES |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 110 | // Use the smallest possible integer type to represent the index of the variant. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 111 | // Previously libc++ used "unsigned int" exclusively. |
| 112 | # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION |
| 113 | // Unstable attempt to provide a more optimized std::function |
| 114 | # define _LIBCPP_ABI_OPTIMIZED_FUNCTION |
| 115 | // All the regex constants must be distinct and nonzero. |
| 116 | # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 117 | // Re-worked external template instantiations for std::string with a focus on |
| 118 | // performance and fast-path inlining. |
| 119 | # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
| 120 | // Enable clang::trivial_abi on std::unique_ptr. |
| 121 | # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI |
| 122 | // Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr |
| 123 | # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI |
| 124 | // std::random_device holds some state when it uses an implementation that gets |
| 125 | // entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this |
| 126 | // implementation to another one on a platform that has already shipped |
| 127 | // std::random_device, one needs to retain the same object layout to remain ABI |
| 128 | // compatible. This switch removes these workarounds for platforms that don't care |
| 129 | // about ABI compatibility. |
| 130 | # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT |
| 131 | // Don't export the legacy __basic_string_common class and its methods from the built library. |
| 132 | # define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON |
| 133 | // Don't export the legacy __vector_base_common class and its methods from the built library. |
| 134 | # define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON |
| 135 | // According to the Standard, `bitset::operator[] const` returns bool |
| 136 | # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL |
| 137 | // Remove the base 10 implementation of std::to_chars from the dylib. |
| 138 | // The implementation moved to the header, but we still export the symbols from |
| 139 | // the dylib for backwards compatibility. |
| 140 | # define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 |
| 141 | # elif _LIBCPP_ABI_VERSION == 1 |
| 142 | # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 143 | // Enable compiling copies of now inline methods into the dylib to support |
| 144 | // applications compiled against older libraries. This is unnecessary with |
| 145 | // COFF dllexport semantics, since dllexport forces a non-inline definition |
| 146 | // of inline functions to be emitted anyway. Our own non-inline copy would |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 147 | // conflict with the dllexport-emitted copy, so we disable it. For XCOFF, |
| 148 | // the linker will take issue with the symbols in the shared object if the |
| 149 | // weak inline methods get visibility (such as from -fvisibility-inlines-hidden), |
| 150 | // so disable it. |
| 151 | # define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS |
| 152 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 153 | // Feature macros for disabling pre ABI v1 features. All of these options |
| 154 | // are deprecated. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 155 | # if defined(__FreeBSD__) |
| 156 | # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR |
| 157 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 158 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 159 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 160 | # if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 |
| 161 | // Enable additional explicit instantiations of iostreams components. This |
| 162 | // reduces the number of weak definitions generated in programs that use |
| 163 | // iostreams by providing a single strong definition in the shared library. |
| 164 | # define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 165 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 166 | // Define a key function for `bad_function_call` in the library, to centralize |
| 167 | // its vtable and typeinfo to libc++ rather than having all other libraries |
| 168 | // using that class define their own copies. |
| 169 | # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION |
| 170 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 171 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 172 | # define _LIBCPP_TOSTRING2(x) #x |
| 173 | # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 174 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 175 | # if __cplusplus < 201103L |
| 176 | # define _LIBCPP_CXX03_LANG |
| 177 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 178 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 179 | # ifndef __has_attribute |
| 180 | # define __has_attribute(__x) 0 |
| 181 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 182 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 183 | # ifndef __has_builtin |
| 184 | # define __has_builtin(__x) 0 |
| 185 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 186 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 187 | # ifndef __has_extension |
| 188 | # define __has_extension(__x) 0 |
| 189 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 190 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 191 | # ifndef __has_feature |
| 192 | # define __has_feature(__x) 0 |
| 193 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 194 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 195 | # ifndef __has_cpp_attribute |
| 196 | # define __has_cpp_attribute(__x) 0 |
| 197 | # endif |
| 198 | |
| 199 | # ifndef __has_constexpr_builtin |
| 200 | # define __has_constexpr_builtin(x) 0 |
| 201 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 202 | |
| 203 | // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by |
| 204 | // the compiler and '1' otherwise. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 205 | # ifndef __is_identifier |
| 206 | # define __is_identifier(__x) 1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 207 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 208 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 209 | # ifndef __has_declspec_attribute |
| 210 | # define __has_declspec_attribute(__x) 0 |
| 211 | # endif |
| 212 | |
| 213 | # define __has_keyword(__x) !(__is_identifier(__x)) |
| 214 | |
| 215 | # ifndef __has_include |
| 216 | # define __has_include(...) 0 |
| 217 | # endif |
| 218 | |
| 219 | # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L |
| 220 | # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" |
| 221 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 222 | |
| 223 | // FIXME: ABI detection should be done via compiler builtin macros. This |
| 224 | // is just a placeholder until Clang implements such macros. For now assume |
| 225 | // that Windows compilers pretending to be MSVC++ target the Microsoft ABI, |
| 226 | // and allow the user to explicitly specify the ABI to handle cases where this |
| 227 | // heuristic falls short. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 228 | # if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) |
| 229 | # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" |
| 230 | # elif defined(_LIBCPP_ABI_FORCE_ITANIUM) |
| 231 | # define _LIBCPP_ABI_ITANIUM |
| 232 | # elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 233 | # define _LIBCPP_ABI_MICROSOFT |
| 234 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 235 | # if defined(_WIN32) && defined(_MSC_VER) |
| 236 | # define _LIBCPP_ABI_MICROSOFT |
| 237 | # else |
| 238 | # define _LIBCPP_ABI_ITANIUM |
| 239 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 240 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 241 | |
| 242 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) |
| 243 | # define _LIBCPP_ABI_VCRUNTIME |
| 244 | # endif |
| 245 | |
| 246 | # if __has_feature(experimental_library) |
| 247 | # ifndef _LIBCPP_ENABLE_EXPERIMENTAL |
| 248 | # define _LIBCPP_ENABLE_EXPERIMENTAL |
| 249 | # endif |
| 250 | # endif |
| 251 | |
| 252 | // Incomplete features get their own specific disabling flags. This makes it |
| 253 | // easier to grep for target specific flags once the feature is complete. |
| 254 | # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) |
| 255 | # define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT |
| 256 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 257 | |
| 258 | // Need to detect which libc we're using if we're on Linux. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 259 | # if defined(__linux__) |
| 260 | # include <features.h> |
| 261 | # if defined(__GLIBC_PREREQ) |
| 262 | # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) |
| 263 | # else |
| 264 | # define _LIBCPP_GLIBC_PREREQ(a, b) 0 |
| 265 | # endif // defined(__GLIBC_PREREQ) |
| 266 | # endif // defined(__linux__) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 267 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 268 | # if defined(__MVS__) |
| 269 | # include <features.h> // for __NATIVE_ASCII_F |
| 270 | # endif |
| 271 | |
| 272 | # ifdef __LITTLE_ENDIAN__ |
| 273 | # if __LITTLE_ENDIAN__ |
| 274 | # define _LIBCPP_LITTLE_ENDIAN |
| 275 | # endif // __LITTLE_ENDIAN__ |
| 276 | # endif // __LITTLE_ENDIAN__ |
| 277 | |
| 278 | # ifdef __BIG_ENDIAN__ |
| 279 | # if __BIG_ENDIAN__ |
| 280 | # define _LIBCPP_BIG_ENDIAN |
| 281 | # endif // __BIG_ENDIAN__ |
| 282 | # endif // __BIG_ENDIAN__ |
| 283 | |
| 284 | # ifdef __BYTE_ORDER__ |
| 285 | # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 286 | # define _LIBCPP_LITTLE_ENDIAN |
| 287 | # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 288 | # define _LIBCPP_BIG_ENDIAN |
| 289 | # endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
| 290 | # endif // __BYTE_ORDER__ |
| 291 | |
| 292 | # ifdef __FreeBSD__ |
| 293 | # include <sys/endian.h> |
| 294 | # include <osreldate.h> |
| 295 | # if _BYTE_ORDER == _LITTLE_ENDIAN |
| 296 | # define _LIBCPP_LITTLE_ENDIAN |
| 297 | # else // _BYTE_ORDER == _LITTLE_ENDIAN |
| 298 | # define _LIBCPP_BIG_ENDIAN |
| 299 | # endif // _BYTE_ORDER == _LITTLE_ENDIAN |
| 300 | # endif // __FreeBSD__ |
| 301 | |
| 302 | # if defined(__NetBSD__) || defined(__OpenBSD__) |
| 303 | # include <sys/endian.h> |
| 304 | # if _BYTE_ORDER == _LITTLE_ENDIAN |
| 305 | # define _LIBCPP_LITTLE_ENDIAN |
| 306 | # else // _BYTE_ORDER == _LITTLE_ENDIAN |
| 307 | # define _LIBCPP_BIG_ENDIAN |
| 308 | # endif // _BYTE_ORDER == _LITTLE_ENDIAN |
| 309 | # endif // defined(__NetBSD__) || defined(__OpenBSD__) |
| 310 | |
| 311 | # if defined(_WIN32) |
| 312 | # define _LIBCPP_WIN32API |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 313 | # define _LIBCPP_LITTLE_ENDIAN |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 314 | # define _LIBCPP_SHORT_WCHAR 1 |
| 315 | // Both MinGW and native MSVC provide a "MSVC"-like environment |
| 316 | # define _LIBCPP_MSVCRT_LIKE |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 317 | // If mingw not explicitly detected, assume using MS C runtime only if |
| 318 | // a MS compatibility version is specified. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 319 | # if defined(_MSC_VER) && !defined(__MINGW32__) |
| 320 | # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 321 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 322 | # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) |
| 323 | # define _LIBCPP_HAS_BITSCAN64 |
| 324 | # endif |
| 325 | # define _LIBCPP_HAS_OPEN_WITH_WCHAR |
| 326 | # endif // defined(_WIN32) |
| 327 | |
| 328 | # ifdef __sun__ |
| 329 | # include <sys/isa_defs.h> |
| 330 | # ifdef _LITTLE_ENDIAN |
| 331 | # define _LIBCPP_LITTLE_ENDIAN |
| 332 | # else |
| 333 | # define _LIBCPP_BIG_ENDIAN |
| 334 | # endif |
| 335 | # endif // __sun__ |
| 336 | |
| 337 | # if defined(_AIX) && !defined(__64BIT__) |
| 338 | // The size of wchar is 2 byte on 32-bit mode on AIX. |
| 339 | # define _LIBCPP_SHORT_WCHAR 1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 340 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 341 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 342 | // Libc++ supports various implementations of std::random_device. |
| 343 | // |
| 344 | // _LIBCPP_USING_DEV_RANDOM |
| 345 | // Read entropy from the given file, by default `/dev/urandom`. |
| 346 | // If a token is provided, it is assumed to be the path to a file |
| 347 | // to read entropy from. This is the default behavior if nothing |
| 348 | // else is specified. This implementation requires storing state |
| 349 | // inside `std::random_device`. |
| 350 | // |
| 351 | // _LIBCPP_USING_ARC4_RANDOM |
| 352 | // Use arc4random(). This allows obtaining random data even when |
| 353 | // using sandboxing mechanisms. On some platforms like Apple, this |
| 354 | // is the recommended source of entropy for user-space programs. |
| 355 | // When this option is used, the token passed to `std::random_device`'s |
| 356 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 357 | // |
| 358 | // _LIBCPP_USING_GETENTROPY |
| 359 | // Use getentropy(). |
| 360 | // When this option is used, the token passed to `std::random_device`'s |
| 361 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 362 | // |
| 363 | // _LIBCPP_USING_FUCHSIA_CPRNG |
| 364 | // Use Fuchsia's zx_cprng_draw() system call, which is specified to |
| 365 | // deliver high-quality entropy and cannot fail. |
| 366 | // When this option is used, the token passed to `std::random_device`'s |
| 367 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 368 | // |
| 369 | // _LIBCPP_USING_NACL_RANDOM |
| 370 | // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, |
| 371 | // including accesses to the special files under `/dev`. This implementation |
| 372 | // uses the NaCL syscall `nacl_secure_random_init()` to get entropy. |
| 373 | // When this option is used, the token passed to `std::random_device`'s |
| 374 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 375 | // |
| 376 | // _LIBCPP_USING_WIN32_RANDOM |
| 377 | // Use rand_s(), for use on Windows. |
| 378 | // When this option is used, the token passed to `std::random_device`'s |
| 379 | // constructor *must* be "/dev/urandom" -- anything else is an error. |
| 380 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ |
| 381 | defined(__DragonFly__) || defined(__sun__) |
| 382 | # define _LIBCPP_USING_ARC4_RANDOM |
| 383 | # elif defined(__wasi__) || defined(__EMSCRIPTEN__) |
| 384 | # define _LIBCPP_USING_GETENTROPY |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 385 | # elif defined(__Fuchsia__) |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 386 | # define _LIBCPP_USING_FUCHSIA_CPRNG |
| 387 | # elif defined(__native_client__) |
| 388 | # define _LIBCPP_USING_NACL_RANDOM |
| 389 | # elif defined(_LIBCPP_WIN32API) |
| 390 | # define _LIBCPP_USING_WIN32_RANDOM |
| 391 | # else |
| 392 | # define _LIBCPP_USING_DEV_RANDOM |
| 393 | # endif |
| 394 | |
| 395 | # if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) |
| 396 | # include <endian.h> |
| 397 | # if __BYTE_ORDER == __LITTLE_ENDIAN |
| 398 | # define _LIBCPP_LITTLE_ENDIAN |
| 399 | # elif __BYTE_ORDER == __BIG_ENDIAN |
| 400 | # define _LIBCPP_BIG_ENDIAN |
| 401 | # else // __BYTE_ORDER == __BIG_ENDIAN |
| 402 | # error unable to determine endian |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 403 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 404 | # endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 405 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 406 | # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) |
| 407 | # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) |
| 408 | # else |
| 409 | # define _LIBCPP_NO_CFI |
| 410 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 411 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 412 | # ifndef _LIBCPP_CXX03_LANG |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 413 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 414 | # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) |
| 415 | # define _ALIGNAS_TYPE(x) alignas(x) |
| 416 | # define _ALIGNAS(x) alignas(x) |
| 417 | # define _LIBCPP_NORETURN [[noreturn]] |
| 418 | # define _NOEXCEPT noexcept |
| 419 | # define _NOEXCEPT_(x) noexcept(x) |
| 420 | # define _LIBCPP_CONSTEXPR constexpr |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 421 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 422 | # else |
| 423 | |
| 424 | # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) |
| 425 | # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) |
| 426 | # define _ALIGNAS(x) __attribute__((__aligned__(x))) |
| 427 | # define _LIBCPP_NORETURN __attribute__((__noreturn__)) |
| 428 | # define _LIBCPP_HAS_NO_NOEXCEPT |
| 429 | # define nullptr __nullptr |
| 430 | # define _NOEXCEPT throw() |
| 431 | # define _NOEXCEPT_(x) |
| 432 | # define static_assert(...) _Static_assert(__VA_ARGS__) |
| 433 | # define decltype(...) __decltype(__VA_ARGS__) |
| 434 | # define _LIBCPP_CONSTEXPR |
| 435 | |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 436 | typedef __char16_t char16_t; |
| 437 | typedef __char32_t char32_t; |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 438 | |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 439 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 440 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 441 | # if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L |
| 442 | # define _LIBCPP_NO_EXCEPTIONS |
| 443 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 444 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 445 | # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 446 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 447 | # if defined(_LIBCPP_COMPILER_CLANG_BASED) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 448 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 449 | # if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2) |
| 450 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 451 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 452 | |
| 453 | // Objective-C++ features (opt-in) |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 454 | # if __has_feature(objc_arc) |
| 455 | # define _LIBCPP_HAS_OBJC_ARC |
| 456 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 457 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 458 | # if __has_feature(objc_arc_weak) |
| 459 | # define _LIBCPP_HAS_OBJC_ARC_WEAK |
| 460 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 461 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 462 | # if __has_extension(blocks) |
| 463 | # define _LIBCPP_HAS_EXTENSION_BLOCKS |
| 464 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 465 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 466 | # if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) |
| 467 | # define _LIBCPP_HAS_BLOCKS_RUNTIME |
| 468 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 469 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 470 | # if !__has_feature(address_sanitizer) |
| 471 | # define _LIBCPP_HAS_NO_ASAN |
| 472 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 473 | |
| 474 | // Allow for build-time disabling of unsigned integer sanitization |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 475 | # if __has_attribute(no_sanitize) |
| 476 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) |
| 477 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 478 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 479 | # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 480 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 481 | # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 482 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 483 | # elif defined(_LIBCPP_COMPILER_GCC) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 484 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 485 | # if !defined(__SANITIZE_ADDRESS__) |
| 486 | # define _LIBCPP_HAS_NO_ASAN |
| 487 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 488 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 489 | # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 490 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 491 | # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 492 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 493 | # endif // _LIBCPP_COMPILER_[CLANG|GCC] |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 494 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 495 | # if defined(_LIBCPP_OBJECT_FORMAT_COFF) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 496 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 497 | # ifdef _DLL |
| 498 | # define _LIBCPP_CRT_FUNC __declspec(dllimport) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 499 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 500 | # define _LIBCPP_CRT_FUNC |
| 501 | # endif |
| 502 | |
| 503 | # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) |
| 504 | # define _LIBCPP_DLL_VIS |
| 505 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
| 506 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 507 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 508 | # define _LIBCPP_EXPORTED_FROM_ABI |
| 509 | # elif defined(_LIBCPP_BUILDING_LIBRARY) |
| 510 | # define _LIBCPP_DLL_VIS __declspec(dllexport) |
| 511 | # if defined(__MINGW32__) |
| 512 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS |
| 513 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 514 | # else |
| 515 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS |
| 516 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS |
| 517 | # endif |
| 518 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS |
| 519 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) |
| 520 | # else |
| 521 | # define _LIBCPP_DLL_VIS __declspec(dllimport) |
| 522 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS |
| 523 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 524 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 525 | # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) |
| 526 | # endif |
| 527 | |
| 528 | # define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS |
| 529 | # define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS |
| 530 | # define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS |
| 531 | # define _LIBCPP_HIDDEN |
| 532 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
| 533 | # define _LIBCPP_TEMPLATE_VIS |
| 534 | # define _LIBCPP_TEMPLATE_DATA_VIS |
| 535 | # define _LIBCPP_ENUM_VIS |
| 536 | |
| 537 | # else |
| 538 | |
| 539 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 540 | # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) |
| 541 | # else |
| 542 | # define _LIBCPP_VISIBILITY(vis) |
| 543 | # endif |
| 544 | |
| 545 | # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") |
| 546 | # define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default") |
| 547 | # define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default") |
| 548 | # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") |
| 549 | # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") |
| 550 | # define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default") |
| 551 | # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") |
| 552 | # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS |
| 553 | |
| 554 | // TODO: Make this a proper customization point or remove the option to override it. |
| 555 | # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS |
| 556 | # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") |
| 557 | # endif |
| 558 | |
| 559 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 560 | // The inline should be removed once PR32114 is resolved |
| 561 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN |
| 562 | # else |
| 563 | # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
| 564 | # endif |
| 565 | |
| 566 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 567 | # if __has_attribute(__type_visibility__) |
| 568 | # define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default"))) |
| 569 | # else |
| 570 | # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) |
| 571 | # endif |
| 572 | # else |
| 573 | # define _LIBCPP_TEMPLATE_VIS |
| 574 | # endif |
| 575 | |
| 576 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) |
| 577 | # define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default"))) |
| 578 | # else |
| 579 | # define _LIBCPP_ENUM_VIS |
| 580 | # endif |
| 581 | |
| 582 | # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) |
| 583 | |
| 584 | # if __has_attribute(exclude_from_explicit_instantiation) |
| 585 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) |
| 586 | # else |
| 587 | // Try to approximate the effect of exclude_from_explicit_instantiation |
| 588 | // (which is that entities are not assumed to be provided by explicit |
| 589 | // template instantiations in the dylib) by always inlining those entities. |
| 590 | # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE |
| 591 | # endif |
| 592 | |
| 593 | // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved |
| 594 | // on two levels: |
| 595 | // 1. The symbol is given hidden visibility, which ensures that users won't start exporting |
| 596 | // symbols from their dynamic library by means of using the libc++ headers. This ensures |
| 597 | // that those symbols stay private to the dynamic library in which it is defined. |
| 598 | // |
| 599 | // 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures |
| 600 | // that no ODR violation can arise from mixing two TUs compiled with different versions |
| 601 | // of libc++ where we would have changed the definition of a symbol. If the symbols shared |
| 602 | // the same name, the ODR would require that their definitions be token-by-token equivalent, |
| 603 | // which basically prevents us from being able to make any change to any function in our |
| 604 | // headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at |
| 605 | // each release, which lets us change the definition of these symbols at our leisure. |
| 606 | // Note that historically, this has been achieved in various ways, including force-inlining |
| 607 | // all functions or giving internal linkage to all functions. Both these (previous) solutions |
| 608 | // suffer from drawbacks that lead notably to code bloat. |
| 609 | // |
| 610 | // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend |
| 611 | // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. |
| 612 | // |
| 613 | // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions |
| 614 | // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled |
| 615 | // name of a virtual function is part of its ABI, since some architectures like arm64e can sign |
| 616 | // the virtual function pointer in the vtable based on the mangled name of the function. Since |
| 617 | // we use an ABI tag that changes with each released version, the mangled name of the virtual |
| 618 | // function would change, which is incorrect. Note that it doesn't make much sense to change |
| 619 | // the implementation of a virtual function in an ABI-incompatible way in the first place, |
| 620 | // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. |
| 621 | // |
| 622 | // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing |
| 623 | // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and |
| 624 | // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. |
| 625 | # ifndef _LIBCPP_NO_ABI_TAG |
| 626 | # define _LIBCPP_HIDE_FROM_ABI \ |
| 627 | _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ |
| 628 | __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER)))) |
| 629 | # else |
| 630 | # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
| 631 | # endif |
Kaido Kert | b108943 | 2024-03-18 19:46:49 -0700 | [diff] [blame^] | 632 | # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
| 633 | |
| 634 | // This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern |
| 635 | // "C" function, as those lack mangling. |
| 636 | # define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 637 | |
| 638 | # ifdef _LIBCPP_BUILDING_LIBRARY |
| 639 | # if _LIBCPP_ABI_VERSION > 1 |
| 640 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
| 641 | # else |
| 642 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 643 | # endif |
| 644 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 645 | # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 646 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 647 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 648 | // Just so we can migrate to the new macros gradually. |
| 649 | # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 650 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 651 | // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. |
| 652 | // clang-format off |
| 653 | # define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { |
| 654 | # define _LIBCPP_END_NAMESPACE_STD }} |
| 655 | # define _VSTD std |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 656 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 657 | _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD |
| 658 | |
| 659 | # if _LIBCPP_STD_VER > 14 |
| 660 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ |
| 661 | _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 662 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 663 | # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ |
| 664 | _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 665 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 666 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 667 | # define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} |
| 668 | // clang-format on |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 669 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 670 | # define _VSTD_FS std::__fs::filesystem |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 671 | |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 672 | # if __has_attribute(__enable_if__) |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 673 | # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 674 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 675 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 676 | # ifndef __SIZEOF_INT128__ |
| 677 | # define _LIBCPP_HAS_NO_INT128 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 678 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 679 | |
| 680 | # ifndef __cpp_consteval |
| 681 | # define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 682 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 683 | # define _LIBCPP_CONSTEVAL consteval |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 684 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 685 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 686 | # if __has_attribute(__malloc__) |
| 687 | # define _LIBCPP_NOALIAS __attribute__((__malloc__)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 688 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 689 | # define _LIBCPP_NOALIAS |
| 690 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 691 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 692 | # if __has_attribute(__using_if_exists__) |
| 693 | # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 694 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 695 | # define _LIBCPP_USING_IF_EXISTS |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 696 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 697 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 698 | # ifdef _LIBCPP_CXX03_LANG |
| 699 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) \ |
| 700 | struct _LIBCPP_TYPE_VIS x { \ |
| 701 | enum __lx |
| 702 | // clang-format off |
| 703 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ |
| 704 | __lx __v_; \ |
| 705 | _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ |
| 706 | _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ |
| 707 | _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \ |
| 708 | }; |
| 709 | // clang-format on |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 710 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 711 | # else // _LIBCPP_CXX03_LANG |
| 712 | # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x |
| 713 | # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) |
| 714 | # endif // _LIBCPP_CXX03_LANG |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 715 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 716 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \ |
| 717 | defined(__NetBSD__) |
| 718 | # define _LIBCPP_LOCALE__L_EXTENSIONS 1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 719 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 720 | |
| 721 | # ifdef __FreeBSD__ |
| 722 | # define _DECLARE_C99_LDBL_MATH 1 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 723 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 724 | |
| 725 | // If we are getting operator new from the MSVC CRT, then allocation overloads |
| 726 | // for align_val_t were added in 19.12, aka VS 2017 version 15.3. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 727 | # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 |
| 728 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
| 729 | # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) |
| 730 | // We're deferring to Microsoft's STL to provide aligned new et al. We don't |
| 731 | // have it unless the language feature test macro is defined. |
| 732 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
| 733 | # elif defined(__MVS__) |
| 734 | # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 735 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 736 | |
| 737 | # if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) |
| 738 | # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION |
| 739 | # endif |
| 740 | |
| 741 | // It is not yet possible to use aligned_alloc() on all Apple platforms since |
| 742 | // 10.15 was the first version to ship an implementation of aligned_alloc(). |
| 743 | # if defined(__APPLE__) |
| 744 | # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ |
| 745 | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) |
| 746 | # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 747 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 748 | # elif defined(__ANDROID__) && __ANDROID_API__ < 28 |
| 749 | // Android only provides aligned_alloc when targeting API 28 or higher. |
| 750 | # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 751 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 752 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 753 | # if defined(__APPLE__) || defined(__FreeBSD__) |
| 754 | # define _LIBCPP_HAS_DEFAULTRUNELOCALE |
| 755 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 756 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 757 | # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) |
| 758 | # define _LIBCPP_WCTYPE_IS_MASK |
| 759 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 760 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 761 | # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) |
| 762 | # define _LIBCPP_HAS_NO_CHAR8_T |
| 763 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 764 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 765 | // Deprecation macros. |
| 766 | // |
| 767 | // Deprecations warnings are always enabled, except when users explicitly opt-out |
| 768 | // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. |
| 769 | # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) |
| 770 | # if __has_attribute(deprecated) |
| 771 | # define _LIBCPP_DEPRECATED __attribute__((deprecated)) |
| 772 | # define _LIBCPP_DEPRECATED_(m) __attribute__((deprecated(m))) |
| 773 | # elif _LIBCPP_STD_VER > 11 |
| 774 | # define _LIBCPP_DEPRECATED [[deprecated]] |
| 775 | # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] |
| 776 | # else |
| 777 | # define _LIBCPP_DEPRECATED |
| 778 | # define _LIBCPP_DEPRECATED_(m) |
| 779 | # endif |
| 780 | # else |
| 781 | # define _LIBCPP_DEPRECATED |
| 782 | # define _LIBCPP_DEPRECATED_(m) |
| 783 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 784 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 785 | # if !defined(_LIBCPP_CXX03_LANG) |
| 786 | # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED |
| 787 | # else |
| 788 | # define _LIBCPP_DEPRECATED_IN_CXX11 |
| 789 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 790 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 791 | # if _LIBCPP_STD_VER > 11 |
| 792 | # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED |
| 793 | # else |
| 794 | # define _LIBCPP_DEPRECATED_IN_CXX14 |
| 795 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 796 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 797 | # if _LIBCPP_STD_VER > 14 |
| 798 | # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED |
| 799 | # else |
| 800 | # define _LIBCPP_DEPRECATED_IN_CXX17 |
| 801 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 802 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 803 | # if _LIBCPP_STD_VER > 17 |
| 804 | # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED |
| 805 | # else |
| 806 | # define _LIBCPP_DEPRECATED_IN_CXX20 |
| 807 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 808 | |
Kaido Kert | b108943 | 2024-03-18 19:46:49 -0700 | [diff] [blame^] | 809 | #if _LIBCPP_STD_VER >= 23 |
| 810 | # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED |
| 811 | #else |
| 812 | # define _LIBCPP_DEPRECATED_IN_CXX23 |
| 813 | #endif |
| 814 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 815 | # if !defined(_LIBCPP_HAS_NO_CHAR8_T) |
| 816 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED |
| 817 | # else |
| 818 | # define _LIBCPP_DEPRECATED_WITH_CHAR8_T |
| 819 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 820 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 821 | // Macros to enter and leave a state where deprecation warnings are suppressed. |
| 822 | # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) |
| 823 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ |
| 824 | _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ |
| 825 | _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") |
| 826 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") |
| 827 | # else |
| 828 | # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 829 | # define _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 830 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 831 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 832 | # if _LIBCPP_STD_VER <= 11 |
| 833 | # define _LIBCPP_EXPLICIT_AFTER_CXX11 |
| 834 | # else |
| 835 | # define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit |
| 836 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 837 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 838 | # if _LIBCPP_STD_VER > 11 |
| 839 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr |
| 840 | # else |
| 841 | # define _LIBCPP_CONSTEXPR_SINCE_CXX14 |
| 842 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 843 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 844 | # if _LIBCPP_STD_VER > 14 |
| 845 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr |
| 846 | # else |
| 847 | # define _LIBCPP_CONSTEXPR_SINCE_CXX17 |
| 848 | # endif |
| 849 | |
| 850 | # if _LIBCPP_STD_VER > 17 |
| 851 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr |
| 852 | # else |
| 853 | # define _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 854 | # endif |
| 855 | |
| 856 | # if _LIBCPP_STD_VER > 20 |
| 857 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr |
| 858 | # else |
| 859 | # define _LIBCPP_CONSTEXPR_SINCE_CXX23 |
| 860 | # endif |
| 861 | |
| 862 | # if __has_cpp_attribute(nodiscard) |
| 863 | # define _LIBCPP_NODISCARD [[nodiscard]] |
| 864 | # else |
| 865 | // We can't use GCC's [[gnu::warn_unused_result]] and |
| 866 | // __attribute__((warn_unused_result)), because GCC does not silence them via |
| 867 | // (void) cast. |
| 868 | # define _LIBCPP_NODISCARD |
| 869 | # endif |
| 870 | |
| 871 | // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not |
| 872 | // specified as such as an extension. |
| 873 | # if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) |
| 874 | # define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD |
| 875 | # else |
| 876 | # define _LIBCPP_NODISCARD_EXT |
| 877 | # endif |
| 878 | |
| 879 | # if _LIBCPP_STD_VER > 17 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) |
| 880 | # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD |
| 881 | # else |
| 882 | # define _LIBCPP_NODISCARD_AFTER_CXX17 |
| 883 | # endif |
| 884 | |
| 885 | # if __has_attribute(__no_destroy__) |
| 886 | # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) |
| 887 | # else |
| 888 | # define _LIBCPP_NO_DESTROY |
| 889 | # endif |
| 890 | |
| 891 | # ifndef _LIBCPP_HAS_NO_ASAN |
| 892 | extern "C" _LIBCPP_FUNC_VIS void |
| 893 | __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); |
| 894 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 895 | |
| 896 | // Try to find out if RTTI is disabled. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 897 | # if !defined(__cpp_rtti) || __cpp_rtti < 199711L |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 898 | # define _LIBCPP_NO_RTTI |
| 899 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 900 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 901 | # ifndef _LIBCPP_WEAK |
| 902 | # define _LIBCPP_WEAK __attribute__((__weak__)) |
| 903 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 904 | |
| 905 | // Thread API |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 906 | // clang-format off |
| 907 | # if !defined(_LIBCPP_HAS_NO_THREADS) && \ |
| 908 | !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ |
| 909 | !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ |
| 910 | !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 911 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 912 | # if defined(__FreeBSD__) || \ |
| 913 | defined(__wasi__) || \ |
| 914 | defined(__NetBSD__) || \ |
| 915 | defined(__OpenBSD__) || \ |
| 916 | defined(__NuttX__) || \ |
| 917 | defined(__linux__) || \ |
| 918 | defined(__GNU__) || \ |
| 919 | defined(__APPLE__) || \ |
| 920 | defined(__sun__) || \ |
| 921 | defined(__MVS__) || \ |
| 922 | defined(_AIX) || \ |
| 923 | defined(__EMSCRIPTEN__) |
| 924 | // clang-format on |
| 925 | # define _LIBCPP_HAS_THREAD_API_PTHREAD |
| 926 | # elif defined(__Fuchsia__) |
| 927 | // TODO(44575): Switch to C11 thread API when possible. |
| 928 | # define _LIBCPP_HAS_THREAD_API_PTHREAD |
| 929 | # elif defined(_LIBCPP_WIN32API) |
| 930 | # define _LIBCPP_HAS_THREAD_API_WIN32 |
| 931 | # else |
| 932 | # error "No thread API" |
| 933 | # endif // _LIBCPP_HAS_THREAD_API |
| 934 | # endif // _LIBCPP_HAS_NO_THREADS |
| 935 | |
| 936 | # if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 937 | # if defined(__ANDROID__) && __ANDROID_API__ >= 30 |
| 938 | # define _LIBCPP_HAS_COND_CLOCKWAIT |
| 939 | # elif defined(_LIBCPP_GLIBC_PREREQ) |
| 940 | # if _LIBCPP_GLIBC_PREREQ(2, 30) |
| 941 | # define _LIBCPP_HAS_COND_CLOCKWAIT |
| 942 | # endif |
| 943 | # endif |
| 944 | # endif |
| 945 | |
| 946 | # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) |
| 947 | # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 948 | _LIBCPP_HAS_NO_THREADS is not defined. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 949 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 950 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 951 | # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) |
| 952 | # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 953 | _LIBCPP_HAS_NO_THREADS is defined. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 954 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 955 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 956 | # if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) |
| 957 | # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 958 | _LIBCPP_HAS_NO_THREADS is defined. |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 959 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 960 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 961 | # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) |
| 962 | # define __STDCPP_THREADS__ 1 |
| 963 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 964 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 965 | // The glibc and Bionic implementation of pthreads implements |
| 966 | // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 |
| 967 | // mutexes have no destroy mechanism. |
| 968 | // |
| 969 | // This optimization can't be performed on Apple platforms, where |
| 970 | // pthread_mutex_destroy can allow the kernel to release resources. |
| 971 | // See https://llvm.org/D64298 for details. |
| 972 | // |
| 973 | // TODO(EricWF): Enable this optimization on Bionic after speaking to their |
| 974 | // respective stakeholders. |
| 975 | // clang-format off |
| 976 | # if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ |
| 977 | (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ |
| 978 | defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 979 | // clang-format on |
| 980 | # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION |
| 981 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 982 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 983 | // Destroying a condvar is a nop on Windows. |
| 984 | // |
| 985 | // This optimization can't be performed on Apple platforms, where |
| 986 | // pthread_cond_destroy can allow the kernel to release resources. |
| 987 | // See https://llvm.org/D64298 for details. |
| 988 | // |
| 989 | // TODO(EricWF): This is potentially true for some pthread implementations |
| 990 | // as well. |
| 991 | # if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) |
| 992 | # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION |
| 993 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 994 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 995 | // Some systems do not provide gets() in their C library, for security reasons. |
| 996 | # if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) |
| 997 | # define _LIBCPP_C_HAS_NO_GETS |
| 998 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 999 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1000 | # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ |
| 1001 | defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) |
| 1002 | # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE |
| 1003 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1004 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1005 | # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) |
| 1006 | # define _LIBCPP_HAS_C_ATOMIC_IMP |
| 1007 | # elif defined(_LIBCPP_COMPILER_GCC) |
| 1008 | # define _LIBCPP_HAS_GCC_ATOMIC_IMP |
| 1009 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1010 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1011 | # if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ |
| 1012 | !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) |
| 1013 | # define _LIBCPP_HAS_NO_ATOMIC_HEADER |
| 1014 | # else |
| 1015 | # ifndef _LIBCPP_ATOMIC_FLAG_TYPE |
| 1016 | # define _LIBCPP_ATOMIC_FLAG_TYPE bool |
| 1017 | # endif |
| 1018 | # ifdef _LIBCPP_FREESTANDING |
| 1019 | # define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS |
| 1020 | # endif |
| 1021 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1022 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1023 | # ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
| 1024 | # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
| 1025 | # endif |
| 1026 | |
| 1027 | # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) |
| 1028 | # if defined(__clang__) && __has_attribute(acquire_capability) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1029 | // Work around the attribute handling in clang. When both __declspec and |
| 1030 | // __attribute__ are present, the processing goes awry preventing the definition |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1031 | // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus |
| 1032 | // combining the two does work. |
| 1033 | # if !defined(_MSC_VER) |
| 1034 | # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
| 1035 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1036 | # endif |
| 1037 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1038 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1039 | # ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS |
| 1040 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1041 | # else |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1042 | # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1043 | # endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1044 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1045 | # if _LIBCPP_STD_VER > 17 |
| 1046 | # define _LIBCPP_CONSTINIT constinit |
| 1047 | # elif __has_attribute(__require_constant_initialization__) |
| 1048 | # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) |
| 1049 | # else |
| 1050 | # define _LIBCPP_CONSTINIT |
| 1051 | # endif |
| 1052 | |
| 1053 | # if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) |
| 1054 | # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) |
| 1055 | # else |
| 1056 | # define _LIBCPP_DIAGNOSE_WARNING(...) |
| 1057 | # endif |
| 1058 | |
| 1059 | // Use a function like macro to imply that it must be followed by a semicolon |
| 1060 | # if __has_cpp_attribute(fallthrough) |
| 1061 | # define _LIBCPP_FALLTHROUGH() [[fallthrough]] |
| 1062 | # elif __has_attribute(__fallthrough__) |
| 1063 | # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) |
| 1064 | # else |
| 1065 | # define _LIBCPP_FALLTHROUGH() ((void)0) |
| 1066 | # endif |
| 1067 | |
| 1068 | # if __has_cpp_attribute(_Clang::__lifetimebound__) |
| 1069 | # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] |
| 1070 | # else |
| 1071 | # define _LIBCPP_LIFETIMEBOUND |
| 1072 | # endif |
| 1073 | |
| 1074 | # if __has_attribute(__nodebug__) |
| 1075 | # define _LIBCPP_NODEBUG __attribute__((__nodebug__)) |
| 1076 | # else |
| 1077 | # define _LIBCPP_NODEBUG |
| 1078 | # endif |
| 1079 | |
| 1080 | # if __has_attribute(__standalone_debug__) |
| 1081 | # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) |
| 1082 | # else |
| 1083 | # define _LIBCPP_STANDALONE_DEBUG |
| 1084 | # endif |
| 1085 | |
| 1086 | # if __has_attribute(__preferred_name__) |
| 1087 | # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) |
| 1088 | # else |
| 1089 | # define _LIBCPP_PREFERRED_NAME(x) |
| 1090 | # endif |
| 1091 | |
| 1092 | // We often repeat things just for handling wide characters in the library. |
| 1093 | // When wide characters are disabled, it can be useful to have a quick way of |
| 1094 | // disabling it without having to resort to #if-#endif, which has a larger |
| 1095 | // impact on readability. |
| 1096 | # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) |
| 1097 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) |
| 1098 | # else |
| 1099 | # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ |
| 1100 | # endif |
| 1101 | |
| 1102 | # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) |
| 1103 | # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) |
| 1104 | # else |
| 1105 | # define _LIBCPP_DECLSPEC_EMPTY_BASES |
| 1106 | # endif |
| 1107 | |
| 1108 | # if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) |
| 1109 | # define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR |
| 1110 | # define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS |
| 1111 | # define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE |
| 1112 | # define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS |
| 1113 | # define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION |
| 1114 | # endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES |
| 1115 | |
| 1116 | # if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) |
| 1117 | # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS |
| 1118 | # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION |
| 1119 | # define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS |
| 1120 | # define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS |
| 1121 | # define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR |
| 1122 | # define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS |
| 1123 | # endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES |
| 1124 | |
| 1125 | # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") |
| 1126 | # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") |
| 1127 | |
| 1128 | # ifndef _LIBCPP_NO_AUTO_LINK |
| 1129 | # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
| 1130 | # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) |
| 1131 | # pragma comment(lib, "c++.lib") |
| 1132 | # else |
| 1133 | # pragma comment(lib, "libc++.lib") |
| 1134 | # endif |
| 1135 | # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) |
| 1136 | # endif // _LIBCPP_NO_AUTO_LINK |
| 1137 | |
| 1138 | // Configures the fopen close-on-exec mode character, if any. This string will |
| 1139 | // be appended to any mode string used by fstream for fopen/fdopen. |
| 1140 | // |
| 1141 | // Not all platforms support this, but it helps avoid fd-leaks on platforms that |
| 1142 | // do. |
| 1143 | # if defined(__BIONIC__) |
| 1144 | # define _LIBCPP_FOPEN_CLOEXEC_MODE "e" |
| 1145 | # else |
| 1146 | # define _LIBCPP_FOPEN_CLOEXEC_MODE |
| 1147 | # endif |
| 1148 | |
| 1149 | // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set |
| 1150 | // of functions used in cstdio may not be available for low API levels when |
| 1151 | // using 64-bit file offsets on LP32. |
| 1152 | # if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 |
| 1153 | # define _LIBCPP_HAS_NO_FGETPOS_FSETPOS |
| 1154 | # endif |
| 1155 | |
| 1156 | # if __has_attribute(__init_priority__) |
| 1157 | # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) |
| 1158 | # else |
| 1159 | # define _LIBCPP_INIT_PRIORITY_MAX |
| 1160 | # endif |
| 1161 | |
| 1162 | # if __has_attribute(__format__) |
| 1163 | // The attribute uses 1-based indices for ordinary and static member functions. |
| 1164 | // The attribute uses 2-based indices for non-static member functions. |
| 1165 | # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ |
| 1166 | __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) |
| 1167 | # else |
| 1168 | # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ |
| 1169 | # endif |
| 1170 | |
| 1171 | # if __has_cpp_attribute(msvc::no_unique_address) |
| 1172 | // MSVC implements [[no_unique_address]] as a silent no-op currently. |
| 1173 | // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) |
| 1174 | // However, MSVC implements [[msvc::no_unique_address]] which does what |
| 1175 | // [[no_unique_address]] is supposed to do, in general. |
| 1176 | |
| 1177 | // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or |
| 1178 | // [[msvc::no_unique_address]] though. If/when it does implement |
| 1179 | // [[msvc::no_unique_address]], this should be preferred though. |
| 1180 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] |
| 1181 | # elif __has_cpp_attribute(no_unique_address) |
| 1182 | # define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]] |
| 1183 | # else |
| 1184 | # define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ |
| 1185 | // Note that this can be replaced by #error as soon as clang-cl |
| 1186 | // implements msvc::no_unique_address, since there should be no C++20 |
| 1187 | // compiler that doesn't support one of the two attributes at that point. |
| 1188 | // We generally don't want to use this macro outside of C++20-only code, |
| 1189 | // because using it conditionally in one language version only would make |
| 1190 | // the ABI inconsistent. |
| 1191 | # endif |
| 1192 | |
| 1193 | # ifdef _LIBCPP_COMPILER_CLANG_BASED |
| 1194 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") |
| 1195 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") |
| 1196 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) |
| 1197 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
| 1198 | # elif defined(_LIBCPP_COMPILER_GCC) |
| 1199 | # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") |
| 1200 | # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") |
| 1201 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
| 1202 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) |
| 1203 | # else |
| 1204 | # define _LIBCPP_DIAGNOSTIC_PUSH |
| 1205 | # define _LIBCPP_DIAGNOSTIC_POP |
| 1206 | # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) |
| 1207 | # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) |
| 1208 | # endif |
| 1209 | |
| 1210 | # if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) |
| 1211 | # define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") |
| 1212 | # define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") |
| 1213 | # else |
| 1214 | # define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ |
| 1215 | # define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ |
| 1216 | # endif |
| 1217 | |
| 1218 | # if __has_attribute(__packed__) |
| 1219 | # define _LIBCPP_PACKED __attribute__((__packed__)) |
| 1220 | # else |
| 1221 | # define _LIBCPP_PACKED |
| 1222 | # endif |
| 1223 | |
| 1224 | // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these |
| 1225 | // functions is gradually being added to existing C libraries. The conditions |
| 1226 | // below check for known C library versions and conditions under which these |
| 1227 | // functions are declared by the C library. |
| 1228 | # define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 |
| 1229 | // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if |
| 1230 | // __cpp_char8_t is defined or if C2X extensions are enabled. Unfortunately, |
| 1231 | // determining the latter depends on internal GNU libc details. If the |
| 1232 | // __cpp_char8_t feature test macro is not defined, then a char8_t typedef |
| 1233 | // will be declared as well. |
| 1234 | # if defined(_LIBCPP_GLIBC_PREREQ) && defined(__GLIBC_USE) |
| 1235 | # if _LIBCPP_GLIBC_PREREQ(2, 36) && (defined(__cpp_char8_t) || __GLIBC_USE(ISOC2X)) |
| 1236 | # undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1237 | # endif |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1238 | # endif |
| 1239 | |
| 1240 | // There are a handful of public standard library types that are intended to |
| 1241 | // support CTAD but don't need any explicit deduction guides to do so. This |
| 1242 | // macro is used to mark them as such, which suppresses the |
| 1243 | // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code |
| 1244 | // with these classes. |
| 1245 | #if _LIBCPP_STD_VER >= 17 |
| 1246 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ |
| 1247 | template <class ..._Tag> \ |
| 1248 | _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> |
| 1249 | #else |
| 1250 | # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") |
| 1251 | #endif |
Andrew Top | 61a8495 | 2019-04-30 15:07:33 -0700 | [diff] [blame] | 1252 | |
| 1253 | #endif // __cplusplus |
| 1254 | |
Kaido Kert | 788710a | 2023-06-05 07:50:22 -0700 | [diff] [blame] | 1255 | #endif // _LIBCPP___CONFIG |