blob: 30a4f4a9527d7678311deb80f1e297dfda5e955f [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- __config ---------------------------------===//
3//
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
Howard Hinnantc51e1022010-05-11 19:42:16 +000022#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
Howard Hinnantcafe7172012-10-03 20:48:05 +000027#ifdef __GNUC__
Logan Chien7b4845e2018-02-24 07:57:32 +000028# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
Eric Fiselierc9a0e822017-04-12 23:08:46 +000029// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
30// introduced in GCC 5.0.
Logan Chien7b4845e2018-02-24 07:57:32 +000031# define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__)
Eric Fiselier7d223172015-06-13 02:18:44 +000032#else
Logan Chien7b4845e2018-02-24 07:57:32 +000033# define _GNUC_VER 0
34# define _GNUC_VER_NEW 0
Howard Hinnantcafe7172012-10-03 20:48:05 +000035#endif
36
Tom Stellard33b3b1b2021-01-26 19:37:08 -080037#define _LIBCPP_VERSION 13000
Howard Hinnantc51e1022010-05-11 19:42:16 +000038
Eric Fiselierfa1f1c12019-06-26 00:05:14 +000039#ifndef _LIBCPP_ABI_VERSION
40# define _LIBCPP_ABI_VERSION 1
41#endif
42
hyd-devb987b452020-09-02 12:22:29 -040043#if __STDC_HOSTED__ == 0
Davide Italiano011f80a2019-03-05 18:40:49 +000044# define _LIBCPP_FREESTANDING
45#endif
46
Eric Fiselier02cea5e2018-07-27 03:07:09 +000047#ifndef _LIBCPP_STD_VER
48# if __cplusplus <= 201103L
49# define _LIBCPP_STD_VER 11
50# elif __cplusplus <= 201402L
51# define _LIBCPP_STD_VER 14
52# elif __cplusplus <= 201703L
53# define _LIBCPP_STD_VER 17
Marek Kurdej24b4c512021-01-07 12:29:04 +010054# elif __cplusplus <= 202002L
55# define _LIBCPP_STD_VER 20
Eric Fiselier02cea5e2018-07-27 03:07:09 +000056# else
Marek Kurdej24b4c512021-01-07 12:29:04 +010057# define _LIBCPP_STD_VER 21 // current year, or date of c++2b ratification
Eric Fiselier02cea5e2018-07-27 03:07:09 +000058# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -040059#endif // _LIBCPP_STD_VER
Eric Fiselier02cea5e2018-07-27 03:07:09 +000060
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000061#if defined(__ELF__)
Logan Chien7b4845e2018-02-24 07:57:32 +000062# define _LIBCPP_OBJECT_FORMAT_ELF 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000063#elif defined(__MACH__)
Logan Chien7b4845e2018-02-24 07:57:32 +000064# define _LIBCPP_OBJECT_FORMAT_MACHO 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000065#elif defined(_WIN32)
Logan Chien7b4845e2018-02-24 07:57:32 +000066# define _LIBCPP_OBJECT_FORMAT_COFF 1
Sam Cleggfe39b0b2017-12-16 18:59:50 +000067#elif defined(__wasm__)
Logan Chien7b4845e2018-02-24 07:57:32 +000068# define _LIBCPP_OBJECT_FORMAT_WASM 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000069#else
Louis Dionne64dcd862020-11-17 13:17:40 -050070 // ... add new file formats here ...
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000071#endif
72
Eric Fiselierfa1f1c12019-06-26 00:05:14 +000073#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
Shoaib Meenai4bdf4372016-09-12 20:14:44 +000074// Change short string representation so that string data starts at offset 0,
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000075// improving its alignment in some cases.
Logan Chien7b4845e2018-02-24 07:57:32 +000076# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000077// Fix deque iterator type in order to support incomplete types.
Logan Chien7b4845e2018-02-24 07:57:32 +000078# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
Nico Weberd31c3ab2017-07-22 15:16:42 +000079// Fix undefined behavior in how std::list stores its linked nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000080# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
Eric Fiselier70f5f872016-07-19 17:56:20 +000081// Fix undefined behavior in how __tree stores its end and parent nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000082# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
Nico Weberd31c3ab2017-07-22 15:16:42 +000083// Fix undefined behavior in how __hash_table stores its pointer types.
Logan Chien7b4845e2018-02-24 07:57:32 +000084# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
85# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
86# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Eric Fiselierf38846d2016-12-28 11:09:18 +000087// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr
Eric Fiselier83e3ee02016-12-28 09:50:23 +000088// provided under the alternate keyword __nullptr, which changes the mangling
89// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode.
Logan Chien7b4845e2018-02-24 07:57:32 +000090# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
Shoaib Meenaic130eaf2017-03-28 19:33:31 +000091// Define a key function for `bad_function_call` in the library, to centralize
92// its vtable and typeinfo to libc++ rather than having all other libraries
93// using that class define their own copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000094# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
Aditya Kumaraa866182017-06-14 23:17:45 +000095// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000096# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
Eric Fiseliercaccc7b2017-11-19 04:19:44 +000097// Use the smallest possible integer type to represent the index of the variant.
Louis Dionnea8548af2019-03-20 17:05:52 +000098// Previously libc++ used "unsigned int" exclusively.
Logan Chien7b4845e2018-02-24 07:57:32 +000099# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
Eric Fiselierf2e64362018-12-11 00:14:34 +0000100// Unstable attempt to provide a more optimized std::function
101# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
Marshall Clow88a30872019-03-28 17:30:23 +0000102// All the regex constants must be distinct and nonzero.
103# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
Arthur O'Dwyer0a5557f2021-04-20 22:08:00 -0400104// Use raw pointers, not wrapped ones, for std::span's iterator type.
105# define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
Martijn Velsb17d5802020-03-02 10:11:35 -0500106// Re-worked external template instantiations for std::string with a focus on
107// performance and fast-path inlining.
108# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Vy Nguyene369bd92020-07-13 12:34:37 -0400109// Enable clang::trivial_abi on std::unique_ptr.
110# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
111// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
112# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000113#elif _LIBCPP_ABI_VERSION == 1
Logan Chien7b4845e2018-02-24 07:57:32 +0000114# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier98848572017-01-17 03:16:26 +0000115// Enable compiling copies of now inline methods into the dylib to support
Shoaib Meenai5c2d4012017-04-12 19:56:37 +0000116// applications compiled against older libraries. This is unnecessary with
117// COFF dllexport semantics, since dllexport forces a non-inline definition
118// of inline functions to be emitted anyway. Our own non-inline copy would
119// conflict with the dllexport-emitted copy, so we disable it.
Logan Chien7b4845e2018-02-24 07:57:32 +0000120# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
121# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000122// Feature macros for disabling pre ABI v1 features. All of these options
123// are deprecated.
Logan Chien7b4845e2018-02-24 07:57:32 +0000124# if defined(__FreeBSD__)
125# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
126# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000127#endif
128
Louis Dionne8a79be62020-10-21 11:11:45 -0400129#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
130// Enable additional explicit instantiations of iostreams components. This
131// reduces the number of weak definitions generated in programs that use
132// iostreams by providing a single strong definition in the shared library.
133# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
134#endif
135
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
137#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
138
Eric Fiselierb33778a2018-10-30 21:44:53 +0000139#ifndef _LIBCPP_ABI_NAMESPACE
140# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
141#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000143#if __cplusplus < 201103L
144#define _LIBCPP_CXX03_LANG
145#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000146
147#ifndef __has_attribute
148#define __has_attribute(__x) 0
149#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000150
Eric Fiselier86fcc922015-07-10 20:26:38 +0000151#ifndef __has_builtin
152#define __has_builtin(__x) 0
153#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000154
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000155#ifndef __has_extension
156#define __has_extension(__x) 0
157#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000158
Eric Fiselier86fcc922015-07-10 20:26:38 +0000159#ifndef __has_feature
160#define __has_feature(__x) 0
161#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000162
Marshall Clow2a5c4212017-11-14 22:26:50 +0000163#ifndef __has_cpp_attribute
164#define __has_cpp_attribute(__x) 0
165#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000166
Eric Fiselier86fcc922015-07-10 20:26:38 +0000167// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
168// the compiler and '1' otherwise.
169#ifndef __is_identifier
170#define __is_identifier(__x) 1
171#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000172
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000173#ifndef __has_declspec_attribute
174#define __has_declspec_attribute(__x) 0
175#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000176
Eric Fiselierba725072017-01-14 04:27:58 +0000177#define __has_keyword(__x) !(__is_identifier(__x))
178
Alexander Richardsonba1b59e2018-07-24 12:40:56 +0000179#ifndef __has_include
180#define __has_include(...) 0
Eric Fiselierd8a6c892017-05-10 21:34:58 +0000181#endif
182
Marek Kurdejf3197922021-04-01 08:29:55 +0200183#if defined(__apple_build_version__)
184# define _LIBCPP_COMPILER_CLANG_BASED
185# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
186#elif defined(__clang__)
187# define _LIBCPP_COMPILER_CLANG_BASED
188# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000189#elif defined(__GNUC__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000190# define _LIBCPP_COMPILER_GCC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000191#elif defined(_MSC_VER)
Logan Chien7b4845e2018-02-24 07:57:32 +0000192# define _LIBCPP_COMPILER_MSVC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000193#elif defined(__IBMCPP__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000194# define _LIBCPP_COMPILER_IBM
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000195#endif
196
Eric Fiselier75c05562019-06-13 00:37:25 +0000197#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
198#error "libc++ does not support using GCC with C++03. Please enable C++11"
199#endif
200
Eric Fiseliera6d96342017-01-07 02:43:58 +0000201// FIXME: ABI detection should be done via compiler builtin macros. This
202// is just a placeholder until Clang implements such macros. For now assume
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000203// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
204// and allow the user to explicitly specify the ABI to handle cases where this
205// heuristic falls short.
Shoaib Meenai56943f82017-10-05 02:18:08 +0000206#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
Logan Chien7b4845e2018-02-24 07:57:32 +0000207# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
Shoaib Meenai56943f82017-10-05 02:18:08 +0000208#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000209# define _LIBCPP_ABI_ITANIUM
Logan Chien7b4845e2018-02-24 07:57:32 +0000210#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
211# define _LIBCPP_ABI_MICROSOFT
212#else
213# if defined(_WIN32) && defined(_MSC_VER)
214# define _LIBCPP_ABI_MICROSOFT
215# else
216# define _LIBCPP_ABI_ITANIUM
217# endif
Eric Fiseliera6d96342017-01-07 02:43:58 +0000218#endif
219
Eric Fiselier85f66332019-03-05 01:57:01 +0000220#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
221# define _LIBCPP_ABI_VCRUNTIME
222#endif
223
Dan Albert21800dc2016-09-19 18:00:45 +0000224// Need to detect which libc we're using if we're on Linux.
225#if defined(__linux__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000226# include <features.h>
227# if defined(__GLIBC_PREREQ)
228# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
229# else
230# define _LIBCPP_GLIBC_PREREQ(a, b) 0
231# endif // defined(__GLIBC_PREREQ)
Dan Albert21800dc2016-09-19 18:00:45 +0000232#endif // defined(__linux__)
Eric Fiselier86fcc922015-07-10 20:26:38 +0000233
Howard Hinnantc51e1022010-05-11 19:42:16 +0000234#ifdef __LITTLE_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000235# if __LITTLE_ENDIAN__
236# define _LIBCPP_LITTLE_ENDIAN
237# endif // __LITTLE_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400238#endif // __LITTLE_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239
240#ifdef __BIG_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000241# if __BIG_ENDIAN__
242# define _LIBCPP_BIG_ENDIAN
243# endif // __BIG_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400244#endif // __BIG_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
Dan Albert98d97792015-09-16 18:10:47 +0000246#ifdef __BYTE_ORDER__
Logan Chien7b4845e2018-02-24 07:57:32 +0000247# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
248# define _LIBCPP_LITTLE_ENDIAN
249# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
250# define _LIBCPP_BIG_ENDIAN
251# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Dan Albert98d97792015-09-16 18:10:47 +0000252#endif // __BYTE_ORDER__
253
David Chisnall93008f02010-08-11 16:27:20 +0000254#ifdef __FreeBSD__
Logan Chien7b4845e2018-02-24 07:57:32 +0000255# include <sys/endian.h>
Dimitry Andric5600c9b2019-10-19 10:59:23 +0000256# include <osreldate.h>
David Chisnall93008f02010-08-11 16:27:20 +0000257# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000258# define _LIBCPP_LITTLE_ENDIAN
259# else // _BYTE_ORDER == _LITTLE_ENDIAN
260# define _LIBCPP_BIG_ENDIAN
261# endif // _BYTE_ORDER == _LITTLE_ENDIAN
262# ifndef __LONG_LONG_SUPPORTED
263# define _LIBCPP_HAS_NO_LONG_LONG
264# endif // __LONG_LONG_SUPPORTED
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400265#endif // __FreeBSD__
David Chisnall93008f02010-08-11 16:27:20 +0000266
Brad Smithf6f55092021-01-12 14:16:15 -0500267#if defined(__NetBSD__) || defined(__OpenBSD__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000268# include <sys/endian.h>
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000269# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000270# define _LIBCPP_LITTLE_ENDIAN
271# else // _BYTE_ORDER == _LITTLE_ENDIAN
272# define _LIBCPP_BIG_ENDIAN
273# endif // _BYTE_ORDER == _LITTLE_ENDIAN
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400274#endif // defined(__NetBSD__) || defined(__OpenBSD__)
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000275
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000276#if defined(_WIN32)
Eric Fiselierbb999f92017-05-31 22:14:05 +0000277# define _LIBCPP_WIN32API
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000278# define _LIBCPP_LITTLE_ENDIAN
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000279# define _LIBCPP_SHORT_WCHAR 1
Louis Dionnea8548af2019-03-20 17:05:52 +0000280// Both MinGW and native MSVC provide a "MSVC"-like environment
Eric Fiselierbb999f92017-05-31 22:14:05 +0000281# define _LIBCPP_MSVCRT_LIKE
Bruno Cardoso Lopes91572682017-07-17 21:52:31 +0000282// If mingw not explicitly detected, assume using MS C runtime only if
283// a MS compatibility version is specified.
284# if defined(_MSC_VER) && !defined(__MINGW32__)
Howard Hinnant8ad70912013-09-17 01:34:47 +0000285# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
286# endif
Saleem Abdulrasool32300ca2017-01-04 01:53:24 +0000287# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
288# define _LIBCPP_HAS_BITSCAN64
289# endif
Peter Collingbourne63ebbd72018-01-23 02:07:27 +0000290# define _LIBCPP_HAS_OPEN_WITH_WCHAR
Logan Chien7b4845e2018-02-24 07:57:32 +0000291# if defined(_LIBCPP_MSVCRT)
292# define _LIBCPP_HAS_QUICK_EXIT
293# endif
Shoaib Meenaie2ce3602017-04-06 04:47:49 +0000294
295// Some CRT APIs are unavailable to store apps
Logan Chien7b4845e2018-02-24 07:57:32 +0000296# if defined(WINAPI_FAMILY)
297# include <winapifamily.h>
298# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \
299 (!defined(WINAPI_PARTITION_SYSTEM) || \
300 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
301# define _LIBCPP_WINDOWS_STORE_APP
302# endif
303# endif
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000304#endif // defined(_WIN32)
Howard Hinnant34bad2a2011-05-13 17:16:06 +0000305
David Chisnall8074c342012-02-29 13:05:08 +0000306#ifdef __sun__
Logan Chien7b4845e2018-02-24 07:57:32 +0000307# include <sys/isa_defs.h>
308# ifdef _LITTLE_ENDIAN
309# define _LIBCPP_LITTLE_ENDIAN
310# else
311# define _LIBCPP_BIG_ENDIAN
312# endif
David Chisnall8074c342012-02-29 13:05:08 +0000313#endif // __sun__
314
Brad Smithf6f55092021-01-12 14:16:15 -0500315#if defined(__OpenBSD__) || defined(__CloudABI__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000316 // Certain architectures provide arc4random(). Prefer using
317 // arc4random() over /dev/{u,}random to make it possible to obtain
318 // random data even when using sandboxing mechanisms such as chroots,
319 // Capsicum, etc.
320# define _LIBCPP_USING_ARC4_RANDOM
Dan Gohman280fd6b2019-05-01 16:47:30 +0000321#elif defined(__Fuchsia__) || defined(__wasi__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000322# define _LIBCPP_USING_GETENTROPY
Ed Schoutendcf37402015-03-10 07:46:06 +0000323#elif defined(__native_client__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000324 // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
325 // including accesses to the special files under /dev. C++11's
326 // std::random_device is instead exposed through a NaCl syscall.
327# define _LIBCPP_USING_NACL_RANDOM
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000328#elif defined(_LIBCPP_WIN32API)
Logan Chien7b4845e2018-02-24 07:57:32 +0000329# define _LIBCPP_USING_WIN32_RANDOM
Ed Schoutendcf37402015-03-10 07:46:06 +0000330#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000331# define _LIBCPP_USING_DEV_RANDOM
Ed Schoutendcf37402015-03-10 07:46:06 +0000332#endif
JF Bastiend4832032014-12-01 19:19:55 +0000333
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000334#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Logan Chien7b4845e2018-02-24 07:57:32 +0000335# include <endian.h>
336# if __BYTE_ORDER == __LITTLE_ENDIAN
337# define _LIBCPP_LITTLE_ENDIAN
338# elif __BYTE_ORDER == __BIG_ENDIAN
339# define _LIBCPP_BIG_ENDIAN
340# else // __BYTE_ORDER == __BIG_ENDIAN
341# error unable to determine endian
342# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400343#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
Eric Fiselier02cba002017-06-15 03:50:02 +0000345#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +0000346# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000347#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000348# define _LIBCPP_NO_CFI
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000349#endif
350
Marek Kurdejf3197922021-04-01 08:29:55 +0200351#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
Louis Dionne234dd432018-08-15 00:16:41 +0000352# if defined(__FreeBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800353# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000354# define _LIBCPP_HAS_QUICK_EXIT
Dimitry Andrice022a032020-01-30 08:00:28 +0100355# if __FreeBSD_version >= 1300064 || \
356 (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
357# define _LIBCPP_HAS_TIMESPEC_GET
358# endif
Dan Albert1d3cfad2019-11-18 12:16:45 -0800359# elif defined(__BIONIC__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800360# if __ANDROID_API__ >= 21
361# define _LIBCPP_HAS_QUICK_EXIT
362# endif
363# if __ANDROID_API__ >= 28
364# define _LIBCPP_HAS_ALIGNED_ALLOC
365# endif
366# if __ANDROID_API__ >= 29
367# define _LIBCPP_HAS_TIMESPEC_GET
368# endif
Michał Górnyf0426252019-12-14 14:17:19 +0100369# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800370# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000371# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000372# define _LIBCPP_HAS_TIMESPEC_GET
Brad Smithf6f55092021-01-12 14:16:15 -0500373# elif defined(__OpenBSD__)
374# define _LIBCPP_HAS_ALIGNED_ALLOC
375# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000376# elif defined(__linux__)
377# if !defined(_LIBCPP_HAS_MUSL_LIBC)
378# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
379# define _LIBCPP_HAS_QUICK_EXIT
380# endif
381# if _LIBCPP_GLIBC_PREREQ(2, 17)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800382# define _LIBCPP_HAS_ALIGNED_ALLOC
Marshall Clowa6a55a82018-08-15 21:19:08 +0000383# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000384# endif
385# else // defined(_LIBCPP_HAS_MUSL_LIBC)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800386# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000387# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000388# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000389# endif
Louis Dionne5b747292020-07-27 14:25:03 -0400390# elif defined(__APPLE__)
391 // timespec_get and aligned_alloc were introduced in macOS 10.15 and
392 // aligned releases
Marek Kurdej126213e2021-04-02 10:31:18 +0200393# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
394 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
395 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
396 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
Louis Dionne5b747292020-07-27 14:25:03 -0400397# define _LIBCPP_HAS_ALIGNED_ALLOC
Raphael Isemann46c3ac52020-09-02 09:25:31 +0200398# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne5b747292020-07-27 14:25:03 -0400399# endif
400# endif // __APPLE__
Louis Dionne234dd432018-08-15 00:16:41 +0000401#endif
402
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000403#ifndef _LIBCPP_CXX03_LANG
404# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
Marek Kurdejf3197922021-04-01 08:29:55 +0200405#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000406# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
407#else
Louis Dionne72707bf2020-09-02 12:29:42 -0400408# 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 +0000409#endif
410
411#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
412
Marek Kurdejf3197922021-04-01 08:29:55 +0200413#if defined(_LIBCPP_COMPILER_CLANG_BASED)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000414
Louis Dionne3f346932020-06-25 16:31:14 -0400415#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
416# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
417#endif
418#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
419 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
420# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Tim Northoverffc95932014-03-30 11:34:22 +0000421#endif
422
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000423#if __has_feature(cxx_alignas)
Howard Hinnant62cad692012-05-31 19:31:14 +0000424# define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000425# define _ALIGNAS(x) alignas(x)
426#else
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000427# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000428# define _ALIGNAS(x) __attribute__((__aligned__(x)))
429#endif
430
Marshall Clow2b12c312014-02-22 15:13:48 +0000431#if __cplusplus < 201103L
Howard Hinnant31cd14f2010-09-16 23:27:26 +0000432typedef __char16_t char16_t;
433typedef __char32_t char32_t;
Howard Hinnant8e6a3982010-09-07 20:31:18 +0000434#endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000435
Louis Dionne94c6eda2020-07-03 13:46:41 -0400436#if !__has_feature(cxx_exceptions)
437# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000438#endif
439
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000440#if !(__has_feature(cxx_strong_enums))
441#define _LIBCPP_HAS_NO_STRONG_ENUMS
442#endif
443
Howard Hinnant8df96292011-05-26 17:07:32 +0000444#if __has_feature(cxx_attributes)
Richard Smithcabd3922012-07-26 02:04:22 +0000445# define _LIBCPP_NORETURN [[noreturn]]
Howard Hinnant8df96292011-05-26 17:07:32 +0000446#else
Richard Smithcabd3922012-07-26 02:04:22 +0000447# define _LIBCPP_NORETURN __attribute__ ((noreturn))
Howard Hinnant74279a52010-09-04 23:28:19 +0000448#endif
449
Howard Hinnant74279a52010-09-04 23:28:19 +0000450#if !(__has_feature(cxx_nullptr))
Logan Chien7b4845e2018-02-24 07:57:32 +0000451# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
452# define nullptr __nullptr
453# else
454# define _LIBCPP_HAS_NO_NULLPTR
455# endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000456#endif
457
Douglas Gregor13034442011-06-22 22:17:44 +0000458// Objective-C++ features (opt-in)
459#if __has_feature(objc_arc)
460#define _LIBCPP_HAS_OBJC_ARC
461#endif
462
463#if __has_feature(objc_arc_weak)
464#define _LIBCPP_HAS_OBJC_ARC_WEAK
465#endif
466
Louis Dionne2c358282020-01-21 12:39:43 -0800467#if __has_extension(blocks)
468# define _LIBCPP_HAS_EXTENSION_BLOCKS
469#endif
470
Louis Dionne3a632922020-04-23 16:47:52 -0400471#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
472# define _LIBCPP_HAS_BLOCKS_RUNTIME
473#endif
474
Eric Fiselierb4c0c662014-07-17 05:16:18 +0000475#if !(__has_feature(cxx_relaxed_constexpr))
476#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
477#endif
478
Marshall Clowfaae6982015-03-17 15:30:22 +0000479#if !(__has_feature(cxx_variable_templates))
480#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
481#endif
482
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000483#if !(__has_feature(cxx_noexcept))
484#define _LIBCPP_HAS_NO_NOEXCEPT
Howard Hinnant68d13392011-05-11 20:19:40 +0000485#endif
486
Marshall Clow90fc0472014-04-14 15:44:57 +0000487#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer)
488#define _LIBCPP_HAS_NO_ASAN
489#endif
490
Marshall Clow55b23d22016-01-12 00:38:04 +0000491// Allow for build-time disabling of unsigned integer sanitization
Jonathan Roelofs25463502016-01-13 23:27:08 +0000492#if !defined(_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize)
Saleem Abdulrasool38acb642016-02-09 04:05:37 +0000493#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
Logan Chien7b4845e2018-02-24 07:57:32 +0000494#endif
Marshall Clow55b23d22016-01-12 00:38:04 +0000495
Marshall Clowdf5a11f2017-11-22 19:49:03 +0000496#if __has_builtin(__builtin_launder)
Marshall Clow77342692018-01-03 02:32:28 +0000497#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
498#endif
499
Martijn Vels080e26a2020-01-30 14:12:44 -0500500#if __has_builtin(__builtin_constant_p)
501#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
502#endif
503
Marshall Clow77342692018-01-03 02:32:28 +0000504#if !__is_identifier(__has_unique_object_representations)
505#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
Marshall Clowdf5a11f2017-11-22 19:49:03 +0000506#endif
507
Louis Dionne3a197992018-07-27 12:46:03 +0000508#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
509
Louis Dionne0b9caa42019-08-14 17:04:31 +0000510// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1
Marek Kurdejf3197922021-04-01 08:29:55 +0200511#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \
512 (defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001)
Louis Dionne0b9caa42019-08-14 17:04:31 +0000513#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
Marshall Clow26058352018-10-16 17:27:54 +0000514#endif
515
Louis Dionnefaa17452019-09-04 12:44:19 +0000516#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
517
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000518#elif defined(_LIBCPP_COMPILER_GCC)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000519
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000520#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000521#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000522
Richard Smithcabd3922012-07-26 02:04:22 +0000523#define _LIBCPP_NORETURN __attribute__((noreturn))
Howard Hinnant1e570a32011-05-31 13:13:49 +0000524
Louis Dionne94c6eda2020-07-03 13:46:41 -0400525#if !__EXCEPTIONS
526# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000527#endif
528
Marshall Clowe2be6332015-10-20 07:37:11 +0000529// Determine if GCC supports relaxed constexpr
530#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L
Eric Fiselierb4c0c662014-07-17 05:16:18 +0000531#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
Marshall Clowe2be6332015-10-20 07:37:11 +0000532#endif
533
Richard Smithca47d0f2019-04-25 20:02:10 +0000534// GCC 5 supports variable templates
Eric Fiselier88f07122015-12-15 00:32:21 +0000535#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L
Marshall Clowfaae6982015-03-17 15:30:22 +0000536#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
Eric Fiselier88f07122015-12-15 00:32:21 +0000537#endif
Eric Fiselierb4c0c662014-07-17 05:16:18 +0000538
Marshall Clow90fc0472014-04-14 15:44:57 +0000539#if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__)
540#define _LIBCPP_HAS_NO_ASAN
541#endif
542
Marshall Clowdf5a11f2017-11-22 19:49:03 +0000543#if _GNUC_VER >= 700
Marshall Clow77342692018-01-03 02:32:28 +0000544#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
Martijn Vels080e26a2020-01-30 14:12:44 -0500545#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
Marshall Clow77342692018-01-03 02:32:28 +0000546#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
Marshall Clowdf5a11f2017-11-22 19:49:03 +0000547#endif
548
Louis Dionne3a197992018-07-27 12:46:03 +0000549#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
550
Louis Dionnefaa17452019-09-04 12:44:19 +0000551#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
552
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000553#elif defined(_LIBCPP_COMPILER_MSVC)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000554
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000555#define _LIBCPP_TOSTRING2(x) #x
556#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
557#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
558
559#if _MSC_VER < 1900
560#error "MSVC versions prior to Visual Studio 2015 are not supported"
561#endif
562
Eric Fiselierb4c0c662014-07-17 05:16:18 +0000563#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
Marshall Clowfaae6982015-03-17 15:30:22 +0000564#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000565#define __alignof__ __alignof
Richard Smithcabd3922012-07-26 02:04:22 +0000566#define _LIBCPP_NORETURN __declspec(noreturn)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000567#define _ALIGNAS(x) __declspec(align(x))
Eric Fiselier6a537582018-02-07 23:50:25 +0000568#define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000569
Logan Chien7b4845e2018-02-24 07:57:32 +0000570#define _LIBCPP_WEAK
571
Marshall Clow90fc0472014-04-14 15:44:57 +0000572#define _LIBCPP_HAS_NO_ASAN
573
Louis Dionne3a197992018-07-27 12:46:03 +0000574#define _LIBCPP_ALWAYS_INLINE __forceinline
575
Tim Shend87ea292018-07-30 22:27:38 +0000576#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
577
Louis Dionnefaa17452019-09-04 12:44:19 +0000578#define _LIBCPP_DISABLE_EXTENSION_WARNING
579
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000580#elif defined(_LIBCPP_COMPILER_IBM)
Howard Hinnantea382952013-08-14 18:00:20 +0000581
582#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000583#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantea382952013-08-14 18:00:20 +0000584#define _ATTRIBUTE(x) __attribute__((x))
585#define _LIBCPP_NORETURN __attribute__((noreturn))
586
Howard Hinnantea382952013-08-14 18:00:20 +0000587#define _LIBCPP_HAS_NO_UNICODE_CHARS
Marshall Clowfaae6982015-03-17 15:30:22 +0000588#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
Howard Hinnantea382952013-08-14 18:00:20 +0000589
590#if defined(_AIX)
591#define __MULTILOCALE_API
592#endif
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 __attribute__ ((__always_inline__))
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#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000604#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
Logan Chien7b4845e2018-02-24 07:57:32 +0000605
Peter Collingbourne725de942018-01-17 04:37:04 +0000606#ifdef _DLL
Logan Chien7b4845e2018-02-24 07:57:32 +0000607# define _LIBCPP_CRT_FUNC __declspec(dllimport)
Peter Collingbourne725de942018-01-17 04:37:04 +0000608#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000609# define _LIBCPP_CRT_FUNC
Peter Collingbourne725de942018-01-17 04:37:04 +0000610#endif
611
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000612#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +0000613# define _LIBCPP_DLL_VIS
614# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
615# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
616# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000617# define _LIBCPP_EXPORTED_FROM_ABI
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000618#elif defined(_LIBCPP_BUILDING_LIBRARY)
Logan Chien7b4845e2018-02-24 07:57:32 +0000619# define _LIBCPP_DLL_VIS __declspec(dllexport)
Martin Storsjobd254492019-04-25 19:46:28 +0000620# if defined(__MINGW32__)
621# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
622# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
623# else
624# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
625# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
626# endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000627# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000628# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000629#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000630# define _LIBCPP_DLL_VIS __declspec(dllimport)
631# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
632# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
633# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000634# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000635#endif
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000636
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000637#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
638#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
639#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000640#define _LIBCPP_HIDDEN
Shoaib Meenai69c57412017-03-02 03:02:50 +0000641#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000642#define _LIBCPP_TEMPLATE_VIS
Martin Storsjö88890c22021-02-22 01:13:13 +0200643#define _LIBCPP_TEMPLATE_DATA_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000644#define _LIBCPP_ENUM_VIS
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000645
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000646#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000647
648#ifndef _LIBCPP_HIDDEN
Logan Chien7b4845e2018-02-24 07:57:32 +0000649# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
650# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
651# else
652# define _LIBCPP_HIDDEN
653# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000654#endif
655
Shoaib Meenai5331f492017-03-09 00:18:00 +0000656#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000657# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000658// The inline should be removed once PR32114 is resolved
Logan Chien7b4845e2018-02-24 07:57:32 +0000659# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
660# else
661# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
662# endif
Shoaib Meenai5331f492017-03-09 00:18:00 +0000663#endif
Shoaib Meenai69c57412017-03-02 03:02:50 +0000664
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000665#ifndef _LIBCPP_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000666# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
667# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
668# else
669# define _LIBCPP_FUNC_VIS
670# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000671#endif
672
673#ifndef _LIBCPP_TYPE_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000674# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000675# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000676# else
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000677# define _LIBCPP_TYPE_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000678# endif
679#endif
680
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000681#ifndef _LIBCPP_TEMPLATE_VIS
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000682# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
683# if __has_attribute(__type_visibility__)
684# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
685# else
686# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
687# endif
688# else
689# define _LIBCPP_TEMPLATE_VIS
690# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000691#endif
692
Martin Storsjö88890c22021-02-22 01:13:13 +0200693#ifndef _LIBCPP_TEMPLATE_DATA_VIS
694# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
695# define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
696# else
697# define _LIBCPP_TEMPLATE_DATA_VIS
698# endif
699#endif
700
Louis Dionne5254b372018-10-25 12:13:43 +0000701#ifndef _LIBCPP_EXPORTED_FROM_ABI
Thomas Andersone13df2b2018-12-13 20:06:14 +0000702# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
703# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
704# else
705# define _LIBCPP_EXPORTED_FROM_ABI
706# endif
Eric Fiselier99505072017-01-16 21:01:00 +0000707#endif
708
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000709#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000710#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000711#endif
712
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000713#ifndef _LIBCPP_EXCEPTION_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000714# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
715# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
716# else
717# define _LIBCPP_EXCEPTION_ABI
718# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000719#endif
720
721#ifndef _LIBCPP_ENUM_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000722# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000723# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
724# else
725# define _LIBCPP_ENUM_VIS
726# endif
727#endif
728
729#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
Shoaib Meenai491802e2021-01-12 10:29:03 -0800730# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000731# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000732# else
733# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
734# endif
735#endif
736
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000737#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000738#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000739#endif
740
Louis Dionne3a197992018-07-27 12:46:03 +0000741#if __has_attribute(internal_linkage)
742# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
743#else
744# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000745#endif
746
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000747#if __has_attribute(exclude_from_explicit_instantiation)
748# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
749#else
750 // Try to approximate the effect of exclude_from_explicit_instantiation
751 // (which is that entities are not assumed to be provided by explicit
Louis Dionnea8548af2019-03-20 17:05:52 +0000752 // template instantiations in the dylib) by always inlining those entities.
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000753# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
754#endif
755
Louis Dionne1821de42018-08-16 12:44:28 +0000756#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
757# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
758# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
759# else
760# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
761# endif
762#endif
763
Louis Dionne3a197992018-07-27 12:46:03 +0000764#ifndef _LIBCPP_HIDE_FROM_ABI
Louis Dionne1821de42018-08-16 12:44:28 +0000765# if _LIBCPP_HIDE_FROM_ABI_PER_TU
766# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
767# else
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000768# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Louis Dionne1821de42018-08-16 12:44:28 +0000769# endif
Louis Dionne3a197992018-07-27 12:46:03 +0000770#endif
771
Louis Dionned797b8d2018-08-06 14:11:50 +0000772#ifdef _LIBCPP_BUILDING_LIBRARY
773# if _LIBCPP_ABI_VERSION > 1
774# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000775# else
Louis Dionned797b8d2018-08-06 14:11:50 +0000776# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Logan Chien7b4845e2018-02-24 07:57:32 +0000777# endif
Louis Dionned797b8d2018-08-06 14:11:50 +0000778#else
779# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Eric Fiselier815ed732016-09-16 00:00:48 +0000780#endif
781
Louis Dionned797b8d2018-08-06 14:11:50 +0000782// Just so we can migrate to the new macros gradually.
783#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
Louis Dionned797b8d2018-08-06 14:11:50 +0000784
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000785// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000786#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000787#define _LIBCPP_END_NAMESPACE_STD } }
Eric Fiselierb33778a2018-10-30 21:44:53 +0000788#define _VSTD std::_LIBCPP_ABI_NAMESPACE
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000789_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
790
791#if _LIBCPP_STD_VER >= 17
792#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
793 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
794#else
795#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
796 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
797#endif
798
799#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
800 _LIBCPP_END_NAMESPACE_STD } }
801
802#define _VSTD_FS _VSTD::__fs::filesystem
803
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000804#ifndef _LIBCPP_PREFERRED_OVERLOAD
805# if __has_attribute(__enable_if__)
806# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
807# endif
808#endif
809
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000810#ifndef _LIBCPP_HAS_NO_NOEXCEPT
811# define _NOEXCEPT noexcept
812# define _NOEXCEPT_(x) noexcept(x)
813#else
814# define _NOEXCEPT throw()
815# define _NOEXCEPT_(x)
816#endif
817
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000819typedef unsigned short char16_t;
820typedef unsigned int char32_t;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400821#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822
Stephan Tolksdorf0efeb6c2014-03-26 19:45:52 +0000823#ifndef __SIZEOF_INT128__
824#define _LIBCPP_HAS_NO_INT128
825#endif
826
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000827#ifdef _LIBCPP_CXX03_LANG
Eric Fiselier2f05ab92019-06-18 20:50:25 +0000828# define static_assert(...) _Static_assert(__VA_ARGS__)
829# define decltype(...) __decltype(__VA_ARGS__)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400830#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831
Eric Fiselier605af612019-06-21 13:56:13 +0000832#ifdef _LIBCPP_CXX03_LANG
Logan Chien7b4845e2018-02-24 07:57:32 +0000833# define _LIBCPP_CONSTEXPR
Howard Hinnant664183b2012-04-02 00:40:41 +0000834#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000835# define _LIBCPP_CONSTEXPR constexpr
Howard Hinnant62c8c0b2010-09-06 19:10:31 +0000836#endif
837
Richard Smith55a75c82020-07-31 15:03:21 -0700838#ifndef __cpp_consteval
839# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
840#else
841# define _LIBCPP_CONSTEVAL consteval
842#endif
843
Mark de Wever1d4140e2021-02-20 09:13:16 +0100844#if !defined(__cpp_concepts) || __cpp_concepts < 201907L
845#define _LIBCPP_HAS_NO_CONCEPTS
846#endif
847
Martin Storsjö4f646c02021-04-30 13:57:37 +0300848#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_HAS_NO_CONCEPTS)
Christopher Di Bella490fe402021-03-23 03:55:52 +0000849#define _LIBCPP_HAS_NO_RANGES
850#endif
851
Eric Fiselier07b2b552016-11-18 06:42:17 +0000852#ifdef _LIBCPP_CXX03_LANG
Logan Chien7b4845e2018-02-24 07:57:32 +0000853# define _LIBCPP_DEFAULT {}
Howard Hinnant3d284222013-05-02 20:18:43 +0000854#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000855# define _LIBCPP_DEFAULT = default;
Howard Hinnant3d284222013-05-02 20:18:43 +0000856#endif
857
Eric Fiselier2d8515f2017-01-06 20:58:25 +0000858#ifdef _LIBCPP_CXX03_LANG
Logan Chien7b4845e2018-02-24 07:57:32 +0000859# define _LIBCPP_EQUAL_DELETE
Eric Fiselierd06276b2016-03-31 02:15:15 +0000860#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000861# define _LIBCPP_EQUAL_DELETE = delete
Eric Fiselierd06276b2016-03-31 02:15:15 +0000862#endif
863
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000864#ifdef __GNUC__
Louis Dionnee147b352019-02-26 06:34:42 +0000865# define _LIBCPP_NOALIAS __attribute__((__malloc__))
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000866#else
Louis Dionnee147b352019-02-26 06:34:42 +0000867# define _LIBCPP_NOALIAS
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000868#endif
869
Eric Fiselier70d0df32017-01-13 18:03:46 +0000870#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \
Eric Fiselier6a5f6f92016-12-30 14:05:52 +0000871 (!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions
Logan Chien7b4845e2018-02-24 07:57:32 +0000872# define _LIBCPP_EXPLICIT explicit
Howard Hinnant86a291f2012-02-21 21:46:43 +0000873#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000874# define _LIBCPP_EXPLICIT
Howard Hinnant86a291f2012-02-21 21:46:43 +0000875#endif
876
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000877#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000878# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
879# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
880 __lx __v_; \
Louis Dionne16fe2952018-07-11 23:14:33 +0000881 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
882 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
883 _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
Logan Chien7b4845e2018-02-24 07:57:32 +0000884 };
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000885#else // _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000886# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
887# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400888#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000889
Louis Dionneba400782020-10-02 15:02:52 -0400890// _LIBCPP_DEBUG potential values:
891// - undefined: No assertions. This is the default.
892// - 0: Basic assertions
893// - 1: Basic assertions + iterator validity checks.
894#if !defined(_LIBCPP_DEBUG)
895# define _LIBCPP_DEBUG_LEVEL 0
896#elif _LIBCPP_DEBUG == 0
897# define _LIBCPP_DEBUG_LEVEL 1
898#elif _LIBCPP_DEBUG == 1
899# define _LIBCPP_DEBUG_LEVEL 2
900#else
901# error Supported values for _LIBCPP_DEBUG are 0 and 1
Howard Hinnant8ea98242013-08-23 17:37:05 +0000902#endif
903
Louis Dionneba400782020-10-02 15:02:52 -0400904// _LIBCPP_DEBUG_LEVEL is always defined to one of [0, 1, 2] at this point
Louis Dionne9de5a672021-01-14 16:27:53 -0500905#if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_DISABLE_EXTERN_TEMPLATE)
906# define _LIBCPP_EXTERN_TEMPLATE(...)
Eric Fiselier510690e2019-12-13 15:42:07 -0500907#endif
908
Shoaib Meenai2ba461c2017-04-13 20:13:32 +0000909#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE
Louis Dionne9de5a672021-01-14 16:27:53 -0500910# define _LIBCPP_EXTERN_TEMPLATE(...)
911# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...)
Shoaib Meenai2ba461c2017-04-13 20:13:32 +0000912#endif
913
Howard Hinnant862ca992012-11-06 21:08:48 +0000914#ifndef _LIBCPP_EXTERN_TEMPLATE
Justin Bogner67105aa2014-08-15 17:58:56 +0000915#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
Howard Hinnant862ca992012-11-06 21:08:48 +0000916#endif
917
Louis Dionne9de5a672021-01-14 16:27:53 -0500918// When the Debug mode is enabled, we disable extern declarations because we
919// don't want to use the functions compiled in the library, which might not
920// have had the debug mode enabled when built. However, some extern declarations
921// need to be used, because code correctness depends on it (several instances
922// in the <locale>). Those special declarations are declared with
923// _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE, which is enabled even
924// when the debug mode is enabled.
925#ifndef _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE
926# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
927#endif
928
Eric Fiselier5dcce5c2020-01-15 17:12:09 -0500929#ifndef _LIBCPP_EXTERN_TEMPLATE_DEFINE
930#define _LIBCPP_EXTERN_TEMPLATE_DEFINE(...) template __VA_ARGS__;
931#endif
932
Martin Storsjo5482ac62017-11-23 10:38:18 +0000933#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
Ed Schouten13eb7dc2015-03-10 09:26:38 +0000934 defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000935#define _LIBCPP_LOCALE__L_EXTENSIONS 1
936#endif
Yaron Keren804da952013-12-20 13:19:45 +0000937
Marshall Clow82378c02013-03-18 19:34:07 +0000938#ifdef __FreeBSD__
David Chisnall6ae8f352011-11-13 17:15:33 +0000939#define _DECLARE_C99_LDBL_MATH 1
940#endif
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000941
Reid Kleckner85c65e62018-04-19 22:12:10 +0000942// If we are getting operator new from the MSVC CRT, then allocation overloads
943// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
944#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
Louis Dionne2e206ca2018-12-17 22:22:44 +0000945# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Eric Fiselier85f66332019-03-05 01:57:01 +0000946#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
Louis Dionnea8548af2019-03-20 17:05:52 +0000947 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
Thomas Andersone0439182019-01-30 19:08:32 +0000948 // have it unless the language feature test macro is defined.
949# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Zbigniew Sarbinowski001f5d02020-11-12 14:40:35 -0500950#elif defined(__MVS__)
951# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Reid Kleckner85c65e62018-04-19 22:12:10 +0000952#endif
953
Eric Fiselier44832fb2017-01-20 01:47:26 +0000954#if defined(__APPLE__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000955# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
956 defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
957# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
958# endif
Eric Fiselier44832fb2017-01-20 01:47:26 +0000959#endif // defined(__APPLE__)
960
Louis Dionnee5aafbf2018-08-10 13:24:56 +0000961#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
Eric Fiselierff4c8a22018-10-11 00:17:24 +0000962 (defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
963 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606))
Louis Dionnee5aafbf2018-08-10 13:24:56 +0000964# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
965#endif
Eric Fiselier06548ab2018-03-22 04:42:56 +0000966
Marshall Clow82378c02013-03-18 19:34:07 +0000967#if defined(__APPLE__) || defined(__FreeBSD__)
Howard Hinnantf312e3e2011-09-28 23:39:33 +0000968#define _LIBCPP_HAS_DEFAULTRUNELOCALE
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000969#endif
970
Marshall Clow82378c02013-03-18 19:34:07 +0000971#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
Alexis Huntc2017f12011-07-09 03:40:04 +0000972#define _LIBCPP_WCTYPE_IS_MASK
973#endif
974
Marshall Clow8732fed2018-12-11 04:35:44 +0000975#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400976#define _LIBCPP_HAS_NO_CHAR8_T
Marshall Clow8732fed2018-12-11 04:35:44 +0000977#endif
978
Louis Dionne481a2662018-09-23 18:35:00 +0000979// Deprecation macros.
Louis Dionneded5b772019-03-12 20:10:06 +0000980//
981// Deprecations warnings are always enabled, except when users explicitly opt-out
982// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
983#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Louis Dionne481a2662018-09-23 18:35:00 +0000984# if __has_attribute(deprecated)
985# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
986# elif _LIBCPP_STD_VER > 11
987# define _LIBCPP_DEPRECATED [[deprecated]]
988# else
989# define _LIBCPP_DEPRECATED
990# endif
Marshall Clowa2cbe0d2013-09-28 18:35:31 +0000991#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000992# define _LIBCPP_DEPRECATED
Marshall Clowa2cbe0d2013-09-28 18:35:31 +0000993#endif
994
Louis Dionne481a2662018-09-23 18:35:00 +0000995#if !defined(_LIBCPP_CXX03_LANG)
996# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
997#else
998# define _LIBCPP_DEPRECATED_IN_CXX11
999#endif
1000
1001#if _LIBCPP_STD_VER >= 14
1002# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
1003#else
1004# define _LIBCPP_DEPRECATED_IN_CXX14
1005#endif
1006
1007#if _LIBCPP_STD_VER >= 17
1008# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
1009#else
1010# define _LIBCPP_DEPRECATED_IN_CXX17
1011#endif
1012
Marek Kurdejc9848142020-11-26 10:07:16 +01001013#if _LIBCPP_STD_VER > 17
1014# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1015#else
1016# define _LIBCPP_DEPRECATED_IN_CXX20
1017#endif
1018
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001019#if !defined(_LIBCPP_HAS_NO_CHAR8_T)
Martin Storsjöe3a71972020-10-26 13:18:46 +02001020# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1021#else
1022# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1023#endif
1024
Richard Smithbfc256b2019-10-19 00:06:00 +00001025// Macros to enter and leave a state where deprecation warnings are suppressed.
Marek Kurdejf3197922021-04-01 08:29:55 +02001026#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \
1027 (defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC))
Richard Smithbfc256b2019-10-19 00:06:00 +00001028# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
1029 _Pragma("GCC diagnostic push") \
1030 _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
1031# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
1032 _Pragma("GCC diagnostic pop")
1033#endif
1034#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH)
1035# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1036# define _LIBCPP_SUPPRESS_DEPRECATED_POP
1037#endif
1038
Marshall Clow1045cee2013-07-15 14:57:19 +00001039#if _LIBCPP_STD_VER <= 11
Logan Chien7b4845e2018-02-24 07:57:32 +00001040# define _LIBCPP_EXPLICIT_AFTER_CXX11
Marshall Clow1045cee2013-07-15 14:57:19 +00001041#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001042# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
Marshall Clow1045cee2013-07-15 14:57:19 +00001043#endif
1044
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001045#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
Logan Chien7b4845e2018-02-24 07:57:32 +00001046# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001047#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001048# define _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001049#endif
1050
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001051#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
Logan Chien7b4845e2018-02-24 07:57:32 +00001052# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001053#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001054# define _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001055#endif
1056
Marshall Clow2a5c4212017-11-14 22:26:50 +00001057#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
Logan Chien7b4845e2018-02-24 07:57:32 +00001058# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
Marshall Clow2a5c4212017-11-14 22:26:50 +00001059#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001060# define _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001061#endif
1062
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001063// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
1064// NODISCARD macros to the correct attribute.
1065#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
1066# define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]]
Marek Kurdejf3197922021-04-01 08:29:55 +02001067#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001068# define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]]
1069#else
1070// We can't use GCC's [[gnu::warn_unused_result]] and
1071// __attribute__((warn_unused_result)), because GCC does not silence them via
1072// (void) cast.
1073# define _LIBCPP_NODISCARD_ATTRIBUTE
1074#endif
1075
1076// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1077// specified as such as an extension.
1078#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1079# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD_ATTRIBUTE
1080#else
1081# define _LIBCPP_NODISCARD_EXT
1082#endif
1083
1084#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
1085 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
1086# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD_ATTRIBUTE
Marshall Clow2a5c4212017-11-14 22:26:50 +00001087#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001088# define _LIBCPP_NODISCARD_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001089#endif
1090
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001091#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
Logan Chien7b4845e2018-02-24 07:57:32 +00001092# define _LIBCPP_INLINE_VAR inline
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001093#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001094# define _LIBCPP_INLINE_VAR
Eric Fiseliere4837422016-11-17 20:08:43 +00001095#endif
1096
Marshall Clowae4f8312018-07-13 16:35:26 +00001097#ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clow82eec242018-07-13 17:31:36 +00001098#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
Marshall Clowae4f8312018-07-13 16:35:26 +00001099#define _LIBCPP_CONSTEXPR_IF_NODEBUG
Marshall Clowdb0b7a02018-07-13 17:24:59 +00001100#else
1101#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
Marshall Clowae4f8312018-07-13 16:35:26 +00001102#endif
1103#endif
1104
Louis Dionnea39f1ef2019-04-17 18:20:19 +00001105#if __has_attribute(no_destroy)
1106# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1107#else
1108# define _LIBCPP_NO_DESTROY
1109#endif
1110
Marshall Clow2cd9d372014-05-08 14:14:06 +00001111#ifndef _LIBCPP_HAS_NO_ASAN
Azat Khuzhincdfb87f2020-12-17 16:19:50 -05001112extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
Marshall Clow2cd9d372014-05-08 14:14:06 +00001113 const void *, const void *, const void *, const void *);
1114#endif
1115
Howard Hinnant13087882013-10-04 21:24:21 +00001116// Try to find out if RTTI is disabled.
Marek Kurdejf3197922021-04-01 08:29:55 +02001117#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
Louis Dionneef0c6622020-07-14 16:28:41 -04001118# define _LIBCPP_NO_RTTI
1119#elif defined(__GNUC__) && !defined(__GXX_RTTI)
1120# define _LIBCPP_NO_RTTI
1121#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1122# define _LIBCPP_NO_RTTI
Howard Hinnant13087882013-10-04 21:24:21 +00001123#endif
1124
Howard Hinnant33f04722013-10-04 23:56:37 +00001125#ifndef _LIBCPP_WEAK
Logan Chien7b4845e2018-02-24 07:57:32 +00001126#define _LIBCPP_WEAK __attribute__((__weak__))
Howard Hinnant33f04722013-10-04 23:56:37 +00001127#endif
1128
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001129// Thread API
Eric Fiselierbfd45532017-01-06 23:15:16 +00001130#if !defined(_LIBCPP_HAS_NO_THREADS) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001131 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
Eric Fiselierd8a6c892017-05-10 21:34:58 +00001132 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001133 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001134# if defined(__FreeBSD__) || \
Dan Gohman280fd6b2019-05-01 16:47:30 +00001135 defined(__wasi__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001136 defined(__NetBSD__) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001137 defined(__OpenBSD__) || \
Xiang Xiao85529232020-11-18 16:16:18 -05001138 defined(__NuttX__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001139 defined(__linux__) || \
Louis Dionne3cfcaeb2018-11-20 21:14:05 +00001140 defined(__GNU__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001141 defined(__APPLE__) || \
1142 defined(__CloudABI__) || \
1143 defined(__sun__) || \
Zbigniew Sarbinowskica6367d2020-12-05 00:13:23 +00001144 defined(__MVS__) || \
jasonliu8fdf9342021-03-24 17:26:52 +00001145 defined(_AIX) || \
Alexander Richardsonba1b59e2018-07-24 12:40:56 +00001146 (defined(__MINGW32__) && __has_include(<pthread.h>))
Logan Chien7b4845e2018-02-24 07:57:32 +00001147# define _LIBCPP_HAS_THREAD_API_PTHREAD
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001148# elif defined(__Fuchsia__)
Petr Hoseke6ad6e42020-01-16 12:12:38 -08001149 // TODO(44575): Switch to C11 thread API when possible.
1150# define _LIBCPP_HAS_THREAD_API_PTHREAD
Logan Chien7b4845e2018-02-24 07:57:32 +00001151# elif defined(_LIBCPP_WIN32API)
1152# define _LIBCPP_HAS_THREAD_API_WIN32
1153# else
1154# error "No thread API"
1155# endif // _LIBCPP_HAS_THREAD_API
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001156#endif // _LIBCPP_HAS_NO_THREADS
1157
Dan Albertad293012019-09-18 18:13:32 +00001158#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1159#if defined(__ANDROID__) && __ANDROID_API__ >= 30
1160#define _LIBCPP_HAS_COND_CLOCKWAIT
1161#elif defined(_LIBCPP_GLIBC_PREREQ)
1162#if _LIBCPP_GLIBC_PREREQ(2, 30)
1163#define _LIBCPP_HAS_COND_CLOCKWAIT
1164#endif
1165#endif
1166#endif
1167
Ben Craig5593c4f2016-05-25 17:40:09 +00001168#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
Logan Chien7b4845e2018-02-24 07:57:32 +00001169#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1170 _LIBCPP_HAS_NO_THREADS is not defined.
Ben Craig5593c4f2016-05-25 17:40:09 +00001171#endif
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001172
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001173#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001174#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1175 _LIBCPP_HAS_NO_THREADS is defined.
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001176#endif
1177
Eric Fiselier715b4162014-12-06 20:09:11 +00001178#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001179#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1180 _LIBCPP_HAS_NO_THREADS is defined.
Eric Fiselier715b4162014-12-06 20:09:11 +00001181#endif
1182
Nico Weber6b58e1d2019-07-30 14:32:47 +00001183#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1184#define __STDCPP_THREADS__ 1
1185#endif
1186
Louis Dionne66c58fd2019-07-25 20:29:20 +00001187// The glibc and Bionic implementation of pthreads implements
Eric Fiselier256466e2019-07-07 17:24:03 +00001188// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1189// mutexes have no destroy mechanism.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001190//
1191// This optimization can't be performed on Apple platforms, where
1192// pthread_mutex_destroy can allow the kernel to release resources.
1193// See https://llvm.org/D64298 for details.
1194//
1195// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1196// respective stakeholders.
Eric Fiselier256466e2019-07-07 17:24:03 +00001197#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001198 || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \
Eric Fiselier256466e2019-07-07 17:24:03 +00001199 || defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselierf6dac862019-07-07 01:20:54 +00001200# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1201#endif
1202
Eric Fiselier256466e2019-07-07 17:24:03 +00001203// Destroying a condvar is a nop on Windows.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001204//
1205// This optimization can't be performed on Apple platforms, where
1206// pthread_cond_destroy can allow the kernel to release resources.
1207// See https://llvm.org/D64298 for details.
1208//
Eric Fiselier256466e2019-07-07 17:24:03 +00001209// TODO(EricWF): This is potentially true for some pthread implementations
1210// as well.
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001211#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1212 defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselier256466e2019-07-07 17:24:03 +00001213# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1214#endif
1215
Ed Schouten7009f4e2015-03-12 15:44:39 +00001216// Systems that use capability-based security (FreeBSD with Capsicum,
1217// Nuxi CloudABI) may only provide local filesystem access (using *at()).
1218// Functions like open(), rename(), unlink() and stat() should not be
1219// used, as they attempt to access the global filesystem namespace.
1220#ifdef __CloudABI__
1221#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
1222#endif
1223
Ed Schouten3a75c0b2015-03-26 14:35:46 +00001224// CloudABI is intended for running networked services. Processes do not
1225// have standard input and output channels.
1226#ifdef __CloudABI__
1227#define _LIBCPP_HAS_NO_STDIN
1228#define _LIBCPP_HAS_NO_STDOUT
1229#endif
1230
Dimitry Andric2e72c802019-09-07 22:18:20 +00001231// Some systems do not provide gets() in their C library, for security reasons.
1232#ifndef _LIBCPP_C_HAS_NO_GETS
Dimitry Andric5600c9b2019-10-19 10:59:23 +00001233# if defined(_LIBCPP_MSVCRT) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001234 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
1235 defined(__OpenBSD__)
Dimitry Andric2e72c802019-09-07 22:18:20 +00001236# define _LIBCPP_C_HAS_NO_GETS
1237# endif
1238#endif
1239
Xiang Xiao85529232020-11-18 16:16:18 -05001240#if defined(__BIONIC__) || defined(__CloudABI__) || defined(__NuttX__) || \
Muiez Ahmedaf108fb2020-11-10 09:54:03 -05001241 defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001242 defined(__MVS__) || defined(__OpenBSD__)
Dan Albertebdf28b2015-03-11 00:51:06 +00001243#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1244#endif
1245
Ed Schoutena810d5e2016-12-30 10:44:00 +00001246// Thread-unsafe functions such as strtok() and localtime()
Ed Schouten137c8632015-06-24 08:44:38 +00001247// are not available.
1248#ifdef __CloudABI__
1249#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
1250#endif
1251
Eric Fiselierba725072017-01-14 04:27:58 +00001252#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
Logan Chien7b4845e2018-02-24 07:57:32 +00001253# define _LIBCPP_HAS_C_ATOMIC_IMP
Richard Smithca47d0f2019-04-25 20:02:10 +00001254#elif defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +00001255# define _LIBCPP_HAS_GCC_ATOMIC_IMP
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001256#endif
1257
Davide Italiano011f80a2019-03-05 18:40:49 +00001258#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1259 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1260 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001261 || defined(_LIBCPP_HAS_NO_THREADS)
Davide Italiano011f80a2019-03-05 18:40:49 +00001262# define _LIBCPP_HAS_NO_ATOMIC_HEADER
1263#else
1264# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1265# define _LIBCPP_ATOMIC_FLAG_TYPE bool
1266# endif
1267# ifdef _LIBCPP_FREESTANDING
1268# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1269# endif
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001270#endif
1271
Marshall Clow91c7f642016-01-11 19:27:10 +00001272#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1273#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Eric Fiselier100e24b2016-02-11 11:59:44 +00001274#endif
1275
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001276#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001277# if defined(__clang__) && __has_attribute(acquire_capability)
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001278// Work around the attribute handling in clang. When both __declspec and
1279// __attribute__ are present, the processing goes awry preventing the definition
1280// of the types.
Logan Chien7b4845e2018-02-24 07:57:32 +00001281# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1282# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1283# endif
1284# endif
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001285#endif
Eric Fiselierc0c6c982016-03-16 02:30:06 +00001286
Eric Fiselier510690e2019-12-13 15:42:07 -05001287#ifndef _LIBCPP_THREAD_SAFETY_ANNOTATION
1288# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1289# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1290# else
1291# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1292# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001293#endif // _LIBCPP_THREAD_SAFETY_ANNOTATION
Eric Fiselier510690e2019-12-13 15:42:07 -05001294
Eric Fiselier0d3da632016-09-03 00:11:33 +00001295#if __has_attribute(require_constant_initialization)
Logan Chien7b4845e2018-02-24 07:57:32 +00001296# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
Eric Fiselier0d3da632016-09-03 00:11:33 +00001297#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001298# define _LIBCPP_SAFE_STATIC
Eric Fiselier0d3da632016-09-03 00:11:33 +00001299#endif
1300
Eric Fiselierd4ec6352016-10-12 07:46:20 +00001301#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700
Logan Chien7b4845e2018-02-24 07:57:32 +00001302#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
Eric Fiselierd4ec6352016-10-12 07:46:20 +00001303#endif
1304
Eric Fiselier5afe0992019-04-24 17:54:25 +00001305#if !__has_builtin(__builtin_is_constant_evaluated) && _GNUC_VER < 900
1306#define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
1307#endif
1308
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001309#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001310# define _LIBCPP_DIAGNOSE_WARNING(...) \
1311 __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1312# define _LIBCPP_DIAGNOSE_ERROR(...) \
1313 __attribute__((diagnose_if(__VA_ARGS__, "error")))
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001314#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001315# define _LIBCPP_DIAGNOSE_WARNING(...)
1316# define _LIBCPP_DIAGNOSE_ERROR(...)
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001317#endif
1318
Eric Fiselier4db80032017-05-05 20:32:26 +00001319// Use a function like macro to imply that it must be followed by a semicolon
Reid Kleckner75d4e002018-11-01 18:24:03 +00001320#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
1321# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1322#elif __has_cpp_attribute(clang::fallthrough)
1323# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
Kazuaki Ishizaki9bad3a62020-01-08 09:35:12 +08001324#elif __has_attribute(fallthrough) || _GNUC_VER >= 700
Logan Chien7b4845e2018-02-24 07:57:32 +00001325# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
Eric Fiselier4db80032017-05-05 20:32:26 +00001326#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001327# define _LIBCPP_FALLTHROUGH() ((void)0)
Eric Fiselier4db80032017-05-05 20:32:26 +00001328#endif
1329
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001330#if __has_attribute(__nodebug__)
1331#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
Eric Fiselier74ebee62019-06-08 01:31:19 +00001332#else
1333#define _LIBCPP_NODEBUG
1334#endif
1335
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001336#ifndef _LIBCPP_NODEBUG_TYPE
1337#if __has_attribute(__nodebug__) && \
Louis Dionne8bf4c792019-08-14 17:01:08 +00001338 (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 900)
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001339#define _LIBCPP_NODEBUG_TYPE __attribute__((nodebug))
1340#else
1341#define _LIBCPP_NODEBUG_TYPE
1342#endif
1343#endif // !defined(_LIBCPP_NODEBUG_TYPE)
1344
Amy Huang63f53b52021-03-15 14:20:49 -07001345#if __has_attribute(__standalone_debug__)
1346#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1347#else
1348#define _LIBCPP_STANDALONE_DEBUG
1349#endif
1350
Richard Smith256954d2020-11-11 17:12:18 -08001351#if __has_attribute(__preferred_name__)
1352#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1353#else
1354#define _LIBCPP_PREFERRED_NAME(x)
1355#endif
1356
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001357#if defined(_LIBCPP_ABI_MICROSOFT) && \
Logan Chien7b4845e2018-02-24 07:57:32 +00001358 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1359# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001360#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001361# define _LIBCPP_DECLSPEC_EMPTY_BASES
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001362#endif
1363
Eric Fiselierddd77792017-02-17 03:25:08 +00001364#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
Logan Chien7b4845e2018-02-24 07:57:32 +00001365#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
1366#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
1367#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1368#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
Eric Fiselierddd77792017-02-17 03:25:08 +00001369#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1370
Marshall Clow580b6e62017-03-24 03:40:36 +00001371#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611
Logan Chien7b4845e2018-02-24 07:57:32 +00001372#define _LIBCPP_HAS_NO_DEDUCTION_GUIDES
Marshall Clow580b6e62017-03-24 03:40:36 +00001373#endif
1374
Eric Fiselierc9a0e822017-04-12 23:08:46 +00001375#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001)
Logan Chien7b4845e2018-02-24 07:57:32 +00001376#define _LIBCPP_HAS_NO_IS_AGGREGATE
Eric Fiselierc9a0e822017-04-12 23:08:46 +00001377#endif
1378
Eric Fiselier40b66222017-05-26 01:52:59 +00001379#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
Logan Chien7b4845e2018-02-24 07:57:32 +00001380#define _LIBCPP_HAS_NO_COROUTINES
Eric Fiselier40b66222017-05-26 01:52:59 +00001381#endif
1382
David Zarzyckiae2ac4e2020-01-24 13:26:53 -05001383#if !defined(__cpp_impl_three_way_comparison) || __cpp_impl_three_way_comparison < 201907L
Eric Fiseliere0074fc2018-04-06 21:37:23 +00001384#define _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
David Zarzyckiae2ac4e2020-01-24 13:26:53 -05001385#endif
Eric Fiseliere0074fc2018-04-06 21:37:23 +00001386
Eric Fiselierf4433a32017-05-31 22:07:49 +00001387#if defined(_LIBCPP_COMPILER_IBM)
1388#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
1389#endif
1390
1391#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
Logan Chien7b4845e2018-02-24 07:57:32 +00001392# define _LIBCPP_PUSH_MACROS
1393# define _LIBCPP_POP_MACROS
Eric Fiselierf4433a32017-05-31 22:07:49 +00001394#else
1395 // Don't warn about macro conflicts when we can restore them at the
1396 // end of the header.
Logan Chien7b4845e2018-02-24 07:57:32 +00001397# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1398# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1399# endif
1400# if defined(_LIBCPP_COMPILER_MSVC)
1401# define _LIBCPP_PUSH_MACROS \
1402 __pragma(push_macro("min")) \
1403 __pragma(push_macro("max"))
1404# define _LIBCPP_POP_MACROS \
1405 __pragma(pop_macro("min")) \
1406 __pragma(pop_macro("max"))
1407# else
1408# define _LIBCPP_PUSH_MACROS \
1409 _Pragma("push_macro(\"min\")") \
1410 _Pragma("push_macro(\"max\")")
1411# define _LIBCPP_POP_MACROS \
1412 _Pragma("pop_macro(\"min\")") \
1413 _Pragma("pop_macro(\"max\")")
1414# endif
Eric Fiselierf4433a32017-05-31 22:07:49 +00001415#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
1416
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001417#ifndef _LIBCPP_NO_AUTO_LINK
Logan Chien7b4845e2018-02-24 07:57:32 +00001418# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Martin Storsjö57db41b2021-04-15 11:16:28 +03001419# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001420# pragma comment(lib, "c++.lib")
1421# else
1422# pragma comment(lib, "libc++.lib")
1423# endif
1424# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001425#endif // _LIBCPP_NO_AUTO_LINK
Eric Fiselier911dcad2017-06-16 01:57:41 +00001426
Dan Albert9550df62019-09-16 19:26:41 +00001427// Configures the fopen close-on-exec mode character, if any. This string will
1428// be appended to any mode string used by fstream for fopen/fdopen.
1429//
1430// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1431// do.
1432#if defined(__BIONIC__)
1433# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1434#else
1435# define _LIBCPP_FOPEN_CLOEXEC_MODE
1436#endif
1437
Martijn Vels080e26a2020-01-30 14:12:44 -05001438#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
1439#define _LIBCPP_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
1440#else
1441#define _LIBCPP_BUILTIN_CONSTANT_P(x) false
1442#endif
1443
Dan Albert073008c2020-03-12 11:16:30 -07001444// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1445// of functions used in cstdio may not be available for low API levels when
1446// using 64-bit file offsets on LP32.
1447#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1448#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1449#endif
1450
Zbigniew Sarbinowski4536ef42020-11-20 14:46:21 -05001451#if __has_attribute(init_priority)
1452# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1453#else
1454# define _LIBCPP_INIT_PRIORITY_MAX
1455#endif
1456
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001457#if defined(__GNUC__) || defined(__clang__)
1458#define _LIBCPP_FORMAT_PRINTF(a, b) \
1459 __attribute__((__format__(__printf__, a, b)))
1460#else
1461#define _LIBCPP_FORMAT_PRINTF(a, b)
1462#endif
1463
Eric Fiselier911dcad2017-06-16 01:57:41 +00001464#endif // __cplusplus
1465
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001466#endif // _LIBCPP_CONFIG