blob: 98f011e7c6ada8481817cb8de311942405121f4b [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
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
Tom Stellardce41e662021-07-27 21:51:07 -070027#define _LIBCPP_VERSION 14000
Howard Hinnantc51e1022010-05-11 19:42:16 +000028
Eric Fiselierfa1f1c12019-06-26 00:05:14 +000029#ifndef _LIBCPP_ABI_VERSION
30# define _LIBCPP_ABI_VERSION 1
31#endif
32
hyd-devb987b452020-09-02 12:22:29 -040033#if __STDC_HOSTED__ == 0
Davide Italiano011f80a2019-03-05 18:40:49 +000034# define _LIBCPP_FREESTANDING
35#endif
36
Eric Fiselier02cea5e2018-07-27 03:07:09 +000037#ifndef _LIBCPP_STD_VER
38# if __cplusplus <= 201103L
39# define _LIBCPP_STD_VER 11
40# elif __cplusplus <= 201402L
41# define _LIBCPP_STD_VER 14
42# elif __cplusplus <= 201703L
43# define _LIBCPP_STD_VER 17
Marek Kurdej24b4c512021-01-07 12:29:04 +010044# elif __cplusplus <= 202002L
45# define _LIBCPP_STD_VER 20
Eric Fiselier02cea5e2018-07-27 03:07:09 +000046# else
Marek Kurdej24b4c512021-01-07 12:29:04 +010047# define _LIBCPP_STD_VER 21 // current year, or date of c++2b ratification
Eric Fiselier02cea5e2018-07-27 03:07:09 +000048# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -040049#endif // _LIBCPP_STD_VER
Eric Fiselier02cea5e2018-07-27 03:07:09 +000050
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000051#if defined(__ELF__)
Logan Chien7b4845e2018-02-24 07:57:32 +000052# define _LIBCPP_OBJECT_FORMAT_ELF 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000053#elif defined(__MACH__)
Logan Chien7b4845e2018-02-24 07:57:32 +000054# define _LIBCPP_OBJECT_FORMAT_MACHO 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000055#elif defined(_WIN32)
Logan Chien7b4845e2018-02-24 07:57:32 +000056# define _LIBCPP_OBJECT_FORMAT_COFF 1
Sam Cleggfe39b0b2017-12-16 18:59:50 +000057#elif defined(__wasm__)
Logan Chien7b4845e2018-02-24 07:57:32 +000058# define _LIBCPP_OBJECT_FORMAT_WASM 1
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000059#else
Louis Dionne64dcd862020-11-17 13:17:40 -050060 // ... add new file formats here ...
Shoaib Meenai5c2d4012017-04-12 19:56:37 +000061#endif
62
Eric Fiselierfa1f1c12019-06-26 00:05:14 +000063#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
Shoaib Meenai4bdf4372016-09-12 20:14:44 +000064// Change short string representation so that string data starts at offset 0,
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000065// improving its alignment in some cases.
Logan Chien7b4845e2018-02-24 07:57:32 +000066# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Evgeniy Stepanovc299de22015-11-06 22:02:29 +000067// Fix deque iterator type in order to support incomplete types.
Logan Chien7b4845e2018-02-24 07:57:32 +000068# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
Nico Weberd31c3ab2017-07-22 15:16:42 +000069// Fix undefined behavior in how std::list stores its linked nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000070# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
Eric Fiselier70f5f872016-07-19 17:56:20 +000071// Fix undefined behavior in how __tree stores its end and parent nodes.
Logan Chien7b4845e2018-02-24 07:57:32 +000072# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
Nico Weberd31c3ab2017-07-22 15:16:42 +000073// Fix undefined behavior in how __hash_table stores its pointer types.
Logan Chien7b4845e2018-02-24 07:57:32 +000074# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
75# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
76# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
Shoaib Meenaic130eaf2017-03-28 19:33:31 +000077// Define a key function for `bad_function_call` in the library, to centralize
78// its vtable and typeinfo to libc++ rather than having all other libraries
79// using that class define their own copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000080# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
Konstantin Varlamovd96c2d22021-11-15 12:40:55 -080081// Override the default return value of exception::what() for
82// bad_function_call::what() with a string that is specific to
83// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
84// because it changes the vtable layout of bad_function_call.
85# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
Aditya Kumaraa866182017-06-14 23:17:45 +000086// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
Logan Chien7b4845e2018-02-24 07:57:32 +000087# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040088// In C++20 and later, don't derive std::plus from std::binary_function,
89// nor std::negate from std::unary_function.
90# define _LIBCPP_ABI_NO_BINDER_BASES
Louis Dionne8762e2b2021-05-25 18:15:58 -040091// Give reverse_iterator<T> one data member of type T, not two.
92// Also, in C++17 and later, don't derive iterator types from std::iterator.
93# define _LIBCPP_ABI_NO_ITERATOR_BASES
Eric Fiseliercaccc7b2017-11-19 04:19:44 +000094// Use the smallest possible integer type to represent the index of the variant.
Louis Dionnea8548af2019-03-20 17:05:52 +000095// Previously libc++ used "unsigned int" exclusively.
Logan Chien7b4845e2018-02-24 07:57:32 +000096# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
Eric Fiselierf2e64362018-12-11 00:14:34 +000097// Unstable attempt to provide a more optimized std::function
98# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
Marshall Clow88a30872019-03-28 17:30:23 +000099// All the regex constants must be distinct and nonzero.
100# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
Arthur O'Dwyer0a5557f2021-04-20 22:08:00 -0400101// Use raw pointers, not wrapped ones, for std::span's iterator type.
102# define _LIBCPP_ABI_SPAN_POINTER_ITERATORS
Martijn Velsb17d5802020-03-02 10:11:35 -0500103// Re-worked external template instantiations for std::string with a focus on
104// performance and fast-path inlining.
105# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Vy Nguyene369bd92020-07-13 12:34:37 -0400106// Enable clang::trivial_abi on std::unique_ptr.
107# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
108// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
109# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000110#elif _LIBCPP_ABI_VERSION == 1
Logan Chien7b4845e2018-02-24 07:57:32 +0000111# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier98848572017-01-17 03:16:26 +0000112// Enable compiling copies of now inline methods into the dylib to support
Shoaib Meenai5c2d4012017-04-12 19:56:37 +0000113// applications compiled against older libraries. This is unnecessary with
114// COFF dllexport semantics, since dllexport forces a non-inline definition
115// of inline functions to be emitted anyway. Our own non-inline copy would
116// conflict with the dllexport-emitted copy, so we disable it.
Logan Chien7b4845e2018-02-24 07:57:32 +0000117# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
118# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000119// Feature macros for disabling pre ABI v1 features. All of these options
120// are deprecated.
Logan Chien7b4845e2018-02-24 07:57:32 +0000121# if defined(__FreeBSD__)
122# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
123# endif
Eric Fiselier08f7fe82016-07-18 01:58:37 +0000124#endif
125
Louis Dionne495e9ad2021-11-29 16:20:48 -0500126// By default, don't use a nullptr_t emulation type in C++03.
127//
128// This is technically an ABI break from previous releases, however it is
129// very unlikely to impact anyone. If a user is impacted by this break,
130// they can return to using the C++03 nullptr emulation by defining
131// _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION.
132//
133// This switch will be removed entirely in favour of never providing a
134// C++03 emulation after one release.
135//
136// IMPORTANT: IF YOU ARE READING THIS AND YOU TURN THIS MACRO ON, PLEASE LEAVE
137// A COMMENT ON https://reviews.llvm.org/D109459 OR YOU WILL BE BROKEN
138// IN THE FUTURE WHEN WE REMOVE THE ABILITY TO USE THE C++03 EMULATION.
139#ifndef _LIBCPP_ABI_USE_CXX03_NULLPTR_EMULATION
140# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
141#endif
142
Louis Dionne8a79be62020-10-21 11:11:45 -0400143#if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
144// Enable additional explicit instantiations of iostreams components. This
145// reduces the number of weak definitions generated in programs that use
146// iostreams by providing a single strong definition in the shared library.
147# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
Konstantin Varlamovd96c2d22021-11-15 12:40:55 -0800148
149// Define a key function for `bad_function_call` in the library, to centralize
150// its vtable and typeinfo to libc++ rather than having all other libraries
151// using that class define their own copies.
152# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
Louis Dionne8a79be62020-10-21 11:11:45 -0400153#endif
154
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
156#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
157
Eric Fiselierb33778a2018-10-30 21:44:53 +0000158#ifndef _LIBCPP_ABI_NAMESPACE
159# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
160#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000162#if __cplusplus < 201103L
163#define _LIBCPP_CXX03_LANG
164#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000165
166#ifndef __has_attribute
167#define __has_attribute(__x) 0
168#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000169
Eric Fiselier86fcc922015-07-10 20:26:38 +0000170#ifndef __has_builtin
171#define __has_builtin(__x) 0
172#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000173
Eric Fiselier8020b6c2015-08-19 17:21:46 +0000174#ifndef __has_extension
175#define __has_extension(__x) 0
176#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000177
Eric Fiselier86fcc922015-07-10 20:26:38 +0000178#ifndef __has_feature
179#define __has_feature(__x) 0
180#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000181
Marshall Clow2a5c4212017-11-14 22:26:50 +0000182#ifndef __has_cpp_attribute
183#define __has_cpp_attribute(__x) 0
184#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000185
Eric Fiselier86fcc922015-07-10 20:26:38 +0000186// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
187// the compiler and '1' otherwise.
188#ifndef __is_identifier
189#define __is_identifier(__x) 1
190#endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000191
Eric Fiseliere3cec5f2017-01-16 21:15:08 +0000192#ifndef __has_declspec_attribute
193#define __has_declspec_attribute(__x) 0
194#endif
Eric Fiselier86fcc922015-07-10 20:26:38 +0000195
Eric Fiselierba725072017-01-14 04:27:58 +0000196#define __has_keyword(__x) !(__is_identifier(__x))
197
Alexander Richardsonba1b59e2018-07-24 12:40:56 +0000198#ifndef __has_include
199#define __has_include(...) 0
Eric Fiselierd8a6c892017-05-10 21:34:58 +0000200#endif
201
Marek Kurdejf3197922021-04-01 08:29:55 +0200202#if defined(__apple_build_version__)
203# define _LIBCPP_COMPILER_CLANG_BASED
204# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
205#elif defined(__clang__)
206# define _LIBCPP_COMPILER_CLANG_BASED
207# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000208#elif defined(__GNUC__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000209# define _LIBCPP_COMPILER_GCC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000210#elif defined(_MSC_VER)
Logan Chien7b4845e2018-02-24 07:57:32 +0000211# define _LIBCPP_COMPILER_MSVC
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000212#elif defined(__IBMCPP__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000213# define _LIBCPP_COMPILER_IBM
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000214#endif
215
Eric Fiselier75c05562019-06-13 00:37:25 +0000216#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
217#error "libc++ does not support using GCC with C++03. Please enable C++11"
218#endif
219
Eric Fiseliera6d96342017-01-07 02:43:58 +0000220// FIXME: ABI detection should be done via compiler builtin macros. This
221// is just a placeholder until Clang implements such macros. For now assume
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000222// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
223// and allow the user to explicitly specify the ABI to handle cases where this
224// heuristic falls short.
Shoaib Meenai56943f82017-10-05 02:18:08 +0000225#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
Logan Chien7b4845e2018-02-24 07:57:32 +0000226# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
Shoaib Meenai56943f82017-10-05 02:18:08 +0000227#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
Shoaib Meenai69cebe72017-10-04 23:44:38 +0000228# define _LIBCPP_ABI_ITANIUM
Logan Chien7b4845e2018-02-24 07:57:32 +0000229#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
230# define _LIBCPP_ABI_MICROSOFT
231#else
232# if defined(_WIN32) && defined(_MSC_VER)
233# define _LIBCPP_ABI_MICROSOFT
234# else
235# define _LIBCPP_ABI_ITANIUM
236# endif
Eric Fiseliera6d96342017-01-07 02:43:58 +0000237#endif
238
Eric Fiselier85f66332019-03-05 01:57:01 +0000239#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
240# define _LIBCPP_ABI_VCRUNTIME
241#endif
242
Dan Albert21800dc2016-09-19 18:00:45 +0000243// Need to detect which libc we're using if we're on Linux.
244#if defined(__linux__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000245# include <features.h>
246# if defined(__GLIBC_PREREQ)
247# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
248# else
249# define _LIBCPP_GLIBC_PREREQ(a, b) 0
250# endif // defined(__GLIBC_PREREQ)
Dan Albert21800dc2016-09-19 18:00:45 +0000251#endif // defined(__linux__)
Eric Fiselier86fcc922015-07-10 20:26:38 +0000252
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253#ifdef __LITTLE_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000254# if __LITTLE_ENDIAN__
255# define _LIBCPP_LITTLE_ENDIAN
256# endif // __LITTLE_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400257#endif // __LITTLE_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258
259#ifdef __BIG_ENDIAN__
Logan Chien7b4845e2018-02-24 07:57:32 +0000260# if __BIG_ENDIAN__
261# define _LIBCPP_BIG_ENDIAN
262# endif // __BIG_ENDIAN__
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400263#endif // __BIG_ENDIAN__
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264
Dan Albert98d97792015-09-16 18:10:47 +0000265#ifdef __BYTE_ORDER__
Logan Chien7b4845e2018-02-24 07:57:32 +0000266# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
267# define _LIBCPP_LITTLE_ENDIAN
268# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
269# define _LIBCPP_BIG_ENDIAN
270# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
Dan Albert98d97792015-09-16 18:10:47 +0000271#endif // __BYTE_ORDER__
272
David Chisnall93008f02010-08-11 16:27:20 +0000273#ifdef __FreeBSD__
Logan Chien7b4845e2018-02-24 07:57:32 +0000274# include <sys/endian.h>
Dimitry Andric5600c9b2019-10-19 10:59:23 +0000275# include <osreldate.h>
David Chisnall93008f02010-08-11 16:27:20 +0000276# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000277# define _LIBCPP_LITTLE_ENDIAN
278# else // _BYTE_ORDER == _LITTLE_ENDIAN
279# define _LIBCPP_BIG_ENDIAN
280# endif // _BYTE_ORDER == _LITTLE_ENDIAN
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400281#endif // __FreeBSD__
David Chisnall93008f02010-08-11 16:27:20 +0000282
Brad Smithf6f55092021-01-12 14:16:15 -0500283#if defined(__NetBSD__) || defined(__OpenBSD__)
Logan Chien7b4845e2018-02-24 07:57:32 +0000284# include <sys/endian.h>
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000285# if _BYTE_ORDER == _LITTLE_ENDIAN
Logan Chien7b4845e2018-02-24 07:57:32 +0000286# define _LIBCPP_LITTLE_ENDIAN
287# else // _BYTE_ORDER == _LITTLE_ENDIAN
288# define _LIBCPP_BIG_ENDIAN
289# endif // _BYTE_ORDER == _LITTLE_ENDIAN
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400290#endif // defined(__NetBSD__) || defined(__OpenBSD__)
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000291
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000292#if defined(_WIN32)
Eric Fiselierbb999f92017-05-31 22:14:05 +0000293# define _LIBCPP_WIN32API
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000294# define _LIBCPP_LITTLE_ENDIAN
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000295# define _LIBCPP_SHORT_WCHAR 1
Louis Dionnea8548af2019-03-20 17:05:52 +0000296// Both MinGW and native MSVC provide a "MSVC"-like environment
Eric Fiselierbb999f92017-05-31 22:14:05 +0000297# define _LIBCPP_MSVCRT_LIKE
Bruno Cardoso Lopes91572682017-07-17 21:52:31 +0000298// If mingw not explicitly detected, assume using MS C runtime only if
299// a MS compatibility version is specified.
300# if defined(_MSC_VER) && !defined(__MINGW32__)
Howard Hinnant8ad70912013-09-17 01:34:47 +0000301# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
302# endif
Saleem Abdulrasool32300ca2017-01-04 01:53:24 +0000303# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
304# define _LIBCPP_HAS_BITSCAN64
305# endif
Peter Collingbourne63ebbd72018-01-23 02:07:27 +0000306# define _LIBCPP_HAS_OPEN_WITH_WCHAR
Logan Chien7b4845e2018-02-24 07:57:32 +0000307# if defined(_LIBCPP_MSVCRT)
308# define _LIBCPP_HAS_QUICK_EXIT
309# endif
Shoaib Meenaie2ce3602017-04-06 04:47:49 +0000310
311// Some CRT APIs are unavailable to store apps
Logan Chien7b4845e2018-02-24 07:57:32 +0000312# if defined(WINAPI_FAMILY)
313# include <winapifamily.h>
314# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && \
315 (!defined(WINAPI_PARTITION_SYSTEM) || \
316 !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM))
317# define _LIBCPP_WINDOWS_STORE_APP
318# endif
319# endif
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000320#endif // defined(_WIN32)
Howard Hinnant34bad2a2011-05-13 17:16:06 +0000321
David Chisnall8074c342012-02-29 13:05:08 +0000322#ifdef __sun__
Logan Chien7b4845e2018-02-24 07:57:32 +0000323# include <sys/isa_defs.h>
324# ifdef _LITTLE_ENDIAN
325# define _LIBCPP_LITTLE_ENDIAN
326# else
327# define _LIBCPP_BIG_ENDIAN
328# endif
David Chisnall8074c342012-02-29 13:05:08 +0000329#endif // __sun__
330
Xing Xue50b0eb42021-09-09 16:20:36 -0400331#if defined(_AIX) && !defined(__64BIT__)
332 // The size of wchar is 2 byte on 32-bit mode on AIX.
333# define _LIBCPP_SHORT_WCHAR 1
334#endif
335
Louis Dionne62253962021-12-21 16:50:34 -0500336// Libc++ supports various implementations of std::random_device.
337//
338// _LIBCPP_USING_DEV_RANDOM
339// Read entropy from the given file, by default `/dev/urandom`.
340// If a token is provided, it is assumed to be the path to a file
341// to read entropy from. This is the default behavior if nothing
342// else is specified. This implementation requires storing state
343// inside `std::random_device`.
344//
345// _LIBCPP_USING_ARC4_RANDOM
346// Use arc4random(). This allows obtaining random data even when
347// using sandboxing mechanisms. On some platforms like Apple, this
348// is the recommended source of entropy for user-space programs.
349// When this option is used, the token passed to `std::random_device`'s
350// constructor *must* be "/dev/urandom" -- anything else is an error.
351//
352// _LIBCPP_USING_GETENTROPY
353// Use getentropy().
354// When this option is used, the token passed to `std::random_device`'s
355// constructor *must* be "/dev/urandom" -- anything else is an error.
356//
Roland McGrathdea04482022-01-02 11:53:53 -0800357// _LIBCPP_USING_FUCHSIA_CPRNG
358// Use Fuchsia's zx_cprng_draw() system call, which is specified to
359// deliver high-quality entropy and cannot fail.
360// When this option is used, the token passed to `std::random_device`'s
361// constructor *must* be "/dev/urandom" -- anything else is an error.
362//
Louis Dionne62253962021-12-21 16:50:34 -0500363// _LIBCPP_USING_NACL_RANDOM
364// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
365// including accesses to the special files under `/dev`. This implementation
366// uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
367// When this option is used, the token passed to `std::random_device`'s
368// constructor *must* be "/dev/urandom" -- anything else is an error.
369//
370// _LIBCPP_USING_WIN32_RANDOM
371// Use rand_s(), for use on Windows.
372// When this option is used, the token passed to `std::random_device`'s
373// constructor *must* be "/dev/urandom" -- anything else is an error.
374#if defined(__OpenBSD__)
375# define _LIBCPP_USING_ARC4_RANDOM
Roland McGrathdea04482022-01-02 11:53:53 -0800376#elif defined(__wasi__)
Louis Dionne62253962021-12-21 16:50:34 -0500377# define _LIBCPP_USING_GETENTROPY
Roland McGrathdea04482022-01-02 11:53:53 -0800378#elif defined(__Fuchsia__)
379# define _LIBCPP_USING_FUCHSIA_CPRNG
Louis Dionne62253962021-12-21 16:50:34 -0500380#elif defined(__native_client__)
381# define _LIBCPP_USING_NACL_RANDOM
382#elif defined(_LIBCPP_WIN32API)
383# define _LIBCPP_USING_WIN32_RANDOM
384#else
385# define _LIBCPP_USING_DEV_RANDOM
386#endif
387
Eric Fiseliere9cc5922017-10-17 13:16:01 +0000388#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Logan Chien7b4845e2018-02-24 07:57:32 +0000389# include <endian.h>
390# if __BYTE_ORDER == __LITTLE_ENDIAN
391# define _LIBCPP_LITTLE_ENDIAN
392# elif __BYTE_ORDER == __BIG_ENDIAN
393# define _LIBCPP_BIG_ENDIAN
394# else // __BYTE_ORDER == __BIG_ENDIAN
395# error unable to determine endian
396# endif
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400397#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398
Eric Fiselier02cba002017-06-15 03:50:02 +0000399#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +0000400# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000401#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000402# define _LIBCPP_NO_CFI
Evgeniy Stepanov076b2372016-02-10 21:53:28 +0000403#endif
404
Louis Dionne29c6d372021-08-17 11:23:48 -0400405// If the compiler supports using_if_exists, pretend we have those functions and they'll
406// be picked up if the C library provides them.
407//
408// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
409// for platforms that don't have a conforming C11 library, so we can drop this whole thing.
410#if __has_attribute(using_if_exists)
411# define _LIBCPP_HAS_TIMESPEC_GET
412# define _LIBCPP_HAS_QUICK_EXIT
413# define _LIBCPP_HAS_ALIGNED_ALLOC
414#else
Marek Kurdejf3197922021-04-01 08:29:55 +0200415#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
Louis Dionne234dd432018-08-15 00:16:41 +0000416# if defined(__FreeBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800417# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000418# define _LIBCPP_HAS_QUICK_EXIT
Dimitry Andrice022a032020-01-30 08:00:28 +0100419# if __FreeBSD_version >= 1300064 || \
420 (__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
421# define _LIBCPP_HAS_TIMESPEC_GET
422# endif
Dan Albert1d3cfad2019-11-18 12:16:45 -0800423# elif defined(__BIONIC__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800424# if __ANDROID_API__ >= 21
425# define _LIBCPP_HAS_QUICK_EXIT
426# endif
427# if __ANDROID_API__ >= 28
428# define _LIBCPP_HAS_ALIGNED_ALLOC
429# endif
430# if __ANDROID_API__ >= 29
431# define _LIBCPP_HAS_TIMESPEC_GET
432# endif
Michał Górnyf0426252019-12-14 14:17:19 +0100433# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800434# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000435# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000436# define _LIBCPP_HAS_TIMESPEC_GET
Brad Smithf6f55092021-01-12 14:16:15 -0500437# elif defined(__OpenBSD__)
438# define _LIBCPP_HAS_ALIGNED_ALLOC
439# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000440# elif defined(__linux__)
441# if !defined(_LIBCPP_HAS_MUSL_LIBC)
442# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
443# define _LIBCPP_HAS_QUICK_EXIT
444# endif
445# if _LIBCPP_GLIBC_PREREQ(2, 17)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800446# define _LIBCPP_HAS_ALIGNED_ALLOC
Marshall Clowa6a55a82018-08-15 21:19:08 +0000447# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000448# endif
449# else // defined(_LIBCPP_HAS_MUSL_LIBC)
Dan Albert1d3cfad2019-11-18 12:16:45 -0800450# define _LIBCPP_HAS_ALIGNED_ALLOC
Louis Dionne234dd432018-08-15 00:16:41 +0000451# define _LIBCPP_HAS_QUICK_EXIT
Marshall Clowa6a55a82018-08-15 21:19:08 +0000452# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne234dd432018-08-15 00:16:41 +0000453# endif
Martin Storsjö8a174e72021-05-31 09:32:51 +0000454# elif defined(_LIBCPP_MSVCRT)
455 // Using Microsoft's C Runtime library, not MinGW
456# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne5b747292020-07-27 14:25:03 -0400457# elif defined(__APPLE__)
458 // timespec_get and aligned_alloc were introduced in macOS 10.15 and
459 // aligned releases
Marek Kurdej126213e2021-04-02 10:31:18 +0200460# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
461 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
462 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
463 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
Louis Dionne5b747292020-07-27 14:25:03 -0400464# define _LIBCPP_HAS_ALIGNED_ALLOC
Raphael Isemann46c3ac52020-09-02 09:25:31 +0200465# define _LIBCPP_HAS_TIMESPEC_GET
Louis Dionne5b747292020-07-27 14:25:03 -0400466# endif
467# endif // __APPLE__
Louis Dionne234dd432018-08-15 00:16:41 +0000468#endif
Louis Dionne29c6d372021-08-17 11:23:48 -0400469#endif // __has_attribute(using_if_exists)
Louis Dionne234dd432018-08-15 00:16:41 +0000470
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000471#ifndef _LIBCPP_CXX03_LANG
472# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
Marek Kurdejf3197922021-04-01 08:29:55 +0200473#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000474# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
475#else
Louis Dionne72707bf2020-09-02 12:29:42 -0400476# 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 +0000477#endif
478
479#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
480
Marek Kurdejf3197922021-04-01 08:29:55 +0200481#if defined(_LIBCPP_COMPILER_CLANG_BASED)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000482
Louis Dionne3f346932020-06-25 16:31:14 -0400483#if defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
484# error _LIBCPP_ALTERNATE_STRING_LAYOUT is deprecated, please use _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT instead
485#endif
486#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
487 (!defined(__arm__) || __ARM_ARCH_7K__ >= 2)
488# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Tim Northoverffc95932014-03-30 11:34:22 +0000489#endif
490
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000491#if __has_feature(cxx_alignas)
Howard Hinnant62cad692012-05-31 19:31:14 +0000492# define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493# define _ALIGNAS(x) alignas(x)
494#else
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000495# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000496# define _ALIGNAS(x) __attribute__((__aligned__(x)))
497#endif
498
Marshall Clow2b12c312014-02-22 15:13:48 +0000499#if __cplusplus < 201103L
Howard Hinnant31cd14f2010-09-16 23:27:26 +0000500typedef __char16_t char16_t;
501typedef __char32_t char32_t;
Howard Hinnant8e6a3982010-09-07 20:31:18 +0000502#endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000503
Louis Dionne94c6eda2020-07-03 13:46:41 -0400504#if !__has_feature(cxx_exceptions)
505# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000506#endif
507
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000508#if !(__has_feature(cxx_strong_enums))
509#define _LIBCPP_HAS_NO_STRONG_ENUMS
510#endif
511
Howard Hinnant8df96292011-05-26 17:07:32 +0000512#if __has_feature(cxx_attributes)
Richard Smithcabd3922012-07-26 02:04:22 +0000513# define _LIBCPP_NORETURN [[noreturn]]
Howard Hinnant8df96292011-05-26 17:07:32 +0000514#else
Richard Smithcabd3922012-07-26 02:04:22 +0000515# define _LIBCPP_NORETURN __attribute__ ((noreturn))
Howard Hinnant74279a52010-09-04 23:28:19 +0000516#endif
517
Howard Hinnant74279a52010-09-04 23:28:19 +0000518#if !(__has_feature(cxx_nullptr))
Logan Chien7b4845e2018-02-24 07:57:32 +0000519# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
520# define nullptr __nullptr
521# else
522# define _LIBCPP_HAS_NO_NULLPTR
523# endif
Howard Hinnant74279a52010-09-04 23:28:19 +0000524#endif
525
Douglas Gregor13034442011-06-22 22:17:44 +0000526// Objective-C++ features (opt-in)
527#if __has_feature(objc_arc)
528#define _LIBCPP_HAS_OBJC_ARC
529#endif
530
531#if __has_feature(objc_arc_weak)
532#define _LIBCPP_HAS_OBJC_ARC_WEAK
533#endif
534
Louis Dionne2c358282020-01-21 12:39:43 -0800535#if __has_extension(blocks)
536# define _LIBCPP_HAS_EXTENSION_BLOCKS
537#endif
538
Louis Dionne3a632922020-04-23 16:47:52 -0400539#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
540# define _LIBCPP_HAS_BLOCKS_RUNTIME
541#endif
542
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000543#if !(__has_feature(cxx_noexcept))
544#define _LIBCPP_HAS_NO_NOEXCEPT
Howard Hinnant68d13392011-05-11 20:19:40 +0000545#endif
546
Louis Dionne93f1fd72021-06-04 13:31:22 -0400547#if !__has_feature(address_sanitizer)
Marshall Clow90fc0472014-04-14 15:44:57 +0000548#define _LIBCPP_HAS_NO_ASAN
549#endif
550
Marshall Clow55b23d22016-01-12 00:38:04 +0000551// Allow for build-time disabling of unsigned integer sanitization
Louis Dionne93f1fd72021-06-04 13:31:22 -0400552#if __has_attribute(no_sanitize)
Saleem Abdulrasool38acb642016-02-09 04:05:37 +0000553#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
Logan Chien7b4845e2018-02-24 07:57:32 +0000554#endif
Marshall Clow55b23d22016-01-12 00:38:04 +0000555
Louis Dionne3a197992018-07-27 12:46:03 +0000556#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
557
Louis Dionnefaa17452019-09-04 12:44:19 +0000558#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
559
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000560#elif defined(_LIBCPP_COMPILER_GCC)
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000561
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000562#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000563#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000564
Richard Smithcabd3922012-07-26 02:04:22 +0000565#define _LIBCPP_NORETURN __attribute__((noreturn))
Howard Hinnant1e570a32011-05-31 13:13:49 +0000566
Louis Dionneaf6be622021-07-27 17:30:47 -0400567#if !defined(__EXCEPTIONS)
Louis Dionne94c6eda2020-07-03 13:46:41 -0400568# define _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000569#endif
570
Louis Dionne93f1fd72021-06-04 13:31:22 -0400571#if !defined(__SANITIZE_ADDRESS__)
Marshall Clow90fc0472014-04-14 15:44:57 +0000572#define _LIBCPP_HAS_NO_ASAN
573#endif
574
Louis Dionne3a197992018-07-27 12:46:03 +0000575#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
576
Louis Dionnefaa17452019-09-04 12:44:19 +0000577#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
578
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000579#elif defined(_LIBCPP_COMPILER_MSVC)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000580
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000581#define _LIBCPP_TOSTRING2(x) #x
582#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
583#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
584
585#if _MSC_VER < 1900
586#error "MSVC versions prior to Visual Studio 2015 are not supported"
587#endif
588
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000589#define __alignof__ __alignof
Richard Smithcabd3922012-07-26 02:04:22 +0000590#define _LIBCPP_NORETURN __declspec(noreturn)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000591#define _ALIGNAS(x) __declspec(align(x))
Eric Fiselier6a537582018-02-07 23:50:25 +0000592#define _ALIGNAS_TYPE(x) alignas(x)
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000593
Logan Chien7b4845e2018-02-24 07:57:32 +0000594#define _LIBCPP_WEAK
595
Marshall Clow90fc0472014-04-14 15:44:57 +0000596#define _LIBCPP_HAS_NO_ASAN
597
Louis Dionne3a197992018-07-27 12:46:03 +0000598#define _LIBCPP_ALWAYS_INLINE __forceinline
599
Tim Shend87ea292018-07-30 22:27:38 +0000600#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
601
Louis Dionnefaa17452019-09-04 12:44:19 +0000602#define _LIBCPP_DISABLE_EXTENSION_WARNING
603
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000604#elif defined(_LIBCPP_COMPILER_IBM)
Howard Hinnantea382952013-08-14 18:00:20 +0000605
606#define _ALIGNAS(x) __attribute__((__aligned__(x)))
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +0000607#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
Howard Hinnantea382952013-08-14 18:00:20 +0000608#define _ATTRIBUTE(x) __attribute__((x))
609#define _LIBCPP_NORETURN __attribute__((noreturn))
610
Howard Hinnantea382952013-08-14 18:00:20 +0000611#define _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantea382952013-08-14 18:00:20 +0000612
613#if defined(_AIX)
614#define __MULTILOCALE_API
615#endif
616
Marshall Clow90fc0472014-04-14 15:44:57 +0000617#define _LIBCPP_HAS_NO_ASAN
618
Louis Dionne3a197992018-07-27 12:46:03 +0000619#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
620
Tim Shend87ea292018-07-30 22:27:38 +0000621#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
622
Louis Dionnefaa17452019-09-04 12:44:19 +0000623#define _LIBCPP_DISABLE_EXTENSION_WARNING
624
Eric Fiselier8fbccea2017-01-06 21:42:58 +0000625#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000627#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
Logan Chien7b4845e2018-02-24 07:57:32 +0000628
Peter Collingbourne725de942018-01-17 04:37:04 +0000629#ifdef _DLL
Logan Chien7b4845e2018-02-24 07:57:32 +0000630# define _LIBCPP_CRT_FUNC __declspec(dllimport)
Peter Collingbourne725de942018-01-17 04:37:04 +0000631#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000632# define _LIBCPP_CRT_FUNC
Peter Collingbourne725de942018-01-17 04:37:04 +0000633#endif
634
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000635#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +0000636# define _LIBCPP_DLL_VIS
637# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
638# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
639# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000640# define _LIBCPP_EXPORTED_FROM_ABI
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000641#elif defined(_LIBCPP_BUILDING_LIBRARY)
Logan Chien7b4845e2018-02-24 07:57:32 +0000642# define _LIBCPP_DLL_VIS __declspec(dllexport)
Martin Storsjobd254492019-04-25 19:46:28 +0000643# if defined(__MINGW32__)
644# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
645# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
646# else
647# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
648# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
649# endif
Logan Chien7b4845e2018-02-24 07:57:32 +0000650# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000651# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000652#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000653# define _LIBCPP_DLL_VIS __declspec(dllimport)
654# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
655# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
656# define _LIBCPP_OVERRIDABLE_FUNC_VIS
Louis Dionne5254b372018-10-25 12:13:43 +0000657# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000658#endif
Eric Fiselier51e8d2f2016-09-26 22:19:41 +0000659
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000660#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
661#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
662#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000663#define _LIBCPP_HIDDEN
Shoaib Meenai69c57412017-03-02 03:02:50 +0000664#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000665#define _LIBCPP_TEMPLATE_VIS
Martin Storsjö88890c22021-02-22 01:13:13 +0200666#define _LIBCPP_TEMPLATE_DATA_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000667#define _LIBCPP_ENUM_VIS
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000668
Saleem Abdulrasoolee302e42017-01-03 21:53:51 +0000669#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000670
671#ifndef _LIBCPP_HIDDEN
Logan Chien7b4845e2018-02-24 07:57:32 +0000672# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
673# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
674# else
675# define _LIBCPP_HIDDEN
676# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000677#endif
678
Shoaib Meenai5331f492017-03-09 00:18:00 +0000679#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000680# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000681// The inline should be removed once PR32114 is resolved
Logan Chien7b4845e2018-02-24 07:57:32 +0000682# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
683# else
684# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
685# endif
Shoaib Meenai5331f492017-03-09 00:18:00 +0000686#endif
Shoaib Meenai69c57412017-03-02 03:02:50 +0000687
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000688#ifndef _LIBCPP_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000689# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
690# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
691# else
692# define _LIBCPP_FUNC_VIS
693# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000694#endif
695
696#ifndef _LIBCPP_TYPE_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000697# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000698# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000699# else
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000700# define _LIBCPP_TYPE_VIS
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000701# endif
702#endif
703
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000704#ifndef _LIBCPP_TEMPLATE_VIS
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000705# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
706# if __has_attribute(__type_visibility__)
707# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
708# else
709# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
710# endif
711# else
712# define _LIBCPP_TEMPLATE_VIS
713# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000714#endif
715
Martin Storsjö88890c22021-02-22 01:13:13 +0200716#ifndef _LIBCPP_TEMPLATE_DATA_VIS
717# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
718# define _LIBCPP_TEMPLATE_DATA_VIS __attribute__ ((__visibility__("default")))
719# else
720# define _LIBCPP_TEMPLATE_DATA_VIS
721# endif
722#endif
723
Louis Dionne5254b372018-10-25 12:13:43 +0000724#ifndef _LIBCPP_EXPORTED_FROM_ABI
Thomas Andersone13df2b2018-12-13 20:06:14 +0000725# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
726# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
727# else
728# define _LIBCPP_EXPORTED_FROM_ABI
729# endif
Eric Fiselier99505072017-01-16 21:01:00 +0000730#endif
731
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000732#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000733#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
Shoaib Meenai2d71db42016-11-16 22:18:10 +0000734#endif
735
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000736#ifndef _LIBCPP_EXCEPTION_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000737# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
738# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
739# else
740# define _LIBCPP_EXCEPTION_ABI
741# endif
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000742#endif
743
744#ifndef _LIBCPP_ENUM_VIS
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000745# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000746# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
747# else
748# define _LIBCPP_ENUM_VIS
749# endif
750#endif
751
752#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
Shoaib Meenai491802e2021-01-12 10:29:03 -0800753# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Shoaib Meenai69c57412017-03-02 03:02:50 +0000754# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000755# else
756# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
757# endif
758#endif
759
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000760#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Logan Chien7b4845e2018-02-24 07:57:32 +0000761#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
Shoaib Meenai5ac10672016-09-19 18:29:07 +0000762#endif
763
Louis Dionne3a197992018-07-27 12:46:03 +0000764#if __has_attribute(internal_linkage)
765# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
766#else
767# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000768#endif
769
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000770#if __has_attribute(exclude_from_explicit_instantiation)
771# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
772#else
773 // Try to approximate the effect of exclude_from_explicit_instantiation
774 // (which is that entities are not assumed to be provided by explicit
Louis Dionnea8548af2019-03-20 17:05:52 +0000775 // template instantiations in the dylib) by always inlining those entities.
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000776# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
777#endif
778
Louis Dionne1821de42018-08-16 12:44:28 +0000779#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
780# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
781# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
782# else
783# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
784# endif
785#endif
786
Louis Dionne3a197992018-07-27 12:46:03 +0000787#ifndef _LIBCPP_HIDE_FROM_ABI
Louis Dionne1821de42018-08-16 12:44:28 +0000788# if _LIBCPP_HIDE_FROM_ABI_PER_TU
789# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
790# else
Louis Dionne3b8a03f2018-10-29 17:30:04 +0000791# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
Louis Dionne1821de42018-08-16 12:44:28 +0000792# endif
Louis Dionne3a197992018-07-27 12:46:03 +0000793#endif
794
Louis Dionned797b8d2018-08-06 14:11:50 +0000795#ifdef _LIBCPP_BUILDING_LIBRARY
796# if _LIBCPP_ABI_VERSION > 1
797# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Logan Chien7b4845e2018-02-24 07:57:32 +0000798# else
Louis Dionned797b8d2018-08-06 14:11:50 +0000799# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
Logan Chien7b4845e2018-02-24 07:57:32 +0000800# endif
Louis Dionned797b8d2018-08-06 14:11:50 +0000801#else
802# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
Eric Fiselier815ed732016-09-16 00:00:48 +0000803#endif
804
Louis Dionned797b8d2018-08-06 14:11:50 +0000805// Just so we can migrate to the new macros gradually.
806#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
Louis Dionned797b8d2018-08-06 14:11:50 +0000807
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000808// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000809#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000810#define _LIBCPP_END_NAMESPACE_STD } }
Eric Fiselierb33778a2018-10-30 21:44:53 +0000811#define _VSTD std::_LIBCPP_ABI_NAMESPACE
Eric Fiselierb9d04dc2018-10-30 02:02:00 +0000812_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
813
814#if _LIBCPP_STD_VER >= 17
815#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
816 _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
817#else
818#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
819 _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
820#endif
821
822#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
823 _LIBCPP_END_NAMESPACE_STD } }
824
825#define _VSTD_FS _VSTD::__fs::filesystem
826
Louis Dionne93f1fd72021-06-04 13:31:22 -0400827#if __has_attribute(__enable_if__)
828# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000829#endif
830
Eric Fiselier1af87ca2015-12-15 22:16:47 +0000831#ifndef _LIBCPP_HAS_NO_NOEXCEPT
832# define _NOEXCEPT noexcept
833# define _NOEXCEPT_(x) noexcept(x)
834#else
835# define _NOEXCEPT throw()
836# define _NOEXCEPT_(x)
837#endif
838
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantaa87c0f2010-08-10 20:48:29 +0000840typedef unsigned short char16_t;
841typedef unsigned int char32_t;
Louis Dionne96fc5f52021-09-09 11:25:10 -0400842#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843
Stephan Tolksdorf0efeb6c2014-03-26 19:45:52 +0000844#ifndef __SIZEOF_INT128__
845#define _LIBCPP_HAS_NO_INT128
846#endif
847
Eric Fiselierc6f17cc2016-09-25 03:34:28 +0000848#ifdef _LIBCPP_CXX03_LANG
Eric Fiselier2f05ab92019-06-18 20:50:25 +0000849# define static_assert(...) _Static_assert(__VA_ARGS__)
850# define decltype(...) __decltype(__VA_ARGS__)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400851#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Eric Fiselier605af612019-06-21 13:56:13 +0000853#ifdef _LIBCPP_CXX03_LANG
Logan Chien7b4845e2018-02-24 07:57:32 +0000854# define _LIBCPP_CONSTEXPR
Howard Hinnant664183b2012-04-02 00:40:41 +0000855#else
Logan Chien7b4845e2018-02-24 07:57:32 +0000856# define _LIBCPP_CONSTEXPR constexpr
Howard Hinnant62c8c0b2010-09-06 19:10:31 +0000857#endif
858
Richard Smith55a75c82020-07-31 15:03:21 -0700859#ifndef __cpp_consteval
860# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR
861#else
862# define _LIBCPP_CONSTEVAL consteval
863#endif
864
Mark de Wever1d4140e2021-02-20 09:13:16 +0100865#if !defined(__cpp_concepts) || __cpp_concepts < 201907L
866#define _LIBCPP_HAS_NO_CONCEPTS
867#endif
868
Martin Storsjö4f646c02021-04-30 13:57:37 +0300869#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_HAS_NO_CONCEPTS)
Christopher Di Bella490fe402021-03-23 03:55:52 +0000870#define _LIBCPP_HAS_NO_RANGES
871#endif
872
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000873#ifdef __GNUC__
Louis Dionnee147b352019-02-26 06:34:42 +0000874# define _LIBCPP_NOALIAS __attribute__((__malloc__))
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000875#else
Louis Dionnee147b352019-02-26 06:34:42 +0000876# define _LIBCPP_NOALIAS
Nuno Lopes22df2dc2012-06-28 16:47:34 +0000877#endif
878
Louis Dionne9c660c62021-06-02 10:41:37 -0400879#if __has_attribute(using_if_exists)
880# define _LIBCPP_USING_IF_EXISTS __attribute__((using_if_exists))
881#else
882# define _LIBCPP_USING_IF_EXISTS
883#endif
884
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000885#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000886# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
887# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
888 __lx __v_; \
Louis Dionne16fe2952018-07-11 23:14:33 +0000889 _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
890 _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
891 _LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
Logan Chien7b4845e2018-02-24 07:57:32 +0000892 };
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000893#else // _LIBCPP_HAS_NO_STRONG_ENUMS
Logan Chien7b4845e2018-02-24 07:57:32 +0000894# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
895# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400896#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnant09bc0c92011-12-02 19:36:40 +0000897
Louis Dionneba400782020-10-02 15:02:52 -0400898// _LIBCPP_DEBUG potential values:
899// - undefined: No assertions. This is the default.
900// - 0: Basic assertions
Danila Kutenina9cbea12021-11-16 15:48:59 -0500901// - 1: Basic assertions + iterator validity checks + unspecified behavior randomization.
902# if !defined(_LIBCPP_DEBUG)
903# define _LIBCPP_DEBUG_LEVEL 0
904# elif _LIBCPP_DEBUG == 0
905# define _LIBCPP_DEBUG_LEVEL 1
906# elif _LIBCPP_DEBUG == 1
907# define _LIBCPP_DEBUG_LEVEL 2
908# else
909# error Supported values for _LIBCPP_DEBUG are 0 and 1
910# endif
911
912# if _LIBCPP_DEBUG_LEVEL >= 2 && !defined(_LIBCPP_CXX03_LANG)
913# define _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY
914# endif
915
916# if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
917# if defined(_LIBCPP_CXX03_LANG)
918# error Support for unspecified stability is only for C++11 and higher
919# endif
920# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
921 do { \
922 if (!__builtin_is_constant_evaluated()) \
923 _VSTD::shuffle(__first, __last, __libcpp_debug_randomizer()); \
924 } while (false)
925# else
926# define _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last) \
927 do { \
928 } while (false)
929# endif
Howard Hinnant8ea98242013-08-23 17:37:05 +0000930
Louis Dionne732192e2021-06-09 09:41:27 -0400931// Libc++ allows disabling extern template instantiation declarations by
932// means of users defining _LIBCPP_DISABLE_EXTERN_TEMPLATE.
933//
934// Furthermore, when the Debug mode is enabled, we disable extern declarations
935// when building user code because we don't want to use the functions compiled
936// in the library, which might not have had the debug mode enabled when built.
937// However, some extern declarations need to be used, because code correctness
938// depends on it (several instances in <locale>). Those special declarations
939// are declared with _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE, which is enabled
940// even when the debug mode is enabled.
941#if defined(_LIBCPP_DISABLE_EXTERN_TEMPLATE)
942# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
943# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) /* nothing */
944#elif _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_BUILDING_LIBRARY)
945# define _LIBCPP_EXTERN_TEMPLATE(...) /* nothing */
946# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
947#else
948# define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
949# define _LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(...) extern template __VA_ARGS__;
Eric Fiselier510690e2019-12-13 15:42:07 -0500950#endif
951
Martin Storsjo5482ac62017-11-23 10:38:18 +0000952#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
Louis Dionne59426ee2021-08-24 11:40:05 -0400953 defined(__sun__) || defined(__NetBSD__)
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000954#define _LIBCPP_LOCALE__L_EXTENSIONS 1
955#endif
Yaron Keren804da952013-12-20 13:19:45 +0000956
Marshall Clow82378c02013-03-18 19:34:07 +0000957#ifdef __FreeBSD__
David Chisnall6ae8f352011-11-13 17:15:33 +0000958#define _DECLARE_C99_LDBL_MATH 1
959#endif
Alexis Hunt1adf2aa2011-07-15 05:40:33 +0000960
Reid Kleckner85c65e62018-04-19 22:12:10 +0000961// If we are getting operator new from the MSVC CRT, then allocation overloads
962// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
963#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
Louis Dionne2e206ca2018-12-17 22:22:44 +0000964# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Eric Fiselier85f66332019-03-05 01:57:01 +0000965#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
Louis Dionnea8548af2019-03-20 17:05:52 +0000966 // We're deferring to Microsoft's STL to provide aligned new et al. We don't
Thomas Andersone0439182019-01-30 19:08:32 +0000967 // have it unless the language feature test macro is defined.
968# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Zbigniew Sarbinowski001f5d02020-11-12 14:40:35 -0500969#elif defined(__MVS__)
970# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
Reid Kleckner85c65e62018-04-19 22:12:10 +0000971#endif
972
Louis Dionne93f1fd72021-06-04 13:31:22 -0400973#if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
974 (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
Louis Dionnee5aafbf2018-08-10 13:24:56 +0000975# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
976#endif
Eric Fiselier06548ab2018-03-22 04:42:56 +0000977
Marshall Clow82378c02013-03-18 19:34:07 +0000978#if defined(__APPLE__) || defined(__FreeBSD__)
Howard Hinnantf312e3e2011-09-28 23:39:33 +0000979#define _LIBCPP_HAS_DEFAULTRUNELOCALE
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000980#endif
981
Marshall Clow82378c02013-03-18 19:34:07 +0000982#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
Alexis Huntc2017f12011-07-09 03:40:04 +0000983#define _LIBCPP_WCTYPE_IS_MASK
984#endif
985
Marshall Clow8732fed2018-12-11 04:35:44 +0000986#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400987#define _LIBCPP_HAS_NO_CHAR8_T
Marshall Clow8732fed2018-12-11 04:35:44 +0000988#endif
989
Louis Dionne481a2662018-09-23 18:35:00 +0000990// Deprecation macros.
Louis Dionneded5b772019-03-12 20:10:06 +0000991//
992// Deprecations warnings are always enabled, except when users explicitly opt-out
993// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
994#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
Louis Dionne481a2662018-09-23 18:35:00 +0000995# if __has_attribute(deprecated)
996# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
997# elif _LIBCPP_STD_VER > 11
998# define _LIBCPP_DEPRECATED [[deprecated]]
999# else
1000# define _LIBCPP_DEPRECATED
1001# endif
Marshall Clowa2cbe0d2013-09-28 18:35:31 +00001002#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001003# define _LIBCPP_DEPRECATED
Marshall Clowa2cbe0d2013-09-28 18:35:31 +00001004#endif
1005
Louis Dionne481a2662018-09-23 18:35:00 +00001006#if !defined(_LIBCPP_CXX03_LANG)
1007# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
1008#else
1009# define _LIBCPP_DEPRECATED_IN_CXX11
1010#endif
1011
1012#if _LIBCPP_STD_VER >= 14
1013# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
1014#else
1015# define _LIBCPP_DEPRECATED_IN_CXX14
1016#endif
1017
1018#if _LIBCPP_STD_VER >= 17
1019# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
1020#else
1021# define _LIBCPP_DEPRECATED_IN_CXX17
1022#endif
1023
Marek Kurdejc9848142020-11-26 10:07:16 +01001024#if _LIBCPP_STD_VER > 17
1025# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
1026#else
1027# define _LIBCPP_DEPRECATED_IN_CXX20
1028#endif
1029
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001030#if !defined(_LIBCPP_HAS_NO_CHAR8_T)
Martin Storsjöe3a71972020-10-26 13:18:46 +02001031# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
1032#else
1033# define _LIBCPP_DEPRECATED_WITH_CHAR8_T
1034#endif
1035
Richard Smithbfc256b2019-10-19 00:06:00 +00001036// Macros to enter and leave a state where deprecation warnings are suppressed.
Louis Dionne93f1fd72021-06-04 13:31:22 -04001037#if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
1038# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
1039 _Pragma("GCC diagnostic push") \
Louis Dionneaf6be622021-07-27 17:30:47 -04001040 _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
1041 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
Louis Dionne93f1fd72021-06-04 13:31:22 -04001042# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
1043 _Pragma("GCC diagnostic pop")
1044#else
1045# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1046# define _LIBCPP_SUPPRESS_DEPRECATED_POP
Richard Smithbfc256b2019-10-19 00:06:00 +00001047#endif
1048
Marshall Clow1045cee2013-07-15 14:57:19 +00001049#if _LIBCPP_STD_VER <= 11
Logan Chien7b4845e2018-02-24 07:57:32 +00001050# define _LIBCPP_EXPLICIT_AFTER_CXX11
Marshall Clow1045cee2013-07-15 14:57:19 +00001051#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001052# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
Marshall Clow1045cee2013-07-15 14:57:19 +00001053#endif
1054
Louis Dionnee3594f12021-08-24 11:58:36 -04001055#if _LIBCPP_STD_VER > 11
Logan Chien7b4845e2018-02-24 07:57:32 +00001056# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001057#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001058# define _LIBCPP_CONSTEXPR_AFTER_CXX11
Eric Fiselierb4c0c662014-07-17 05:16:18 +00001059#endif
1060
Louis Dionnee3594f12021-08-24 11:58:36 -04001061#if _LIBCPP_STD_VER > 14
Logan Chien7b4845e2018-02-24 07:57:32 +00001062# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001063#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001064# define _LIBCPP_CONSTEXPR_AFTER_CXX14
Eric Fiselier0b3bfbe2016-03-17 03:30:56 +00001065#endif
1066
Louis Dionnee3594f12021-08-24 11:58:36 -04001067#if _LIBCPP_STD_VER > 17
Logan Chien7b4845e2018-02-24 07:57:32 +00001068# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
Marshall Clow2a5c4212017-11-14 22:26:50 +00001069#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001070# define _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001071#endif
1072
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001073#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
Louis Dionne91182922021-08-30 16:01:38 -04001074# define _LIBCPP_NODISCARD [[nodiscard]]
Marek Kurdejf3197922021-04-01 08:29:55 +02001075#elif defined(_LIBCPP_COMPILER_CLANG_BASED) && !defined(_LIBCPP_CXX03_LANG)
Louis Dionne91182922021-08-30 16:01:38 -04001076# define _LIBCPP_NODISCARD [[clang::warn_unused_result]]
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001077#else
1078// We can't use GCC's [[gnu::warn_unused_result]] and
1079// __attribute__((warn_unused_result)), because GCC does not silence them via
1080// (void) cast.
Louis Dionne91182922021-08-30 16:01:38 -04001081# define _LIBCPP_NODISCARD
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001082#endif
1083
1084// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1085// specified as such as an extension.
1086#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
Louis Dionne91182922021-08-30 16:01:38 -04001087# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
Roman Lebedevb5959fa2018-09-22 17:54:48 +00001088#else
1089# define _LIBCPP_NODISCARD_EXT
1090#endif
1091
1092#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
1093 (_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
Louis Dionne91182922021-08-30 16:01:38 -04001094# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
Marshall Clow2a5c4212017-11-14 22:26:50 +00001095#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001096# define _LIBCPP_NODISCARD_AFTER_CXX17
Marshall Clow2a5c4212017-11-14 22:26:50 +00001097#endif
1098
Louis Dionnea39f1ef2019-04-17 18:20:19 +00001099#if __has_attribute(no_destroy)
1100# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1101#else
1102# define _LIBCPP_NO_DESTROY
1103#endif
1104
Marshall Clow2cd9d372014-05-08 14:14:06 +00001105#ifndef _LIBCPP_HAS_NO_ASAN
Azat Khuzhincdfb87f2020-12-17 16:19:50 -05001106extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
Marshall Clow2cd9d372014-05-08 14:14:06 +00001107 const void *, const void *, const void *, const void *);
1108#endif
1109
Howard Hinnant13087882013-10-04 21:24:21 +00001110// Try to find out if RTTI is disabled.
Marek Kurdejf3197922021-04-01 08:29:55 +02001111#if defined(_LIBCPP_COMPILER_CLANG_BASED) && !__has_feature(cxx_rtti)
Louis Dionneef0c6622020-07-14 16:28:41 -04001112# define _LIBCPP_NO_RTTI
1113#elif defined(__GNUC__) && !defined(__GXX_RTTI)
1114# define _LIBCPP_NO_RTTI
1115#elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
1116# define _LIBCPP_NO_RTTI
Howard Hinnant13087882013-10-04 21:24:21 +00001117#endif
1118
Howard Hinnant33f04722013-10-04 23:56:37 +00001119#ifndef _LIBCPP_WEAK
Logan Chien7b4845e2018-02-24 07:57:32 +00001120#define _LIBCPP_WEAK __attribute__((__weak__))
Howard Hinnant33f04722013-10-04 23:56:37 +00001121#endif
1122
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001123// Thread API
Eric Fiselierbfd45532017-01-06 23:15:16 +00001124#if !defined(_LIBCPP_HAS_NO_THREADS) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001125 !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
Eric Fiselierd8a6c892017-05-10 21:34:58 +00001126 !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
Asiri Rathnayakec07f0be2017-02-27 16:10:57 +00001127 !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001128# if defined(__FreeBSD__) || \
Dan Gohman280fd6b2019-05-01 16:47:30 +00001129 defined(__wasi__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001130 defined(__NetBSD__) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001131 defined(__OpenBSD__) || \
Xiang Xiao85529232020-11-18 16:16:18 -05001132 defined(__NuttX__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001133 defined(__linux__) || \
Louis Dionne3cfcaeb2018-11-20 21:14:05 +00001134 defined(__GNU__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001135 defined(__APPLE__) || \
Logan Chien7b4845e2018-02-24 07:57:32 +00001136 defined(__sun__) || \
Zbigniew Sarbinowskica6367d2020-12-05 00:13:23 +00001137 defined(__MVS__) || \
Martin Storsjöc86337b2021-10-01 23:44:17 +03001138 defined(_AIX)
Logan Chien7b4845e2018-02-24 07:57:32 +00001139# define _LIBCPP_HAS_THREAD_API_PTHREAD
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001140# elif defined(__Fuchsia__)
Petr Hoseke6ad6e42020-01-16 12:12:38 -08001141 // TODO(44575): Switch to C11 thread API when possible.
1142# define _LIBCPP_HAS_THREAD_API_PTHREAD
Logan Chien7b4845e2018-02-24 07:57:32 +00001143# elif defined(_LIBCPP_WIN32API)
1144# define _LIBCPP_HAS_THREAD_API_WIN32
1145# else
1146# error "No thread API"
1147# endif // _LIBCPP_HAS_THREAD_API
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001148#endif // _LIBCPP_HAS_NO_THREADS
1149
Dan Albertad293012019-09-18 18:13:32 +00001150#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
1151#if defined(__ANDROID__) && __ANDROID_API__ >= 30
1152#define _LIBCPP_HAS_COND_CLOCKWAIT
1153#elif defined(_LIBCPP_GLIBC_PREREQ)
1154#if _LIBCPP_GLIBC_PREREQ(2, 30)
1155#define _LIBCPP_HAS_COND_CLOCKWAIT
1156#endif
1157#endif
1158#endif
1159
Ben Craig5593c4f2016-05-25 17:40:09 +00001160#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
Logan Chien7b4845e2018-02-24 07:57:32 +00001161#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
1162 _LIBCPP_HAS_NO_THREADS is not defined.
Ben Craig5593c4f2016-05-25 17:40:09 +00001163#endif
Asiri Rathnayakefa2e2032016-05-06 14:06:29 +00001164
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001165#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
Logan Chien7b4845e2018-02-24 07:57:32 +00001166#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
1167 _LIBCPP_HAS_NO_THREADS is defined.
Asiri Rathnayake94340d22016-09-11 21:46:40 +00001168#endif
1169
Eric Fiselier715b4162014-12-06 20:09:11 +00001170#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001171#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
1172 _LIBCPP_HAS_NO_THREADS is defined.
Eric Fiselier715b4162014-12-06 20:09:11 +00001173#endif
1174
Nico Weber6b58e1d2019-07-30 14:32:47 +00001175#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
1176#define __STDCPP_THREADS__ 1
1177#endif
1178
Louis Dionne66c58fd2019-07-25 20:29:20 +00001179// The glibc and Bionic implementation of pthreads implements
Eric Fiselier256466e2019-07-07 17:24:03 +00001180// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
1181// mutexes have no destroy mechanism.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001182//
1183// This optimization can't be performed on Apple platforms, where
1184// pthread_mutex_destroy can allow the kernel to release resources.
1185// See https://llvm.org/D64298 for details.
1186//
1187// TODO(EricWF): Enable this optimization on Bionic after speaking to their
1188// respective stakeholders.
Eric Fiselier256466e2019-07-07 17:24:03 +00001189#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001190 || (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) \
Eric Fiselier256466e2019-07-07 17:24:03 +00001191 || defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselierf6dac862019-07-07 01:20:54 +00001192# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
1193#endif
1194
Eric Fiselier256466e2019-07-07 17:24:03 +00001195// Destroying a condvar is a nop on Windows.
Louis Dionne66c58fd2019-07-25 20:29:20 +00001196//
1197// This optimization can't be performed on Apple platforms, where
1198// pthread_cond_destroy can allow the kernel to release resources.
1199// See https://llvm.org/D64298 for details.
1200//
Eric Fiselier256466e2019-07-07 17:24:03 +00001201// TODO(EricWF): This is potentially true for some pthread implementations
1202// as well.
Petr Hosekd0e7fe42019-12-04 10:38:22 -08001203#if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
1204 defined(_LIBCPP_HAS_THREAD_API_WIN32)
Eric Fiselier256466e2019-07-07 17:24:03 +00001205# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
1206#endif
1207
Dimitry Andric2e72c802019-09-07 22:18:20 +00001208// Some systems do not provide gets() in their C library, for security reasons.
Louis Dionne93f1fd72021-06-04 13:31:22 -04001209#if defined(_LIBCPP_MSVCRT) || \
1210 (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || \
1211 defined(__OpenBSD__)
1212# define _LIBCPP_C_HAS_NO_GETS
Dimitry Andric2e72c802019-09-07 22:18:20 +00001213#endif
1214
Louis Dionne59426ee2021-08-24 11:40:05 -04001215#if defined(__BIONIC__) || defined(__NuttX__) || \
Muiez Ahmedaf108fb2020-11-10 09:54:03 -05001216 defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) || \
Brad Smithf6f55092021-01-12 14:16:15 -05001217 defined(__MVS__) || defined(__OpenBSD__)
Dan Albertebdf28b2015-03-11 00:51:06 +00001218#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1219#endif
1220
Eric Fiselierba725072017-01-14 04:27:58 +00001221#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
Logan Chien7b4845e2018-02-24 07:57:32 +00001222# define _LIBCPP_HAS_C_ATOMIC_IMP
Richard Smithca47d0f2019-04-25 20:02:10 +00001223#elif defined(_LIBCPP_COMPILER_GCC)
Logan Chien7b4845e2018-02-24 07:57:32 +00001224# define _LIBCPP_HAS_GCC_ATOMIC_IMP
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001225#endif
1226
Louis Dionneaf2d2a82021-11-17 10:59:31 -05001227#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
1228 !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
1229 !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
Davide Italiano011f80a2019-03-05 18:40:49 +00001230# define _LIBCPP_HAS_NO_ATOMIC_HEADER
1231#else
1232# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
1233# define _LIBCPP_ATOMIC_FLAG_TYPE bool
1234# endif
1235# ifdef _LIBCPP_FREESTANDING
1236# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
1237# endif
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001238#endif
1239
Marshall Clow91c7f642016-01-11 19:27:10 +00001240#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1241#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Eric Fiselier100e24b2016-02-11 11:59:44 +00001242#endif
1243
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001244#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001245# if defined(__clang__) && __has_attribute(acquire_capability)
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001246// Work around the attribute handling in clang. When both __declspec and
1247// __attribute__ are present, the processing goes awry preventing the definition
1248// of the types.
Logan Chien7b4845e2018-02-24 07:57:32 +00001249# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
1250# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1251# endif
1252# endif
Saleem Abdulrasoolb82f9602017-02-13 15:26:51 +00001253#endif
Eric Fiselierc0c6c982016-03-16 02:30:06 +00001254
Louis Dionne93f1fd72021-06-04 13:31:22 -04001255#ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
1256# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
1257#else
1258# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
1259#endif
Eric Fiselier510690e2019-12-13 15:42:07 -05001260
Eric Fiselier0d3da632016-09-03 00:11:33 +00001261#if __has_attribute(require_constant_initialization)
Logan Chien7b4845e2018-02-24 07:57:32 +00001262# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
Eric Fiselier0d3da632016-09-03 00:11:33 +00001263#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001264# define _LIBCPP_SAFE_STATIC
Eric Fiselier0d3da632016-09-03 00:11:33 +00001265#endif
1266
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001267#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001268# define _LIBCPP_DIAGNOSE_WARNING(...) \
1269 __attribute__((diagnose_if(__VA_ARGS__, "warning")))
1270# define _LIBCPP_DIAGNOSE_ERROR(...) \
1271 __attribute__((diagnose_if(__VA_ARGS__, "error")))
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001272#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001273# define _LIBCPP_DIAGNOSE_WARNING(...)
1274# define _LIBCPP_DIAGNOSE_ERROR(...)
Eric Fiseliera7a14ed2017-01-13 22:02:08 +00001275#endif
1276
Eric Fiselier4db80032017-05-05 20:32:26 +00001277// Use a function like macro to imply that it must be followed by a semicolon
Reid Kleckner75d4e002018-11-01 18:24:03 +00001278#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
1279# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1280#elif __has_cpp_attribute(clang::fallthrough)
1281# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
Louis Dionne3e0c4332021-08-31 10:49:06 -04001282#elif __has_attribute(__fallthrough__)
Logan Chien7b4845e2018-02-24 07:57:32 +00001283# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
Eric Fiselier4db80032017-05-05 20:32:26 +00001284#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001285# define _LIBCPP_FALLTHROUGH() ((void)0)
Eric Fiselier4db80032017-05-05 20:32:26 +00001286#endif
1287
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001288#if __has_attribute(__nodebug__)
1289#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
Eric Fiselier74ebee62019-06-08 01:31:19 +00001290#else
1291#define _LIBCPP_NODEBUG
1292#endif
1293
Amy Huang63f53b52021-03-15 14:20:49 -07001294#if __has_attribute(__standalone_debug__)
1295#define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1296#else
1297#define _LIBCPP_STANDALONE_DEBUG
1298#endif
1299
Richard Smith256954d2020-11-11 17:12:18 -08001300#if __has_attribute(__preferred_name__)
1301#define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1302#else
1303#define _LIBCPP_PREFERRED_NAME(x)
1304#endif
1305
Louis Dionne89258142021-08-23 15:32:36 -04001306// We often repeat things just for handling wide characters in the library.
1307// When wide characters are disabled, it can be useful to have a quick way of
1308// disabling it without having to resort to #if-#endif, which has a larger
1309// impact on readability.
1310#if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
1311# define _LIBCPP_IF_WIDE_CHARACTERS(...)
1312#else
1313# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
1314#endif
1315
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001316#if defined(_LIBCPP_ABI_MICROSOFT) && \
Logan Chien7b4845e2018-02-24 07:57:32 +00001317 (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
1318# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001319#else
Logan Chien7b4845e2018-02-24 07:57:32 +00001320# define _LIBCPP_DECLSPEC_EMPTY_BASES
Eric Fiseliere3cec5f2017-01-16 21:15:08 +00001321#endif
1322
Eric Fiselierddd77792017-02-17 03:25:08 +00001323#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
Logan Chien7b4845e2018-02-24 07:57:32 +00001324#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
Logan Chien7b4845e2018-02-24 07:57:32 +00001325#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001326#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
1327#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
Eric Fiselierddd77792017-02-17 03:25:08 +00001328#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
1329
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001330#if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
1331#define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001332#define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001333#define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
1334#define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
wmbatf5b33762021-07-02 17:08:36 +00001335#define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001336#endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
1337
Chuanqi Xu6fdf6192021-11-16 14:05:34 +08001338#if !defined(__cpp_impl_coroutine) || __cpp_impl_coroutine < 201902L
1339#define _LIBCPP_HAS_NO_CXX20_COROUTINES
Eric Fiselier40b66222017-05-26 01:52:59 +00001340#endif
1341
Eric Fiselierf4433a32017-05-31 22:07:49 +00001342#if defined(_LIBCPP_COMPILER_IBM)
1343#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
1344#endif
1345
1346#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
Logan Chien7b4845e2018-02-24 07:57:32 +00001347# define _LIBCPP_PUSH_MACROS
1348# define _LIBCPP_POP_MACROS
Eric Fiselierf4433a32017-05-31 22:07:49 +00001349#else
1350 // Don't warn about macro conflicts when we can restore them at the
1351 // end of the header.
Logan Chien7b4845e2018-02-24 07:57:32 +00001352# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1353# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
1354# endif
1355# if defined(_LIBCPP_COMPILER_MSVC)
1356# define _LIBCPP_PUSH_MACROS \
1357 __pragma(push_macro("min")) \
1358 __pragma(push_macro("max"))
1359# define _LIBCPP_POP_MACROS \
1360 __pragma(pop_macro("min")) \
1361 __pragma(pop_macro("max"))
1362# else
1363# define _LIBCPP_PUSH_MACROS \
1364 _Pragma("push_macro(\"min\")") \
1365 _Pragma("push_macro(\"max\")")
1366# define _LIBCPP_POP_MACROS \
1367 _Pragma("pop_macro(\"min\")") \
1368 _Pragma("pop_macro(\"max\")")
1369# endif
Eric Fiselierf4433a32017-05-31 22:07:49 +00001370#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
1371
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001372#ifndef _LIBCPP_NO_AUTO_LINK
Logan Chien7b4845e2018-02-24 07:57:32 +00001373# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Martin Storsjö57db41b2021-04-15 11:16:28 +03001374# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
Logan Chien7b4845e2018-02-24 07:57:32 +00001375# pragma comment(lib, "c++.lib")
1376# else
1377# pragma comment(lib, "libc++.lib")
1378# endif
1379# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
Peter Collingbourne1aa99c52018-01-24 04:30:19 +00001380#endif // _LIBCPP_NO_AUTO_LINK
Eric Fiselier911dcad2017-06-16 01:57:41 +00001381
Dan Albert9550df62019-09-16 19:26:41 +00001382// Configures the fopen close-on-exec mode character, if any. This string will
1383// be appended to any mode string used by fstream for fopen/fdopen.
1384//
1385// Not all platforms support this, but it helps avoid fd-leaks on platforms that
1386// do.
1387#if defined(__BIONIC__)
1388# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
1389#else
1390# define _LIBCPP_FOPEN_CLOEXEC_MODE
1391#endif
1392
Dan Albert073008c2020-03-12 11:16:30 -07001393// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
1394// of functions used in cstdio may not be available for low API levels when
1395// using 64-bit file offsets on LP32.
1396#if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
1397#define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
1398#endif
1399
Zbigniew Sarbinowski4536ef42020-11-20 14:46:21 -05001400#if __has_attribute(init_priority)
Louis Dionne1f14cea2021-02-03 16:25:06 -05001401 // TODO: Remove this once we drop support for building libc++ with old Clangs
1402# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \
1403 (defined(__apple_build_version__) && __apple_build_version__ < 13000000)
1404# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101)))
1405# else
1406# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100)))
1407# endif
Zbigniew Sarbinowski4536ef42020-11-20 14:46:21 -05001408#else
1409# define _LIBCPP_INIT_PRIORITY_MAX
1410#endif
1411
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001412#if defined(__GNUC__) || defined(__clang__)
Louis Dionnee1ad4572021-11-16 15:22:10 -05001413 // The attribute uses 1-based indices for ordinary and static member functions.
1414 // The attribute uses 2-based indices for non-static member functions.
1415# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1416 __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001417#else
Louis Dionnee1ad4572021-11-16 15:22:10 -05001418# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
Arthur O'Dwyer4cbc3232021-03-05 20:13:35 -05001419#endif
1420
Eric Fiselier911dcad2017-06-16 01:57:41 +00001421#endif // __cplusplus
1422
Eric Fiselier8020b6c2015-08-19 17:21:46 +00001423#endif // _LIBCPP_CONFIG