__config 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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 <__config_site>
  12. #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
  13. # pragma GCC system_header
  14. #endif
  15. #if defined(__apple_build_version__)
  16. // Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403)
  17. # define _LIBCPP_COMPILER_CLANG_BASED
  18. # define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
  19. #elif defined(__clang__)
  20. # define _LIBCPP_COMPILER_CLANG_BASED
  21. # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
  22. #elif defined(__GNUC__)
  23. # define _LIBCPP_COMPILER_GCC
  24. # define _LIBCPP_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
  25. #endif
  26. // Move outside #ifdef __cplusplus because this needs to work in both C and C++ headers.
  27. #if defined(__apple_build_version__)
  28. # define _LIBCPP_COMPILER_CLANG_BASED
  29. # define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000)
  30. #elif defined(__clang__)
  31. # define _LIBCPP_COMPILER_CLANG
  32. # define _LIBCPP_COMPILER_CLANG_BASED
  33. # define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
  34. #elif defined(__GNUC__)
  35. # define _LIBCPP_COMPILER_GCC
  36. #elif defined(_MSC_VER)
  37. # define _LIBCPP_COMPILER_MSVC
  38. # if _MSVC_LANG == 201705L
  39. # define _LIBCPP_STD_VER 20
  40. # elif _MSVC_LANG == 201703L
  41. # define _LIBCPP_STD_VER 17
  42. # else
  43. # define _LIBCPP_STD_VER 14
  44. # endif
  45. #endif
  46. #ifdef __cplusplus
  47. // Warn if a compiler version is used that is not supported anymore
  48. // LLVM RELEASE Update the minimum compiler versions
  49. # if defined(_LIBCPP_CLANG_VER)
  50. # if _LIBCPP_CLANG_VER < 1500
  51. // we temporary allow old clang-s # warning "Libc++ only supports Clang 15 and later"
  52. # endif
  53. # elif defined(_LIBCPP_APPLE_CLANG_VER)
  54. # if _LIBCPP_APPLE_CLANG_VER < 1500
  55. # warning "Libc++ only supports AppleClang 15 and later"
  56. # endif
  57. # elif defined(_LIBCPP_GCC_VER)
  58. # if _LIBCPP_GCC_VER < 1300
  59. # warning "Libc++ only supports GCC 13 and later"
  60. # endif
  61. # endif
  62. // The attributes supported by clang are documented at https://clang.llvm.org/docs/AttributeReference.html
  63. // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM.
  64. // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is
  65. // defined to XXYYZZ.
  66. # define _LIBCPP_VERSION 180000
  67. # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y
  68. # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y)
  69. // Valid C++ identifier that revs with every libc++ version. This can be used to
  70. // generate identifiers that must be unique for every released libc++ version.
  71. # define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION)
  72. # if __STDC_HOSTED__ == 0
  73. # define _LIBCPP_FREESTANDING
  74. # endif
  75. // NOLINTBEGIN(libcpp-cpp-version-check)
  76. # ifndef _LIBCPP_STD_VER
  77. # if __cplusplus <= 201103L
  78. # define _LIBCPP_STD_VER 11
  79. # elif __cplusplus <= 201402L
  80. # define _LIBCPP_STD_VER 14
  81. # elif __cplusplus <= 201703L
  82. # define _LIBCPP_STD_VER 17
  83. # elif __cplusplus <= 202002L
  84. # define _LIBCPP_STD_VER 20
  85. # elif __cplusplus <= 202302L
  86. # define _LIBCPP_STD_VER 23
  87. # else
  88. // Expected release year of the next C++ standard
  89. # define _LIBCPP_STD_VER 26
  90. # endif
  91. # endif // _LIBCPP_STD_VER
  92. // NOLINTEND(libcpp-cpp-version-check)
  93. # if defined(__ELF__)
  94. # define _LIBCPP_OBJECT_FORMAT_ELF 1
  95. # elif defined(__MACH__)
  96. # define _LIBCPP_OBJECT_FORMAT_MACHO 1
  97. # elif defined(_WIN32) || defined(__CYGWIN__)
  98. # define _LIBCPP_OBJECT_FORMAT_COFF 1
  99. # elif defined(__wasm__)
  100. # define _LIBCPP_OBJECT_FORMAT_WASM 1
  101. # elif defined(_AIX)
  102. # define _LIBCPP_OBJECT_FORMAT_XCOFF 1
  103. # else
  104. // ... add new file formats here ...
  105. # endif
  106. // ABI {
  107. # if _LIBCPP_ABI_VERSION >= 2
  108. // Change short string representation so that string data starts at offset 0,
  109. // improving its alignment in some cases.
  110. # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  111. // Fix deque iterator type in order to support incomplete types.
  112. # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
  113. // Fix undefined behavior in how std::list stores its linked nodes.
  114. # define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
  115. // Fix undefined behavior in how __tree stores its end and parent nodes.
  116. # define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
  117. // Fix undefined behavior in how __hash_table stores its pointer types.
  118. # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
  119. # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
  120. # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
  121. // Define a key function for `bad_function_call` in the library, to centralize
  122. // its vtable and typeinfo to libc++ rather than having all other libraries
  123. // using that class define their own copies.
  124. # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
  125. // Override the default return value of exception::what() for
  126. // bad_function_call::what() with a string that is specific to
  127. // bad_function_call (see http://wg21.link/LWG2233). This is an ABI break
  128. // because it changes the vtable layout of bad_function_call.
  129. # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
  130. // Enable optimized version of __do_get_(un)signed which avoids redundant copies.
  131. # define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
  132. // Give reverse_iterator<T> one data member of type T, not two.
  133. // Also, in C++17 and later, don't derive iterator types from std::iterator.
  134. # define _LIBCPP_ABI_NO_ITERATOR_BASES
  135. // Use the smallest possible integer type to represent the index of the variant.
  136. // Previously libc++ used "unsigned int" exclusively.
  137. # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
  138. // Unstable attempt to provide a more optimized std::function
  139. #ifdef __EMSCRIPTEN__
  140. // XXX EMSCRIPTEN https://github.com/emscripten-core/emscripten/issues/11022
  141. //# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
  142. #else
  143. # define _LIBCPP_ABI_OPTIMIZED_FUNCTION
  144. #endif
  145. // All the regex constants must be distinct and nonzero.
  146. # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
  147. // Re-worked external template instantiations for std::string with a focus on
  148. // performance and fast-path inlining.
  149. # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
  150. // Enable clang::trivial_abi on std::unique_ptr.
  151. # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
  152. // Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr
  153. # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
  154. // std::random_device holds some state when it uses an implementation that gets
  155. // entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this
  156. // implementation to another one on a platform that has already shipped
  157. // std::random_device, one needs to retain the same object layout to remain ABI
  158. // compatible. This switch removes these workarounds for platforms that don't care
  159. // about ABI compatibility.
  160. # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
  161. // Don't export the legacy __basic_string_common class and its methods from the built library.
  162. # define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
  163. // Don't export the legacy __vector_base_common class and its methods from the built library.
  164. # define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
  165. // According to the Standard, `bitset::operator[] const` returns bool
  166. # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
  167. // Fix the implementation of CityHash used for std::hash<fundamental-type>.
  168. // This is an ABI break because `std::hash` will return a different result,
  169. // which means that hashing the same object in translation units built against
  170. // different versions of libc++ can return inconsistent results. This is especially
  171. // tricky since std::hash is used in the implementation of unordered containers.
  172. //
  173. // The incorrect implementation of CityHash has the problem that it drops some
  174. // bits on the floor.
  175. # define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
  176. // Remove the base 10 implementation of std::to_chars from the dylib.
  177. // The implementation moved to the header, but we still export the symbols from
  178. // the dylib for backwards compatibility.
  179. # define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
  180. # elif _LIBCPP_ABI_VERSION == 1
  181. # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
  182. // Enable compiling copies of now inline methods into the dylib to support
  183. // applications compiled against older libraries. This is unnecessary with
  184. // COFF dllexport semantics, since dllexport forces a non-inline definition
  185. // of inline functions to be emitted anyway. Our own non-inline copy would
  186. // conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
  187. // the linker will take issue with the symbols in the shared object if the
  188. // weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
  189. // so disable it.
  190. # define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
  191. # endif
  192. // Feature macros for disabling pre ABI v1 features. All of these options
  193. // are deprecated.
  194. # if defined(__FreeBSD__) && __FreeBSD__ < 14
  195. # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
  196. # endif
  197. // For XCOFF linkers, we have problems if we see a weak hidden version of a symbol
  198. // in user code (like you get with -fvisibility-inlines-hidden) and then a strong def
  199. // in the library, so we need to always rely on the library version.
  200. # if defined(_AIX)
  201. # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
  202. # endif
  203. # endif
  204. # if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2
  205. // Enable additional explicit instantiations of iostreams components. This
  206. // reduces the number of weak definitions generated in programs that use
  207. // iostreams by providing a single strong definition in the shared library.
  208. # define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
  209. // Define a key function for `bad_function_call` in the library, to centralize
  210. // its vtable and typeinfo to libc++ rather than having all other libraries
  211. // using that class define their own copies.
  212. # define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
  213. # endif
  214. // Changes the iterator type of select containers (see below) to a bounded iterator that keeps track of whether it's
  215. // within the bounds of the original container and asserts it on every dereference.
  216. //
  217. // ABI impact: changes the iterator type of the relevant containers.
  218. //
  219. // Supported containers:
  220. // - `span`;
  221. // - `string_view`;
  222. // - `array`.
  223. // #define _LIBCPP_ABI_BOUNDED_ITERATORS
  224. // } ABI
  225. // HARDENING {
  226. // TODO(hardening): remove this in LLVM 19.
  227. // This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes)
  228. // equivalent to setting the safe mode.
  229. # ifdef _LIBCPP_ENABLE_ASSERTIONS
  230. # warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_SAFE_MODE instead."
  231. # if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1
  232. # error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1"
  233. # endif
  234. # if _LIBCPP_ENABLE_ASSERTIONS
  235. # define _LIBCPP_ENABLE_SAFE_MODE 1
  236. # endif
  237. # endif
  238. // Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes
  239. // security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with
  240. // `_LIBCPP_ENABLE_SAFE_MODE` and `_LIBCPP_ENABLE_DEBUG_MODE`.
  241. //
  242. // #define _LIBCPP_ENABLE_HARDENED_MODE 1
  243. // Enables the safe mode which extends the hardened mode with checks that are relatively cheap and prevent common types
  244. // of errors but are not security-critical. Mutually exclusive with `_LIBCPP_ENABLE_HARDENED_MODE` and
  245. // `_LIBCPP_ENABLE_DEBUG_MODE`.
  246. //
  247. // #define _LIBCPP_ENABLE_SAFE_MODE 1
  248. // Enables the debug mode which contains all the checks from the hardened mode and additionally more expensive checks
  249. // that may affect the complexity of algorithms. The debug mode is intended to be used for testing, not in production.
  250. // Mutually exclusive with `_LIBCPP_ENABLE_HARDENED_MODE` and `_LIBCPP_ENABLE_SAFE_MODE`.
  251. //
  252. // #define _LIBCPP_ENABLE_DEBUG_MODE 1
  253. // Inside the library, assertions are categorized so they can be cherry-picked based on the chosen hardening mode. These
  254. // macros are only for internal use -- users should only pick one of the high-level hardening modes described above.
  255. //
  256. // - `_LIBCPP_ASSERT_VALID_INPUT_RANGE` -- checks that ranges (whether expressed as an iterator pair, an iterator and
  257. // a sentinel, an iterator and a count, or a `std::range`) given as input to library functions are valid:
  258. // - the sentinel is reachable from the begin iterator;
  259. // - TODO(hardening): both iterators refer to the same container.
  260. //
  261. // - `_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS` -- checks that any attempts to access a container element, whether through
  262. // the container object or through an iterator, are valid and do not attempt to go out of bounds or otherwise access
  263. // a non-existent element. For iterator checks to work, bounded iterators must be enabled in the ABI. Types like
  264. // `optional` and `function` are considered one-element containers for the purposes of this check.
  265. //
  266. // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take several ranges as arguments, checks that the
  267. // given ranges do not overlap.
  268. //
  269. // - `_LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR` -- checks any operations that exchange nodes between containers to make sure
  270. // the containers have compatible allocators.
  271. //
  272. // - `_LIBCPP_ASSERT_INTERNAL` -- checks that internal invariants of the library hold. These assertions don't depend on
  273. // user input.
  274. //
  275. // - `_LIBCPP_ASSERT_UNCATEGORIZED` -- for assertions that haven't been properly classified yet.
  276. # ifndef _LIBCPP_ENABLE_HARDENED_MODE
  277. # define _LIBCPP_ENABLE_HARDENED_MODE _LIBCPP_ENABLE_HARDENED_MODE_DEFAULT
  278. # endif
  279. # if _LIBCPP_ENABLE_HARDENED_MODE != 0 && _LIBCPP_ENABLE_HARDENED_MODE != 1
  280. # error "_LIBCPP_ENABLE_HARDENED_MODE must be set to 0 or 1."
  281. # endif
  282. # ifndef _LIBCPP_ENABLE_SAFE_MODE
  283. # define _LIBCPP_ENABLE_SAFE_MODE _LIBCPP_ENABLE_SAFE_MODE_DEFAULT
  284. # endif
  285. # if _LIBCPP_ENABLE_SAFE_MODE != 0 && _LIBCPP_ENABLE_SAFE_MODE != 1
  286. # error "_LIBCPP_ENABLE_SAFE_MODE must be set to 0 or 1."
  287. # endif
  288. # ifndef _LIBCPP_ENABLE_DEBUG_MODE
  289. # define _LIBCPP_ENABLE_DEBUG_MODE _LIBCPP_ENABLE_DEBUG_MODE_DEFAULT
  290. # endif
  291. # if _LIBCPP_ENABLE_DEBUG_MODE != 0 && _LIBCPP_ENABLE_DEBUG_MODE != 1
  292. # error "_LIBCPP_ENABLE_DEBUG_MODE must be set to 0 or 1."
  293. # endif
  294. # if (_LIBCPP_ENABLE_HARDENED_MODE && _LIBCPP_ENABLE_SAFE_MODE) || \
  295. (_LIBCPP_ENABLE_HARDENED_MODE && _LIBCPP_ENABLE_DEBUG_MODE) || \
  296. (_LIBCPP_ENABLE_SAFE_MODE && _LIBCPP_ENABLE_DEBUG_MODE)
  297. # error \
  298. "Only one of _LIBCPP_ENABLE_HARDENED_MODE, _LIBCPP_ENABLE_SAFE_MODE and _LIBCPP_ENABLE_DEBUG_MODE can be enabled."
  299. # endif
  300. // clang-format off
  301. // Hardened mode checks.
  302. # if _LIBCPP_ENABLE_HARDENED_MODE
  303. // Enabled checks.
  304. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message)
  305. # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
  306. // Disabled checks.
  307. // Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security
  308. // vulnerability.
  309. # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
  310. # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
  311. # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
  312. # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
  313. // Safe mode checks.
  314. # elif _LIBCPP_ENABLE_SAFE_MODE
  315. // Enabled checks.
  316. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message)
  317. # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
  318. # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message)
  319. # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message)
  320. # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message)
  321. // Disabled checks.
  322. # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
  323. // Debug mode checks.
  324. # elif _LIBCPP_ENABLE_DEBUG_MODE
  325. // All checks enabled.
  326. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message)
  327. # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message)
  328. # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSERT(expression, message)
  329. # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message)
  330. # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message)
  331. # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message)
  332. // Disable all checks if hardening is not enabled.
  333. # else
  334. // All checks disabled.
  335. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression)
  336. # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression)
  337. # define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression)
  338. # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression)
  339. # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression)
  340. # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression)
  341. # endif // _LIBCPP_ENABLE_HARDENED_MODE
  342. // clang-format on
  343. // } HARDENING
  344. # define _LIBCPP_TOSTRING2(x) #x
  345. # define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
  346. // NOLINTNEXTLINE(libcpp-cpp-version-check)
  347. # if __cplusplus < 201103L
  348. # define _LIBCPP_CXX03_LANG
  349. # endif
  350. # ifndef __has_attribute
  351. # define __has_attribute(__x) 0
  352. # endif
  353. # ifndef __has_builtin
  354. # define __has_builtin(__x) 0
  355. # endif
  356. # ifndef __has_extension
  357. # define __has_extension(__x) 0
  358. # endif
  359. # ifndef __has_feature
  360. # define __has_feature(__x) 0
  361. # endif
  362. # ifndef __has_cpp_attribute
  363. # define __has_cpp_attribute(__x) 0
  364. # endif
  365. # ifndef __has_constexpr_builtin
  366. # define __has_constexpr_builtin(x) 0
  367. # endif
  368. // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
  369. // the compiler and '1' otherwise.
  370. # ifndef __is_identifier
  371. # define __is_identifier(__x) 1
  372. # endif
  373. # ifndef __has_declspec_attribute
  374. # define __has_declspec_attribute(__x) 0
  375. # endif
  376. # define __has_keyword(__x) !(__is_identifier(__x))
  377. # ifndef __has_include
  378. # define __has_include(...) 0
  379. # endif
  380. # if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L
  381. # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11"
  382. # endif
  383. // FIXME: ABI detection should be done via compiler builtin macros. This
  384. // is just a placeholder until Clang implements such macros. For now assume
  385. // that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
  386. // and allow the user to explicitly specify the ABI to handle cases where this
  387. // heuristic falls short.
  388. # if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
  389. # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
  390. # elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
  391. # define _LIBCPP_ABI_ITANIUM
  392. # elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
  393. # define _LIBCPP_ABI_MICROSOFT
  394. # else
  395. # if defined(_WIN32) && defined(_MSC_VER)
  396. # define _LIBCPP_ABI_MICROSOFT
  397. # else
  398. # define _LIBCPP_ABI_ITANIUM
  399. # endif
  400. # endif
  401. # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
  402. # define _LIBCPP_ABI_VCRUNTIME
  403. # endif
  404. # if __has_feature(experimental_library)
  405. # ifndef _LIBCPP_ENABLE_EXPERIMENTAL
  406. # define _LIBCPP_ENABLE_EXPERIMENTAL
  407. # endif
  408. # endif
  409. // Incomplete features get their own specific disabling flags. This makes it
  410. // easier to grep for target specific flags once the feature is complete.
  411. # if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY)
  412. # define _LIBCPP_HAS_NO_INCOMPLETE_PSTL
  413. # define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN
  414. # define _LIBCPP_HAS_NO_INCOMPLETE_TZDB
  415. # endif
  416. // Need to detect which libc we're using if we're on Linux.
  417. # if defined(__linux__)
  418. # include <features.h>
  419. # if defined(__GLIBC_PREREQ)
  420. # define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
  421. # else
  422. # define _LIBCPP_GLIBC_PREREQ(a, b) 0
  423. # endif // defined(__GLIBC_PREREQ)
  424. # endif // defined(__linux__)
  425. # if defined(__MVS__)
  426. # include <features.h> // for __NATIVE_ASCII_F
  427. # endif
  428. # ifndef __BYTE_ORDER__
  429. # error \
  430. "Your compiler doesn't seem to define __BYTE_ORDER__, which is required by libc++ to know the endianness of your target platform"
  431. # endif
  432. # if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  433. # define _LIBCPP_LITTLE_ENDIAN
  434. # elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  435. # define _LIBCPP_BIG_ENDIAN
  436. # endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  437. # if defined(_WIN32)
  438. # define _LIBCPP_WIN32API
  439. # define _LIBCPP_SHORT_WCHAR 1
  440. // Both MinGW and native MSVC provide a "MSVC"-like environment
  441. # define _LIBCPP_MSVCRT_LIKE
  442. // If mingw not explicitly detected, assume using MS C runtime only if
  443. // a MS compatibility version is specified.
  444. # if defined(_MSC_VER) && !defined(__MINGW32__)
  445. # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library
  446. # endif
  447. # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__))
  448. # define _LIBCPP_HAS_BITSCAN64
  449. # endif
  450. # define _LIBCPP_HAS_OPEN_WITH_WCHAR
  451. # endif // defined(_WIN32)
  452. # if defined(_AIX) && !defined(__64BIT__)
  453. // The size of wchar is 2 byte on 32-bit mode on AIX.
  454. # define _LIBCPP_SHORT_WCHAR 1
  455. # endif
  456. // Libc++ supports various implementations of std::random_device.
  457. //
  458. // _LIBCPP_USING_DEV_RANDOM
  459. // Read entropy from the given file, by default `/dev/urandom`.
  460. // If a token is provided, it is assumed to be the path to a file
  461. // to read entropy from. This is the default behavior if nothing
  462. // else is specified. This implementation requires storing state
  463. // inside `std::random_device`.
  464. //
  465. // _LIBCPP_USING_ARC4_RANDOM
  466. // Use arc4random(). This allows obtaining random data even when
  467. // using sandboxing mechanisms. On some platforms like Apple, this
  468. // is the recommended source of entropy for user-space programs.
  469. // When this option is used, the token passed to `std::random_device`'s
  470. // constructor *must* be "/dev/urandom" -- anything else is an error.
  471. //
  472. // _LIBCPP_USING_GETENTROPY
  473. // Use getentropy().
  474. // When this option is used, the token passed to `std::random_device`'s
  475. // constructor *must* be "/dev/urandom" -- anything else is an error.
  476. //
  477. // _LIBCPP_USING_FUCHSIA_CPRNG
  478. // Use Fuchsia's zx_cprng_draw() system call, which is specified to
  479. // deliver high-quality entropy and cannot fail.
  480. // When this option is used, the token passed to `std::random_device`'s
  481. // constructor *must* be "/dev/urandom" -- anything else is an error.
  482. //
  483. // _LIBCPP_USING_NACL_RANDOM
  484. // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
  485. // including accesses to the special files under `/dev`. This implementation
  486. // uses the NaCL syscall `nacl_secure_random_init()` to get entropy.
  487. // When this option is used, the token passed to `std::random_device`'s
  488. // constructor *must* be "/dev/urandom" -- anything else is an error.
  489. //
  490. // _LIBCPP_USING_WIN32_RANDOM
  491. // Use rand_s(), for use on Windows.
  492. // When this option is used, the token passed to `std::random_device`'s
  493. // constructor *must* be "/dev/urandom" -- anything else is an error.
  494. # if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
  495. defined(__DragonFly__)
  496. # define _LIBCPP_USING_ARC4_RANDOM
  497. # elif defined(__wasi__) || defined(__EMSCRIPTEN__)
  498. # define _LIBCPP_USING_GETENTROPY
  499. # elif defined(__Fuchsia__)
  500. # define _LIBCPP_USING_FUCHSIA_CPRNG
  501. # elif defined(__native_client__)
  502. # define _LIBCPP_USING_NACL_RANDOM
  503. # elif defined(_LIBCPP_WIN32API)
  504. # define _LIBCPP_USING_WIN32_RANDOM
  505. # else
  506. # define _LIBCPP_USING_DEV_RANDOM
  507. # endif
  508. # if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
  509. # define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
  510. # else
  511. # define _LIBCPP_NO_CFI
  512. # endif
  513. # ifndef _LIBCPP_CXX03_LANG
  514. # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
  515. # define _ALIGNAS_TYPE(x) alignas(x)
  516. # define _ALIGNAS(x) alignas(x)
  517. # define _LIBCPP_NORETURN [[noreturn]]
  518. # define _NOEXCEPT noexcept
  519. # define _NOEXCEPT_(x) noexcept(x)
  520. # define _LIBCPP_CONSTEXPR constexpr
  521. # else
  522. # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
  523. # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
  524. # define _ALIGNAS(x) __attribute__((__aligned__(x)))
  525. # define _LIBCPP_NORETURN __attribute__((__noreturn__))
  526. # define _LIBCPP_HAS_NO_NOEXCEPT
  527. # define nullptr __nullptr
  528. # define _NOEXCEPT throw()
  529. # define _NOEXCEPT_(x)
  530. # define static_assert(...) _Static_assert(__VA_ARGS__)
  531. # define decltype(...) __decltype(__VA_ARGS__)
  532. # define _LIBCPP_CONSTEXPR
  533. typedef __char16_t char16_t;
  534. typedef __char32_t char32_t;
  535. # endif
  536. # if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L
  537. # define _LIBCPP_HAS_NO_EXCEPTIONS
  538. # endif
  539. # define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
  540. # if defined(_LIBCPP_COMPILER_CLANG_BASED)
  541. # if defined(__APPLE__)
  542. # if defined(__i386__) || defined(__x86_64__)
  543. // use old string layout on x86_64 and i386
  544. # elif defined(__arm__)
  545. // use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
  546. # if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
  547. # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  548. # endif
  549. # else
  550. # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
  551. # endif
  552. # endif
  553. // Objective-C++ features (opt-in)
  554. # if __has_feature(objc_arc)
  555. # define _LIBCPP_HAS_OBJC_ARC
  556. # endif
  557. # if __has_feature(objc_arc_weak)
  558. # define _LIBCPP_HAS_OBJC_ARC_WEAK
  559. # endif
  560. # if __has_extension(blocks)
  561. # define _LIBCPP_HAS_EXTENSION_BLOCKS
  562. # endif
  563. # if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__)
  564. # define _LIBCPP_HAS_BLOCKS_RUNTIME
  565. # endif
  566. # if !__has_feature(address_sanitizer)
  567. # define _LIBCPP_HAS_NO_ASAN
  568. # endif
  569. // Allow for build-time disabling of unsigned integer sanitization
  570. # if __has_attribute(no_sanitize)
  571. # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
  572. # endif
  573. # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
  574. # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
  575. # elif defined(_LIBCPP_COMPILER_GCC)
  576. # if !defined(__SANITIZE_ADDRESS__)
  577. # define _LIBCPP_HAS_NO_ASAN
  578. # endif
  579. # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
  580. # define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
  581. # endif // _LIBCPP_COMPILER_[CLANG|GCC]
  582. # if defined(_LIBCPP_OBJECT_FORMAT_COFF)
  583. # ifdef _DLL
  584. # define _LIBCPP_CRT_FUNC __declspec(dllimport)
  585. # else
  586. # define _LIBCPP_CRT_FUNC
  587. # endif
  588. # if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
  589. # define _LIBCPP_DLL_VIS
  590. # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
  591. # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
  592. # define _LIBCPP_OVERRIDABLE_FUNC_VIS
  593. # define _LIBCPP_EXPORTED_FROM_ABI
  594. # elif defined(_LIBCPP_BUILDING_LIBRARY)
  595. # define _LIBCPP_DLL_VIS __declspec(dllexport)
  596. # if defined(__MINGW32__)
  597. # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
  598. # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
  599. # else
  600. # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
  601. # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
  602. # endif
  603. # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
  604. # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
  605. # else
  606. # define _LIBCPP_DLL_VIS __declspec(dllimport)
  607. # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
  608. # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
  609. # define _LIBCPP_OVERRIDABLE_FUNC_VIS
  610. # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
  611. # endif
  612. # define _LIBCPP_HIDDEN
  613. # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  614. # define _LIBCPP_TEMPLATE_VIS
  615. # define _LIBCPP_TEMPLATE_DATA_VIS
  616. # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
  617. # else
  618. # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
  619. # define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis)))
  620. # else
  621. # define _LIBCPP_VISIBILITY(vis)
  622. # endif
  623. # define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden")
  624. # define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default")
  625. # define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default")
  626. # define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default")
  627. # define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
  628. // TODO: Make this a proper customization point or remove the option to override it.
  629. # ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
  630. # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default")
  631. # endif
  632. # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
  633. // The inline should be removed once PR32114 is resolved
  634. # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
  635. # else
  636. # define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  637. # endif
  638. // GCC doesn't support the type_visibility attribute, so we have to keep the visibility attribute on templates
  639. # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && !__has_attribute(__type_visibility__)
  640. # define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default")))
  641. # else
  642. # define _LIBCPP_TEMPLATE_VIS
  643. # endif
  644. # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
  645. # define _LIBCPP_TYPE_VISIBILITY_DEFAULT __attribute__((__type_visibility__("default")))
  646. # else
  647. # define _LIBCPP_TYPE_VISIBILITY_DEFAULT
  648. # endif
  649. # endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
  650. # if __has_attribute(exclude_from_explicit_instantiation)
  651. # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__))
  652. # else
  653. // Try to approximate the effect of exclude_from_explicit_instantiation
  654. // (which is that entities are not assumed to be provided by explicit
  655. // template instantiations in the dylib) by always inlining those entities.
  656. # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
  657. # endif
  658. // This macro marks a symbol as being hidden from libc++'s ABI. This is achieved
  659. // on two levels:
  660. // 1. The symbol is given hidden visibility, which ensures that users won't start exporting
  661. // symbols from their dynamic library by means of using the libc++ headers. This ensures
  662. // that those symbols stay private to the dynamic library in which it is defined.
  663. //
  664. // 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures
  665. // that no ODR violation can arise from mixing two TUs compiled with different versions
  666. // of libc++ where we would have changed the definition of a symbol. If the symbols shared
  667. // the same name, the ODR would require that their definitions be token-by-token equivalent,
  668. // which basically prevents us from being able to make any change to any function in our
  669. // headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at
  670. // each release, which lets us change the definition of these symbols at our leisure.
  671. // Note that historically, this has been achieved in various ways, including force-inlining
  672. // all functions or giving internal linkage to all functions. Both these (previous) solutions
  673. // suffer from drawbacks that lead notably to code bloat.
  674. //
  675. // Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend
  676. // on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library.
  677. //
  678. // Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions
  679. // instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled
  680. // name of a virtual function is part of its ABI, since some architectures like arm64e can sign
  681. // the virtual function pointer in the vtable based on the mangled name of the function. Since
  682. // we use an ABI tag that changes with each released version, the mangled name of the virtual
  683. // function would change, which is incorrect. Note that it doesn't make much sense to change
  684. // the implementation of a virtual function in an ABI-incompatible way in the first place,
  685. // since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable.
  686. //
  687. // TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing
  688. // the length of symbols with an ABI tag. In practice, we should remove the escape hatch and
  689. // use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70.
  690. # if !defined(_LIBCPP_NO_ABI_TAG) && !defined(__CUDACC__)
  691. # define _LIBCPP_HIDE_FROM_ABI \
  692. _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \
  693. __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER))))
  694. # else
  695. # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
  696. # endif
  697. # define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
  698. // This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern
  699. // "C" function, as those lack mangling.
  700. # define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
  701. # ifdef _LIBCPP_BUILDING_LIBRARY
  702. # if _LIBCPP_ABI_VERSION > 1
  703. # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
  704. # else
  705. # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
  706. # endif
  707. # else
  708. # define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
  709. # endif
  710. // Just so we can migrate to the new macros gradually.
  711. # define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
  712. // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
  713. // clang-format off
  714. # define _LIBCPP_BEGIN_NAMESPACE_STD namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
  715. inline namespace _LIBCPP_ABI_NAMESPACE {
  716. # define _LIBCPP_END_NAMESPACE_STD }}
  717. # define _VSTD std
  718. _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
  719. # if _LIBCPP_STD_VER >= 17
  720. # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
  721. _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
  722. # else
  723. # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
  724. _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
  725. # endif
  726. # define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }}
  727. // clang-format on
  728. # define _VSTD_FS std::__fs::filesystem
  729. # if __has_attribute(__enable_if__)
  730. # define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, "")))
  731. # endif
  732. # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER)
  733. # define _LIBCPP_HAS_NO_INT128
  734. # endif
  735. # if __has_attribute(__malloc__)
  736. # define _LIBCPP_NOALIAS __attribute__((__malloc__))
  737. # else
  738. # define _LIBCPP_NOALIAS
  739. # endif
  740. # if __has_attribute(__using_if_exists__)
  741. # define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
  742. # else
  743. # define _LIBCPP_USING_IF_EXISTS
  744. # endif
  745. # ifdef _LIBCPP_CXX03_LANG
  746. # define _LIBCPP_DECLARE_STRONG_ENUM(x) \
  747. struct _LIBCPP_EXPORTED_FROM_ABI x { \
  748. enum __lx
  749. // clang-format off
  750. # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
  751. __lx __v_; \
  752. _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
  753. _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
  754. _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \
  755. };
  756. // clang-format on
  757. # else // _LIBCPP_CXX03_LANG
  758. # define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class x
  759. # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
  760. # endif // _LIBCPP_CXX03_LANG
  761. # if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__)
  762. # define _LIBCPP_LOCALE__L_EXTENSIONS 1
  763. # endif
  764. # ifdef __FreeBSD__
  765. # define _DECLARE_C99_LDBL_MATH 1
  766. # endif
  767. // If we are getting operator new from the MSVC CRT, then allocation overloads
  768. // for align_val_t were added in 19.12, aka VS 2017 version 15.3.
  769. # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
  770. # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
  771. # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
  772. // We're deferring to Microsoft's STL to provide aligned new et al. We don't
  773. // have it unless the language feature test macro is defined.
  774. # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
  775. # elif defined(__MVS__)
  776. # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
  777. # endif
  778. # if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606)
  779. # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
  780. # endif
  781. // It is not yet possible to use aligned_alloc() on all Apple platforms since
  782. // 10.15 was the first version to ship an implementation of aligned_alloc().
  783. # if defined(__APPLE__)
  784. # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  785. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500)
  786. # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
  787. # endif
  788. # elif defined(__ANDROID__) && __ANDROID_API__ < 28
  789. // Android only provides aligned_alloc when targeting API 28 or higher.
  790. # define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC
  791. # endif
  792. # if defined(__APPLE__) || defined(__FreeBSD__)
  793. # define _LIBCPP_HAS_DEFAULTRUNELOCALE
  794. # endif
  795. # if defined(__APPLE__) || defined(__FreeBSD__)
  796. # define _LIBCPP_WCTYPE_IS_MASK
  797. # endif
  798. # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
  799. # define _LIBCPP_HAS_NO_CHAR8_T
  800. # endif
  801. // Deprecation macros.
  802. //
  803. // Deprecations warnings are always enabled, except when users explicitly opt-out
  804. // by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
  805. # if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
  806. # if __has_attribute(__deprecated__)
  807. # define _LIBCPP_DEPRECATED __attribute__((__deprecated__))
  808. # define _LIBCPP_DEPRECATED_(m) __attribute__((__deprecated__(m)))
  809. # elif _LIBCPP_STD_VER >= 14
  810. # define _LIBCPP_DEPRECATED [[deprecated]]
  811. # define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]]
  812. # else
  813. # define _LIBCPP_DEPRECATED
  814. # define _LIBCPP_DEPRECATED_(m)
  815. # endif
  816. # else
  817. # define _LIBCPP_DEPRECATED
  818. # define _LIBCPP_DEPRECATED_(m)
  819. # endif
  820. # if !defined(_LIBCPP_CXX03_LANG)
  821. # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
  822. # else
  823. # define _LIBCPP_DEPRECATED_IN_CXX11
  824. # endif
  825. # if _LIBCPP_STD_VER >= 14
  826. # define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
  827. # else
  828. # define _LIBCPP_DEPRECATED_IN_CXX14
  829. # endif
  830. # if _LIBCPP_STD_VER >= 17
  831. # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
  832. # else
  833. # define _LIBCPP_DEPRECATED_IN_CXX17
  834. # endif
  835. # if _LIBCPP_STD_VER >= 20
  836. # define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED
  837. # else
  838. # define _LIBCPP_DEPRECATED_IN_CXX20
  839. # endif
  840. # if _LIBCPP_STD_VER >= 23
  841. # define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED
  842. # else
  843. # define _LIBCPP_DEPRECATED_IN_CXX23
  844. # endif
  845. # if !defined(_LIBCPP_HAS_NO_CHAR8_T)
  846. # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED
  847. # else
  848. # define _LIBCPP_DEPRECATED_WITH_CHAR8_T
  849. # endif
  850. // Macros to enter and leave a state where deprecation warnings are suppressed.
  851. # if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC)
  852. # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
  853. _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \
  854. _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  855. # define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
  856. # else
  857. # define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  858. # define _LIBCPP_SUPPRESS_DEPRECATED_POP
  859. # endif
  860. # if _LIBCPP_STD_VER <= 11
  861. # define _LIBCPP_EXPLICIT_SINCE_CXX14
  862. # else
  863. # define _LIBCPP_EXPLICIT_SINCE_CXX14 explicit
  864. # endif
  865. # if _LIBCPP_STD_VER >= 23
  866. # define _LIBCPP_EXPLICIT_SINCE_CXX23 explicit
  867. # else
  868. # define _LIBCPP_EXPLICIT_SINCE_CXX23
  869. # endif
  870. # if _LIBCPP_STD_VER >= 14
  871. # define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr
  872. # else
  873. # define _LIBCPP_CONSTEXPR_SINCE_CXX14
  874. # endif
  875. # if _LIBCPP_STD_VER >= 17
  876. # define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr
  877. # else
  878. # define _LIBCPP_CONSTEXPR_SINCE_CXX17
  879. # endif
  880. # if _LIBCPP_STD_VER >= 20
  881. # define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr
  882. # else
  883. # define _LIBCPP_CONSTEXPR_SINCE_CXX20
  884. # endif
  885. # if _LIBCPP_STD_VER >= 23
  886. # define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr
  887. # else
  888. # define _LIBCPP_CONSTEXPR_SINCE_CXX23
  889. # endif
  890. # if __has_cpp_attribute(nodiscard)
  891. # define _LIBCPP_NODISCARD [[__nodiscard__]]
  892. # else
  893. // We can't use GCC's [[gnu::warn_unused_result]] and
  894. // __attribute__((warn_unused_result)), because GCC does not silence them via
  895. // (void) cast.
  896. # define _LIBCPP_NODISCARD
  897. # endif
  898. // _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
  899. // specified as such as an extension.
  900. # if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
  901. # define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
  902. # else
  903. # define _LIBCPP_NODISCARD_EXT
  904. # endif
  905. # if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
  906. # define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
  907. # else
  908. # define _LIBCPP_NODISCARD_AFTER_CXX17
  909. # endif
  910. # if __has_attribute(__no_destroy__)
  911. # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
  912. # else
  913. # define _LIBCPP_NO_DESTROY
  914. # endif
  915. # ifndef _LIBCPP_HAS_NO_ASAN
  916. extern "C" _LIBCPP_EXPORTED_FROM_ABI void
  917. __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
  918. # if _LIBCPP_CLANG_VER >= 1600 && !defined(_LIBCPP_NO_ASAN_CONTIGUOUS_CONTAINER_FEATURES)
  919. extern "C" _LIBCPP_EXPORTED_FROM_ABI void __sanitizer_annotate_double_ended_contiguous_container(
  920. const void*, const void*, const void*, const void*, const void*, const void*);
  921. extern "C" _LIBCPP_EXPORTED_FROM_ABI int
  922. __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*);
  923. # endif
  924. # endif
  925. // Try to find out if RTTI is disabled.
  926. # if !defined(__cpp_rtti) || __cpp_rtti < 199711L
  927. # define _LIBCPP_HAS_NO_RTTI
  928. # endif
  929. # ifndef _LIBCPP_WEAK
  930. # define _LIBCPP_WEAK __attribute__((__weak__))
  931. # endif
  932. // Thread API
  933. // clang-format off
  934. # if !defined(_LIBCPP_HAS_NO_THREADS) && \
  935. !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
  936. !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
  937. !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  938. # if defined(__FreeBSD__) || \
  939. defined(__wasi__) || \
  940. defined(__NetBSD__) || \
  941. defined(__OpenBSD__) || \
  942. defined(__NuttX__) || \
  943. defined(__linux__) || \
  944. defined(__GNU__) || \
  945. defined(__APPLE__) || \
  946. defined(__MVS__) || \
  947. defined(_AIX) || \
  948. defined(__EMSCRIPTEN__) || \
  949. defined(__CYGWIN__)
  950. // clang-format on
  951. # define _LIBCPP_HAS_THREAD_API_PTHREAD
  952. # elif defined(__Fuchsia__)
  953. // TODO(44575): Switch to C11 thread API when possible.
  954. # define _LIBCPP_HAS_THREAD_API_PTHREAD
  955. # elif defined(_LIBCPP_WIN32API)
  956. # define _LIBCPP_HAS_THREAD_API_WIN32
  957. # else
  958. # error "No thread API"
  959. # endif // _LIBCPP_HAS_THREAD_API
  960. # endif // _LIBCPP_HAS_NO_THREADS
  961. # if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
  962. # if defined(__ANDROID__) && __ANDROID_API__ >= 30
  963. # define _LIBCPP_HAS_COND_CLOCKWAIT
  964. # elif defined(_LIBCPP_GLIBC_PREREQ)
  965. # if _LIBCPP_GLIBC_PREREQ(2, 30)
  966. # define _LIBCPP_HAS_COND_CLOCKWAIT
  967. # endif
  968. # endif
  969. # endif
  970. # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
  971. # error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
  972. _LIBCPP_HAS_NO_THREADS is not defined.
  973. # endif
  974. # if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
  975. # error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
  976. _LIBCPP_HAS_NO_THREADS is defined.
  977. # endif
  978. # if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
  979. # error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
  980. _LIBCPP_HAS_NO_THREADS is defined.
  981. # endif
  982. # if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
  983. # define __STDCPP_THREADS__ 1
  984. # endif
  985. // The glibc and Bionic implementation of pthreads implements
  986. // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
  987. // mutexes have no destroy mechanism.
  988. //
  989. // This optimization can't be performed on Apple platforms, where
  990. // pthread_mutex_destroy can allow the kernel to release resources.
  991. // See https://llvm.org/D64298 for details.
  992. //
  993. // TODO(EricWF): Enable this optimization on Bionic after speaking to their
  994. // respective stakeholders.
  995. // clang-format off
  996. # if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \
  997. (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \
  998. defined(_LIBCPP_HAS_THREAD_API_WIN32)
  999. // clang-format on
  1000. # define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
  1001. # endif
  1002. // Destroying a condvar is a nop on Windows.
  1003. //
  1004. // This optimization can't be performed on Apple platforms, where
  1005. // pthread_cond_destroy can allow the kernel to release resources.
  1006. // See https://llvm.org/D64298 for details.
  1007. //
  1008. // TODO(EricWF): This is potentially true for some pthread implementations
  1009. // as well.
  1010. # if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32)
  1011. # define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
  1012. # endif
  1013. // Some systems do not provide gets() in their C library, for security reasons.
  1014. # if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__)
  1015. # define _LIBCPP_C_HAS_NO_GETS
  1016. # endif
  1017. # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
  1018. defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
  1019. # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
  1020. # endif
  1021. # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
  1022. # define _LIBCPP_HAS_C_ATOMIC_IMP
  1023. # elif defined(_LIBCPP_COMPILER_GCC)
  1024. # define _LIBCPP_HAS_GCC_ATOMIC_IMP
  1025. # endif
  1026. # if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
  1027. !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)
  1028. # define _LIBCPP_HAS_NO_ATOMIC_HEADER
  1029. # else
  1030. # ifndef _LIBCPP_ATOMIC_FLAG_TYPE
  1031. # define _LIBCPP_ATOMIC_FLAG_TYPE bool
  1032. # endif
  1033. # ifdef _LIBCPP_FREESTANDING
  1034. # define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
  1035. # endif
  1036. # endif
  1037. # ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
  1038. # define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
  1039. # endif
  1040. # if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
  1041. # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
  1042. # else
  1043. # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
  1044. # endif
  1045. # if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
  1046. # if defined(__clang__) && __has_attribute(acquire_capability)
  1047. // Work around the attribute handling in clang. When both __declspec and
  1048. // __attribute__ are present, the processing goes awry preventing the definition
  1049. // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus
  1050. // combining the two does work.
  1051. # if !defined(_MSC_VER)
  1052. # define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
  1053. # endif
  1054. # endif
  1055. # endif
  1056. # ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
  1057. # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
  1058. # else
  1059. # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
  1060. # endif
  1061. # if _LIBCPP_STD_VER >= 20
  1062. # define _LIBCPP_CONSTINIT constinit
  1063. # elif __has_attribute(__require_constant_initialization__)
  1064. # define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__))
  1065. # else
  1066. # define _LIBCPP_CONSTINIT
  1067. # endif
  1068. # if !__has_builtin(__builtin_is_constant_evaluated) || (defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER < 900) || __CUDACC_VER_MAJOR__ == 10
  1069. # define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
  1070. # endif
  1071. # if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
  1072. # define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
  1073. # else
  1074. # define _LIBCPP_DIAGNOSE_WARNING(...)
  1075. # endif
  1076. // Use a function like macro to imply that it must be followed by a semicolon
  1077. # if __has_cpp_attribute(fallthrough)
  1078. # define _LIBCPP_FALLTHROUGH() [[fallthrough]]
  1079. # elif __has_attribute(__fallthrough__)
  1080. # define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
  1081. # else
  1082. # define _LIBCPP_FALLTHROUGH() ((void)0)
  1083. # endif
  1084. # if __has_cpp_attribute(_Clang::__lifetimebound__)
  1085. # define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
  1086. # else
  1087. # define _LIBCPP_LIFETIMEBOUND
  1088. # endif
  1089. # if defined(_LIBCPP_COMPILER_CLANG_BASED)
  1090. # define _LIBCPP_REINITIALIZES_OBJECT [[clang::reinitializes]]
  1091. # else
  1092. # define _LIBCPP_REINITIALIZES_OBJECT
  1093. # endif
  1094. # if __has_attribute(__nodebug__)
  1095. # define _LIBCPP_NODEBUG __attribute__((__nodebug__))
  1096. # else
  1097. # define _LIBCPP_NODEBUG
  1098. # endif
  1099. # if __has_attribute(__standalone_debug__)
  1100. # define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
  1101. # else
  1102. # define _LIBCPP_STANDALONE_DEBUG
  1103. # endif
  1104. # if __has_attribute(__preferred_name__)
  1105. # define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
  1106. # else
  1107. # define _LIBCPP_PREFERRED_NAME(x)
  1108. # endif
  1109. # if __has_attribute(__no_sanitize__)
  1110. # define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
  1111. # else
  1112. # define _LIBCPP_NO_SANITIZE(...)
  1113. # endif
  1114. // We often repeat things just for handling wide characters in the library.
  1115. // When wide characters are disabled, it can be useful to have a quick way of
  1116. // disabling it without having to resort to #if-#endif, which has a larger
  1117. // impact on readability.
  1118. # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
  1119. # define _LIBCPP_IF_WIDE_CHARACTERS(...)
  1120. # else
  1121. # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
  1122. # endif
  1123. # if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
  1124. # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
  1125. # else
  1126. # define _LIBCPP_DECLSPEC_EMPTY_BASES
  1127. # endif
  1128. # if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
  1129. # define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
  1130. # define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
  1131. # define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
  1132. # define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
  1133. # define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
  1134. # endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
  1135. # if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES)
  1136. # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
  1137. # define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION
  1138. # define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS
  1139. # define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS
  1140. # define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR
  1141. # define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS
  1142. # endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES
  1143. // Yandex-specific: We build our own libc++, so it has everything available
  1144. # define _LIBCPP_DISABLE_AVAILABILITY
  1145. // End of Yandex-specific
  1146. // clang-format off
  1147. # define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") _Pragma("push_macro(\"refresh()\")") _Pragma("push_macro(\"move(int, int)\")") _Pragma("push_macro(\"erase()\")")
  1148. # define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") _Pragma("pop_macro(\"refresh()\")") _Pragma("pop_macro(\"move(int, int)\")") _Pragma("pop_macro(\"erase()\")")
  1149. // clang-format on
  1150. # ifndef _LIBCPP_NO_AUTO_LINK
  1151. # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
  1152. # if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
  1153. # pragma comment(lib, "c++.lib")
  1154. # else
  1155. # pragma comment(lib, "libc++.lib")
  1156. # endif
  1157. # endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
  1158. # endif // _LIBCPP_NO_AUTO_LINK
  1159. // Configures the fopen close-on-exec mode character, if any. This string will
  1160. // be appended to any mode string used by fstream for fopen/fdopen.
  1161. //
  1162. // Not all platforms support this, but it helps avoid fd-leaks on platforms that
  1163. // do.
  1164. # if defined(__BIONIC__)
  1165. # define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
  1166. # else
  1167. # define _LIBCPP_FOPEN_CLOEXEC_MODE
  1168. # endif
  1169. // Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
  1170. // of functions used in cstdio may not be available for low API levels when
  1171. // using 64-bit file offsets on LP32.
  1172. # if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24
  1173. # define _LIBCPP_HAS_NO_FGETPOS_FSETPOS
  1174. # endif
  1175. # if __has_attribute(__init_priority__)
  1176. # define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
  1177. # else
  1178. # define _LIBCPP_INIT_PRIORITY_MAX
  1179. # endif
  1180. # if __has_attribute(__format__)
  1181. // The attribute uses 1-based indices for ordinary and static member functions.
  1182. // The attribute uses 2-based indices for non-static member functions.
  1183. # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
  1184. __attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
  1185. # else
  1186. # define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
  1187. # endif
  1188. # if __has_cpp_attribute(msvc::no_unique_address)
  1189. // MSVC implements [[no_unique_address]] as a silent no-op currently.
  1190. // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
  1191. // However, MSVC implements [[msvc::no_unique_address]] which does what
  1192. // [[no_unique_address]] is supposed to do, in general.
  1193. // Clang-cl does not yet (14.0) implement either [[no_unique_address]] or
  1194. // [[msvc::no_unique_address]] though. If/when it does implement
  1195. // [[msvc::no_unique_address]], this should be preferred though.
  1196. # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
  1197. # elif __has_cpp_attribute(no_unique_address)
  1198. # define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]]
  1199. # else
  1200. # define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */
  1201. // Note that this can be replaced by #error as soon as clang-cl
  1202. // implements msvc::no_unique_address, since there should be no C++20
  1203. // compiler that doesn't support one of the two attributes at that point.
  1204. // We generally don't want to use this macro outside of C++20-only code,
  1205. // because using it conditionally in one language version only would make
  1206. // the ABI inconsistent.
  1207. # endif
  1208. # ifdef _LIBCPP_COMPILER_CLANG_BASED
  1209. # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
  1210. # define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
  1211. # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str))
  1212. # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
  1213. # elif defined(_LIBCPP_COMPILER_GCC)
  1214. # define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
  1215. # define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
  1216. # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
  1217. # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str))
  1218. # else
  1219. # define _LIBCPP_DIAGNOSTIC_PUSH
  1220. # define _LIBCPP_DIAGNOSTIC_POP
  1221. # define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str)
  1222. # define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
  1223. # endif
  1224. # if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC)
  1225. # define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)")
  1226. # define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)")
  1227. # else
  1228. # define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */
  1229. # define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */
  1230. # endif
  1231. # if __has_attribute(__packed__)
  1232. # define _LIBCPP_PACKED __attribute__((__packed__))
  1233. # else
  1234. # define _LIBCPP_PACKED
  1235. # endif
  1236. // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
  1237. // functions is gradually being added to existing C libraries. The conditions
  1238. // below check for known C library versions and conditions under which these
  1239. // functions are declared by the C library.
  1240. # define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
  1241. // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if
  1242. // __cpp_char8_t is defined or if C2X extensions are enabled. Determining
  1243. // the latter depends on internal GNU libc details that are not appropriate
  1244. // to depend on here, so any declarations present when __cpp_char8_t is not
  1245. // defined are ignored.
  1246. # if defined(_LIBCPP_GLIBC_PREREQ)
  1247. # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
  1248. # undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8
  1249. # endif
  1250. # endif
  1251. // There are a handful of public standard library types that are intended to
  1252. // support CTAD but don't need any explicit deduction guides to do so. This
  1253. // macro is used to mark them as such, which suppresses the
  1254. // '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code
  1255. // with these classes.
  1256. # if _LIBCPP_STD_VER >= 17
  1257. # ifdef _LIBCPP_COMPILER_CLANG_BASED
  1258. # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \
  1259. template <class... _Tag> \
  1260. [[maybe_unused]] _ClassName(typename _Tag::__allow_ctad...)->_ClassName<_Tag...>
  1261. # else
  1262. # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(ClassName) \
  1263. template <class... _Tag> \
  1264. ClassName(typename _Tag::__allow_ctad...)->ClassName<_Tag...>
  1265. # endif
  1266. # else
  1267. # define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "")
  1268. # endif
  1269. // TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use
  1270. // compiler intrinsics in the Objective-C++ mode.
  1271. # ifdef __OBJC__
  1272. # define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS
  1273. # endif
  1274. # define _PSTL_PRAGMA(x) _Pragma(#x)
  1275. // Enable SIMD for compilers that support OpenMP 4.0
  1276. # if (defined(_OPENMP) && _OPENMP >= 201307)
  1277. # define _PSTL_UDR_PRESENT
  1278. # define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
  1279. # define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
  1280. # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
  1281. # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
  1282. # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
  1283. # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
  1284. // Declaration of reduction functor, where
  1285. // NAME - the name of the functor
  1286. // OP - type of the callable object with the reduction operation
  1287. // omp_in - refers to the local partial result
  1288. // omp_out - refers to the final value of the combiner operator
  1289. // omp_priv - refers to the private copy of the initial value
  1290. // omp_orig - refers to the original variable to be reduced
  1291. # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
  1292. _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
  1293. # elif defined(_LIBCPP_COMPILER_CLANG_BASED)
  1294. # define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
  1295. # define _PSTL_PRAGMA_DECLARE_SIMD
  1296. # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
  1297. # define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
  1298. # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
  1299. # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
  1300. # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
  1301. # else // (defined(_OPENMP) && _OPENMP >= 201307)
  1302. # define _PSTL_PRAGMA_SIMD
  1303. # define _PSTL_PRAGMA_DECLARE_SIMD
  1304. # define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
  1305. # define _PSTL_PRAGMA_SIMD_SCAN(PRM)
  1306. # define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
  1307. # define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
  1308. # define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
  1309. # endif // (defined(_OPENMP) && _OPENMP >= 201307)
  1310. # define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
  1311. #endif // __cplusplus
  1312. #include <__config_epilogue.h>
  1313. #endif // _LIBCPP___CONFIG