Debian Codegraph @

libcxx/include/__cxx03/__config

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