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