__config 52 KB

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