blob: 55bb6d61487d3f89f1f445278fb967191bb55e2e [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CONFIG
11#define _LIBCPP_CONFIG
12
Louis Dionne94870d82020-06-26 12:08:59 -040013#include <__config_site>
14
Eric Fiseliera80af822015-11-06 06:30:12 +000015#if defined(_MSC_VER) && !defined(__clang__)
Logan Chien7b4845e2018-02-24 07:57:32 +000016# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
18# endif
Saleem Abdulrasoolf154c772017-01-29 18:16:33 +000019#endif
Eric Fiseliera80af822015-11-06 06:30:12 +000020
21#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -050022# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000023#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000024
Eric Fiseliera80af822015-11-06 06:30:12 +000025#ifdef __cplusplus
26
Tom Stellard688b1e22022-02-01 23:29:29 -080027#define _LIBCPP_VERSION 15000
Howard Hinnantc51e1022010-05-11 19:42:16 +000028
Nikolas Klausera66d4db2022-02-04 14:28:19 +010029#ifdef _LIBCPP_ABI_UNSTABLE
30# define _LIBCPP_ABI_VERSION 2
31#endif
32
Eric Fiselierfa1f1c12019-06-26 00:05:14 +000033#ifndef _LIBCPP_ABI_VERSION
34# define _LIBCPP_ABI_VERSION 1
35#endif
36
hyd-devb987b452020-09-02 12:22:29 -040037#if __STDC_HOSTED__ == 0
Davide Italiano011f80a2019-03-05 18:40:49 +000038# define _LIBCPP_FREESTANDING
39#endif
40
Eric Fiselier02cea5e2018-07-27 03:07:09 +000041#ifndef _LIBCPP_STD_VER
42# if __cplusplus <= 201103L
43# define _LIBCPP_STD_VER 11
44# elif __cplusplus <= 201402L
45# define _LIBCPP_STD_VER 14
46# elif __cplusplus <= 201703L
47# define _LIBCPP_STD_VER 17
Marek Kurdej24b4c512021-01-07 12:29:04 +010048# elif __cplusplus <= 202002L
49# define _LIBCPP_STD_VER 20
Eric Fiselier02cea5e2018-07-27 03:07:09 +000050# else
Nikolas Klausera66d4db2022-02-04 14:28:19 +010051# define _LIBCPP_STD_VER 22 // current year, or date of c++2b ratification
Eric Fiselier02cea5e2018-07-27 03:07:09 +000052# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -040053#endif // _LIBCPP_STD_VER
Eric Fiselier02cea5e2018-07-27 03:07:09 +000054
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000055#if defined(__ELF__)
Logan Chien7b4845e2018-02-24 07:57:32 +000056# define _LIBCPP_OBJECT_FORMAT_ELF 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000057#elif defined(__MACH__)
Logan Chien7b4845e2018-02-24 07:57:32 +000058# define _LIBCPP_OBJECT_FORMAT_MACHO 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000059#elif defined(_WIN32)
Logan Chien7b4845e2018-02-24 07:57:32 +000060# define _LIBCPP_OBJECT_FORMAT_COFF 1
Sam Cleggfe39b0b2017-12-16 18:59:50 +000061#elif defined(__wasm__)
Logan Chien7b4845e2018-02-24 07:57:32 +000062# define _LIBCPP_OBJECT_FORMAT_WASM 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000063#else
Louis Dionne64dcd862020-11-17 13:17:40 -050064 // ... add new file formats here ...
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000065#endif
66
Nikolas Klausera66d4db2022-02-04 14:28:19 +010067#if _LIBCPP_ABI_VERSION >= 2
Shoaib Meenai4bdf4372016-09-12 20:14:44 +000068// Change short string representation so that string data starts at offset 0,
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000069// improving its alignment in some cases.
Logan Chien7b4845e2018-02-24 07:57:32 +000070# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000071// Fix deque iterator type in order to support incomplete types.
Logan Chien7b4845e2018-02-24 07:57:32 +000072# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
Nico Weberd31c3ab2017-07-22 15:16:42 +000073// Fix undefined behavior in how std::list stores its linked nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000074# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
Eric Fiselier70f5f872016-07-19 17:56:20 +000075// Fix undefined behavior in how __tree stores its end and parent nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000076# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
Nico Weberd31c3ab2017-07-22 15:16:42 +000077// Fix undefined behavior in how __hash_table stores its pointer types.
Logan Chien7b4845e2018-02-24 07:57:32 +000078# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
79# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
80# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Shoaib Meenaic130eaf2017-03-28 19:33:31 +000081// Define a key function for `bad_function_call` in the library, to centralize
82// its vtable and typeinfo to libc++ rather than having all other libraries
83// using that class define their own copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000084# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
Konstantin Varlamovd96c2d22021-11-15 12:40:55 -080085// Override the default return value of exception::what() for
86// bad_function_call::what() with a string that is specific to
87// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
88// because it changes the vtable layout of bad_function_call.
89# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
Aditya Kumaraa866182017-06-14 23:17:45 +000090// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000091# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040092// In C++20 and later, don't derive std::plus from std::binary_function,
93// nor std::negate from std::unary_function.
94# define _LIBCPP_ABI_NO_BINDER_BASES
Louis Dionne8762e2b2021-05-25 18:15:58 -040095// Give reverse_iterator<T> one data member of type T, not two.
96// Also, in C++17 and later, don't derive iterator types from std::iterator.
97# define _LIBCPP_ABI_NO_ITERATOR_BASES
Eric Fiseliercaccc7b2017-11-19 04:19:44 +000098// Use the smallest possible integer type to represent the index of the variant.
Louis Dionnea8548af2019-03-20 17:05:52 +000099// Previously libc++ used "unsigned int" exclusively.
Logan Chien7b4845e2018-02-24 07:57:32 +0000100# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
Eric Fiselierf2e64362018-12-11 00:14:34 +0000101// Unstable attempt to provide a more optimized std::function
102# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
Marshall Clow88a30872019-03-28 17:30:23 +0000103// All the regex constants must be distinct and nonzero.
104# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
Arthur O'Dwyer0a5557f2021-04-20 22:08:00 -0400105// Use raw pointers, not wrapped ones, for std::span's iterator type.
106# define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
Martijn Velsb17d5802020-03-02 10:11:35 -0500107// Re-worked external template instantiations for std::string with a focus on
108// performance and fast-path inlining.
109# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Vy Nguyene369bd92020-07-13 12:34:37 -0400110// Enable clang::trivial_abi on std::unique_ptr.
111# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
112// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
113# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
Louis Dionne1eb0c9d2021-12-21 11:49:04 -0500114// std::random_device holds some state when it uses an implementation that gets
115// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
116// implementation to another one on a platform that has already shipped
117// std::random_device, one needs to retain the same object layout to remain ABI
118// compatible. This switch removes these workarounds for platforms that don't care
119// about ABI compatibility.
120# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
Nikolas Klauserf89bb932022-01-24 19:44:34 +0100121// Remove basic_string common base
Nikolas Klausera2453e82022-02-02 20:15:40 +0100122# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
Nikolas Klauser129974f2022-02-03 23:09:37 +0100123// Remove vector base class
124# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000125#elif _LIBCPP_ABI_VERSION == 1
Logan Chien7b4845e2018-02-24 07:57:32 +0000126# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier98848572017-01-17 03:16:26 +0000127// Enable compiling copies of now inline methods into the dylib to support
Shoaib Meenai5c2d4012017-04-12 19:56:37 +0000128// applications compiled against older libraries. This is unnecessary with
129// COFF dllexport semantics, since dllexport forces a non-inline definition
130// of inline functions to be emitted anyway. Our own non-inline copy would
131// conflict with the dllexport-emitted copy, so we disable it.
Logan Chien7b4845e2018-02-24 07:57:32 +0000132# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
133# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000134// Feature macros for disabling pre ABI v1 features. All of these options
135// are deprecated.
Logan Chien7b4845e2018-02-24 07:57:32 +0000136# if defined(__FreeBSD__)
137# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
138# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000139#endif
140
Nikolas Klausera66d4db2022-02-04 14:28:19 +0100141#if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
Louis Dionne8a79be62020-10-21 11:11:45 -0400142// Enable additional explicit instantiations of iostreams components. This
143// reduces the number of weak definitions generated in programs that use
144// iostreams by providing a single strong definition in the shared library.
145# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
Konstantin Varlamovd96c2d22021-11-15 12:40:55 -0800146
147// Define a key function for `bad_function_call` in the library, to centralize
148// its vtable and typeinfo to libc++ rather than having all other libraries
149// using that class define their own copies.
150# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
Louis Dionne8a79be62020-10-21 11:11:45 -0400151#endif
152
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
154#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
155
Eric Fiselierb33778a2018-10-30 21:44:53 +0000156#ifndef _LIBCPP_ABI_NAMESPACE
157# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
158#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000160#if __cplusplus < 201103L
161#define _LIBCPP_CXX03_LANG
162#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000163
164#ifndef __has_attribute
165#define __has_attribute(__x) 0
166#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000167
Eric Fiselier86fcc922015-07-10 20:26:38 +0000168#ifndef __has_builtin
169#define __has_builtin(__x) 0
170#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000171
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000172#ifndef __has_extension
173#define __has_extension(__x) 0
174#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000175
Eric Fiselier86fcc922015-07-10 20:26:38 +0000176#ifndef __has_feature
177#define __has_feature(__x) 0
178#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000179
Marshall Clow2a5c4212017-11-14 22:26:50 +0000180#ifndef __has_cpp_attribute
181#define __has_cpp_attribute(__x) 0
182#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000183
Eric Fiselier86fcc922015-07-10 20:26:38 +0000184// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
185// the compiler and '1' otherwise.
186#ifndef __is_identifier
187#define __is_identifier(__x) 1
188#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000189
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000190#ifndef __has_declspec_attribute
191#define __has_declspec_attribute(__x) 0
192#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000193
Eric Fiselierba725072017-01-14 04:27:58 +0000194#define __has_keyword(__x) !(__is_identifier(__x))
195
Alexander Richardsonba1b59e2018-07-24 12:40:56 +0000196#ifndef __has_include
197#define __has_include(...) 0
Eric Fiselierd8a6c892017-05-10 21:34:58 +0000198#endif
199
Marek Kurdejf3197922021-04-01 08:29:55 +0200200#if defined(__apple_build_version__)
201# define _LIBCPP_COMPILER_CLANG_BASED
202# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
203#elif defined(__clang__)
204# define _LIBCPP_COMPILER_CLANG_BASED
205# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000206#elif defined(__GNUC__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000207# define _LIBCPP_COMPILER_GCC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000208#elif defined(_MSC_VER)
Logan Chien7b4845e2018-02-24 07:57:32 +0000209# define _LIBCPP_COMPILER_MSVC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000210#elif defined(__IBMCPP__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000211# define _LIBCPP_COMPILER_IBM
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000212#endif
213
Eric Fiselier75c05562019-06-13 00:37:25 +0000214#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
215#error "libc++ does not support using GCC with C++03. Please enable C++11"
216#endif
217
Eric Fiseliera6d96342017-01-07 02:43:58 +0000218// FIXME: ABI detection should be done via compiler builtin macros. This
219// is just a placeholder until Clang implements such macros. For now assume
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000220// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
221// and allow the user to explicitly specify the ABI to handle cases where this
222// heuristic falls short.
Shoaib Meenai56943f82017-10-05 02:18:08 +0000223#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
Logan Chien7b4845e2018-02-24 07:57:32 +0000224# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
Shoaib Meenai56943f82017-10-05 02:18:08 +0000225#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000226# define _LIBCPP_ABI_ITANIUM
Logan Chien7b4845e2018-02-24 07:57:32 +0000227#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
228# define _LIBCPP_ABI_MICROSOFT
229#else
230# if defined(_WIN32) && defined(_MSC_VER)
231# define _LIBCPP_ABI_MICROSOFT
232# else
233# define _LIBCPP_ABI_ITANIUM
234# endif
Eric Fiseliera6d96342017-01-07 02:43:58 +0000235#endif
236
Eric Fiselier85f66332019-03-05 01:57:01 +0000237#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
238# define _LIBCPP_ABI_VCRUNTIME
239#endif
240
Dan Albert21800dc2016-09-19 18:00:45 +0000241// Need to detect which libc we're using if we're on Linux.
242#if defined(__linux__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000243# include <features.h>
244# if defined(__GLIBC_PREREQ)
245# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
246# else
247# define _LIBCPP_GLIBC_PREREQ(a, b) 0
248# endif // defined(__GLIBC_PREREQ)
Dan Albert21800dc2016-09-19 18:00:45 +0000249#endif // defined(__linux__)
Eric Fiselier86fcc922015-07-10 20:26:38 +0000250
Muiez Ahmed38aa7872022-01-14 11:35:53 -0500251#if defined(__MVS__)
252# include <features.h> // for __NATIVE_ASCII_F
253#endif
254
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255#ifdef __LITTLE_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000256# if __LITTLE_ENDIAN__
257# define _LIBCPP_LITTLE_ENDIAN
258# endif // __LITTLE_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400259#endif // __LITTLE_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
261#ifdef __BIG_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000262# if __BIG_ENDIAN__
263# define _LIBCPP_BIG_ENDIAN
264# endif // __BIG_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400265#endif // __BIG_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266
Dan Albert98d97792015-09-16 18:10:47 +0000267#ifdef __BYTE_ORDER__
Logan Chien7b4845e2018-02-24 07:57:32 +0000268# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
269# define _LIBCPP_LITTLE_ENDIAN
270# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
271# define _LIBCPP_BIG_ENDIAN
272# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Dan Albert98d97792015-09-16 18:10:47 +0000273#endif // __BYTE_ORDER__
274
David Chisnall93008f02010-08-11 16:27:20 +0000275#ifdef __FreeBSD__
Logan Chien7b4845e2018-02-24 07:57:32 +0000276# include <sys/endian.h>
Dimitry Andric5600c9b2019-10-19 10:59:23 +0000277# include <osreldate.h>
David Chisnall93008f02010-08-11 16:27:20 +0000278# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000279# define _LIBCPP_LITTLE_ENDIAN
280# else // _BYTE_ORDER == _LITTLE_ENDIAN
281# define _LIBCPP_BIG_ENDIAN
282# endif // _BYTE_ORDER == _LITTLE_ENDIAN
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400283#endif // __FreeBSD__
David Chisnall93008f02010-08-11 16:27:20 +0000284
Brad Smithf6f55092021-01-12 14:16:15 -0500285#if defined(__NetBSD__) || defined(__OpenBSD__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000286# include <sys/endian.h>
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000287# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000288# define _LIBCPP_LITTLE_ENDIAN
289# else // _BYTE_ORDER == _LITTLE_ENDIAN
290# define _LIBCPP_BIG_ENDIAN
291# endif // _BYTE_ORDER == _LITTLE_ENDIAN
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400292#endif // defined(__NetBSD__) || defined(__OpenBSD__)
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000293
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000294#if defined(_WIN32)
Eric Fiselierbb999f92017-05-31 22:14:05 +0000295# define _LIBCPP_WIN32API
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000296# define _LIBCPP_LITTLE_ENDIAN
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000297# define _LIBCPP_SHORT_WCHAR 1
Louis Dionnea8548af2019-03-20 17:05:52 +0000298// Both MinGW and native MSVC provide a "MSVC"-like environment
Eric Fiselierbb999f92017-05-31 22:14:05 +0000299# define _LIBCPP_MSVCRT_LIKE
Bruno Cardoso Lopes91572682017-07-17 21:52:31 +0000300// If mingw not explicitly detected, assume using MS C runtime only if
301// a MS compatibility version is specified.
302# if defined(_MSC_VER) && !defined(__MINGW32__)
Howard Hinnant8ad70912013-09-17 01:34:47 +0000303# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
304# endif
Saleem Abdulrasool32300ca2017-01-04 01:53:24 +0000305# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
306# define _LIBCPP_HAS_BITSCAN64
307# endif
Peter Collingbourne63ebbd72018-01-23 02:07:27 +0000308# define _LIBCPP_HAS_OPEN_WITH_WCHAR
Logan Chien7b4845e2018-02-24 07:57:32 +0000309# if defined(_LIBCPP_MSVCRT)
310# define _LIBCPP_HAS_QUICK_EXIT
311# endif
Shoaib Meenaie2ce3602017-04-06 04:47:49 +0000312
313// Some CRT APIs are unavailable to store apps
Logan Chien7b4845e2018-02-24 07:57:32 +0000314# if defined(WINAPI_FAMILY)
315# include <winapifamily.h>
316# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \
317 (!defined(WINAPI_PARTITION_SYSTEM) || \
318 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
319# define _LIBCPP_WINDOWS_STORE_APP
320# endif
321# endif
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000322#endif // defined(_WIN32)
Howard Hinnant34bad2a2011-05-13 17:16:06 +0000323
David Chisnall8074c342012-02-29 13:05:08 +0000324#ifdef __sun__
Logan Chien7b4845e2018-02-24 07:57:32 +0000325# include <sys/isa_defs.h>
326# ifdef _LITTLE_ENDIAN
327# define _LIBCPP_LITTLE_ENDIAN
328# else
329# define _LIBCPP_BIG_ENDIAN
330# endif
David Chisnall8074c342012-02-29 13:05:08 +0000331#endif // __sun__
332
Xing Xue50b0eb42021-09-09 16:20:36 -0400333#if defined(_AIX) && !defined(__64BIT__)
334 // The size of wchar is 2 byte on 32-bit mode on AIX.
335# define _LIBCPP_SHORT_WCHAR 1
336#endif
337
Louis Dionne62253962021-12-21 16:50:34 -0500338// Libc++ supports various implementations of std::random_device.
339//
340// _LIBCPP_USING_DEV_RANDOM
341// Read entropy from the given file, by default `/dev/urandom`.
342// If a token is provided, it is assumed to be the path to a file
343// to read entropy from. This is the default behavior if nothing
344// else is specified. This implementation requires storing state
345// inside `std::random_device`.
346//
347// _LIBCPP_USING_ARC4_RANDOM
348// Use arc4random(). This allows obtaining random data even when
349// using sandboxing mechanisms. On some platforms like Apple, this
350// is the recommended source of entropy for user-space programs.
351// When this option is used, the token passed to `std::random_device`'s
352// constructor *must* be "/dev/urandom" -- anything else is an error.
353//
354// _LIBCPP_USING_GETENTROPY
355// Use getentropy().
356// When this option is used, the token passed to `std::random_device`'s
357// constructor *must* be "/dev/urandom" -- anything else is an error.
358//
Roland McGrathdea04482022-01-02 11:53:53 -0800359// _LIBCPP_USING_FUCHSIA_CPRNG
360// Use Fuchsia's zx_cprng_draw() system call, which is specified to
361// deliver high-quality entropy and cannot fail.
362// When this option is used, the token passed to `std::random_device`'s
363// constructor *must* be "/dev/urandom" -- anything else is an error.
364//
Louis Dionne62253962021-12-21 16:50:34 -0500365// _LIBCPP_USING_NACL_RANDOM
366// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
367// including accesses to the special files under `/dev`. This implementation
368// uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
369// When this option is used, the token passed to `std::random_device`'s
370// constructor *must* be "/dev/urandom" -- anything else is an error.
371//
372// _LIBCPP_USING_WIN32_RANDOM
373// Use rand_s(), for use on Windows.
374// When this option is used, the token passed to `std::random_device`'s
375// constructor *must* be "/dev/urandom" -- anything else is an error.
Louis Dionne1eb0c9d2021-12-21 11:49:04 -0500376#if defined(__OpenBSD__) || defined(__APPLE__)
Louis Dionne62253962021-12-21 16:50:34 -0500377# define _LIBCPP_USING_ARC4_RANDOM
Roland McGrathdea04482022-01-02 11:53:53 -0800378#elif defined(__wasi__)
Louis Dionne62253962021-12-21 16:50:34 -0500379# define _LIBCPP_USING_GETENTROPY
Roland McGrathdea04482022-01-02 11:53:53 -0800380#elif defined(__Fuchsia__)
381# define _LIBCPP_USING_FUCHSIA_CPRNG
Louis Dionne62253962021-12-21 16:50:34 -0500382#elif defined(__native_client__)
383# define _LIBCPP_USING_NACL_RANDOM
384#elif defined(_LIBCPP_WIN32API)
385# define _LIBCPP_USING_WIN32_RANDOM
386#else
387# define _LIBCPP_USING_DEV_RANDOM
388#endif
389
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000390#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Logan Chien7b4845e2018-02-24 07:57:32 +0000391# include <endian.h>
392# if __BYTE_ORDER == __LITTLE_ENDIAN
393# define _LIBCPP_LITTLE_ENDIAN
394# elif __BYTE_ORDER == __BIG_ENDIAN
395# define _LIBCPP_BIG_ENDIAN
396# else // __BYTE_ORDER == __BIG_ENDIAN
397# error unable to determine endian
398# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400399#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400
Eric Fiselier02cba002017-06-15 03:50:02 +0000401#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +0000402# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000403#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000404# define _LIBCPP_NO_CFI
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000405#endif
406
Louis Dionne29c6d372021-08-17 11:23:48 -0400407// If the compiler supports using_if_exists, pretend we have those functions and they'll
408// be picked up if the C library provides them.
409//
410// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
411// for platforms that don't have a conforming C11 library, so we can drop this whole thing.
412#if __has_attribute(using_if_exists)
413# define _LIBCPP_HAS_TIMESPEC_GET
414# define _LIBCPP_HAS_QUICK_EXIT
415# define _LIBCPP_HAS_ALIGNED_ALLOC
416#else
Marek Kurdejf3197922021-04-01 08:29:55 +0200417#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
Louis Dionne234dd432018-08-15 00:16:41 +0000418# if defined(__FreeBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800419# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000420# define _LIBCPP_HAS_QUICK_EXIT
Dimitry Andrice022a032020-01-30 08:00:28 +0100421# if __FreeBSD_version >= 1300064 || \
422 (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
423# define _LIBCPP_HAS_TIMESPEC_GET
424# endif
Dan Albert1d3cfad2019-11-18 12:16:45 -0800425# elif defined(__BIONIC__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800426# if __ANDROID_API__ >= 21
427# define _LIBCPP_HAS_QUICK_EXIT
428# endif
429# if __ANDROID_API__ >= 28
430# define _LIBCPP_HAS_ALIGNED_ALLOC
431# endif
432# if __ANDROID_API__ >= 29
433# define _LIBCPP_HAS_TIMESPEC_GET
434# endif
Michał Górnyf0426252019-12-14 14:17:19 +0100435# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800436# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000437# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000438# define _LIBCPP_HAS_TIMESPEC_GET
Brad Smithf6f55092021-01-12 14:16:15 -0500439# elif defined(__OpenBSD__)
440# define _LIBCPP_HAS_ALIGNED_ALLOC
441# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000442# elif defined(__linux__)
443# if !defined(_LIBCPP_HAS_MUSL_LIBC)
444# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
445# define _LIBCPP_HAS_QUICK_EXIT
446# endif
447# if _LIBCPP_GLIBC_PREREQ(2, 17)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800448# define _LIBCPP_HAS_ALIGNED_ALLOC
Marshall Clowa6a55a82018-08-15 21:19:08 +0000449# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000450# endif
451# else // defined(_LIBCPP_HAS_MUSL_LIBC)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800452# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000453# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000454# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000455# endif
Martin Storsjö8a174e72021-05-31 09:32:51 +0000456# elif defined(_LIBCPP_MSVCRT)
457 // Using Microsoft's C Runtime library, not MinGW
458# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne5b747292020-07-27 14:25:03 -0400459# elif defined(__APPLE__)
460 // timespec_get and aligned_alloc were introduced in macOS 10.15 and
461 // aligned releases
Marek Kurdej126213e2021-04-02 10:31:18 +0200462# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
463 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
464 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
465 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
Louis Dionne5b747292020-07-27 14:25:03 -0400466# define _LIBCPP_HAS_ALIGNED_ALLOC
Raphael Isemann46c3ac52020-09-02 09:25:31 +0200467# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne5b747292020-07-27 14:25:03 -0400468# endif
469# endif // __APPLE__
Louis Dionne234dd432018-08-15 00:16:41 +0000470#endif
Louis Dionne29c6d372021-08-17 11:23:48 -0400471#endif // __has_attribute(using_if_exists)
Louis Dionne234dd432018-08-15 00:16:41 +0000472
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000473#ifndef _LIBCPP_CXX03_LANG
474# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
Marek Kurdejf3197922021-04-01 08:29:55 +0200475#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000476# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
477#else
Louis Dionne72707bf2020-09-02 12:29:42 -0400478# error "We don't know a correct way to implement alignof(T) in C++03 outside of Clang"
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000479#endif
480
481#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
482
Marek Kurdejf3197922021-04-01 08:29:55 +0200483#if defined(_LIBCPP_COMPILER_CLANG_BASED)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000484
Louis Dionne3f346932020-06-25 16:31:14 -0400485#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
486# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
487#endif
488#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
489 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
490# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Tim Northoverffc95932014-03-30 11:34:22 +0000491#endif
492
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493#if __has_feature(cxx_alignas)
Howard Hinnant62cad692012-05-31 19:31:14 +0000494# define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000495# define _ALIGNAS(x) alignas(x)
496#else
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000497# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000498# define _ALIGNAS(x) __attribute__((__aligned__(x)))
499#endif
500
Marshall Clow2b12c312014-02-22 15:13:48 +0000501#if __cplusplus < 201103L
Howard Hinnant31cd14f2010-09-16 23:27:26 +0000502typedef __char16_t char16_t;
503typedef __char32_t char32_t;
Howard Hinnant8e6a3982010-09-07 20:31:18 +0000504#endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000505
Louis Dionne94c6eda2020-07-03 13:46:41 -0400506#if !__has_feature(cxx_exceptions)
507# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000508#endif
509
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000510#if !(__has_feature(cxx_strong_enums))
511#define _LIBCPP_HAS_NO_STRONG_ENUMS
512#endif
513
Howard Hinnant8df96292011-05-26 17:07:32 +0000514#if __has_feature(cxx_attributes)
Richard Smithcabd3922012-07-26 02:04:22 +0000515# define _LIBCPP_NORETURN [[noreturn]]
Howard Hinnant8df96292011-05-26 17:07:32 +0000516#else
Richard Smithcabd3922012-07-26 02:04:22 +0000517# define _LIBCPP_NORETURN __attribute__ ((noreturn))
Howard Hinnant74279a52010-09-04 23:28:19 +0000518#endif
519
Louis Dionne9bb7cf42021-09-08 12:57:58 -0400520#ifdef _LIBCPP_CXX03_LANG
521# define nullptr __nullptr
Howard Hinnant74279a52010-09-04 23:28:19 +0000522#endif
523
Douglas Gregor13034442011-06-22 22:17:44 +0000524// Objective-C++ features (opt-in)
525#if __has_feature(objc_arc)
526#define _LIBCPP_HAS_OBJC_ARC
527#endif
528
529#if __has_feature(objc_arc_weak)
530#define _LIBCPP_HAS_OBJC_ARC_WEAK
531#endif
532
Louis Dionne2c358282020-01-21 12:39:43 -0800533#if __has_extension(blocks)
534# define _LIBCPP_HAS_EXTENSION_BLOCKS
535#endif
536
Louis Dionne3a632922020-04-23 16:47:52 -0400537#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
538# define _LIBCPP_HAS_BLOCKS_RUNTIME
539#endif
540
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000541#if !(__has_feature(cxx_noexcept))
542#define _LIBCPP_HAS_NO_NOEXCEPT
Howard Hinnant68d13392011-05-11 20:19:40 +0000543#endif
544
Louis Dionne93f1fd72021-06-04 13:31:22 -0400545#if !__has_feature(address_sanitizer)
Marshall Clow90fc0472014-04-14 15:44:57 +0000546#define _LIBCPP_HAS_NO_ASAN
547#endif
548
Marshall Clow55b23d22016-01-12 00:38:04 +0000549// Allow for build-time disabling of unsigned integer sanitization
Louis Dionne93f1fd72021-06-04 13:31:22 -0400550#if __has_attribute(no_sanitize)
Saleem Abdulrasool38acb642016-02-09 04:05:37 +0000551#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
Logan Chien7b4845e2018-02-24 07:57:32 +0000552#endif
Marshall Clow55b23d22016-01-12 00:38:04 +0000553
Louis Dionne3a197992018-07-27 12:46:03 +0000554#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
555
Louis Dionnefaa17452019-09-04 12:44:19 +0000556#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
557
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000558#elif defined(_LIBCPP_COMPILER_GCC)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000559
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000560#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000561#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000562
Richard Smithcabd3922012-07-26 02:04:22 +0000563#define _LIBCPP_NORETURN __attribute__((noreturn))
Howard Hinnant1e570a32011-05-31 13:13:49 +0000564
Louis Dionneaf6be622021-07-27 17:30:47 -0400565#if !defined(__EXCEPTIONS)
Louis Dionne94c6eda2020-07-03 13:46:41 -0400566# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000567#endif
568
Louis Dionne93f1fd72021-06-04 13:31:22 -0400569#if !defined(__SANITIZE_ADDRESS__)
Marshall Clow90fc0472014-04-14 15:44:57 +0000570#define _LIBCPP_HAS_NO_ASAN
571#endif
572
Louis Dionne3a197992018-07-27 12:46:03 +0000573#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
574
Louis Dionnefaa17452019-09-04 12:44:19 +0000575#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
576
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000577#elif defined(_LIBCPP_COMPILER_MSVC)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000578
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000579#define _LIBCPP_TOSTRING2(x) #x
580#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
581#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
582
583#if _MSC_VER < 1900
584#error "MSVC versions prior to Visual Studio 2015 are not supported"
585#endif
586
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000587#define __alignof__ __alignof
Richard Smithcabd3922012-07-26 02:04:22 +0000588#define _LIBCPP_NORETURN __declspec(noreturn)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000589#define _ALIGNAS(x) __declspec(align(x))
Eric Fiselier6a537582018-02-07 23:50:25 +0000590#define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000591
Logan Chien7b4845e2018-02-24 07:57:32 +0000592#define _LIBCPP_WEAK
593
Marshall Clow90fc0472014-04-14 15:44:57 +0000594#define _LIBCPP_HAS_NO_ASAN
595
Louis Dionne3a197992018-07-27 12:46:03 +0000596#define _LIBCPP_ALWAYS_INLINE __forceinline
597
Tim Shend87ea292018-07-30 22:27:38 +0000598#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
599
Louis Dionnefaa17452019-09-04 12:44:19 +0000600#define _LIBCPP_DISABLE_EXTENSION_WARNING
601
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000602#elif defined(_LIBCPP_COMPILER_IBM)
Howard Hinnantea382952013-08-14 18:00:20 +0000603
604#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000605#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantea382952013-08-14 18:00:20 +0000606#define _ATTRIBUTE(x) __attribute__((x))
607#define _LIBCPP_NORETURN __attribute__((noreturn))
608
Howard Hinnantea382952013-08-14 18:00:20 +0000609#define _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantea382952013-08-14 18:00:20 +0000610
611#if defined(_AIX)
612#define __MULTILOCALE_API
613#endif
614
Marshall Clow90fc0472014-04-14 15:44:57 +0000615#define _LIBCPP_HAS_NO_ASAN
616
Louis Dionne3a197992018-07-27 12:46:03 +0000617#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
618
Tim Shend87ea292018-07-30 22:27:38 +0000619#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
620
Louis Dionnefaa17452019-09-04 12:44:19 +0000621#define _LIBCPP_DISABLE_EXTENSION_WARNING
622
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000623#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000625#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
Logan Chien7b4845e2018-02-24 07:57:32 +0000626
Peter Collingbourne725de942018-01-17 04:37:04 +0000627#ifdef _DLL
Logan Chien7b4845e2018-02-24 07:57:32 +0000628# define _LIBCPP_CRT_FUNC __declspec(dllimport)
Peter Collingbourne725de942018-01-17 04:37:04 +0000629#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000630# define _LIBCPP_CRT_FUNC
Peter Collingbourne725de942018-01-17 04:37:04 +0000631#endif
632
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000633#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +0000634# define _LIBCPP_DLL_VIS
635# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
636# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
637# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000638# define _LIBCPP_EXPORTED_FROM_ABI
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000639#elif defined(_LIBCPP_BUILDING_LIBRARY)
Logan Chien7b4845e2018-02-24 07:57:32 +0000640# define _LIBCPP_DLL_VIS __declspec(dllexport)
Martin Storsjobd254492019-04-25 19:46:28 +0000641# if defined(__MINGW32__)
642# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
643# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
644# else
645# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
646# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
647# endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000648# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000649# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000650#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000651# define _LIBCPP_DLL_VIS __declspec(dllimport)
652# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
653# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
654# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000655# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000656#endif
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000657
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000658#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
659#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
660#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000661#define _LIBCPP_HIDDEN
Shoaib Meenai69c57412017-03-02 03:02:50 +0000662#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000663#define _LIBCPP_TEMPLATE_VIS
Martin Storsjö88890c22021-02-22 01:13:13 +0200664#define _LIBCPP_TEMPLATE_DATA_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000665#define _LIBCPP_ENUM_VIS
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000666
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000667#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000668
669#ifndef _LIBCPP_HIDDEN
Logan Chien7b4845e2018-02-24 07:57:32 +0000670# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
671# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
672# else
673# define _LIBCPP_HIDDEN
674# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000675#endif
676
Shoaib Meenai5331f492017-03-09 00:18:00 +0000677#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000678# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000679// The inline should be removed once PR32114 is resolved
Logan Chien7b4845e2018-02-24 07:57:32 +0000680# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
681# else
682# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
683# endif
Shoaib Meenai5331f492017-03-09 00:18:00 +0000684#endif
Shoaib Meenai69c57412017-03-02 03:02:50 +0000685
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000686#ifndef _LIBCPP_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000687# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
688# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
689# else
690# define _LIBCPP_FUNC_VIS
691# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000692#endif
693
694#ifndef _LIBCPP_TYPE_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000695# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000696# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000697# else
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000698# define _LIBCPP_TYPE_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000699# endif
700#endif
701
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000702#ifndef _LIBCPP_TEMPLATE_VIS
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000703# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
704# if __has_attribute(__type_visibility__)
705# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
706# else
707# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
708# endif
709# else
710# define _LIBCPP_TEMPLATE_VIS
711# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000712#endif
713
Martin Storsjö88890c22021-02-22 01:13:13 +0200714#ifndef _LIBCPP_TEMPLATE_DATA_VIS
715# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
716# define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
717# else
718# define _LIBCPP_TEMPLATE_DATA_VIS
719# endif
720#endif
721
Louis Dionne5254b372018-10-25 12:13:43 +0000722#ifndef _LIBCPP_EXPORTED_FROM_ABI
Thomas Andersone13df2b2018-12-13 20:06:14 +0000723# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
724# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
725# else
726# define _LIBCPP_EXPORTED_FROM_ABI
727# endif
Eric Fiselier99505072017-01-16 21:01:00 +0000728#endif
729
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000730#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000731#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000732#endif
733
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000734#ifndef _LIBCPP_EXCEPTION_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000735# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
736# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
737# else
738# define _LIBCPP_EXCEPTION_ABI
739# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000740#endif
741
742#ifndef _LIBCPP_ENUM_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000743# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000744# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
745# else
746# define _LIBCPP_ENUM_VIS
747# endif
748#endif
749
750#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
Shoaib Meenai491802e2021-01-12 10:29:03 -0800751# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000752# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000753# else
754# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
755# endif
756#endif
757
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000758#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000759#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000760#endif
761
Louis Dionne3a197992018-07-27 12:46:03 +0000762#if __has_attribute(internal_linkage)
763# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
764#else
765# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000766#endif
767
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000768#if __has_attribute(exclude_from_explicit_instantiation)
769# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
770#else
771 // Try to approximate the effect of exclude_from_explicit_instantiation
772 // (which is that entities are not assumed to be provided by explicit
Louis Dionnea8548af2019-03-20 17:05:52 +0000773 // template instantiations in the dylib) by always inlining those entities.
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000774# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
775#endif
776
Louis Dionne1821de42018-08-16 12:44:28 +0000777#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
778# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
779# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
780# else
781# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
782# endif
783#endif
784
Louis Dionne3a197992018-07-27 12:46:03 +0000785#ifndef _LIBCPP_HIDE_FROM_ABI
Louis Dionne1821de42018-08-16 12:44:28 +0000786# if _LIBCPP_HIDE_FROM_ABI_PER_TU
787# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
788# else
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000789# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Louis Dionne1821de42018-08-16 12:44:28 +0000790# endif
Louis Dionne3a197992018-07-27 12:46:03 +0000791#endif
792
Louis Dionned797b8d2018-08-06 14:11:50 +0000793#ifdef _LIBCPP_BUILDING_LIBRARY
794# if _LIBCPP_ABI_VERSION > 1
795# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000796# else
Louis Dionned797b8d2018-08-06 14:11:50 +0000797# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Logan Chien7b4845e2018-02-24 07:57:32 +0000798# endif
Louis Dionned797b8d2018-08-06 14:11:50 +0000799#else
800# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Eric Fiselier815ed732016-09-16 00:00:48 +0000801#endif
802
Louis Dionned797b8d2018-08-06 14:11:50 +0000803// Just so we can migrate to the new macros gradually.
804#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
Louis Dionned797b8d2018-08-06 14:11:50 +0000805
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000806// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000807#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000808#define _LIBCPP_END_NAMESPACE_STD } }
Nikolas Klauser46ed0bb2022-02-01 22:38:27 +0100809#define _VSTD std
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000810_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
811
Nikolas Klauser46ed0bb2022-02-01 22:38:27 +0100812#if _LIBCPP_STD_VER > 14
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000813#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
814 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
815#else
816#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
817 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
818#endif
819
820#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
821 _LIBCPP_END_NAMESPACE_STD } }
822
Nikolas Klausera66d4db2022-02-04 14:28:19 +0100823#define _VSTD_FS std::__fs::filesystem
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000824
Louis Dionne93f1fd72021-06-04 13:31:22 -0400825#if __has_attribute(__enable_if__)
826# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000827#endif
828
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000829#ifndef _LIBCPP_HAS_NO_NOEXCEPT
830# define _NOEXCEPT noexcept
831# define _NOEXCEPT_(x) noexcept(x)
832#else
833# define _NOEXCEPT throw()
834# define _NOEXCEPT_(x)
835#endif
836
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000838typedef unsigned short char16_t;
839typedef unsigned int char32_t;
Louis Dionne96fc5f52021-09-09 11:25:10 -0400840#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841
Stephan Tolksdorf0efeb6c2014-03-26 19:45:52 +0000842#ifndef __SIZEOF_INT128__
843#define _LIBCPP_HAS_NO_INT128
844#endif
845
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000846#ifdef _LIBCPP_CXX03_LANG
Eric Fiselier2f05ab92019-06-18 20:50:25 +0000847# define static_assert(...) _Static_assert(__VA_ARGS__)
848# define decltype(...) __decltype(__VA_ARGS__)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400849#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850
Eric Fiselier605af612019-06-21 13:56:13 +0000851#ifdef _LIBCPP_CXX03_LANG
Logan Chien7b4845e2018-02-24 07:57:32 +0000852# define _LIBCPP_CONSTEXPR
Howard Hinnant664183b2012-04-02 00:40:41 +0000853#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000854# define _LIBCPP_CONSTEXPR constexpr
Howard Hinnant62c8c0b2010-09-06 19:10:31 +0000855#endif
856
Richard Smith55a75c82020-07-31 15:03:21 -0700857#ifndef __cpp_consteval
858# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
859#else
860# define _LIBCPP_CONSTEVAL consteval
861#endif
862
Arthur O'Dwyer654b4db2022-01-31 12:04:08 -0500863#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_concepts) || __cpp_concepts < 201907L
Mark de Wever1d4140e2021-02-20 09:13:16 +0100864#define _LIBCPP_HAS_NO_CONCEPTS
865#endif
866
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000867#ifdef __GNUC__
Louis Dionnee147b352019-02-26 06:34:42 +0000868# define _LIBCPP_NOALIAS __attribute__((__malloc__))
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000869#else
Louis Dionnee147b352019-02-26 06:34:42 +0000870# define _LIBCPP_NOALIAS
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000871#endif
872
Louis Dionne9c660c62021-06-02 10:41:37 -0400873#if __has_attribute(using_if_exists)
874# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
875#else
876# define _LIBCPP_USING_IF_EXISTS
877#endif
878
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000879#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000880# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
881# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
882 __lx __v_; \
Louis Dionne16fe2952018-07-11 23:14:33 +0000883 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
884 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
885 _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
Logan Chien7b4845e2018-02-24 07:57:32 +0000886 };
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000887#else // _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000888# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
889# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400890#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000891
Louis Dionneba400782020-10-02 15:02:52 -0400892// _LIBCPP_DEBUG potential values:
893// - undefined: No assertions. This is the default.
894// - 0: Basic assertions
Danila Kutenina9cbea12021-11-16 15:48:59 -0500895// - 1: Basic assertions + iterator validity checks + unspecified behavior randomization.
896# if !defined(_LIBCPP_DEBUG)
897# define _LIBCPP_DEBUG_LEVEL 0
898# elif _LIBCPP_DEBUG == 0
899# define _LIBCPP_DEBUG_LEVEL 1
900# elif _LIBCPP_DEBUG == 1
901# define _LIBCPP_DEBUG_LEVEL 2
902# else
903# error Supported values for _LIBCPP_DEBUG are 0 and 1
904# endif
905
906# if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
907# define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
908# endif
909
910# if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
911# if defined(_LIBCPP_CXX03_LANG)
912# error Support for unspecified stability is only for C++11 and higher
913# endif
914# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
915 do { \
916 if (!__builtin_is_constant_evaluated()) \
917 _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer()); \
918 } while (false)
919# else
920# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
921 do { \
922 } while (false)
923# endif
Howard Hinnant8ea98242013-08-23 17:37:05 +0000924
Louis Dionne732192e2021-06-09 09:41:27 -0400925// Libc++ allows disabling extern template instantiation declarations by
926// means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
927//
928// Furthermore, when the Debug mode is enabled, we disable extern declarations
929// when building user code because we don't want to use the functions compiled
930// in the library, which might not have had the debug mode enabled when built.
931// However, some extern declarations need to be used, because code correctness
932// depends on it (several instances in <locale>). Those special declarations
933// are declared with _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE, which is enabled
934// even when the debug mode is enabled.
935#if defined(_LIBCPP_DISABLE_EXTERN_TEMPLATE)
936# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
937# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) /* nothing */
938#elif _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_BUILDING_LIBRARY)
939# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
940# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
941#else
942# define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
943# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
Eric Fiselier510690e2019-12-13 15:42:07 -0500944#endif
945
Martin Storsjo5482ac62017-11-23 10:38:18 +0000946#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
Louis Dionne59426ee2021-08-24 11:40:05 -0400947 defined(__sun__) || defined(__NetBSD__)
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000948#define _LIBCPP_LOCALE__L_EXTENSIONS 1
949#endif
Yaron Keren804da952013-12-20 13:19:45 +0000950
Marshall Clow82378c02013-03-18 19:34:07 +0000951#ifdef __FreeBSD__
David Chisnall6ae8f352011-11-13 17:15:33 +0000952#define _DECLARE_C99_LDBL_MATH 1
953#endif
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000954
Reid Kleckner85c65e62018-04-19 22:12:10 +0000955// If we are getting operator new from the MSVC CRT, then allocation overloads
956// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
957#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
Louis Dionne2e206ca2018-12-17 22:22:44 +0000958# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Eric Fiselier85f66332019-03-05 01:57:01 +0000959#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
Louis Dionnea8548af2019-03-20 17:05:52 +0000960 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
Thomas Andersone0439182019-01-30 19:08:32 +0000961 // have it unless the language feature test macro is defined.
962# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Zbigniew Sarbinowski001f5d02020-11-12 14:40:35 -0500963#elif defined(__MVS__)
964# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Reid Kleckner85c65e62018-04-19 22:12:10 +0000965#endif
966
Louis Dionne93f1fd72021-06-04 13:31:22 -0400967#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
968 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
Louis Dionnee5aafbf2018-08-10 13:24:56 +0000969# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
970#endif
Eric Fiselier06548ab2018-03-22 04:42:56 +0000971
Marshall Clow82378c02013-03-18 19:34:07 +0000972#if defined(__APPLE__) || defined(__FreeBSD__)
Howard Hinnantf312e3e2011-09-28 23:39:33 +0000973#define _LIBCPP_HAS_DEFAULTRUNELOCALE
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000974#endif
975
Marshall Clow82378c02013-03-18 19:34:07 +0000976#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
Alexis Huntc2017f12011-07-09 03:40:04 +0000977#define _LIBCPP_WCTYPE_IS_MASK
978#endif
979
Marshall Clow8732fed2018-12-11 04:35:44 +0000980#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400981#define _LIBCPP_HAS_NO_CHAR8_T
Marshall Clow8732fed2018-12-11 04:35:44 +0000982#endif
983
Louis Dionne481a2662018-09-23 18:35:00 +0000984// Deprecation macros.
Louis Dionneded5b772019-03-12 20:10:06 +0000985//
986// Deprecations warnings are always enabled, except when users explicitly opt-out
987// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
988#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Louis Dionne481a2662018-09-23 18:35:00 +0000989# if __has_attribute(deprecated)
990# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
991# elif _LIBCPP_STD_VER > 11
992# define _LIBCPP_DEPRECATED [[deprecated]]
993# else
994# define _LIBCPP_DEPRECATED
995# endif
Marshall Clowa2cbe0d2013-09-28 18:35:31 +0000996#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000997# define _LIBCPP_DEPRECATED
Marshall Clowa2cbe0d2013-09-28 18:35:31 +0000998#endif
999
Louis Dionne481a2662018-09-23 18:35:00 +00001000#if !defined(_LIBCPP_CXX03_LANG)
1001# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
1002#else
1003# define _LIBCPP_DEPRECATED_IN_CXX11
1004#endif
1005
Nikolas Klausera66d4db2022-02-04 14:28:19 +01001006#if _LIBCPP_STD_VER > 11
Louis Dionne481a2662018-09-23 18:35:00 +00001007# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
1008#else
1009# define _LIBCPP_DEPRECATED_IN_CXX14
1010#endif
1011
Nikolas Klausera66d4db2022-02-04 14:28:19 +01001012#if _LIBCPP_STD_VER > 14
Louis Dionne481a2662018-09-23 18:35:00 +00001013# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
1014#else
1015# define _LIBCPP_DEPRECATED_IN_CXX17
1016#endif
1017
Marek Kurdejc9848142020-11-26 10:07:16 +01001018#if _LIBCPP_STD_VER > 17
1019# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1020#else
1021# define _LIBCPP_DEPRECATED_IN_CXX20
1022#endif
1023
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001024#if !defined(_LIBCPP_HAS_NO_CHAR8_T)
Martin Storsjöe3a71972020-10-26 13:18:46 +02001025# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1026#else
1027# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1028#endif
1029
Richard Smithbfc256b2019-10-19 00:06:00 +00001030// Macros to enter and leave a state where deprecation warnings are suppressed.
Louis Dionne93f1fd72021-06-04 13:31:22 -04001031#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1032# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
1033 _Pragma("GCC diagnostic push") \
Louis Dionneaf6be622021-07-27 17:30:47 -04001034 _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
1035 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
Louis Dionne93f1fd72021-06-04 13:31:22 -04001036# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
1037 _Pragma("GCC diagnostic pop")
1038#else
1039# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1040# define _LIBCPP_SUPPRESS_DEPRECATED_POP
Richard Smithbfc256b2019-10-19 00:06:00 +00001041#endif
1042
Marshall Clow1045cee2013-07-15 14:57:19 +00001043#if _LIBCPP_STD_VER <= 11
Logan Chien7b4845e2018-02-24 07:57:32 +00001044# define _LIBCPP_EXPLICIT_AFTER_CXX11
Marshall Clow1045cee2013-07-15 14:57:19 +00001045#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001046# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
Marshall Clow1045cee2013-07-15 14:57:19 +00001047#endif
1048
Louis Dionnee3594f12021-08-24 11:58:36 -04001049#if _LIBCPP_STD_VER > 11
Logan Chien7b4845e2018-02-24 07:57:32 +00001050# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001051#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001052# define _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001053#endif
1054
Louis Dionnee3594f12021-08-24 11:58:36 -04001055#if _LIBCPP_STD_VER > 14
Logan Chien7b4845e2018-02-24 07:57:32 +00001056# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001057#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001058# define _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001059#endif
1060
Louis Dionnee3594f12021-08-24 11:58:36 -04001061#if _LIBCPP_STD_VER > 17
Logan Chien7b4845e2018-02-24 07:57:32 +00001062# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
Marshall Clow2a5c4212017-11-14 22:26:50 +00001063#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001064# define _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001065#endif
1066
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001067#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
Louis Dionne91182922021-08-30 16:01:38 -04001068# define _LIBCPP_NODISCARD [[nodiscard]]
Marek Kurdejf3197922021-04-01 08:29:55 +02001069#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
Louis Dionne91182922021-08-30 16:01:38 -04001070# define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001071#else
1072// We can't use GCC's [[gnu::warn_unused_result]] and
1073// __attribute__((warn_unused_result)), because GCC does not silence them via
1074// (void) cast.
Louis Dionne91182922021-08-30 16:01:38 -04001075# define _LIBCPP_NODISCARD
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001076#endif
1077
1078// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1079// specified as such as an extension.
1080#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
Louis Dionne91182922021-08-30 16:01:38 -04001081# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001082#else
1083# define _LIBCPP_NODISCARD_EXT
1084#endif
1085
1086#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
1087 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
Louis Dionne91182922021-08-30 16:01:38 -04001088# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
Marshall Clow2a5c4212017-11-14 22:26:50 +00001089#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001090# define _LIBCPP_NODISCARD_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001091#endif
1092
Louis Dionnea39f1ef2019-04-17 18:20:19 +00001093#if __has_attribute(no_destroy)
1094# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1095#else
1096# define _LIBCPP_NO_DESTROY
1097#endif
1098
Marshall Clow2cd9d372014-05-08 14:14:06 +00001099#ifndef _LIBCPP_HAS_NO_ASAN
Azat Khuzhincdfb87f2020-12-17 16:19:50 -05001100extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
Marshall Clow2cd9d372014-05-08 14:14:06 +00001101 const void *, const void *, const void *, const void *);
1102#endif
1103
Howard Hinnant13087882013-10-04 21:24:21 +00001104// Try to find out if RTTI is disabled.
Marek Kurdejf3197922021-04-01 08:29:55 +02001105#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
Louis Dionneef0c6622020-07-14 16:28:41 -04001106# define _LIBCPP_NO_RTTI
1107#elif defined(__GNUC__) && !defined(__GXX_RTTI)
1108# define _LIBCPP_NO_RTTI
1109#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1110# define _LIBCPP_NO_RTTI
Howard Hinnant13087882013-10-04 21:24:21 +00001111#endif
1112
Howard Hinnant33f04722013-10-04 23:56:37 +00001113#ifndef _LIBCPP_WEAK
Logan Chien7b4845e2018-02-24 07:57:32 +00001114#define _LIBCPP_WEAK __attribute__((__weak__))
Howard Hinnant33f04722013-10-04 23:56:37 +00001115#endif
1116
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001117// Thread API
Eric Fiselierbfd45532017-01-06 23:15:16 +00001118#if !defined(_LIBCPP_HAS_NO_THREADS) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001119 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
Eric Fiselierd8a6c892017-05-10 21:34:58 +00001120 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001121 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001122# if defined(__FreeBSD__) || \
Dan Gohman280fd6b2019-05-01 16:47:30 +00001123 defined(__wasi__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001124 defined(__NetBSD__) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001125 defined(__OpenBSD__) || \
Xiang Xiao85529232020-11-18 16:16:18 -05001126 defined(__NuttX__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001127 defined(__linux__) || \
Louis Dionne3cfcaeb2018-11-20 21:14:05 +00001128 defined(__GNU__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001129 defined(__APPLE__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001130 defined(__sun__) || \
Zbigniew Sarbinowskica6367d2020-12-05 00:13:23 +00001131 defined(__MVS__) || \
Martin Storsjöc86337b2021-10-01 23:44:17 +03001132 defined(_AIX)
Logan Chien7b4845e2018-02-24 07:57:32 +00001133# define _LIBCPP_HAS_THREAD_API_PTHREAD
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001134# elif defined(__Fuchsia__)
Petr Hoseke6ad6e42020-01-16 12:12:38 -08001135 // TODO(44575): Switch to C11 thread API when possible.
1136# define _LIBCPP_HAS_THREAD_API_PTHREAD
Logan Chien7b4845e2018-02-24 07:57:32 +00001137# elif defined(_LIBCPP_WIN32API)
1138# define _LIBCPP_HAS_THREAD_API_WIN32
1139# else
1140# error "No thread API"
1141# endif // _LIBCPP_HAS_THREAD_API
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001142#endif // _LIBCPP_HAS_NO_THREADS
1143
Dan Albertad293012019-09-18 18:13:32 +00001144#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1145#if defined(__ANDROID__) && __ANDROID_API__ >= 30
1146#define _LIBCPP_HAS_COND_CLOCKWAIT
1147#elif defined(_LIBCPP_GLIBC_PREREQ)
1148#if _LIBCPP_GLIBC_PREREQ(2, 30)
1149#define _LIBCPP_HAS_COND_CLOCKWAIT
1150#endif
1151#endif
1152#endif
1153
Ben Craig5593c4f2016-05-25 17:40:09 +00001154#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
Logan Chien7b4845e2018-02-24 07:57:32 +00001155#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1156 _LIBCPP_HAS_NO_THREADS is not defined.
Ben Craig5593c4f2016-05-25 17:40:09 +00001157#endif
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001158
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001159#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001160#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1161 _LIBCPP_HAS_NO_THREADS is defined.
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001162#endif
1163
Eric Fiselier715b4162014-12-06 20:09:11 +00001164#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001165#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1166 _LIBCPP_HAS_NO_THREADS is defined.
Eric Fiselier715b4162014-12-06 20:09:11 +00001167#endif
1168
Nico Weber6b58e1d2019-07-30 14:32:47 +00001169#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1170#define __STDCPP_THREADS__ 1
1171#endif
1172
Louis Dionne66c58fd2019-07-25 20:29:20 +00001173// The glibc and Bionic implementation of pthreads implements
Eric Fiselier256466e2019-07-07 17:24:03 +00001174// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1175// mutexes have no destroy mechanism.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001176//
1177// This optimization can't be performed on Apple platforms, where
1178// pthread_mutex_destroy can allow the kernel to release resources.
1179// See https://llvm.org/D64298 for details.
1180//
1181// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1182// respective stakeholders.
Eric Fiselier256466e2019-07-07 17:24:03 +00001183#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001184 || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \
Eric Fiselier256466e2019-07-07 17:24:03 +00001185 || defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselierf6dac862019-07-07 01:20:54 +00001186# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1187#endif
1188
Eric Fiselier256466e2019-07-07 17:24:03 +00001189// Destroying a condvar is a nop on Windows.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001190//
1191// This optimization can't be performed on Apple platforms, where
1192// pthread_cond_destroy can allow the kernel to release resources.
1193// See https://llvm.org/D64298 for details.
1194//
Eric Fiselier256466e2019-07-07 17:24:03 +00001195// TODO(EricWF): This is potentially true for some pthread implementations
1196// as well.
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001197#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1198 defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselier256466e2019-07-07 17:24:03 +00001199# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1200#endif
1201
Dimitry Andric2e72c802019-09-07 22:18:20 +00001202// Some systems do not provide gets() in their C library, for security reasons.
Louis Dionne93f1fd72021-06-04 13:31:22 -04001203#if defined(_LIBCPP_MSVCRT) || \
1204 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
1205 defined(__OpenBSD__)
1206# define _LIBCPP_C_HAS_NO_GETS
Dimitry Andric2e72c802019-09-07 22:18:20 +00001207#endif
1208
Arthur O'Dwyer7f736372022-01-14 12:18:44 -05001209#if defined(__BIONIC__) || defined(__NuttX__) || \
1210 defined(__Fuchsia__) || defined(__wasi__) || \
Muiez Ahmed38aa7872022-01-14 11:35:53 -05001211 defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
Dan Albertebdf28b2015-03-11 00:51:06 +00001212#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1213#endif
1214
Eric Fiselierba725072017-01-14 04:27:58 +00001215#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
Logan Chien7b4845e2018-02-24 07:57:32 +00001216# define _LIBCPP_HAS_C_ATOMIC_IMP
Richard Smithca47d0f2019-04-25 20:02:10 +00001217#elif defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +00001218# define _LIBCPP_HAS_GCC_ATOMIC_IMP
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001219#endif
1220
Louis Dionneaf2d2a82021-11-17 10:59:31 -05001221#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1222 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1223 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
Davide Italiano011f80a2019-03-05 18:40:49 +00001224# define _LIBCPP_HAS_NO_ATOMIC_HEADER
1225#else
1226# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1227# define _LIBCPP_ATOMIC_FLAG_TYPE bool
1228# endif
1229# ifdef _LIBCPP_FREESTANDING
1230# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1231# endif
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001232#endif
1233
Marshall Clow91c7f642016-01-11 19:27:10 +00001234#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1235#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Eric Fiselier100e24b2016-02-11 11:59:44 +00001236#endif
1237
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001238#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001239# if defined(__clang__) && __has_attribute(acquire_capability)
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001240// Work around the attribute handling in clang. When both __declspec and
1241// __attribute__ are present, the processing goes awry preventing the definition
Martin Storsjö4e9e4712022-01-11 09:23:39 +00001242// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
1243// combining the two does work.
1244# if !defined(_MSC_VER)
Logan Chien7b4845e2018-02-24 07:57:32 +00001245# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1246# endif
1247# endif
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001248#endif
Eric Fiselierc0c6c982016-03-16 02:30:06 +00001249
Louis Dionne93f1fd72021-06-04 13:31:22 -04001250#ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1251# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1252#else
1253# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1254#endif
Eric Fiselier510690e2019-12-13 15:42:07 -05001255
Eric Fiselier0d3da632016-09-03 00:11:33 +00001256#if __has_attribute(require_constant_initialization)
Logan Chien7b4845e2018-02-24 07:57:32 +00001257# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
Eric Fiselier0d3da632016-09-03 00:11:33 +00001258#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001259# define _LIBCPP_SAFE_STATIC
Eric Fiselier0d3da632016-09-03 00:11:33 +00001260#endif
1261
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001262#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001263# define _LIBCPP_DIAGNOSE_WARNING(...) \
1264 __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1265# define _LIBCPP_DIAGNOSE_ERROR(...) \
1266 __attribute__((diagnose_if(__VA_ARGS__, "error")))
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001267#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001268# define _LIBCPP_DIAGNOSE_WARNING(...)
1269# define _LIBCPP_DIAGNOSE_ERROR(...)
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001270#endif
1271
Eric Fiselier4db80032017-05-05 20:32:26 +00001272// Use a function like macro to imply that it must be followed by a semicolon
Nikolas Klausera66d4db2022-02-04 14:28:19 +01001273#if _LIBCPP_STD_VER > 14 && __has_cpp_attribute(fallthrough)
Reid Kleckner75d4e002018-11-01 18:24:03 +00001274# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1275#elif __has_cpp_attribute(clang::fallthrough)
1276# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
Louis Dionne3e0c4332021-08-31 10:49:06 -04001277#elif __has_attribute(__fallthrough__)
Logan Chien7b4845e2018-02-24 07:57:32 +00001278# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
Eric Fiselier4db80032017-05-05 20:32:26 +00001279#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001280# define _LIBCPP_FALLTHROUGH() ((void)0)
Eric Fiselier4db80032017-05-05 20:32:26 +00001281#endif
1282
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001283#if __has_attribute(__nodebug__)
1284#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
Eric Fiselier74ebee62019-06-08 01:31:19 +00001285#else
1286#define _LIBCPP_NODEBUG
1287#endif
1288
Amy Huang63f53b52021-03-15 14:20:49 -07001289#if __has_attribute(__standalone_debug__)
1290#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1291#else
1292#define _LIBCPP_STANDALONE_DEBUG
1293#endif
1294
Richard Smith256954d2020-11-11 17:12:18 -08001295#if __has_attribute(__preferred_name__)
1296#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1297#else
1298#define _LIBCPP_PREFERRED_NAME(x)
1299#endif
1300
Louis Dionne89258142021-08-23 15:32:36 -04001301// We often repeat things just for handling wide characters in the library.
1302// When wide characters are disabled, it can be useful to have a quick way of
1303// disabling it without having to resort to #if-#endif, which has a larger
1304// impact on readability.
1305#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1306# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1307#else
1308# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1309#endif
1310
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001311#if defined(_LIBCPP_ABI_MICROSOFT) && \
Logan Chien7b4845e2018-02-24 07:57:32 +00001312 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1313# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001314#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001315# define _LIBCPP_DECLSPEC_EMPTY_BASES
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001316#endif
1317
Eric Fiselierddd77792017-02-17 03:25:08 +00001318#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
Logan Chien7b4845e2018-02-24 07:57:32 +00001319#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
Logan Chien7b4845e2018-02-24 07:57:32 +00001320#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001321#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1322#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
Eric Fiselierddd77792017-02-17 03:25:08 +00001323#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1324
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001325#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1326#define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001327#define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001328#define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1329#define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
wmbatf5b33762021-07-02 17:08:36 +00001330#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001331#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1332
Chuanqi Xu6fdf6192021-11-16 14:05:34 +08001333#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1334#define _LIBCPP_HAS_NO_CXX20_COROUTINES
Eric Fiselier40b66222017-05-26 01:52:59 +00001335#endif
1336
Eric Fiselierf4433a32017-05-31 22:07:49 +00001337#if defined(_LIBCPP_COMPILER_IBM)
1338#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
1339#endif
1340
1341#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
Logan Chien7b4845e2018-02-24 07:57:32 +00001342# define _LIBCPP_PUSH_MACROS
1343# define _LIBCPP_POP_MACROS
Eric Fiselierf4433a32017-05-31 22:07:49 +00001344#else
1345 // Don't warn about macro conflicts when we can restore them at the
1346 // end of the header.
Logan Chien7b4845e2018-02-24 07:57:32 +00001347# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1348# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1349# endif
1350# if defined(_LIBCPP_COMPILER_MSVC)
1351# define _LIBCPP_PUSH_MACROS \
1352 __pragma(push_macro("min")) \
1353 __pragma(push_macro("max"))
1354# define _LIBCPP_POP_MACROS \
1355 __pragma(pop_macro("min")) \
1356 __pragma(pop_macro("max"))
1357# else
1358# define _LIBCPP_PUSH_MACROS \
1359 _Pragma("push_macro(\"min\")") \
1360 _Pragma("push_macro(\"max\")")
1361# define _LIBCPP_POP_MACROS \
1362 _Pragma("pop_macro(\"min\")") \
1363 _Pragma("pop_macro(\"max\")")
1364# endif
Eric Fiselierf4433a32017-05-31 22:07:49 +00001365#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
1366
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001367#ifndef _LIBCPP_NO_AUTO_LINK
Logan Chien7b4845e2018-02-24 07:57:32 +00001368# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Martin Storsjö57db41b2021-04-15 11:16:28 +03001369# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001370# pragma comment(lib, "c++.lib")
1371# else
1372# pragma comment(lib, "libc++.lib")
1373# endif
1374# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001375#endif // _LIBCPP_NO_AUTO_LINK
Eric Fiselier911dcad2017-06-16 01:57:41 +00001376
Dan Albert9550df62019-09-16 19:26:41 +00001377// Configures the fopen close-on-exec mode character, if any. This string will
1378// be appended to any mode string used by fstream for fopen/fdopen.
1379//
1380// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1381// do.
1382#if defined(__BIONIC__)
1383# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1384#else
1385# define _LIBCPP_FOPEN_CLOEXEC_MODE
1386#endif
1387
Dan Albert073008c2020-03-12 11:16:30 -07001388// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1389// of functions used in cstdio may not be available for low API levels when
1390// using 64-bit file offsets on LP32.
1391#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1392#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1393#endif
1394
Zbigniew Sarbinowski4536ef42020-11-20 14:46:21 -05001395#if __has_attribute(init_priority)
Louis Dionne1f14cea2021-02-03 16:25:06 -05001396 // TODO: Remove this once we drop support for building libc++ with old Clangs
1397# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1398 (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1399# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1400# else
1401# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1402# endif
Zbigniew Sarbinowski4536ef42020-11-20 14:46:21 -05001403#else
1404# define _LIBCPP_INIT_PRIORITY_MAX
1405#endif
1406
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001407#if defined(__GNUC__) || defined(__clang__)
Louis Dionnee1ad4572021-11-16 15:22:10 -05001408 // The attribute uses 1-based indices for ordinary and static member functions.
1409 // The attribute uses 2-based indices for non-static member functions.
1410# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1411 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001412#else
Louis Dionnee1ad4572021-11-16 15:22:10 -05001413# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001414#endif
1415
Eric Fiselier911dcad2017-06-16 01:57:41 +00001416#endif // __cplusplus
1417
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001418#endif // _LIBCPP_CONFIG