10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 1081ad6265SDimitry Andric#ifndef _LIBCPP___CONFIG 1181ad6265SDimitry Andric#define _LIBCPP___CONFIG 120b57cec5SDimitry Andric 13fe6060f1SDimitry Andric#include <__config_site> 14fe6060f1SDimitry Andric 150b57cec5SDimitry Andric#if defined(_MSC_VER) && !defined(__clang__) 160b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 170b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 180b57cec5SDimitry Andric# endif 190b57cec5SDimitry Andric#endif 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER 220b57cec5SDimitry Andric# pragma GCC system_header 230b57cec5SDimitry Andric#endif 240b57cec5SDimitry Andric 256246ae0bSDimitry Andric#if defined(__apple_build_version__) 26*1ac55f4cSDimitry Andric// Given AppleClang XX.Y.Z, _LIBCPP_APPLE_CLANG_VER is XXYZ (e.g. AppleClang 14.0.3 => 1403) 276246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 286246ae0bSDimitry Andric# define _LIBCPP_APPLE_CLANG_VER (__apple_build_version__ / 10000) 296246ae0bSDimitry Andric#elif defined(__clang__) 306246ae0bSDimitry Andric# define _LIBCPP_COMPILER_CLANG_BASED 316246ae0bSDimitry Andric# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__) 326246ae0bSDimitry Andric#elif defined(__GNUC__) 336246ae0bSDimitry Andric# define _LIBCPP_COMPILER_GCC 346246ae0bSDimitry Andric#endif 356246ae0bSDimitry Andric 360b57cec5SDimitry Andric#ifdef __cplusplus 370b57cec5SDimitry Andric 38bdd1243dSDimitry Andric// _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. 39bdd1243dSDimitry Andric// Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 16.0.1 == 16.00.01), _LIBCPP_VERSION is 40bdd1243dSDimitry Andric// defined to XXYYZZ. 41*1ac55f4cSDimitry Andric# define _LIBCPP_VERSION 160001 420b57cec5SDimitry Andric 43753f127fSDimitry Andric# define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y 44753f127fSDimitry Andric# define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) 45753f127fSDimitry Andric 46753f127fSDimitry Andric// Valid C++ identifier that revs with every libc++ version. This can be used to 47753f127fSDimitry Andric// generate identifiers that must be unique for every released libc++ version. 48753f127fSDimitry Andric# define _LIBCPP_VERSIONED_IDENTIFIER _LIBCPP_CONCAT(v, _LIBCPP_VERSION) 49753f127fSDimitry Andric 50e8d8bef9SDimitry Andric# if __STDC_HOSTED__ == 0 510b57cec5SDimitry Andric# define _LIBCPP_FREESTANDING 520b57cec5SDimitry Andric# endif 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric# ifndef _LIBCPP_STD_VER 550b57cec5SDimitry Andric# if __cplusplus <= 201103L 560b57cec5SDimitry Andric# define _LIBCPP_STD_VER 11 570b57cec5SDimitry Andric# elif __cplusplus <= 201402L 580b57cec5SDimitry Andric# define _LIBCPP_STD_VER 14 590b57cec5SDimitry Andric# elif __cplusplus <= 201703L 600b57cec5SDimitry Andric# define _LIBCPP_STD_VER 17 61e8d8bef9SDimitry Andric# elif __cplusplus <= 202002L 62e8d8bef9SDimitry Andric# define _LIBCPP_STD_VER 20 630b57cec5SDimitry Andric# else 64bdd1243dSDimitry Andric// Expected release year of the next C++ standard 65bdd1243dSDimitry Andric# define _LIBCPP_STD_VER 23 660b57cec5SDimitry Andric# endif 670b57cec5SDimitry Andric# endif // _LIBCPP_STD_VER 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric# if defined(__ELF__) 700b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_ELF 1 710b57cec5SDimitry Andric# elif defined(__MACH__) 720b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_MACHO 1 730b57cec5SDimitry Andric# elif defined(_WIN32) 740b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_COFF 1 750b57cec5SDimitry Andric# elif defined(__wasm__) 760b57cec5SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_WASM 1 7781ad6265SDimitry Andric# elif defined(_AIX) 7881ad6265SDimitry Andric# define _LIBCPP_OBJECT_FORMAT_XCOFF 1 790b57cec5SDimitry Andric# else 80e8d8bef9SDimitry Andric// ... add new file formats here ... 810b57cec5SDimitry Andric# endif 820b57cec5SDimitry Andric 8381ad6265SDimitry Andric# if _LIBCPP_ABI_VERSION >= 2 840b57cec5SDimitry Andric// Change short string representation so that string data starts at offset 0, 850b57cec5SDimitry Andric// improving its alignment in some cases. 860b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 870b57cec5SDimitry Andric// Fix deque iterator type in order to support incomplete types. 880b57cec5SDimitry Andric# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE 890b57cec5SDimitry Andric// Fix undefined behavior in how std::list stores its linked nodes. 900b57cec5SDimitry Andric# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB 910b57cec5SDimitry Andric// Fix undefined behavior in how __tree stores its end and parent nodes. 920b57cec5SDimitry Andric# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB 930b57cec5SDimitry Andric// Fix undefined behavior in how __hash_table stores its pointer types. 940b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB 950b57cec5SDimitry Andric# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB 960b57cec5SDimitry Andric# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE 970b57cec5SDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 980b57cec5SDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 990b57cec5SDimitry Andric// using that class define their own copies. 1000b57cec5SDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 101349cc55cSDimitry Andric// Override the default return value of exception::what() for 102349cc55cSDimitry Andric// bad_function_call::what() with a string that is specific to 103349cc55cSDimitry Andric// bad_function_call (see http://wg21.link/LWG2233). This is an ABI break 104349cc55cSDimitry Andric// because it changes the vtable layout of bad_function_call. 105349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE 1060b57cec5SDimitry Andric// Enable optimized version of __do_get_(un)signed which avoids redundant copies. 1070b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET 108fe6060f1SDimitry Andric// Give reverse_iterator<T> one data member of type T, not two. 109fe6060f1SDimitry Andric// Also, in C++17 and later, don't derive iterator types from std::iterator. 110fe6060f1SDimitry Andric# define _LIBCPP_ABI_NO_ITERATOR_BASES 1110b57cec5SDimitry Andric// Use the smallest possible integer type to represent the index of the variant. 1120b57cec5SDimitry Andric// Previously libc++ used "unsigned int" exclusively. 1130b57cec5SDimitry Andric# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION 1140b57cec5SDimitry Andric// Unstable attempt to provide a more optimized std::function 1150b57cec5SDimitry Andric# define _LIBCPP_ABI_OPTIMIZED_FUNCTION 1160b57cec5SDimitry Andric// All the regex constants must be distinct and nonzero. 1170b57cec5SDimitry Andric# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO 1185ffd83dbSDimitry Andric// Re-worked external template instantiations for std::string with a focus on 1195ffd83dbSDimitry Andric// performance and fast-path inlining. 1205ffd83dbSDimitry Andric# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 121e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::unique_ptr. 122e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI 123e8d8bef9SDimitry Andric// Enable clang::trivial_abi on std::shared_ptr and std::weak_ptr 124e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI 12504eeddc0SDimitry Andric// std::random_device holds some state when it uses an implementation that gets 12604eeddc0SDimitry Andric// entropy from a file (see _LIBCPP_USING_DEV_RANDOM). When switching from this 12704eeddc0SDimitry Andric// implementation to another one on a platform that has already shipped 12804eeddc0SDimitry Andric// std::random_device, one needs to retain the same object layout to remain ABI 12904eeddc0SDimitry Andric// compatible. This switch removes these workarounds for platforms that don't care 13004eeddc0SDimitry Andric// about ABI compatibility. 13104eeddc0SDimitry Andric# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT 13281ad6265SDimitry Andric// Don't export the legacy __basic_string_common class and its methods from the built library. 1331838bd0fSDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON 13481ad6265SDimitry Andric// Don't export the legacy __vector_base_common class and its methods from the built library. 135d56accc7SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON 13681ad6265SDimitry Andric// According to the Standard, `bitset::operator[] const` returns bool 13781ad6265SDimitry Andric# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 138*1ac55f4cSDimitry Andric// Fix the implementation of CityHash used for std::hash<fundamental-type>. 139*1ac55f4cSDimitry Andric// This is an ABI break because `std::hash` will return a different result, 140*1ac55f4cSDimitry Andric// which means that hashing the same object in translation units built against 141*1ac55f4cSDimitry Andric// different versions of libc++ can return inconsistent results. This is especially 142*1ac55f4cSDimitry Andric// tricky since std::hash is used in the implementation of unordered containers. 143*1ac55f4cSDimitry Andric// 144*1ac55f4cSDimitry Andric// The incorrect implementation of CityHash has the problem that it drops some 145*1ac55f4cSDimitry Andric// bits on the floor. 146*1ac55f4cSDimitry Andric# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION 14781ad6265SDimitry Andric// Remove the base 10 implementation of std::to_chars from the dylib. 14881ad6265SDimitry Andric// The implementation moved to the header, but we still export the symbols from 14981ad6265SDimitry Andric// the dylib for backwards compatibility. 15081ad6265SDimitry Andric# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 1510b57cec5SDimitry Andric# elif _LIBCPP_ABI_VERSION == 1 15281ad6265SDimitry Andric# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) 1530b57cec5SDimitry Andric// Enable compiling copies of now inline methods into the dylib to support 1540b57cec5SDimitry Andric// applications compiled against older libraries. This is unnecessary with 1550b57cec5SDimitry Andric// COFF dllexport semantics, since dllexport forces a non-inline definition 1560b57cec5SDimitry Andric// of inline functions to be emitted anyway. Our own non-inline copy would 15781ad6265SDimitry Andric// conflict with the dllexport-emitted copy, so we disable it. For XCOFF, 15881ad6265SDimitry Andric// the linker will take issue with the symbols in the shared object if the 15981ad6265SDimitry Andric// weak inline methods get visibility (such as from -fvisibility-inlines-hidden), 16081ad6265SDimitry Andric// so disable it. 1610b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS 1620b57cec5SDimitry Andric# endif 1630b57cec5SDimitry Andric// Feature macros for disabling pre ABI v1 features. All of these options 1640b57cec5SDimitry Andric// are deprecated. 1650b57cec5SDimitry Andric# if defined(__FreeBSD__) 1660b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR 1670b57cec5SDimitry Andric# endif 1680b57cec5SDimitry Andric# endif 1690b57cec5SDimitry Andric 17081ad6265SDimitry Andric# if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 171e8d8bef9SDimitry Andric// Enable additional explicit instantiations of iostreams components. This 172e8d8bef9SDimitry Andric// reduces the number of weak definitions generated in programs that use 173e8d8bef9SDimitry Andric// iostreams by providing a single strong definition in the shared library. 174e8d8bef9SDimitry Andric# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 175349cc55cSDimitry Andric 176349cc55cSDimitry Andric// Define a key function for `bad_function_call` in the library, to centralize 177349cc55cSDimitry Andric// its vtable and typeinfo to libc++ rather than having all other libraries 178349cc55cSDimitry Andric// using that class define their own copies. 179349cc55cSDimitry Andric# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION 1800b57cec5SDimitry Andric# endif 1810b57cec5SDimitry Andric 18281ad6265SDimitry Andric# define _LIBCPP_TOSTRING2(x) #x 18381ad6265SDimitry Andric# define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x) 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric# if __cplusplus < 201103L 1860b57cec5SDimitry Andric# define _LIBCPP_CXX03_LANG 1870b57cec5SDimitry Andric# endif 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric# ifndef __has_attribute 1900b57cec5SDimitry Andric# define __has_attribute(__x) 0 1910b57cec5SDimitry Andric# endif 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric# ifndef __has_builtin 1940b57cec5SDimitry Andric# define __has_builtin(__x) 0 1950b57cec5SDimitry Andric# endif 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric# ifndef __has_extension 1980b57cec5SDimitry Andric# define __has_extension(__x) 0 1990b57cec5SDimitry Andric# endif 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric# ifndef __has_feature 2020b57cec5SDimitry Andric# define __has_feature(__x) 0 2030b57cec5SDimitry Andric# endif 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andric# ifndef __has_cpp_attribute 2060b57cec5SDimitry Andric# define __has_cpp_attribute(__x) 0 2070b57cec5SDimitry Andric# endif 2080b57cec5SDimitry Andric 209bdd1243dSDimitry Andric# ifndef __has_constexpr_builtin 210bdd1243dSDimitry Andric# define __has_constexpr_builtin(x) 0 211bdd1243dSDimitry Andric# endif 212bdd1243dSDimitry Andric 2130b57cec5SDimitry Andric// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by 2140b57cec5SDimitry Andric// the compiler and '1' otherwise. 2150b57cec5SDimitry Andric# ifndef __is_identifier 2160b57cec5SDimitry Andric# define __is_identifier(__x) 1 2170b57cec5SDimitry Andric# endif 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric# ifndef __has_declspec_attribute 2200b57cec5SDimitry Andric# define __has_declspec_attribute(__x) 0 2210b57cec5SDimitry Andric# endif 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric# define __has_keyword(__x) !(__is_identifier(__x)) 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andric# ifndef __has_include 2260b57cec5SDimitry Andric# define __has_include(...) 0 2270b57cec5SDimitry Andric# endif 2280b57cec5SDimitry Andric 22981ad6265SDimitry Andric# if !defined(_LIBCPP_COMPILER_CLANG_BASED) && __cplusplus < 201103L 23081ad6265SDimitry Andric# error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" 2310b57cec5SDimitry Andric# endif 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric// FIXME: ABI detection should be done via compiler builtin macros. This 2340b57cec5SDimitry Andric// is just a placeholder until Clang implements such macros. For now assume 2350b57cec5SDimitry Andric// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, 2360b57cec5SDimitry Andric// and allow the user to explicitly specify the ABI to handle cases where this 2370b57cec5SDimitry Andric// heuristic falls short. 2380b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) 2390b57cec5SDimitry Andric# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" 2400b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) 2410b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 2420b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) 2430b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 2440b57cec5SDimitry Andric# else 2450b57cec5SDimitry Andric# if defined(_WIN32) && defined(_MSC_VER) 2460b57cec5SDimitry Andric# define _LIBCPP_ABI_MICROSOFT 2470b57cec5SDimitry Andric# else 2480b57cec5SDimitry Andric# define _LIBCPP_ABI_ITANIUM 2490b57cec5SDimitry Andric# endif 2500b57cec5SDimitry Andric# endif 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) 2530b57cec5SDimitry Andric# define _LIBCPP_ABI_VCRUNTIME 2540b57cec5SDimitry Andric# endif 2550b57cec5SDimitry Andric 256fcaf7f86SDimitry Andric# if __has_feature(experimental_library) 257fcaf7f86SDimitry Andric# ifndef _LIBCPP_ENABLE_EXPERIMENTAL 258fcaf7f86SDimitry Andric# define _LIBCPP_ENABLE_EXPERIMENTAL 259fcaf7f86SDimitry Andric# endif 260fcaf7f86SDimitry Andric# endif 261fcaf7f86SDimitry Andric 262fcaf7f86SDimitry Andric// Incomplete features get their own specific disabling flags. This makes it 263fcaf7f86SDimitry Andric// easier to grep for target specific flags once the feature is complete. 264fcaf7f86SDimitry Andric# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) 265fcaf7f86SDimitry Andric# define _LIBCPP_HAS_NO_INCOMPLETE_FORMAT 266fcaf7f86SDimitry Andric# endif 267fcaf7f86SDimitry Andric 2680b57cec5SDimitry Andric// Need to detect which libc we're using if we're on Linux. 2690b57cec5SDimitry Andric# if defined(__linux__) 2700b57cec5SDimitry Andric# include <features.h> 2710b57cec5SDimitry Andric# if defined(__GLIBC_PREREQ) 2720b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) 2730b57cec5SDimitry Andric# else 2740b57cec5SDimitry Andric# define _LIBCPP_GLIBC_PREREQ(a, b) 0 2750b57cec5SDimitry Andric# endif // defined(__GLIBC_PREREQ) 2760b57cec5SDimitry Andric# endif // defined(__linux__) 2770b57cec5SDimitry Andric 27804eeddc0SDimitry Andric# if defined(__MVS__) 27904eeddc0SDimitry Andric# include <features.h> // for __NATIVE_ASCII_F 28004eeddc0SDimitry Andric# endif 28104eeddc0SDimitry Andric 2820b57cec5SDimitry Andric# ifdef __LITTLE_ENDIAN__ 2830b57cec5SDimitry Andric# if __LITTLE_ENDIAN__ 2840b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 2850b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 2860b57cec5SDimitry Andric# endif // __LITTLE_ENDIAN__ 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andric# ifdef __BIG_ENDIAN__ 2890b57cec5SDimitry Andric# if __BIG_ENDIAN__ 2900b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 2910b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 2920b57cec5SDimitry Andric# endif // __BIG_ENDIAN__ 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andric# ifdef __BYTE_ORDER__ 2950b57cec5SDimitry Andric# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 2960b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 2970b57cec5SDimitry Andric# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 2980b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 2990b57cec5SDimitry Andric# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 3000b57cec5SDimitry Andric# endif // __BYTE_ORDER__ 3010b57cec5SDimitry Andric 3020b57cec5SDimitry Andric# ifdef __FreeBSD__ 3030b57cec5SDimitry Andric# include <sys/endian.h> 3040b57cec5SDimitry Andric# include <osreldate.h> 3050b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 3060b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 3070b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 3080b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 3090b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 3100b57cec5SDimitry Andric# endif // __FreeBSD__ 3110b57cec5SDimitry Andric 312e8d8bef9SDimitry Andric# if defined(__NetBSD__) || defined(__OpenBSD__) 3130b57cec5SDimitry Andric# include <sys/endian.h> 3140b57cec5SDimitry Andric# if _BYTE_ORDER == _LITTLE_ENDIAN 3150b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 3160b57cec5SDimitry Andric# else // _BYTE_ORDER == _LITTLE_ENDIAN 3170b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 3180b57cec5SDimitry Andric# endif // _BYTE_ORDER == _LITTLE_ENDIAN 319e8d8bef9SDimitry Andric# endif // defined(__NetBSD__) || defined(__OpenBSD__) 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric# if defined(_WIN32) 3220b57cec5SDimitry Andric# define _LIBCPP_WIN32API 3230b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 3240b57cec5SDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 3250b57cec5SDimitry Andric// Both MinGW and native MSVC provide a "MSVC"-like environment 3260b57cec5SDimitry Andric# define _LIBCPP_MSVCRT_LIKE 3270b57cec5SDimitry Andric// If mingw not explicitly detected, assume using MS C runtime only if 3280b57cec5SDimitry Andric// a MS compatibility version is specified. 3290b57cec5SDimitry Andric# if defined(_MSC_VER) && !defined(__MINGW32__) 3300b57cec5SDimitry Andric# define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library 3310b57cec5SDimitry Andric# endif 3320b57cec5SDimitry Andric# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) 3330b57cec5SDimitry Andric# define _LIBCPP_HAS_BITSCAN64 3340b57cec5SDimitry Andric# endif 3350b57cec5SDimitry Andric# define _LIBCPP_HAS_OPEN_WITH_WCHAR 3360b57cec5SDimitry Andric# endif // defined(_WIN32) 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric# ifdef __sun__ 3390b57cec5SDimitry Andric# include <sys/isa_defs.h> 3400b57cec5SDimitry Andric# ifdef _LITTLE_ENDIAN 3410b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 3420b57cec5SDimitry Andric# else 3430b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 3440b57cec5SDimitry Andric# endif 3450b57cec5SDimitry Andric# endif // __sun__ 3460b57cec5SDimitry Andric 347349cc55cSDimitry Andric# if defined(_AIX) && !defined(__64BIT__) 348349cc55cSDimitry Andric// The size of wchar is 2 byte on 32-bit mode on AIX. 349349cc55cSDimitry Andric# define _LIBCPP_SHORT_WCHAR 1 350349cc55cSDimitry Andric# endif 351349cc55cSDimitry Andric 3520eae32dcSDimitry Andric// Libc++ supports various implementations of std::random_device. 3530eae32dcSDimitry Andric// 3540eae32dcSDimitry Andric// _LIBCPP_USING_DEV_RANDOM 3550eae32dcSDimitry Andric// Read entropy from the given file, by default `/dev/urandom`. 3560eae32dcSDimitry Andric// If a token is provided, it is assumed to be the path to a file 3570eae32dcSDimitry Andric// to read entropy from. This is the default behavior if nothing 3580eae32dcSDimitry Andric// else is specified. This implementation requires storing state 3590eae32dcSDimitry Andric// inside `std::random_device`. 3600eae32dcSDimitry Andric// 3610eae32dcSDimitry Andric// _LIBCPP_USING_ARC4_RANDOM 3620eae32dcSDimitry Andric// Use arc4random(). This allows obtaining random data even when 3630eae32dcSDimitry Andric// using sandboxing mechanisms. On some platforms like Apple, this 3640eae32dcSDimitry Andric// is the recommended source of entropy for user-space programs. 3650eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 3660eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 3670eae32dcSDimitry Andric// 3680eae32dcSDimitry Andric// _LIBCPP_USING_GETENTROPY 3690eae32dcSDimitry Andric// Use getentropy(). 3700eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 3710eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 3720eae32dcSDimitry Andric// 37304eeddc0SDimitry Andric// _LIBCPP_USING_FUCHSIA_CPRNG 37404eeddc0SDimitry Andric// Use Fuchsia's zx_cprng_draw() system call, which is specified to 37504eeddc0SDimitry Andric// deliver high-quality entropy and cannot fail. 37604eeddc0SDimitry Andric// When this option is used, the token passed to `std::random_device`'s 37704eeddc0SDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 37804eeddc0SDimitry Andric// 3790eae32dcSDimitry Andric// _LIBCPP_USING_NACL_RANDOM 3800eae32dcSDimitry Andric// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, 3810eae32dcSDimitry Andric// including accesses to the special files under `/dev`. This implementation 3820eae32dcSDimitry Andric// uses the NaCL syscall `nacl_secure_random_init()` to get entropy. 3830eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 3840eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 3850eae32dcSDimitry Andric// 3860eae32dcSDimitry Andric// _LIBCPP_USING_WIN32_RANDOM 3870eae32dcSDimitry Andric// Use rand_s(), for use on Windows. 3880eae32dcSDimitry Andric// When this option is used, the token passed to `std::random_device`'s 3890eae32dcSDimitry Andric// constructor *must* be "/dev/urandom" -- anything else is an error. 39081ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 39181ad6265SDimitry Andric defined(__DragonFly__) || defined(__sun__) 3920b57cec5SDimitry Andric# define _LIBCPP_USING_ARC4_RANDOM 39381ad6265SDimitry Andric# elif defined(__wasi__) || defined(__EMSCRIPTEN__) 3940b57cec5SDimitry Andric# define _LIBCPP_USING_GETENTROPY 39504eeddc0SDimitry Andric# elif defined(__Fuchsia__) 39604eeddc0SDimitry Andric# define _LIBCPP_USING_FUCHSIA_CPRNG 3970b57cec5SDimitry Andric# elif defined(__native_client__) 3980b57cec5SDimitry Andric# define _LIBCPP_USING_NACL_RANDOM 3990b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 4000b57cec5SDimitry Andric# define _LIBCPP_USING_WIN32_RANDOM 4010b57cec5SDimitry Andric# else 4020b57cec5SDimitry Andric# define _LIBCPP_USING_DEV_RANDOM 4030b57cec5SDimitry Andric# endif 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andric# if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 4060b57cec5SDimitry Andric# include <endian.h> 4070b57cec5SDimitry Andric# if __BYTE_ORDER == __LITTLE_ENDIAN 4080b57cec5SDimitry Andric# define _LIBCPP_LITTLE_ENDIAN 4090b57cec5SDimitry Andric# elif __BYTE_ORDER == __BIG_ENDIAN 4100b57cec5SDimitry Andric# define _LIBCPP_BIG_ENDIAN 4110b57cec5SDimitry Andric# else // __BYTE_ORDER == __BIG_ENDIAN 4120b57cec5SDimitry Andric# error unable to determine endian 4130b57cec5SDimitry Andric# endif 4140b57cec5SDimitry Andric# endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andric# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) 4170b57cec5SDimitry Andric# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) 4180b57cec5SDimitry Andric# else 4190b57cec5SDimitry Andric# define _LIBCPP_NO_CFI 4200b57cec5SDimitry Andric# endif 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andric# ifndef _LIBCPP_CXX03_LANG 42381ad6265SDimitry Andric 4240b57cec5SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) 42581ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) alignas(x) 42681ad6265SDimitry Andric# define _ALIGNAS(x) alignas(x) 42781ad6265SDimitry Andric# define _LIBCPP_NORETURN [[noreturn]] 42881ad6265SDimitry Andric# define _NOEXCEPT noexcept 42981ad6265SDimitry Andric# define _NOEXCEPT_(x) noexcept(x) 430bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR constexpr 43181ad6265SDimitry Andric 4320b57cec5SDimitry Andric# else 43381ad6265SDimitry Andric 43481ad6265SDimitry Andric# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) 43581ad6265SDimitry Andric# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) 43681ad6265SDimitry Andric# define _ALIGNAS(x) __attribute__((__aligned__(x))) 437bdd1243dSDimitry Andric# define _LIBCPP_NORETURN __attribute__((__noreturn__)) 43881ad6265SDimitry Andric# define _LIBCPP_HAS_NO_NOEXCEPT 43981ad6265SDimitry Andric# define nullptr __nullptr 44081ad6265SDimitry Andric# define _NOEXCEPT throw() 44181ad6265SDimitry Andric# define _NOEXCEPT_(x) 442bdd1243dSDimitry Andric# define static_assert(...) _Static_assert(__VA_ARGS__) 443bdd1243dSDimitry Andric# define decltype(...) __decltype(__VA_ARGS__) 444bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR 44581ad6265SDimitry Andric 44681ad6265SDimitry Andrictypedef __char16_t char16_t; 44781ad6265SDimitry Andrictypedef __char32_t char32_t; 44881ad6265SDimitry Andric 44981ad6265SDimitry Andric# endif 45081ad6265SDimitry Andric 45181ad6265SDimitry Andric# if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L 45281ad6265SDimitry Andric# define _LIBCPP_NO_EXCEPTIONS 4530b57cec5SDimitry Andric# endif 4540b57cec5SDimitry Andric 4550b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp) 4560b57cec5SDimitry Andric 457fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) 4580b57cec5SDimitry Andric 45981ad6265SDimitry Andric# if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && (!defined(__arm__) || __ARM_ARCH_7K__ >= 2) 4600b57cec5SDimitry Andric# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 4610b57cec5SDimitry Andric# endif 4620b57cec5SDimitry Andric 4630b57cec5SDimitry Andric// Objective-C++ features (opt-in) 4640b57cec5SDimitry Andric# if __has_feature(objc_arc) 4650b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC 4660b57cec5SDimitry Andric# endif 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric# if __has_feature(objc_arc_weak) 4690b57cec5SDimitry Andric# define _LIBCPP_HAS_OBJC_ARC_WEAK 4700b57cec5SDimitry Andric# endif 4710b57cec5SDimitry Andric 4725ffd83dbSDimitry Andric# if __has_extension(blocks) 4735ffd83dbSDimitry Andric# define _LIBCPP_HAS_EXTENSION_BLOCKS 4745ffd83dbSDimitry Andric# endif 4755ffd83dbSDimitry Andric 4765ffd83dbSDimitry Andric# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) 4775ffd83dbSDimitry Andric# define _LIBCPP_HAS_BLOCKS_RUNTIME 4785ffd83dbSDimitry Andric# endif 4795ffd83dbSDimitry Andric 480fe6060f1SDimitry Andric# if !__has_feature(address_sanitizer) 4810b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 4820b57cec5SDimitry Andric# endif 4830b57cec5SDimitry Andric 4840b57cec5SDimitry Andric// Allow for build-time disabling of unsigned integer sanitization 485fe6060f1SDimitry Andric# if __has_attribute(no_sanitize) 4860b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) 4870b57cec5SDimitry Andric# endif 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 4900b57cec5SDimitry Andric 491e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 492e40139ffSDimitry Andric 4930b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 4940b57cec5SDimitry Andric 495fe6060f1SDimitry Andric# if !defined(__SANITIZE_ADDRESS__) 4960b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ASAN 4970b57cec5SDimitry Andric# endif 4980b57cec5SDimitry Andric 4990b57cec5SDimitry Andric# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) 5000b57cec5SDimitry Andric 501e40139ffSDimitry Andric# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__ 502e40139ffSDimitry Andric 503bdd1243dSDimitry Andric# endif // _LIBCPP_COMPILER_[CLANG|GCC] 5040b57cec5SDimitry Andric 5050b57cec5SDimitry Andric# if defined(_LIBCPP_OBJECT_FORMAT_COFF) 5060b57cec5SDimitry Andric 5070b57cec5SDimitry Andric# ifdef _DLL 5080b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC __declspec(dllimport) 5090b57cec5SDimitry Andric# else 5100b57cec5SDimitry Andric# define _LIBCPP_CRT_FUNC 5110b57cec5SDimitry Andric# endif 5120b57cec5SDimitry Andric 51381ad6265SDimitry Andric# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY)) 5140b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS 5150b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 5160b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 5170b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 5180b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI 5190b57cec5SDimitry Andric# elif defined(_LIBCPP_BUILDING_LIBRARY) 5200b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllexport) 5210b57cec5SDimitry Andric# if defined(__MINGW32__) 5220b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 5230b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 5240b57cec5SDimitry Andric# else 5250b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS 5260b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS 5270b57cec5SDimitry Andric# endif 5280b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS 5290b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) 5300b57cec5SDimitry Andric# else 5310b57cec5SDimitry Andric# define _LIBCPP_DLL_VIS __declspec(dllimport) 5320b57cec5SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS 5330b57cec5SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 5340b57cec5SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS 5350b57cec5SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport) 5360b57cec5SDimitry Andric# endif 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric# define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS 5390b57cec5SDimitry Andric# define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS 5400b57cec5SDimitry Andric# define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS 5410b57cec5SDimitry Andric# define _LIBCPP_HIDDEN 5420b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 5430b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 544fe6060f1SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS 5450b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andric# else 54881ad6265SDimitry Andric 54981ad6265SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 55081ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) __attribute__((__visibility__(vis))) 55181ad6265SDimitry Andric# else 55281ad6265SDimitry Andric# define _LIBCPP_VISIBILITY(vis) 5530b57cec5SDimitry Andric# endif 5540b57cec5SDimitry Andric 55581ad6265SDimitry Andric# define _LIBCPP_HIDDEN _LIBCPP_VISIBILITY("hidden") 55681ad6265SDimitry Andric# define _LIBCPP_FUNC_VIS _LIBCPP_VISIBILITY("default") 55781ad6265SDimitry Andric# define _LIBCPP_TYPE_VIS _LIBCPP_VISIBILITY("default") 55881ad6265SDimitry Andric# define _LIBCPP_TEMPLATE_DATA_VIS _LIBCPP_VISIBILITY("default") 55981ad6265SDimitry Andric# define _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_VISIBILITY("default") 56081ad6265SDimitry Andric# define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBILITY("default") 56181ad6265SDimitry Andric# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_VISIBILITY("default") 56281ad6265SDimitry Andric# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 56381ad6265SDimitry Andric 564fcaf7f86SDimitry Andric// TODO: Make this a proper customization point or remove the option to override it. 565fcaf7f86SDimitry Andric# ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS 566fcaf7f86SDimitry Andric# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_VISIBILITY("default") 567fcaf7f86SDimitry Andric# endif 568fcaf7f86SDimitry Andric 5690b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 5700b57cec5SDimitry Andric// The inline should be removed once PR32114 is resolved 5710b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN 5720b57cec5SDimitry Andric# else 5730b57cec5SDimitry Andric# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 5740b57cec5SDimitry Andric# endif 5750b57cec5SDimitry Andric 5760b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 5770b57cec5SDimitry Andric# if __has_attribute(__type_visibility__) 5780b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__type_visibility__("default"))) 5790b57cec5SDimitry Andric# else 5800b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS __attribute__((__visibility__("default"))) 5810b57cec5SDimitry Andric# endif 5820b57cec5SDimitry Andric# else 5830b57cec5SDimitry Andric# define _LIBCPP_TEMPLATE_VIS 5840b57cec5SDimitry Andric# endif 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__) 5870b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS __attribute__((__type_visibility__("default"))) 5880b57cec5SDimitry Andric# else 5890b57cec5SDimitry Andric# define _LIBCPP_ENUM_VIS 5900b57cec5SDimitry Andric# endif 5910b57cec5SDimitry Andric 59281ad6265SDimitry Andric# endif // defined(_LIBCPP_OBJECT_FORMAT_COFF) 5930b57cec5SDimitry Andric 5940b57cec5SDimitry Andric# if __has_attribute(exclude_from_explicit_instantiation) 5950b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((__exclude_from_explicit_instantiation__)) 5960b57cec5SDimitry Andric# else 5970b57cec5SDimitry Andric// Try to approximate the effect of exclude_from_explicit_instantiation 5980b57cec5SDimitry Andric// (which is that entities are not assumed to be provided by explicit 5990b57cec5SDimitry Andric// template instantiations in the dylib) by always inlining those entities. 6000b57cec5SDimitry Andric# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE 6010b57cec5SDimitry Andric# endif 6020b57cec5SDimitry Andric 603753f127fSDimitry Andric// This macro marks a symbol as being hidden from libc++'s ABI. This is achieved 604753f127fSDimitry Andric// on two levels: 605753f127fSDimitry Andric// 1. The symbol is given hidden visibility, which ensures that users won't start exporting 606753f127fSDimitry Andric// symbols from their dynamic library by means of using the libc++ headers. This ensures 607753f127fSDimitry Andric// that those symbols stay private to the dynamic library in which it is defined. 608753f127fSDimitry Andric// 609753f127fSDimitry Andric// 2. The symbol is given an ABI tag that changes with each version of libc++. This ensures 610753f127fSDimitry Andric// that no ODR violation can arise from mixing two TUs compiled with different versions 611753f127fSDimitry Andric// of libc++ where we would have changed the definition of a symbol. If the symbols shared 612753f127fSDimitry Andric// the same name, the ODR would require that their definitions be token-by-token equivalent, 613753f127fSDimitry Andric// which basically prevents us from being able to make any change to any function in our 614753f127fSDimitry Andric// headers. Using this ABI tag ensures that the symbol name is "bumped" artificially at 615753f127fSDimitry Andric// each release, which lets us change the definition of these symbols at our leisure. 616753f127fSDimitry Andric// Note that historically, this has been achieved in various ways, including force-inlining 617753f127fSDimitry Andric// all functions or giving internal linkage to all functions. Both these (previous) solutions 618753f127fSDimitry Andric// suffer from drawbacks that lead notably to code bloat. 619753f127fSDimitry Andric// 620753f127fSDimitry Andric// Note that we use _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION to ensure that we don't depend 621753f127fSDimitry Andric// on _LIBCPP_HIDE_FROM_ABI methods of classes explicitly instantiated in the dynamic library. 622753f127fSDimitry Andric// 623bdd1243dSDimitry Andric// Also note that the _LIBCPP_HIDE_FROM_ABI_VIRTUAL macro should be used on virtual functions 624bdd1243dSDimitry Andric// instead of _LIBCPP_HIDE_FROM_ABI. That macro does not use an ABI tag. Indeed, the mangled 625bdd1243dSDimitry Andric// name of a virtual function is part of its ABI, since some architectures like arm64e can sign 626bdd1243dSDimitry Andric// the virtual function pointer in the vtable based on the mangled name of the function. Since 627bdd1243dSDimitry Andric// we use an ABI tag that changes with each released version, the mangled name of the virtual 628bdd1243dSDimitry Andric// function would change, which is incorrect. Note that it doesn't make much sense to change 629bdd1243dSDimitry Andric// the implementation of a virtual function in an ABI-incompatible way in the first place, 630bdd1243dSDimitry Andric// since that would be an ABI break anyway. Hence, the lack of ABI tag should not be noticeable. 631bdd1243dSDimitry Andric// 632753f127fSDimitry Andric// TODO: We provide a escape hatch with _LIBCPP_NO_ABI_TAG for folks who want to avoid increasing 633753f127fSDimitry Andric// the length of symbols with an ABI tag. In practice, we should remove the escape hatch and 634753f127fSDimitry Andric// use compression mangling instead, see https://github.com/itanium-cxx-abi/cxx-abi/issues/70. 635753f127fSDimitry Andric# ifndef _LIBCPP_NO_ABI_TAG 636753f127fSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI \ 637753f127fSDimitry Andric _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION \ 638753f127fSDimitry Andric __attribute__((__abi_tag__(_LIBCPP_TOSTRING(_LIBCPP_VERSIONED_IDENTIFIER)))) 6390b57cec5SDimitry Andric# else 6400b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 6410b57cec5SDimitry Andric# endif 642bdd1243dSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_VIRTUAL _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 6430b57cec5SDimitry Andric 644*1ac55f4cSDimitry Andric// This macro provides a HIDE_FROM_ABI equivalent that can be applied to extern 645*1ac55f4cSDimitry Andric// "C" function, as those lack mangling. 646*1ac55f4cSDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_C _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION 647*1ac55f4cSDimitry Andric 6480b57cec5SDimitry Andric# ifdef _LIBCPP_BUILDING_LIBRARY 6490b57cec5SDimitry Andric# if _LIBCPP_ABI_VERSION > 1 6500b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 6510b57cec5SDimitry Andric# else 6520b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 6530b57cec5SDimitry Andric# endif 6540b57cec5SDimitry Andric# else 6550b57cec5SDimitry Andric# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI 6560b57cec5SDimitry Andric# endif 6570b57cec5SDimitry Andric 6580b57cec5SDimitry Andric// Just so we can migrate to the new macros gradually. 6590b57cec5SDimitry Andric# define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI 6600b57cec5SDimitry Andric 6610b57cec5SDimitry Andric// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect. 66281ad6265SDimitry Andric// clang-format off 6630b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE { 6640b57cec5SDimitry Andric# define _LIBCPP_END_NAMESPACE_STD }} 6651fd87a68SDimitry Andric# define _VSTD std 66681ad6265SDimitry Andric 6670b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD 6680b57cec5SDimitry Andric 6691fd87a68SDimitry Andric# if _LIBCPP_STD_VER > 14 6700b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 6710b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem { 6720b57cec5SDimitry Andric# else 6730b57cec5SDimitry Andric# define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \ 6740b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem { 6750b57cec5SDimitry Andric# endif 6760b57cec5SDimitry Andric 67781ad6265SDimitry Andric# define _LIBCPP_END_NAMESPACE_FILESYSTEM _LIBCPP_END_NAMESPACE_STD }} 67881ad6265SDimitry Andric// clang-format on 6790b57cec5SDimitry Andric 68081ad6265SDimitry Andric# define _VSTD_FS std::__fs::filesystem 6810b57cec5SDimitry Andric 6820b57cec5SDimitry Andric# if __has_attribute(__enable_if__) 6830b57cec5SDimitry Andric# define _LIBCPP_PREFERRED_OVERLOAD __attribute__((__enable_if__(true, ""))) 6840b57cec5SDimitry Andric# endif 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andric# ifndef __SIZEOF_INT128__ 6870b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_INT128 6880b57cec5SDimitry Andric# endif 6890b57cec5SDimitry Andric 690e8d8bef9SDimitry Andric# ifndef __cpp_consteval 691e8d8bef9SDimitry Andric# define _LIBCPP_CONSTEVAL _LIBCPP_CONSTEXPR 692e8d8bef9SDimitry Andric# else 693e8d8bef9SDimitry Andric# define _LIBCPP_CONSTEVAL consteval 694e8d8bef9SDimitry Andric# endif 695e8d8bef9SDimitry Andric 696bdd1243dSDimitry Andric# if __has_attribute(__malloc__) 6970b57cec5SDimitry Andric# define _LIBCPP_NOALIAS __attribute__((__malloc__)) 6980b57cec5SDimitry Andric# else 6990b57cec5SDimitry Andric# define _LIBCPP_NOALIAS 7000b57cec5SDimitry Andric# endif 7010b57cec5SDimitry Andric 702bdd1243dSDimitry Andric# if __has_attribute(__using_if_exists__) 703bdd1243dSDimitry Andric# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__)) 7040b57cec5SDimitry Andric# else 705fe6060f1SDimitry Andric# define _LIBCPP_USING_IF_EXISTS 7060b57cec5SDimitry Andric# endif 7070b57cec5SDimitry Andric 70881ad6265SDimitry Andric# ifdef _LIBCPP_CXX03_LANG 70981ad6265SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) \ 71081ad6265SDimitry Andric struct _LIBCPP_TYPE_VIS x { \ 71181ad6265SDimitry Andric enum __lx 71281ad6265SDimitry Andric// clang-format off 7130b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ 7140b57cec5SDimitry Andric __lx __v_; \ 7150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \ 7160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \ 7170b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY operator int() const { return __v_; } \ 7180b57cec5SDimitry Andric }; 71981ad6265SDimitry Andric// clang-format on 72081ad6265SDimitry Andric 72181ad6265SDimitry Andric# else // _LIBCPP_CXX03_LANG 7220b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x 7230b57cec5SDimitry Andric# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) 72481ad6265SDimitry Andric# endif // _LIBCPP_CXX03_LANG 7250b57cec5SDimitry Andric 72681ad6265SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__sun__) || \ 72781ad6265SDimitry Andric defined(__NetBSD__) 7280b57cec5SDimitry Andric# define _LIBCPP_LOCALE__L_EXTENSIONS 1 7290b57cec5SDimitry Andric# endif 7300b57cec5SDimitry Andric 7310b57cec5SDimitry Andric# ifdef __FreeBSD__ 7320b57cec5SDimitry Andric# define _DECLARE_C99_LDBL_MATH 1 7330b57cec5SDimitry Andric# endif 7340b57cec5SDimitry Andric 7350b57cec5SDimitry Andric// If we are getting operator new from the MSVC CRT, then allocation overloads 7360b57cec5SDimitry Andric// for align_val_t were added in 19.12, aka VS 2017 version 15.3. 7370b57cec5SDimitry Andric# if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 7380b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 7390b57cec5SDimitry Andric# elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) 7400b57cec5SDimitry Andric// We're deferring to Microsoft's STL to provide aligned new et al. We don't 7410b57cec5SDimitry Andric// have it unless the language feature test macro is defined. 7420b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 743e8d8bef9SDimitry Andric# elif defined(__MVS__) 744e8d8bef9SDimitry Andric# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION 7450b57cec5SDimitry Andric# endif 7460b57cec5SDimitry Andric 74781ad6265SDimitry Andric# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) 7480b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION 7490b57cec5SDimitry Andric# endif 7500b57cec5SDimitry Andric 751bdd1243dSDimitry Andric// It is not yet possible to use aligned_alloc() on all Apple platforms since 752bdd1243dSDimitry Andric// 10.15 was the first version to ship an implementation of aligned_alloc(). 753bdd1243dSDimitry Andric# if defined(__APPLE__) 754bdd1243dSDimitry Andric# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 755bdd1243dSDimitry Andric __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) 756bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 757bdd1243dSDimitry Andric# endif 758bdd1243dSDimitry Andric# elif defined(__ANDROID__) && __ANDROID_API__ < 28 759bdd1243dSDimitry Andric// Android only provides aligned_alloc when targeting API 28 or higher. 760bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC 761bdd1243dSDimitry Andric# endif 762bdd1243dSDimitry Andric 7630b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) 7640b57cec5SDimitry Andric# define _LIBCPP_HAS_DEFAULTRUNELOCALE 7650b57cec5SDimitry Andric# endif 7660b57cec5SDimitry Andric 7670b57cec5SDimitry Andric# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__) 7680b57cec5SDimitry Andric# define _LIBCPP_WCTYPE_IS_MASK 7690b57cec5SDimitry Andric# endif 7700b57cec5SDimitry Andric 7710b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) 772fe6060f1SDimitry Andric# define _LIBCPP_HAS_NO_CHAR8_T 7730b57cec5SDimitry Andric# endif 7740b57cec5SDimitry Andric 7750b57cec5SDimitry Andric// Deprecation macros. 7760b57cec5SDimitry Andric// 7770b57cec5SDimitry Andric// Deprecations warnings are always enabled, except when users explicitly opt-out 7780b57cec5SDimitry Andric// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. 7790b57cec5SDimitry Andric# if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) 7800b57cec5SDimitry Andric# if __has_attribute(deprecated) 7810b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED __attribute__((deprecated)) 782bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_(m) __attribute__((deprecated(m))) 7830b57cec5SDimitry Andric# elif _LIBCPP_STD_VER > 11 7840b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED [[deprecated]] 78581ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) [[deprecated(m)]] 7860b57cec5SDimitry Andric# else 7870b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 78881ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 7890b57cec5SDimitry Andric# endif 7900b57cec5SDimitry Andric# else 7910b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED 79281ad6265SDimitry Andric# define _LIBCPP_DEPRECATED_(m) 7930b57cec5SDimitry Andric# endif 7940b57cec5SDimitry Andric 7950b57cec5SDimitry Andric# if !defined(_LIBCPP_CXX03_LANG) 7960b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED 7970b57cec5SDimitry Andric# else 7980b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX11 7990b57cec5SDimitry Andric# endif 8000b57cec5SDimitry Andric 80181ad6265SDimitry Andric# if _LIBCPP_STD_VER > 11 8020b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED 8030b57cec5SDimitry Andric# else 8040b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX14 8050b57cec5SDimitry Andric# endif 8060b57cec5SDimitry Andric 80781ad6265SDimitry Andric# if _LIBCPP_STD_VER > 14 8080b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED 8090b57cec5SDimitry Andric# else 8100b57cec5SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX17 8110b57cec5SDimitry Andric# endif 8120b57cec5SDimitry Andric 813e8d8bef9SDimitry Andric# if _LIBCPP_STD_VER > 17 814e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_DEPRECATED 815e8d8bef9SDimitry Andric# else 816e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX20 817e8d8bef9SDimitry Andric# endif 818e8d8bef9SDimitry Andric 819bdd1243dSDimitry Andric#if _LIBCPP_STD_VER >= 23 820bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_DEPRECATED 821bdd1243dSDimitry Andric#else 822bdd1243dSDimitry Andric# define _LIBCPP_DEPRECATED_IN_CXX23 823bdd1243dSDimitry Andric#endif 824bdd1243dSDimitry Andric 825fe6060f1SDimitry Andric# if !defined(_LIBCPP_HAS_NO_CHAR8_T) 826e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED 827e8d8bef9SDimitry Andric# else 828e8d8bef9SDimitry Andric# define _LIBCPP_DEPRECATED_WITH_CHAR8_T 829e8d8bef9SDimitry Andric# endif 830e8d8bef9SDimitry Andric 831e40139ffSDimitry Andric// Macros to enter and leave a state where deprecation warnings are suppressed. 832fe6060f1SDimitry Andric# if defined(_LIBCPP_COMPILER_CLANG_BASED) || defined(_LIBCPP_COMPILER_GCC) 833e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \ 83481ad6265SDimitry Andric _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"") \ 835fe6060f1SDimitry Andric _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 83681ad6265SDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop") 837fe6060f1SDimitry Andric# else 838e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH 839e40139ffSDimitry Andric# define _LIBCPP_SUPPRESS_DEPRECATED_POP 840e40139ffSDimitry Andric# endif 841e40139ffSDimitry Andric 8420b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 11 8430b57cec5SDimitry Andric# define _LIBCPP_EXPLICIT_AFTER_CXX11 8440b57cec5SDimitry Andric# else 8450b57cec5SDimitry Andric# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit 8460b57cec5SDimitry Andric# endif 8470b57cec5SDimitry Andric 848349cc55cSDimitry Andric# if _LIBCPP_STD_VER > 11 849bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 constexpr 8500b57cec5SDimitry Andric# else 851bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX14 8520b57cec5SDimitry Andric# endif 8530b57cec5SDimitry Andric 854349cc55cSDimitry Andric# if _LIBCPP_STD_VER > 14 855bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 constexpr 8560b57cec5SDimitry Andric# else 857bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX17 8580b57cec5SDimitry Andric# endif 8590b57cec5SDimitry Andric 860349cc55cSDimitry Andric# if _LIBCPP_STD_VER > 17 861bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 constexpr 8620b57cec5SDimitry Andric# else 863bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX20 8640b57cec5SDimitry Andric# endif 8650b57cec5SDimitry Andric 866bdd1243dSDimitry Andric# if _LIBCPP_STD_VER > 20 867bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 constexpr 868bdd1243dSDimitry Andric# else 869bdd1243dSDimitry Andric# define _LIBCPP_CONSTEXPR_SINCE_CXX23 870bdd1243dSDimitry Andric# endif 871bdd1243dSDimitry Andric 872bdd1243dSDimitry Andric# if __has_cpp_attribute(nodiscard) 873349cc55cSDimitry Andric# define _LIBCPP_NODISCARD [[nodiscard]] 8740b57cec5SDimitry Andric# else 8750b57cec5SDimitry Andric// We can't use GCC's [[gnu::warn_unused_result]] and 8760b57cec5SDimitry Andric// __attribute__((warn_unused_result)), because GCC does not silence them via 8770b57cec5SDimitry Andric// (void) cast. 878349cc55cSDimitry Andric# define _LIBCPP_NODISCARD 8790b57cec5SDimitry Andric# endif 8800b57cec5SDimitry Andric 8810b57cec5SDimitry Andric// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not 8820b57cec5SDimitry Andric// specified as such as an extension. 883bdd1243dSDimitry Andric# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 884349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD 8850b57cec5SDimitry Andric# else 8860b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_EXT 8870b57cec5SDimitry Andric# endif 8880b57cec5SDimitry Andric 889bdd1243dSDimitry Andric# if _LIBCPP_STD_VER > 17 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT) 890349cc55cSDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD 8910b57cec5SDimitry Andric# else 8920b57cec5SDimitry Andric# define _LIBCPP_NODISCARD_AFTER_CXX17 8930b57cec5SDimitry Andric# endif 8940b57cec5SDimitry Andric 895bdd1243dSDimitry Andric# if __has_attribute(__no_destroy__) 8960b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) 8970b57cec5SDimitry Andric# else 8980b57cec5SDimitry Andric# define _LIBCPP_NO_DESTROY 8990b57cec5SDimitry Andric# endif 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andric# ifndef _LIBCPP_HAS_NO_ASAN 90281ad6265SDimitry Andric extern "C" _LIBCPP_FUNC_VIS void 90381ad6265SDimitry Andric __sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*); 9040b57cec5SDimitry Andric# endif 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andric// Try to find out if RTTI is disabled. 90781ad6265SDimitry Andric# if !defined(__cpp_rtti) || __cpp_rtti < 199711L 908*1ac55f4cSDimitry Andric# define _LIBCPP_HAS_NO_RTTI 9090b57cec5SDimitry Andric# endif 9100b57cec5SDimitry Andric 9110b57cec5SDimitry Andric# ifndef _LIBCPP_WEAK 9120b57cec5SDimitry Andric# define _LIBCPP_WEAK __attribute__((__weak__)) 9130b57cec5SDimitry Andric# endif 9140b57cec5SDimitry Andric 9150b57cec5SDimitry Andric// Thread API 91681ad6265SDimitry Andric// clang-format off 9170b57cec5SDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && \ 9180b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ 9190b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ 9200b57cec5SDimitry Andric !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 92181ad6265SDimitry Andric 9220b57cec5SDimitry Andric# if defined(__FreeBSD__) || \ 9230b57cec5SDimitry Andric defined(__wasi__) || \ 9240b57cec5SDimitry Andric defined(__NetBSD__) || \ 925e8d8bef9SDimitry Andric defined(__OpenBSD__) || \ 926e8d8bef9SDimitry Andric defined(__NuttX__) || \ 9270b57cec5SDimitry Andric defined(__linux__) || \ 9280b57cec5SDimitry Andric defined(__GNU__) || \ 9290b57cec5SDimitry Andric defined(__APPLE__) || \ 9300b57cec5SDimitry Andric defined(__sun__) || \ 931e8d8bef9SDimitry Andric defined(__MVS__) || \ 93281ad6265SDimitry Andric defined(_AIX) || \ 93381ad6265SDimitry Andric defined(__EMSCRIPTEN__) 93481ad6265SDimitry Andric// clang-format on 9350b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 936480093f4SDimitry Andric# elif defined(__Fuchsia__) 9375ffd83dbSDimitry Andric// TODO(44575): Switch to C11 thread API when possible. 9385ffd83dbSDimitry Andric# define _LIBCPP_HAS_THREAD_API_PTHREAD 9390b57cec5SDimitry Andric# elif defined(_LIBCPP_WIN32API) 9400b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_API_WIN32 9410b57cec5SDimitry Andric# else 9420b57cec5SDimitry Andric# error "No thread API" 9430b57cec5SDimitry Andric# endif // _LIBCPP_HAS_THREAD_API 9440b57cec5SDimitry Andric# endif // _LIBCPP_HAS_NO_THREADS 9450b57cec5SDimitry Andric 946e40139ffSDimitry Andric# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 947e40139ffSDimitry Andric# if defined(__ANDROID__) && __ANDROID_API__ >= 30 948e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 949e40139ffSDimitry Andric# elif defined(_LIBCPP_GLIBC_PREREQ) 950e40139ffSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 30) 951e40139ffSDimitry Andric# define _LIBCPP_HAS_COND_CLOCKWAIT 952e40139ffSDimitry Andric# endif 953e40139ffSDimitry Andric# endif 954e40139ffSDimitry Andric# endif 955e40139ffSDimitry Andric 9560b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) 9570b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ 9580b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is not defined. 9590b57cec5SDimitry Andric# endif 9600b57cec5SDimitry Andric 9610b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) 9620b57cec5SDimitry Andric# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ 9630b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 9640b57cec5SDimitry Andric# endif 9650b57cec5SDimitry Andric 9660b57cec5SDimitry Andric# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) 9670b57cec5SDimitry Andric# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ 9680b57cec5SDimitry Andric _LIBCPP_HAS_NO_THREADS is defined. 9690b57cec5SDimitry Andric# endif 9700b57cec5SDimitry Andric 971e40139ffSDimitry Andric# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) 972e40139ffSDimitry Andric# define __STDCPP_THREADS__ 1 973e40139ffSDimitry Andric# endif 974e40139ffSDimitry Andric 975e40139ffSDimitry Andric// The glibc and Bionic implementation of pthreads implements 9760b57cec5SDimitry Andric// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 9770b57cec5SDimitry Andric// mutexes have no destroy mechanism. 978e40139ffSDimitry Andric// 979e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 980e40139ffSDimitry Andric// pthread_mutex_destroy can allow the kernel to release resources. 981e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 982e40139ffSDimitry Andric// 983e40139ffSDimitry Andric// TODO(EricWF): Enable this optimization on Bionic after speaking to their 984e40139ffSDimitry Andric// respective stakeholders. 98581ad6265SDimitry Andric// clang-format off 98681ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ 98781ad6265SDimitry Andric (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ 98881ad6265SDimitry Andric defined(_LIBCPP_HAS_THREAD_API_WIN32) 98981ad6265SDimitry Andric// clang-format on 9900b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 9910b57cec5SDimitry Andric# endif 9920b57cec5SDimitry Andric 9930b57cec5SDimitry Andric// Destroying a condvar is a nop on Windows. 994e40139ffSDimitry Andric// 995e40139ffSDimitry Andric// This optimization can't be performed on Apple platforms, where 996e40139ffSDimitry Andric// pthread_cond_destroy can allow the kernel to release resources. 997e40139ffSDimitry Andric// See https://llvm.org/D64298 for details. 998e40139ffSDimitry Andric// 9990b57cec5SDimitry Andric// TODO(EricWF): This is potentially true for some pthread implementations 10000b57cec5SDimitry Andric// as well. 100181ad6265SDimitry Andric# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) 10020b57cec5SDimitry Andric# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 10030b57cec5SDimitry Andric# endif 10040b57cec5SDimitry Andric 10050b57cec5SDimitry Andric// Some systems do not provide gets() in their C library, for security reasons. 100681ad6265SDimitry Andric# if defined(_LIBCPP_MSVCRT) || (defined(__FreeBSD_version) && __FreeBSD_version >= 1300043) || defined(__OpenBSD__) 10070b57cec5SDimitry Andric# define _LIBCPP_C_HAS_NO_GETS 10080b57cec5SDimitry Andric# endif 10090b57cec5SDimitry Andric 101081ad6265SDimitry Andric# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ 101104eeddc0SDimitry Andric defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) 10120b57cec5SDimitry Andric# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE 10130b57cec5SDimitry Andric# endif 10140b57cec5SDimitry Andric 10150b57cec5SDimitry Andric# if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) 10160b57cec5SDimitry Andric# define _LIBCPP_HAS_C_ATOMIC_IMP 10170b57cec5SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 10180b57cec5SDimitry Andric# define _LIBCPP_HAS_GCC_ATOMIC_IMP 10190b57cec5SDimitry Andric# endif 10200b57cec5SDimitry Andric 102181ad6265SDimitry Andric# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ 1022349cc55cSDimitry Andric !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) 10230b57cec5SDimitry Andric# define _LIBCPP_HAS_NO_ATOMIC_HEADER 10240b57cec5SDimitry Andric# else 10250b57cec5SDimitry Andric# ifndef _LIBCPP_ATOMIC_FLAG_TYPE 10260b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_FLAG_TYPE bool 10270b57cec5SDimitry Andric# endif 10280b57cec5SDimitry Andric# ifdef _LIBCPP_FREESTANDING 10290b57cec5SDimitry Andric# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS 10300b57cec5SDimitry Andric# endif 10310b57cec5SDimitry Andric# endif 10320b57cec5SDimitry Andric 10330b57cec5SDimitry Andric# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 10340b57cec5SDimitry Andric# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 10350b57cec5SDimitry Andric# endif 10360b57cec5SDimitry Andric 10370b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) 10380b57cec5SDimitry Andric# if defined(__clang__) && __has_attribute(acquire_capability) 10390b57cec5SDimitry Andric// Work around the attribute handling in clang. When both __declspec and 10400b57cec5SDimitry Andric// __attribute__ are present, the processing goes awry preventing the definition 10411fd87a68SDimitry Andric// of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus 10421fd87a68SDimitry Andric// combining the two does work. 10431fd87a68SDimitry Andric# if !defined(_MSC_VER) 10440b57cec5SDimitry Andric# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 10450b57cec5SDimitry Andric# endif 10460b57cec5SDimitry Andric# endif 10470b57cec5SDimitry Andric# endif 10480b57cec5SDimitry Andric 1049480093f4SDimitry Andric# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1050480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) 1051480093f4SDimitry Andric# else 1052480093f4SDimitry Andric# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) 1053480093f4SDimitry Andric# endif 1054480093f4SDimitry Andric 105581ad6265SDimitry Andric# if _LIBCPP_STD_VER > 17 105681ad6265SDimitry Andric# define _LIBCPP_CONSTINIT constinit 1057bdd1243dSDimitry Andric# elif __has_attribute(__require_constant_initialization__) 105881ad6265SDimitry Andric# define _LIBCPP_CONSTINIT __attribute__((__require_constant_initialization__)) 10590b57cec5SDimitry Andric# else 106081ad6265SDimitry Andric# define _LIBCPP_CONSTINIT 10610b57cec5SDimitry Andric# endif 10620b57cec5SDimitry Andric 1063bdd1243dSDimitry Andric# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS) 1064bdd1243dSDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning"))) 10650b57cec5SDimitry Andric# else 10660b57cec5SDimitry Andric# define _LIBCPP_DIAGNOSE_WARNING(...) 10670b57cec5SDimitry Andric# endif 10680b57cec5SDimitry Andric 10690b57cec5SDimitry Andric// Use a function like macro to imply that it must be followed by a semicolon 107081ad6265SDimitry Andric# if __has_cpp_attribute(fallthrough) 10710b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() [[fallthrough]] 1072349cc55cSDimitry Andric# elif __has_attribute(__fallthrough__) 10730b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__)) 10740b57cec5SDimitry Andric# else 10750b57cec5SDimitry Andric# define _LIBCPP_FALLTHROUGH() ((void)0) 10760b57cec5SDimitry Andric# endif 10770b57cec5SDimitry Andric 1078bdd1243dSDimitry Andric# if __has_cpp_attribute(_Clang::__lifetimebound__) 1079bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]] 1080bdd1243dSDimitry Andric# else 1081bdd1243dSDimitry Andric# define _LIBCPP_LIFETIMEBOUND 1082bdd1243dSDimitry Andric# endif 1083bdd1243dSDimitry Andric 10840b57cec5SDimitry Andric# if __has_attribute(__nodebug__) 10850b57cec5SDimitry Andric# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) 10860b57cec5SDimitry Andric# else 10870b57cec5SDimitry Andric# define _LIBCPP_NODEBUG 10880b57cec5SDimitry Andric# endif 10890b57cec5SDimitry Andric 1090fe6060f1SDimitry Andric# if __has_attribute(__standalone_debug__) 1091fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__)) 1092fe6060f1SDimitry Andric# else 1093fe6060f1SDimitry Andric# define _LIBCPP_STANDALONE_DEBUG 1094fe6060f1SDimitry Andric# endif 10950b57cec5SDimitry Andric 1096e8d8bef9SDimitry Andric# if __has_attribute(__preferred_name__) 1097e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x))) 1098e8d8bef9SDimitry Andric# else 1099e8d8bef9SDimitry Andric# define _LIBCPP_PREFERRED_NAME(x) 1100e8d8bef9SDimitry Andric# endif 1101e8d8bef9SDimitry Andric 1102349cc55cSDimitry Andric// We often repeat things just for handling wide characters in the library. 1103349cc55cSDimitry Andric// When wide characters are disabled, it can be useful to have a quick way of 1104349cc55cSDimitry Andric// disabling it without having to resort to #if-#endif, which has a larger 1105349cc55cSDimitry Andric// impact on readability. 1106349cc55cSDimitry Andric# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) 1107349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) 1108349cc55cSDimitry Andric# else 1109349cc55cSDimitry Andric# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ 1110349cc55cSDimitry Andric# endif 1111349cc55cSDimitry Andric 1112bdd1243dSDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases) 11130b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) 11140b57cec5SDimitry Andric# else 11150b57cec5SDimitry Andric# define _LIBCPP_DECLSPEC_EMPTY_BASES 11160b57cec5SDimitry Andric# endif 11170b57cec5SDimitry Andric 11180b57cec5SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) 11190b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR 11200b57cec5SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS 1121fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE 1122fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 112381ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION 11240b57cec5SDimitry Andric# endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES 11250b57cec5SDimitry Andric 1126fe6060f1SDimitry Andric# if defined(_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES) 1127fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS 112881ad6265SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION 1129fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS 1130fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS 1131fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR 1132fe6060f1SDimitry Andric# define _LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS 1133fe6060f1SDimitry Andric# endif // _LIBCPP_ENABLE_CXX20_REMOVED_FEATURES 1134fe6060f1SDimitry Andric 113581ad6265SDimitry Andric# define _LIBCPP_PUSH_MACROS _Pragma("push_macro(\"min\")") _Pragma("push_macro(\"max\")") 113681ad6265SDimitry Andric# define _LIBCPP_POP_MACROS _Pragma("pop_macro(\"min\")") _Pragma("pop_macro(\"max\")") 11370b57cec5SDimitry Andric 11380b57cec5SDimitry Andric# ifndef _LIBCPP_NO_AUTO_LINK 11390b57cec5SDimitry Andric# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 1140fe6060f1SDimitry Andric# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) 11410b57cec5SDimitry Andric# pragma comment(lib, "c++.lib") 11420b57cec5SDimitry Andric# else 11430b57cec5SDimitry Andric# pragma comment(lib, "libc++.lib") 11440b57cec5SDimitry Andric# endif 11450b57cec5SDimitry Andric# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) 11460b57cec5SDimitry Andric# endif // _LIBCPP_NO_AUTO_LINK 11470b57cec5SDimitry Andric 1148e40139ffSDimitry Andric// Configures the fopen close-on-exec mode character, if any. This string will 1149e40139ffSDimitry Andric// be appended to any mode string used by fstream for fopen/fdopen. 1150e40139ffSDimitry Andric// 1151e40139ffSDimitry Andric// Not all platforms support this, but it helps avoid fd-leaks on platforms that 1152e40139ffSDimitry Andric// do. 1153e40139ffSDimitry Andric# if defined(__BIONIC__) 1154e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE "e" 1155e40139ffSDimitry Andric# else 1156e40139ffSDimitry Andric# define _LIBCPP_FOPEN_CLOEXEC_MODE 1157e40139ffSDimitry Andric# endif 1158e40139ffSDimitry Andric 11595ffd83dbSDimitry Andric// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set 11605ffd83dbSDimitry Andric// of functions used in cstdio may not be available for low API levels when 11615ffd83dbSDimitry Andric// using 64-bit file offsets on LP32. 11625ffd83dbSDimitry Andric# if defined(__BIONIC__) && defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 24 11635ffd83dbSDimitry Andric# define _LIBCPP_HAS_NO_FGETPOS_FSETPOS 11645ffd83dbSDimitry Andric# endif 11655ffd83dbSDimitry Andric 1166bdd1243dSDimitry Andric# if __has_attribute(__init_priority__) 1167bdd1243dSDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100))) 1168349cc55cSDimitry Andric# else 1169e8d8bef9SDimitry Andric# define _LIBCPP_INIT_PRIORITY_MAX 1170e8d8bef9SDimitry Andric# endif 1171e8d8bef9SDimitry Andric 1172bdd1243dSDimitry Andric# if __has_attribute(__format__) 11734824e7fdSDimitry Andric// The attribute uses 1-based indices for ordinary and static member functions. 11744824e7fdSDimitry Andric// The attribute uses 2-based indices for non-static member functions. 11754824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \ 11764824e7fdSDimitry Andric __attribute__((__format__(archetype, format_string_index, first_format_arg_index))) 1177fe6060f1SDimitry Andric# else 11784824e7fdSDimitry Andric# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */ 1179fe6060f1SDimitry Andric# endif 1180fe6060f1SDimitry Andric 118181ad6265SDimitry Andric# if __has_cpp_attribute(msvc::no_unique_address) 118281ad6265SDimitry Andric// MSVC implements [[no_unique_address]] as a silent no-op currently. 118381ad6265SDimitry Andric// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) 118481ad6265SDimitry Andric// However, MSVC implements [[msvc::no_unique_address]] which does what 118581ad6265SDimitry Andric// [[no_unique_address]] is supposed to do, in general. 118681ad6265SDimitry Andric 118781ad6265SDimitry Andric// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or 118881ad6265SDimitry Andric// [[msvc::no_unique_address]] though. If/when it does implement 118981ad6265SDimitry Andric// [[msvc::no_unique_address]], this should be preferred though. 119081ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] 119181ad6265SDimitry Andric# elif __has_cpp_attribute(no_unique_address) 119281ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS [[no_unique_address]] 119381ad6265SDimitry Andric# else 119481ad6265SDimitry Andric# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ 119581ad6265SDimitry Andric// Note that this can be replaced by #error as soon as clang-cl 119681ad6265SDimitry Andric// implements msvc::no_unique_address, since there should be no C++20 119781ad6265SDimitry Andric// compiler that doesn't support one of the two attributes at that point. 119881ad6265SDimitry Andric// We generally don't want to use this macro outside of C++20-only code, 119981ad6265SDimitry Andric// because using it conditionally in one language version only would make 120081ad6265SDimitry Andric// the ABI inconsistent. 120181ad6265SDimitry Andric# endif 120281ad6265SDimitry Andric 120381ad6265SDimitry Andric# ifdef _LIBCPP_COMPILER_CLANG_BASED 120481ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") 120581ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") 120681ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(clang diagnostic ignored str)) 120781ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 120881ad6265SDimitry Andric# elif defined(_LIBCPP_COMPILER_GCC) 120981ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") 121081ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") 121181ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 121281ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) _Pragma(_LIBCPP_TOSTRING(GCC diagnostic ignored str)) 121381ad6265SDimitry Andric# else 121481ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_PUSH 121581ad6265SDimitry Andric# define _LIBCPP_DIAGNOSTIC_POP 121681ad6265SDimitry Andric# define _LIBCPP_CLANG_DIAGNOSTIC_IGNORED(str) 121781ad6265SDimitry Andric# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str) 121881ad6265SDimitry Andric# endif 121981ad6265SDimitry Andric 122081ad6265SDimitry Andric# if defined(_AIX) && !defined(_LIBCPP_COMPILER_GCC) 122181ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX _Pragma("pack(1)") 122281ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END _Pragma("pack(pop)") 122381ad6265SDimitry Andric# else 122481ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX /* empty */ 122581ad6265SDimitry Andric# define _LIBCPP_PACKED_BYTE_FOR_AIX_END /* empty */ 122681ad6265SDimitry Andric# endif 122781ad6265SDimitry Andric 122881ad6265SDimitry Andric# if __has_attribute(__packed__) 122981ad6265SDimitry Andric# define _LIBCPP_PACKED __attribute__((__packed__)) 123081ad6265SDimitry Andric# else 123181ad6265SDimitry Andric# define _LIBCPP_PACKED 123281ad6265SDimitry Andric# endif 123381ad6265SDimitry Andric 1234bdd1243dSDimitry Andric// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these 1235bdd1243dSDimitry Andric// functions is gradually being added to existing C libraries. The conditions 1236bdd1243dSDimitry Andric// below check for known C library versions and conditions under which these 1237bdd1243dSDimitry Andric// functions are declared by the C library. 1238bdd1243dSDimitry Andric# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1239bdd1243dSDimitry Andric// GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if 1240*1ac55f4cSDimitry Andric// __cpp_char8_t is defined or if C2X extensions are enabled. Determining 1241*1ac55f4cSDimitry Andric// the latter depends on internal GNU libc details that are not appropriate 1242*1ac55f4cSDimitry Andric// to depend on here, so any declarations present when __cpp_char8_t is not 1243*1ac55f4cSDimitry Andric// defined are ignored. 1244*1ac55f4cSDimitry Andric# if defined(_LIBCPP_GLIBC_PREREQ) 1245*1ac55f4cSDimitry Andric# if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) 1246bdd1243dSDimitry Andric# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 1247bdd1243dSDimitry Andric# endif 1248bdd1243dSDimitry Andric# endif 1249bdd1243dSDimitry Andric 1250bdd1243dSDimitry Andric// There are a handful of public standard library types that are intended to 1251bdd1243dSDimitry Andric// support CTAD but don't need any explicit deduction guides to do so. This 1252bdd1243dSDimitry Andric// macro is used to mark them as such, which suppresses the 1253bdd1243dSDimitry Andric// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code 1254bdd1243dSDimitry Andric// with these classes. 1255bdd1243dSDimitry Andric#if _LIBCPP_STD_VER >= 17 1256bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ 1257bdd1243dSDimitry Andric template <class ..._Tag> \ 1258bdd1243dSDimitry Andric _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> 1259bdd1243dSDimitry Andric#else 1260bdd1243dSDimitry Andric# define _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") 1261bdd1243dSDimitry Andric#endif 1262bdd1243dSDimitry Andric 1263*1ac55f4cSDimitry Andric// TODO(varconst): currently, there are bugs in Clang's intrinsics when handling Objective-C++ `id`, so don't use 1264*1ac55f4cSDimitry Andric// compiler intrinsics in the Objective-C++ mode. 1265*1ac55f4cSDimitry Andric# ifdef __OBJC__ 1266*1ac55f4cSDimitry Andric# define _LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS 1267*1ac55f4cSDimitry Andric# endif 1268*1ac55f4cSDimitry Andric 12690b57cec5SDimitry Andric#endif // __cplusplus 12700b57cec5SDimitry Andric 127181ad6265SDimitry Andric#endif // _LIBCPP___CONFIG 1272