diff --git a/contrib/libc++/CREDITS.TXT b/contrib/libc++/CREDITS.TXT index 92123d736bf0..88d923a48e91 100644 --- a/contrib/libc++/CREDITS.TXT +++ b/contrib/libc++/CREDITS.TXT @@ -41,6 +41,10 @@ N: Jonathan B Coe E: jbcoe@me.com D: Implementation of propagate_const. +N: Glen Joseph Fernandes +E: glenjofe@gmail.com +D: Implementation of to_address. + N: Eric Fiselier E: eric@efcs.ca D: LFTS support, patches and bug fixes. diff --git a/contrib/libc++/include/__config b/contrib/libc++/include/__config index f15d2d06e564..d0f95ef28342 100644 --- a/contrib/libc++/include/__config +++ b/contrib/libc++/include/__config @@ -33,7 +33,7 @@ #define _GNUC_VER_NEW 0 #endif -#define _LIBCPP_VERSION 5000 +#define _LIBCPP_VERSION 6000 #ifndef _LIBCPP_ABI_VERSION #define _LIBCPP_ABI_VERSION 1 @@ -45,6 +45,8 @@ #define _LIBCPP_OBJECT_FORMAT_MACHO 1 #elif defined(_WIN32) #define _LIBCPP_OBJECT_FORMAT_COFF 1 +#elif defined(__wasm__) +#define _LIBCPP_OBJECT_FORMAT_WASM 1 #else #error Unknown object file format #endif @@ -55,11 +57,11 @@ #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT // Fix deque iterator type in order to support incomplete types. #define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE -// Fix undefined behavior in how std::list stores it's linked nodes. +// Fix undefined behavior in how std::list stores its linked nodes. #define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB // Fix undefined behavior in how __tree stores its end and parent nodes. #define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB -// Fix undefined behavior in how __hash_table stores it's pointer types +// Fix undefined behavior in how __hash_table stores its pointer types. #define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB #define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE @@ -76,9 +78,11 @@ // its vtable and typeinfo to libc++ rather than having all other libraries // using that class define their own copies. #define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION - // Enable optimized version of __do_get_(un)signed which avoids redundant copies. #define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET +// Use the smallest possible integer type to represent the index of the variant. +// Previously libc++ used "unsigned int" exclusivly. +#define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION #elif _LIBCPP_ABI_VERSION == 1 #if !defined(_LIBCPP_OBJECT_FORMAT_COFF) // Enable compiling copies of now inline methods into the dylib to support @@ -121,6 +125,9 @@ #ifndef __has_feature #define __has_feature(__x) 0 #endif +#ifndef __has_cpp_attribute +#define __has_cpp_attribute(__x) 0 +#endif // '__is_identifier' returns '0' if '__x' is a reserved identifier provided by // the compiler and '1' otherwise. #ifndef __is_identifier @@ -157,11 +164,21 @@ // FIXME: ABI detection should be done via compiler builtin macros. This // is just a placeholder until Clang implements such macros. For now assume -// that Windows compilers pretending to be MSVC++ target the microsoft ABI. -#if defined(_WIN32) && defined(_MSC_VER) +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) +# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" +#elif defined(_LIBCPP_ABI_FORCE_ITANIUM) +# define _LIBCPP_ABI_ITANIUM +#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) # define _LIBCPP_ABI_MICROSOFT #else -# define _LIBCPP_ABI_ITANIUM +# if defined(_WIN32) && defined(_MSC_VER) +# define _LIBCPP_ABI_MICROSOFT +# else +# define _LIBCPP_ABI_ITANIUM +# endif #endif // Need to detect which libc we're using if we're on Linux. @@ -174,36 +191,30 @@ #ifdef __LITTLE_ENDIAN__ #if __LITTLE_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 1 -#define _LIBCPP_BIG_ENDIAN 0 +#define _LIBCPP_LITTLE_ENDIAN #endif // __LITTLE_ENDIAN__ #endif // __LITTLE_ENDIAN__ #ifdef __BIG_ENDIAN__ #if __BIG_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 0 -#define _LIBCPP_BIG_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN #endif // __BIG_ENDIAN__ #endif // __BIG_ENDIAN__ #ifdef __BYTE_ORDER__ #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 1 -#define _LIBCPP_BIG_ENDIAN 0 +#define _LIBCPP_LITTLE_ENDIAN #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define _LIBCPP_LITTLE_ENDIAN 0 -#define _LIBCPP_BIG_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #endif // __BYTE_ORDER__ #ifdef __FreeBSD__ # include # if _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 1 -# define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_LITTLE_ENDIAN # else // _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # endif // _BYTE_ORDER == _LITTLE_ENDIAN # ifndef __LONG_LONG_SUPPORTED # define _LIBCPP_HAS_NO_LONG_LONG @@ -213,19 +224,16 @@ #ifdef __NetBSD__ # include # if _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 1 -# define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_LITTLE_ENDIAN # else // _BYTE_ORDER == _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # endif // _BYTE_ORDER == _LITTLE_ENDIAN # define _LIBCPP_HAS_QUICK_EXIT #endif // __NetBSD__ #if defined(_WIN32) # define _LIBCPP_WIN32API -# define _LIBCPP_LITTLE_ENDIAN 1 -# define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_LITTLE_ENDIAN # define _LIBCPP_SHORT_WCHAR 1 // Both MinGW and native MSVC provide a "MSVC"-like enviroment # define _LIBCPP_MSVCRT_LIKE @@ -255,11 +263,9 @@ #ifdef __sun__ # include # ifdef _LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 1 -# define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_LITTLE_ENDIAN # else -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # endif #endif // __sun__ @@ -269,6 +275,8 @@ // random data even when using sandboxing mechanisms such as chroots, // Capsicum, etc. # define _LIBCPP_USING_ARC4_RANDOM +#elif defined(__Fuchsia__) +# define _LIBCPP_USING_GETENTROPY #elif defined(__native_client__) // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, // including accesses to the special files under /dev. C++11's @@ -280,18 +288,16 @@ # define _LIBCPP_USING_DEV_RANDOM #endif -#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) # include # if __BYTE_ORDER == __LITTLE_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 1 -# define _LIBCPP_BIG_ENDIAN 0 +# define _LIBCPP_LITTLE_ENDIAN # elif __BYTE_ORDER == __BIG_ENDIAN -# define _LIBCPP_LITTLE_ENDIAN 0 -# define _LIBCPP_BIG_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN # else // __BYTE_ORDER == __BIG_ENDIAN # error unable to determine endian # endif -#endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN) #if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC) #define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi"))) @@ -454,6 +460,10 @@ namespace std { #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow"))) #endif +#if __has_builtin(__builtin_launder) +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#endif + #elif defined(_LIBCPP_COMPILER_GCC) #define _ALIGNAS(x) __attribute__((__aligned__(x))) @@ -536,6 +546,10 @@ namespace std { #define _LIBCPP_HAS_NO_ASAN #endif +#if _GNUC_VER >= 700 +#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER +#endif + #elif defined(_LIBCPP_COMPILER_MSVC) #define _LIBCPP_TOSTRING2(x) #x @@ -880,7 +894,7 @@ template struct __static_assert_check {}; #define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63) #endif -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT) || \ +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \ defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) #define _LIBCPP_LOCALE__L_EXTENSIONS 1 #endif @@ -954,6 +968,18 @@ template struct __static_assert_check {}; #define _LIBCPP_CONSTEXPR_AFTER_CXX14 #endif +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR) +#define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr +#else +#define _LIBCPP_CONSTEXPR_AFTER_CXX17 +#endif + +#if __has_cpp_attribute(nodiscard) && _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) +#define _LIBCPP_NODISCARD_AFTER_CXX17 [[nodiscard]] +#else +#define _LIBCPP_NODISCARD_AFTER_CXX17 +#endif + // FIXME: Remove all usages of this macro once compilers catch up. #if !defined(__cpp_inline_variables) || (__cpp_inline_variables < 201606L) # define _LIBCPP_HAS_NO_INLINE_VARIABLES @@ -1241,6 +1267,13 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # endif #endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) +# if defined(_DLL) +# pragma(lib, "c++.lib") +# else +# pragma(lib, "libc++.lib") +# endif +#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY) #endif // __cplusplus diff --git a/contrib/libc++/include/__libcpp_version b/contrib/libc++/include/__libcpp_version index e9c02dad1826..a77fd92cf17b 100644 --- a/contrib/libc++/include/__libcpp_version +++ b/contrib/libc++/include/__libcpp_version @@ -1 +1 @@ -5000 +6000 diff --git a/contrib/libc++/include/__locale b/contrib/libc++/include/__locale index 91ed9e709ee3..601f0d1ec325 100644 --- a/contrib/libc++/include/__locale +++ b/contrib/libc++/include/__locale @@ -49,7 +49,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT) +#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) struct __libcpp_locale_guard { _LIBCPP_INLINE_VISIBILITY __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} @@ -65,6 +65,32 @@ private: __libcpp_locale_guard(__libcpp_locale_guard const&); __libcpp_locale_guard& operator=(__libcpp_locale_guard const&); }; +#elif defined(_LIBCPP_MSVCRT_LIKE) +struct __libcpp_locale_guard { + __libcpp_locale_guard(locale_t __l) : + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)), + __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())), + __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())), + __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())), + __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())), + __locale_time(setlocale(LC_TIME, __l.__get_locale())) + // LC_MESSAGES is not supported on Windows. + {} + ~__libcpp_locale_guard() { + setlocale(LC_COLLATE, __locale_collate); + setlocale(LC_CTYPE, __locale_ctype); + setlocale(LC_MONETARY, __locale_monetary); + setlocale(LC_NUMERIC, __locale_numeric); + setlocale(LC_TIME, __locale_time); + _configthreadlocale(__status); + } + int __status; + char* __locale_collate; + char* __locale_ctype; + char* __locale_monetary; + char* __locale_numeric; + char* __locale_time; +}; #endif diff --git a/contrib/libc++/include/__tree b/contrib/libc++/include/__tree index 792870aa6ebc..3ccfcb700310 100644 --- a/contrib/libc++/include/__tree +++ b/contrib/libc++/include/__tree @@ -84,7 +84,7 @@ __tree_is_left_child(_NodePtr __x) _NOEXCEPT return __x == __x->__parent_->__left_; } -// Determintes if the subtree rooted at __x is a proper red black subtree. If +// Determines if the subtree rooted at __x is a proper red black subtree. If // __x is a proper subtree, returns the black height (null counts as 1). If // __x is an improper subtree, returns 0. template @@ -119,7 +119,7 @@ __tree_sub_invariant(_NodePtr __x) return __h + __x->__is_black_; // return black height of this node } -// Determintes if the red black tree rooted at __root is a proper red black tree. +// Determines if the red black tree rooted at __root is a proper red black tree. // __root == nullptr is a proper tree. Returns true is __root is a proper // red black tree, else returns false. template diff --git a/contrib/libc++/include/algorithm b/contrib/libc++/include/algorithm index 00db6d7e7c87..35c6129ea508 100644 --- a/contrib/libc++/include/algorithm +++ b/contrib/libc++/include/algorithm @@ -734,15 +734,15 @@ struct __less<_T1, const _T1> }; template -class __negate +class __invert // invert the sense of a comparison { private: _Predicate __p_; public: - _LIBCPP_INLINE_VISIBILITY __negate() {} + _LIBCPP_INLINE_VISIBILITY __invert() {} _LIBCPP_INLINE_VISIBILITY - explicit __negate(_Predicate __p) : __p_(__p) {} + explicit __invert(_Predicate __p) : __p_(__p) {} template _LIBCPP_INLINE_VISIBILITY @@ -750,7 +750,7 @@ public: template _LIBCPP_INLINE_VISIBILITY - bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);} + bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);} }; #ifdef _LIBCPP_DEBUG @@ -797,7 +797,7 @@ unsigned __ctz(unsigned __x) { unsigned long where; // Search from LSB to MSB for first set bit. // Returns zero if no set bit is found. - if (_BitScanForward(&where, mask)) + if (_BitScanForward(&where, __x)) return where; return 32; #endif @@ -823,15 +823,15 @@ unsigned long long __ctz(unsigned long long __x) { // Returns zero if no set bit is found. #if defined(_LIBCPP_HAS_BITSCAN64) (defined(_M_AMD64) || defined(__x86_64__)) - if (_BitScanForward64(&where, mask)) + if (_BitScanForward64(&where, __x)) return static_cast(where); #else // Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. // Scan the Low Word. - if (_BitScanForward(&where, static_cast(mask))) + if (_BitScanForward(&where, static_cast(__x))) return where; // Scan the High Word. - if (_BitScanForward(&where, static_cast(mask >> 32))) + if (_BitScanForward(&where, static_cast(__x >> 32))) return where + 32; // Create a bit offset from the LSB. #endif return 64; @@ -849,7 +849,7 @@ unsigned __clz(unsigned __x) { unsigned long where; // Search from LSB to MSB for first set bit. // Returns zero if no set bit is found. - if (_BitScanReverse(&where, mask)) + if (_BitScanReverse(&where, __x)) return 31 - where; return 32; // Undefined Behavior. #endif @@ -874,14 +874,14 @@ unsigned long long __clz(unsigned long long __x) { // BitScanReverse scans from MSB to LSB for first set bit. // Returns 0 if no set bit is found. #if defined(_LIBCPP_HAS_BITSCAN64) - if (_BitScanReverse64(&where, mask)) + if (_BitScanReverse64(&where, __x)) return static_cast(63 - where); #else // Scan the high 32 bits. - if (_BitScanReverse(&where, static_cast(mask >> 32))) + if (_BitScanReverse(&where, static_cast(__x >> 32))) return 63 - (where + 32); // Create a bit offset from the MSB. // Scan the low 32 bits. - if (_BitScanReverse(&where, static_cast(mask))) + if (_BitScanReverse(&where, static_cast(__x))) return 63 - where; #endif return 64; // Undefined Behavior. @@ -3210,28 +3210,28 @@ template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator & __g, input_iterator_tag) { _Distance __k = 0; for (; __first != __last && __k < __n; ++__first, (void)++__k) - __output[__k] = *__first; + __output_iter[__k] = *__first; _Distance __sz = __k; for (; __first != __last; ++__first, (void)++__k) { _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g); if (__r < __sz) - __output[__r] = *__first; + __output_iter[__r] = *__first; } - return __output + _VSTD::min(__n, __k); + return __output_iter + _VSTD::min(__n, __k); } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator& __g, forward_iterator_tag) { @@ -3240,18 +3240,18 @@ _SampleIterator __sample(_PopulationIterator __first, _Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g); if (__r < __n) { - *__output++ = *__first; + *__output_iter++ = *__first; --__n; } } - return __output; + return __output_iter; } template _LIBCPP_INLINE_VISIBILITY _SampleIterator __sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator& __g) { typedef typename iterator_traits<_PopulationIterator>::iterator_category _PopCategory; @@ -3263,7 +3263,7 @@ _SampleIterator __sample(_PopulationIterator __first, typedef typename common_type<_Distance, _Difference>::type _CommonType; _LIBCPP_ASSERT(__n >= 0, "N must be a positive number."); return _VSTD::__sample( - __first, __last, __output, _CommonType(__n), + __first, __last, __output_iter, _CommonType(__n), __g, _PopCategory()); } @@ -3272,9 +3272,9 @@ template inline _LIBCPP_INLINE_VISIBILITY _SampleIterator sample(_PopulationIterator __first, - _PopulationIterator __last, _SampleIterator __output, + _PopulationIterator __last, _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator&& __g) { - return _VSTD::__sample(__first, __last, __output, __n, __g); + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); } #endif // _LIBCPP_STD_VER > 14 @@ -4568,7 +4568,7 @@ __buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator typedef reverse_iterator _Rv; __half_inplace_merge(_Rv(__p), _Rv(__buff), _RBi(__middle), _RBi(__first), - _RBi(__last), __negate<_Compare>(__comp)); + _RBi(__last), __invert<_Compare>(__comp)); } } @@ -5547,9 +5547,9 @@ __set_union(_InputIterator1 __first1, _InputIterator1 __last1, } else { - *__result = *__first1; if (!__comp(*__first1, *__first2)) ++__first2; + *__result = *__first1; ++__first1; } } diff --git a/contrib/libc++/include/array b/contrib/libc++/include/array index 12780992e5c4..4eb2fe6fc624 100644 --- a/contrib/libc++/include/array +++ b/contrib/libc++/include/array @@ -183,7 +183,7 @@ struct _LIBCPP_TEMPLATE_VIS array _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} // element access: diff --git a/contrib/libc++/include/bitset b/contrib/libc++/include/bitset index 583122fbfdab..cd6c289b4c48 100644 --- a/contrib/libc++/include/bitset +++ b/contrib/libc++/include/bitset @@ -235,8 +235,13 @@ void __bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT { __storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)]; - for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word) - __t[__i] = static_cast<__storage_type>(__v); + size_t __sz = _Size; + for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word ) + if ( __sz < __bits_per_word) + __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1; + else + __t[__i] = static_cast<__storage_type>(__v); + _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_); _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); @@ -248,6 +253,9 @@ void __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT { __first_[0] = __v; + if (_Size < __bits_per_word) + __first_[0] &= ( 1ULL << _Size ) - 1; + _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0)); } @@ -261,7 +269,9 @@ __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT #if __SIZEOF_SIZE_T__ == 8 : __first_{__v} #elif __SIZEOF_SIZE_T__ == 4 - : __first_{static_cast<__storage_type>(__v), static_cast<__storage_type>(__v >> __bits_per_word)} + : __first_{static_cast<__storage_type>(__v), + _Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word) + : static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)} #else #error This constructor has not been ported to this platform #endif @@ -503,7 +513,10 @@ template inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT - : __first_(static_cast<__storage_type>(__v)) + : __first_( + _Size == __bits_per_word ? static_cast<__storage_type>(__v) + : static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1) + ) { } diff --git a/contrib/libc++/include/chrono b/contrib/libc++/include/chrono index 4b793c760559..c69e88ae4ded 100644 --- a/contrib/libc++/include/chrono +++ b/contrib/libc++/include/chrono @@ -283,18 +283,18 @@ typedef steady_clock high_resolution_clock; } // chrono -constexpr chrono::hours operator "" h(unsigned long long); // C++14 -constexpr chrono::duration> operator "" h(long double); // C++14 -constexpr chrono::minutes operator "" min(unsigned long long); // C++14 -constexpr chrono::duration> operator "" min(long double); // C++14 -constexpr chrono::seconds operator "" s(unsigned long long); // C++14 -constexpr chrono::duration operator "" s(long double); // C++14 -constexpr chrono::milliseconds operator "" ms(unsigned long long); // C++14 -constexpr chrono::duration operator "" ms(long double); // C++14 -constexpr chrono::microseconds operator "" us(unsigned long long); // C++14 -constexpr chrono::duration operator "" us(long double); // C++14 -constexpr chrono::nanoseconds operator "" ns(unsigned long long); // C++14 -constexpr chrono::duration operator "" ns(long double); // C++14 +constexpr chrono::hours operator ""h(unsigned long long); // C++14 +constexpr chrono::duration> operator ""h(long double); // C++14 +constexpr chrono::minutes operator ""min(unsigned long long); // C++14 +constexpr chrono::duration> operator ""min(long double); // C++14 +constexpr chrono::seconds operator ""s(unsigned long long); // C++14 +constexpr chrono::duration operator ""s(long double); // C++14 +constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 +constexpr chrono::duration operator ""ms(long double); // C++14 +constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 +constexpr chrono::duration operator ""us(long double); // C++14 +constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 +constexpr chrono::duration operator ""ns(long double); // C++14 } // std */ @@ -1087,67 +1087,67 @@ inline namespace literals inline namespace chrono_literals { - constexpr chrono::hours operator"" h(unsigned long long __h) + constexpr chrono::hours operator""h(unsigned long long __h) { return chrono::hours(static_cast(__h)); } - constexpr chrono::duration> operator"" h(long double __h) + constexpr chrono::duration> operator""h(long double __h) { return chrono::duration>(__h); } - constexpr chrono::minutes operator"" min(unsigned long long __m) + constexpr chrono::minutes operator""min(unsigned long long __m) { return chrono::minutes(static_cast(__m)); } - constexpr chrono::duration> operator"" min(long double __m) + constexpr chrono::duration> operator""min(long double __m) { return chrono::duration> (__m); } - constexpr chrono::seconds operator"" s(unsigned long long __s) + constexpr chrono::seconds operator""s(unsigned long long __s) { return chrono::seconds(static_cast(__s)); } - constexpr chrono::duration operator"" s(long double __s) + constexpr chrono::duration operator""s(long double __s) { return chrono::duration (__s); } - constexpr chrono::milliseconds operator"" ms(unsigned long long __ms) + constexpr chrono::milliseconds operator""ms(unsigned long long __ms) { return chrono::milliseconds(static_cast(__ms)); } - constexpr chrono::duration operator"" ms(long double __ms) + constexpr chrono::duration operator""ms(long double __ms) { return chrono::duration(__ms); } - constexpr chrono::microseconds operator"" us(unsigned long long __us) + constexpr chrono::microseconds operator""us(unsigned long long __us) { return chrono::microseconds(static_cast(__us)); } - constexpr chrono::duration operator"" us(long double __us) + constexpr chrono::duration operator""us(long double __us) { return chrono::duration (__us); } - constexpr chrono::nanoseconds operator"" ns(unsigned long long __ns) + constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) { return chrono::nanoseconds(static_cast(__ns)); } - constexpr chrono::duration operator"" ns(long double __ns) + constexpr chrono::duration operator""ns(long double __ns) { return chrono::duration (__ns); } diff --git a/contrib/libc++/include/cstddef b/contrib/libc++/include/cstddef index 62584494d97c..adeefdac9be6 100644 --- a/contrib/libc++/include/cstddef +++ b/contrib/libc++/include/cstddef @@ -64,23 +64,46 @@ namespace std // purposefully not versioned { enum class byte : unsigned char {}; -constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) | static_cast(__rhs)); } constexpr byte operator| (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) | static_cast(__rhs)); } +{ + return static_cast( + static_cast( + static_cast(__lhs) | static_cast(__rhs) + )); +} + +constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept +{ return __lhs = __lhs | __rhs; } + +constexpr byte operator& (byte __lhs, byte __rhs) noexcept +{ + return static_cast( + static_cast( + static_cast(__lhs) & static_cast(__rhs) + )); +} constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) & static_cast(__rhs)); } -constexpr byte operator& (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) & static_cast(__rhs)); } +{ return __lhs = __lhs & __rhs; } + +constexpr byte operator^ (byte __lhs, byte __rhs) noexcept +{ + return static_cast( + static_cast( + static_cast(__lhs) ^ static_cast(__rhs) + )); +} constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept -{ return __lhs = byte(static_cast(__lhs) ^ static_cast(__rhs)); } -constexpr byte operator^ (byte __lhs, byte __rhs) noexcept -{ return byte(static_cast(__lhs) ^ static_cast(__rhs)); } +{ return __lhs = __lhs ^ __rhs; } constexpr byte operator~ (byte __b) noexcept -{ return byte(~static_cast(__b)); } +{ + return static_cast( + static_cast( + ~static_cast(__b) + )); +} } diff --git a/contrib/libc++/include/deque b/contrib/libc++/include/deque index fee75614b97f..08cb295408be 100644 --- a/contrib/libc++/include/deque +++ b/contrib/libc++/include/deque @@ -1314,7 +1314,7 @@ public: void resize(size_type __n); void resize(size_type __n, const value_type& __v); void shrink_to_fit() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __base::size() == 0;} // element access: diff --git a/contrib/libc++/include/exception b/contrib/libc++/include/exception index ca2eaf5c6a04..79bd6ac2ae35 100644 --- a/contrib/libc++/include/exception +++ b/contrib/libc++/include/exception @@ -82,7 +82,7 @@ template void rethrow_if_nested(const E& e); #include #include -#if defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) #include #endif @@ -93,7 +93,7 @@ template void rethrow_if_nested(const E& e); namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) class _LIBCPP_EXCEPTION_ABI exception { public: @@ -110,7 +110,7 @@ public: virtual ~bad_exception() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; -#endif // !_LIBCPP_ABI_MICROSOFT +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME #if _LIBCPP_STD_VER <= 14 \ || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ diff --git a/contrib/libc++/include/experimental/algorithm b/contrib/libc++/include/experimental/algorithm index 3801cae4f16e..a6a28f07181b 100644 --- a/contrib/libc++/include/experimental/algorithm +++ b/contrib/libc++/include/experimental/algorithm @@ -61,9 +61,9 @@ template inline _LIBCPP_INLINE_VISIBILITY _SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last, - _SampleIterator __output, _Distance __n, + _SampleIterator __output_iter, _Distance __n, _UniformRandomNumberGenerator &&__g) { - return _VSTD::__sample(__first, __last, __output, __n, __g); + return _VSTD::__sample(__first, __last, __output_iter, __n, __g); } _LIBCPP_END_NAMESPACE_LFTS diff --git a/contrib/libc++/include/experimental/filesystem b/contrib/libc++/include/experimental/filesystem index 42157ba309bc..674490f60381 100644 --- a/contrib/libc++/include/experimental/filesystem +++ b/contrib/libc++/include/experimental/filesystem @@ -81,10 +81,10 @@ path canonical(const path& p, const path& base, error_code& ec); void copy(const path& from, const path& to); - void copy(const path& from, const path& to, error_code& ec) _NOEXCEPT; + void copy(const path& from, const path& to, error_code& ec); void copy(const path& from, const path& to, copy_options options); void copy(const path& from, const path& to, copy_options options, - error_code& ec) _NOEXCEPT; + error_code& ec); bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) _NOEXCEPT; @@ -972,7 +972,8 @@ public: _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); } // query - _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); } + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT { return __pn_.empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { return !__root_directory().empty(); } @@ -1351,7 +1352,7 @@ void copy(const path& __from, const path& __to) { } inline _LIBCPP_INLINE_VISIBILITY -void copy(const path& __from, const path& __to, error_code& __ec) _NOEXCEPT { +void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); } @@ -1362,7 +1363,7 @@ void copy(const path& __from, const path& __to, copy_options __opt) { inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to, - copy_options __opt, error_code& __ec) _NOEXCEPT { + copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); } @@ -1561,7 +1562,7 @@ bool is_empty(const path& __p) { } inline _LIBCPP_INLINE_VISIBILITY -bool is_empty(const path& __p, error_code& __ec) _NOEXCEPT { +bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); } @@ -1903,12 +1904,12 @@ public: : directory_iterator(__p, nullptr, __opts) { } - directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + directory_iterator(const path& __p, error_code& __ec) : directory_iterator(__p, &__ec) { } directory_iterator(const path& __p, directory_options __opts, - error_code& __ec) _NOEXCEPT + error_code& __ec) : directory_iterator(__p, &__ec, __opts) { } @@ -1943,7 +1944,7 @@ public: return __p; } - directory_iterator& increment(error_code& __ec) _NOEXCEPT + directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } private: @@ -2013,12 +2014,12 @@ public: _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator(const path& __p, - directory_options __xoptions, error_code& __ec) _NOEXCEPT + directory_options __xoptions, error_code& __ec) : recursive_directory_iterator(__p, __xoptions, &__ec) { } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator(const path& __p, error_code& __ec) _NOEXCEPT + recursive_directory_iterator(const path& __p, error_code& __ec) : recursive_directory_iterator(__p, directory_options::none, &__ec) { } @@ -2060,7 +2061,7 @@ public: } _LIBCPP_INLINE_VISIBILITY - recursive_directory_iterator& increment(error_code& __ec) _NOEXCEPT + recursive_directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } _LIBCPP_FUNC_VIS directory_options options() const; diff --git a/contrib/libc++/include/experimental/iterator b/contrib/libc++/include/experimental/iterator index 37186b3d0b30..ea672e966315 100644 --- a/contrib/libc++/include/experimental/iterator +++ b/contrib/libc++/include/experimental/iterator @@ -75,19 +75,19 @@ public: typedef void reference; ostream_joiner(ostream_type& __os, _Delim&& __d) - : __output(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} ostream_joiner(ostream_type& __os, const _Delim& __d) - : __output(_VSTD::addressof(__os)), __delim(__d), __first(true) {} + : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} template ostream_joiner& operator=(const _Tp& __v) { if (!__first) - *__output << __delim; + *__output_iter << __delim; __first = false; - *__output << __v; + *__output_iter << __v; return *this; } @@ -96,7 +96,7 @@ public: ostream_joiner& operator++(int) _NOEXCEPT { return *this; } private: - ostream_type* __output; + ostream_type* __output_iter; _Delim __delim; bool __first; }; diff --git a/contrib/libc++/include/forward_list b/contrib/libc++/include/forward_list index 8bfa9a084338..7b8204137201 100644 --- a/contrib/libc++/include/forward_list +++ b/contrib/libc++/include/forward_list @@ -728,7 +728,7 @@ public: const_iterator cbefore_begin() const _NOEXCEPT {return const_iterator(base::__before_begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::__before_begin()->__next_ == nullptr;} _LIBCPP_INLINE_VISIBILITY diff --git a/contrib/libc++/include/fstream b/contrib/libc++/include/fstream index ffd569839bd4..f57908c8dfaf 100644 --- a/contrib/libc++/include/fstream +++ b/contrib/libc++/include/fstream @@ -315,7 +315,7 @@ basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) else this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); - this->pbump(__rhs. pptr() - __rhs.pbase()); + this->__pbump(__rhs. pptr() - __rhs.pbase()); } else if (__rhs.eback()) { @@ -434,7 +434,7 @@ basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) ptrdiff_t __e = this->epptr() - this->pbase(); this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e); - this->pbump(__n); + this->__pbump(__n); } if (__rhs.eback() == (char_type*)__extbuf_min_) { @@ -450,7 +450,7 @@ basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e); - __rhs.pbump(__n); + __rhs.__pbump(__n); } } @@ -724,7 +724,7 @@ basic_filebuf<_CharT, _Traits>::overflow(int_type __c) if (__r == codecvt_base::partial) { this->setp(const_cast(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else diff --git a/contrib/libc++/include/future b/contrib/libc++/include/future index e38876758e13..a7c28a4746cf 100644 --- a/contrib/libc++/include/future +++ b/contrib/libc++/include/future @@ -2335,6 +2335,7 @@ inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, lau { return (int(__policy) & int(__value)) != 0; } template +_LIBCPP_NODISCARD_AFTER_CXX17 future::type, typename decay<_Args>::type...>::type> async(launch __policy, _Fp&& __f, _Args&&... __args) { @@ -2360,7 +2361,7 @@ async(launch __policy, _Fp&& __f, _Args&&... __args) } template -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY future::type, typename decay<_Args>::type...>::type> async(_Fp&& __f, _Args&&... __args) { diff --git a/contrib/libc++/include/istream b/contrib/libc++/include/istream index 0b8e05d95bd8..5c73df38f650 100644 --- a/contrib/libc++/include/istream +++ b/contrib/libc++/include/istream @@ -1069,16 +1069,18 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ this->rdbuf()->sbumpc(); ++__gc_; } - if (__n > 0) - *__s = char_type(); if (__gc_ == 0) __err |= ios_base::failbit; this->setstate(__err); } + if (__n > 0) + *__s = char_type(); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { + if (__n > 0) + *__s = char_type(); this->__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS diff --git a/contrib/libc++/include/iterator b/contrib/libc++/include/iterator index d163ab1b0910..8b887db037b9 100644 --- a/contrib/libc++/include/iterator +++ b/contrib/libc++/include/iterator @@ -37,16 +37,6 @@ struct iterator_traits typedef random_access_iterator_tag iterator_category; }; -template -struct iterator_traits -{ - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef const T* pointer; - typedef const T& reference; - typedef random_access_iterator_tag iterator_category; -}; - template struct iterator @@ -494,7 +484,7 @@ template struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> { typedef ptrdiff_t difference_type; - typedef typename remove_const<_Tp>::type value_type; + typedef typename remove_cv<_Tp>::type value_type; typedef _Tp* pointer; typedef _Tp& reference; typedef random_access_iterator_tag iterator_category; @@ -604,21 +594,27 @@ distance(_InputIter __first, _InputIter __last) template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_InputIter +typename enable_if +< + __is_input_iterator<_InputIter>::value, + _InputIter +>::type next(_InputIter __x, - typename iterator_traits<_InputIter>::difference_type __n = 1, - typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0) + typename iterator_traits<_InputIter>::difference_type __n = 1) { _VSTD::advance(__x, __n); return __x; } -template +template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -_BidiretionalIter -prev(_BidiretionalIter __x, - typename iterator_traits<_BidiretionalIter>::difference_type __n = 1, - typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0) +typename enable_if +< + __is_bidirectional_iterator<_BidirectionalIter>::value, + _BidirectionalIter +>::type +prev(_BidirectionalIter __x, + typename iterator_traits<_BidirectionalIter>::difference_type __n = 1) { _VSTD::advance(__x, -__n); return __x; @@ -908,15 +904,37 @@ public: _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) {istream_iterator __t(*this); ++(*this); return __t;} + template friend _LIBCPP_INLINE_VISIBILITY - bool operator==(const istream_iterator& __x, const istream_iterator& __y) - {return __x.__in_stream_ == __y.__in_stream_;} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); + template friend _LIBCPP_INLINE_VISIBILITY - bool operator!=(const istream_iterator& __x, const istream_iterator& __y) - {return !(__x == __y);} + bool + operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, + const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); }; +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return __x.__in_stream_ == __y.__in_stream_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, + const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) +{ + return !(__x == __y); +} + template > class _LIBCPP_TEMPLATE_VIS ostream_iterator : public iterator @@ -1794,31 +1812,67 @@ end(const _Cp& __c) #endif // !defined(_LIBCPP_CXX03_LANG) #if _LIBCPP_STD_VER > 14 + +// #if _LIBCPP_STD_VER > 11 +// template <> +// struct _LIBCPP_TEMPLATE_VIS plus +// { +// template +// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY +// auto operator()(_T1&& __t, _T2&& __u) const +// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) +// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) +// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } +// typedef void is_transparent; +// }; +// #endif + template -constexpr auto size(const _Cont& __c) -> decltype(__c.size()) { return __c.size(); } +inline _LIBCPP_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } template +inline _LIBCPP_INLINE_VISIBILITY constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } template -constexpr auto empty(const _Cont& __c) -> decltype(__c.empty()) { return __c.empty(); } +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } template +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } template +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } template constexpr -auto data(_Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template constexpr -auto data(const _Cont& __c) -> decltype(__c.data()) { return __c.data(); } +inline _LIBCPP_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } template +inline _LIBCPP_INLINE_VISIBILITY constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } template +inline _LIBCPP_INLINE_VISIBILITY constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } #endif diff --git a/contrib/libc++/include/list b/contrib/libc++/include/list index 9c70fff946c7..32e9a27bd2a4 100644 --- a/contrib/libc++/include/list +++ b/contrib/libc++/include/list @@ -481,7 +481,7 @@ public: { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), - "Attempted to dereference a non-dereferenceable list::iterator"); + "Attempted to dereference a non-dereferenceable list::const_iterator"); #endif return pointer_traits::pointer_to(__ptr_->__as_node()->__value_); } @@ -896,7 +896,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return base::__sz();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return base::empty();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT @@ -1071,6 +1071,16 @@ public: bool __invariants() const; + typedef __allocator_destructor<__node_allocator> __node_destructor; + typedef unique_ptr<__node, __node_destructor> __hold_pointer; + + _LIBCPP_INLINE_VISIBILITY + __hold_pointer __allocate_node(__node_allocator& __na) { + __node_pointer __p = __node_alloc_traits::allocate(__na, 1); + __p->__prev_ = nullptr; + return __hold_pointer(__p, __node_destructor(__na, 1)); + } + #if _LIBCPP_DEBUG_LEVEL >= 2 bool __dereferenceable(const const_iterator* __i) const; @@ -1397,9 +1407,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); ++base::__sz(); @@ -1426,9 +1434,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1494,9 +1500,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, { size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1549,8 +1553,7 @@ void list<_Tp, _Alloc>::push_front(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_front(__nl, __nl); @@ -1563,8 +1566,7 @@ void list<_Tp, _Alloc>::push_back(const value_type& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); @@ -1578,8 +1580,7 @@ void list<_Tp, _Alloc>::push_front(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); @@ -1591,8 +1592,7 @@ void list<_Tp, _Alloc>::push_back(value_type&& __x) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); @@ -1609,8 +1609,7 @@ void list<_Tp, _Alloc>::emplace_front(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); ++base::__sz(); @@ -1631,8 +1630,7 @@ void list<_Tp, _Alloc>::emplace_back(_Args&&... __args) { __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold->__as_link(); __link_nodes_at_back(__nl, __nl); @@ -1655,9 +1653,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); __link_pointer __nl = __hold.get()->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); @@ -1680,9 +1676,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) " referring to this list"); #endif __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); __link_pointer __nl = __hold->__as_link(); __link_nodes(__p.__ptr_, __nl, __nl); @@ -1855,9 +1849,7 @@ list<_Tp, _Alloc>::resize(size_type __n) __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); ++__ds; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1914,9 +1906,7 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) __n -= base::__sz(); size_type __ds = 0; __node_allocator& __na = base::__node_alloc(); - typedef __allocator_destructor<__node_allocator> _Dp; - unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); - __hold->__prev_ = 0; + __hold_pointer __hold = __allocate_node(__na); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); ++__ds; __link_pointer __nl = __hold.release()->__as_link(); diff --git a/contrib/libc++/include/locale b/contrib/libc++/include/locale index d30d950c7f85..a86645d2cc4b 100644 --- a/contrib/libc++/include/locale +++ b/contrib/libc++/include/locale @@ -4110,7 +4110,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) if (__r == codecvt_base::partial) { this->setp(const_cast(__e), this->pptr()); - this->pbump(this->epptr() - this->pbase()); + this->__pbump(this->epptr() - this->pbase()); } } else diff --git a/contrib/libc++/include/map b/contrib/libc++/include/map index 71f18693f6d1..952149389814 100644 --- a/contrib/libc++/include/map +++ b/contrib/libc++/include/map @@ -1012,7 +1012,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -1669,7 +1669,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} diff --git a/contrib/libc++/include/memory b/contrib/libc++/include/memory index 22706d029d5f..df221ffa7510 100644 --- a/contrib/libc++/include/memory +++ b/contrib/libc++/include/memory @@ -46,6 +46,9 @@ struct pointer_traits static pointer pointer_to(
) noexcept; }; +template constexpr T* to_address(T* p) noexcept; // C++20 +template auto to_address(const Ptr& p) noexcept; // C++20 + template struct allocator_traits { @@ -81,8 +84,8 @@ struct allocator_traits template using rebind_alloc = Alloc::rebind::other | Alloc; template using rebind_traits = allocator_traits>; - static pointer allocate(allocator_type& a, size_type n); - static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); + static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20 + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; @@ -384,6 +387,9 @@ template unique_ptr make_unique(Args&&... args); template unique_ptr make_unique(size_t n); // C++14 template unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] +template + basic_ostream& operator<< (basic_ostream& os, unique_ptr const& p); + template class shared_ptr { @@ -724,7 +730,7 @@ template struct __has_element_type : false_type {}; template -struct __has_element_type<_Tp, +struct __has_element_type<_Tp, typename __void_t::type> : true_type {}; template ::value> @@ -808,7 +814,7 @@ template struct __has_difference_type : false_type {}; template -struct __has_difference_type<_Tp, +struct __has_difference_type<_Tp, typename __void_t::type> : true_type {}; template ::value> @@ -994,7 +1000,7 @@ template struct __has_pointer_type : false_type {}; template -struct __has_pointer_type<_Tp, +struct __has_pointer_type<_Tp, typename __void_t::type> : true_type {}; namespace __pointer_type_imp @@ -1024,7 +1030,7 @@ template struct __has_const_pointer : false_type {}; template -struct __has_const_pointer<_Tp, +struct __has_const_pointer<_Tp, typename __void_t::type> : true_type {}; template ::value> @@ -1047,7 +1053,7 @@ template struct __has_void_pointer : false_type {}; template -struct __has_void_pointer<_Tp, +struct __has_void_pointer<_Tp, typename __void_t::type> : true_type {}; template ::value> @@ -1070,7 +1076,7 @@ template struct __has_const_void_pointer : false_type {}; template -struct __has_const_void_pointer<_Tp, +struct __has_const_void_pointer<_Tp, typename __void_t::type> : true_type {}; template ::value> @@ -1090,13 +1096,14 @@ struct __const_void_pointer<_Ptr, _Alloc, false> }; template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR _Tp* __to_raw_pointer(_Tp* __p) _NOEXCEPT { return __p; } +#if _LIBCPP_STD_VER <= 17 template inline _LIBCPP_INLINE_VISIBILITY typename pointer_traits<_Pointer>::element_type* @@ -1104,6 +1111,41 @@ __to_raw_pointer(_Pointer __p) _NOEXCEPT { return _VSTD::__to_raw_pointer(__p.operator->()); } +#else +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p) _NOEXCEPT +-> decltype(pointer_traits<_Pointer>::to_address(__p)) +{ + return pointer_traits<_Pointer>::to_address(__p); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p.operator->()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY constexpr +_Tp* +to_address(_Tp* __p) _NOEXCEPT +{ + static_assert(!is_function_v<_Tp>, "_Tp is a function type"); + return __p; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +auto +to_address(const _Pointer& __p) _NOEXCEPT +{ + return _VSTD::__to_raw_pointer(__p); +} +#endif template struct __has_size_type : false_type {}; @@ -1148,7 +1190,7 @@ template struct __has_propagate_on_container_move_assignment : false_type {}; template -struct __has_propagate_on_container_move_assignment<_Tp, +struct __has_propagate_on_container_move_assignment<_Tp, typename __void_t::type> : true_type {}; @@ -1168,7 +1210,7 @@ template struct __has_propagate_on_container_swap : false_type {}; template -struct __has_propagate_on_container_swap<_Tp, +struct __has_propagate_on_container_swap<_Tp, typename __void_t::type> : true_type {}; @@ -1188,7 +1230,7 @@ template struct __has_is_always_equal : false_type {}; template -struct __has_is_always_equal<_Tp, +struct __has_is_always_equal<_Tp, typename __void_t::type> : true_type {}; @@ -1302,7 +1344,7 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false> template auto __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p) - -> decltype(__a.allocate(__sz, __p), true_type()); + -> decltype((void)__a.allocate(__sz, __p), true_type()); template auto @@ -1313,7 +1355,7 @@ template struct __has_allocate_hint : integral_constant(), + decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(), declval<_SizeType>(), declval<_ConstVoidPtr>())), true_type>::value> @@ -1346,7 +1388,7 @@ template struct __has_construct : integral_constant(), + decltype(_VSTD::__has_construct_test(declval<_Alloc>(), declval<_Pointer>(), declval<_Args>()...)), true_type>::value> @@ -1367,7 +1409,7 @@ template struct __has_destroy : integral_constant(), + decltype(_VSTD::__has_destroy_test(declval<_Alloc>(), declval<_Pointer>())), true_type>::value> { @@ -1387,7 +1429,7 @@ template struct __has_max_size : integral_constant())), + decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())), true_type>::value> { }; @@ -1406,7 +1448,7 @@ template struct __has_select_on_container_copy_construction : integral_constant())), + decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())), true_type>::value> { }; @@ -1497,10 +1539,10 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits {typedef allocator_traits::other> other;}; #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n) {return __a.allocate(__n);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {return __allocate(__a, __n, __hint, __has_allocate_hint());} @@ -1688,10 +1730,10 @@ private: } _LIBCPP_INLINE_VISIBILITY - static size_type __max_size(true_type, const allocator_type& __a) + static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT {return __a.max_size();} _LIBCPP_INLINE_VISIBILITY - static size_type __max_size(false_type, const allocator_type&) + static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT {return numeric_limits::max() / sizeof(value_type);} _LIBCPP_INLINE_VISIBILITY @@ -1739,7 +1781,8 @@ public: {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} - _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator::const_pointer = 0) + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + pointer allocate(size_type __n, allocator::const_pointer = 0) { if (__n > max_size()) __throw_length_error("allocator::allocate(size_t n)" @@ -1941,7 +1984,7 @@ public: _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) {raw_storage_iterator __t(*this); ++__x_; return __t;} #if _LIBCPP_STD_VER >= 14 - _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } + _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } #endif }; @@ -2040,11 +2083,12 @@ struct __compressed_pair_elem { typedef const _Tp& const_reference; #ifndef _LIBCPP_CXX03_LANG - constexpr __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {} template ::type>::value >::type> + _LIBCPP_INLINE_VISIBILITY constexpr explicit __compressed_pair_elem(_Up&& __u) : __value_(_VSTD::forward<_Up>(__u)){}; @@ -2055,11 +2099,13 @@ struct __compressed_pair_elem { __tuple_indices<_Indexes...>) : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} #else - __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {} + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {} #endif - reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; } + _LIBCPP_INLINE_VISIBILITY const_reference __get() const _NOEXCEPT { return __value_; } private: @@ -2074,11 +2120,12 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { typedef _Tp __value_type; #ifndef _LIBCPP_CXX03_LANG - constexpr __compressed_pair_elem() = default; + _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default; template ::type>::value >::type> + _LIBCPP_INLINE_VISIBILITY constexpr explicit __compressed_pair_elem(_Up&& __u) : __value_type(_VSTD::forward<_Up>(__u)){}; @@ -2089,12 +2136,14 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { __tuple_indices<_Indexes...>) : __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {} #else - __compressed_pair_elem() : __value_type() {} + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {} + _LIBCPP_INLINE_VISIBILITY __compressed_pair_elem(_ParamT __p) : __value_type(std::forward<_ParamT>(__p)) {} #endif - reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; } + _LIBCPP_INLINE_VISIBILITY const_reference __get() const _NOEXCEPT { return *this; } }; @@ -3850,7 +3899,7 @@ public: _LIBCPP_INLINE_VISIBILITY _Dp* __get_deleter() const _NOEXCEPT {return static_cast<_Dp*>(__cntrl_ - ? const_cast(__cntrl_->__get_deleter(typeid(_Dp))) + ? const_cast(__cntrl_->__get_deleter(typeid(_Dp))) : nullptr);} #endif // _LIBCPP_NO_RTTI @@ -4216,6 +4265,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_Args&& ...__args) { + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _A2; typedef __allocator_destructor<_A2> _D2; @@ -4234,6 +4284,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) { + static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; typedef __allocator_destructor<_A2> _D2; @@ -4254,6 +4305,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::make_shared() { + static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4272,6 +4324,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0) { + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4290,6 +4343,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1) { + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4308,6 +4362,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2) { + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4326,6 +4381,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a) { + static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4345,6 +4401,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0) { + static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4364,6 +4421,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1) { + static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4383,6 +4441,7 @@ template shared_ptr<_Tp> shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2) { + static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2; typedef __allocator_destructor<_Alloc2> _D2; @@ -4477,7 +4536,7 @@ inline typename enable_if < !is_array<_Yp>::value && - is_convertible::pointer, + is_convertible::pointer, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type @@ -4512,7 +4571,7 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if < !is_array<_Yp>::value && - is_convertible::pointer, + is_convertible::pointer, typename shared_ptr<_Tp>::element_type*>::value, shared_ptr<_Tp>& >::type @@ -5311,7 +5370,7 @@ atomic_load(const shared_ptr<_Tp>* __p) __m.unlock(); return __q; } - + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR @@ -5352,7 +5411,7 @@ atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) __m.unlock(); return __r; } - + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR @@ -5484,7 +5543,7 @@ void __swap_allocator(_Alloc & __a1, _Alloc & __a2) _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) #endif { - __swap_allocator(__a1, __a2, + __swap_allocator(__a1, __a2, integral_constant::propagate_on_container_swap::value>()); } @@ -5506,7 +5565,7 @@ inline _LIBCPP_INLINE_VISIBILITY void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} template > -struct __noexcept_move_assign_container : public integral_constant 14 || _Traits::is_always_equal::value @@ -5520,17 +5579,17 @@ struct __noexcept_move_assign_container : public integral_constant struct __temp_value { typedef allocator_traits<_Alloc> _Traits; - + typename aligned_storage::type __v; _Alloc &__a; _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } _Tp & get() { return *__addr(); } - + template __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); } - + ~__temp_value() { _Traits::destroy(__a, __addr()); } }; #endif diff --git a/contrib/libc++/include/new b/contrib/libc++/include/new index 34df2efee09e..4e527501b1e2 100644 --- a/contrib/libc++/include/new +++ b/contrib/libc++/include/new @@ -46,13 +46,15 @@ typedef void (*new_handler)(); new_handler set_new_handler(new_handler new_p) noexcept; new_handler get_new_handler() noexcept; +// 21.6.4, pointer optimization barrier +template constexpr T* launder(T* p) noexcept; // C++17 } // std -void* operator new(std::size_t size); // replaceable -void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17 -void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable +void* operator new(std::size_t size); // replaceable, nodiscard in C++2a +void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a +void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a void* operator new(std::size_t size, std::align_val_t alignment, - const std::nothrow_t&) noexcept; // replaceable, C++17 + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a void operator delete(void* ptr) noexcept; // replaceable void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14 void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17 @@ -62,12 +64,12 @@ void operator delete(void* ptr, const std::nothrow_t&) noexcept; // repla void operator delete(void* ptr, std:align_val_t alignment, const std::nothrow_t&) noexcept; // replaceable, C++17 -void* operator new[](std::size_t size); // replaceable +void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a void* operator new[](std::size_t size, - std::align_val_t alignment) noexcept; // replaceable, C++17 -void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable + std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a +void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a void* operator new[](std::size_t size, std::align_val_t alignment, - const std::nothrow_t&) noexcept; // replaceable, C++17 + const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a void operator delete[](void* ptr) noexcept; // replaceable void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14 void operator delete[](void* ptr, @@ -78,8 +80,8 @@ void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // repla void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept; // replaceable, C++17 -void* operator new (std::size_t size, void* ptr) noexcept; -void* operator new[](std::size_t size, void* ptr) noexcept; +void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a +void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a void operator delete (void* ptr, void*) noexcept; void operator delete[](void* ptr, void*) noexcept; @@ -92,7 +94,7 @@ void operator delete[](void* ptr, void*) noexcept; #include #endif -#if defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) #include #endif @@ -114,7 +116,7 @@ void operator delete[](void* ptr, void*) noexcept; namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) struct _LIBCPP_TYPE_VIS nothrow_t {}; extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; @@ -140,7 +142,7 @@ typedef void (*new_handler)(); _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; -#endif // !_LIBCPP_ABI_MICROSOFT +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec @@ -174,18 +176,18 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 }; #define _THROW_BAD_ALLOC #endif -#if !defined(_LIBCPP_ABI_MICROSOFT) +#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT; #endif -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION @@ -193,16 +195,16 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operato #endif #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT; #endif -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; -_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION @@ -210,12 +212,12 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operato #endif #endif -inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} -inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;} +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;} inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} -#endif // !_LIBCPP_ABI_MICROSOFT +#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME _LIBCPP_BEGIN_NAMESPACE_STD @@ -250,6 +252,29 @@ void __throw_bad_array_length() } #endif +template +_LIBCPP_NODISCARD_AFTER_CXX17 inline +_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT +{ + static_assert (!(is_function<_Tp>::value), "can't launder functions" ); + static_assert (!(is_same::type>::value), "can't launder cv-void" ); +#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER + return __builtin_launder(__p); +#else + return __p; +#endif +} + + +#if _LIBCPP_STD_VER > 14 +template +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp* launder(_Tp* __p) noexcept +{ + return _VSTD::__launder(__p); +} +#endif + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_NEW diff --git a/contrib/libc++/include/optional b/contrib/libc++/include/optional index 1fb953bab743..35a4d74c2e86 100644 --- a/contrib/libc++/include/optional +++ b/contrib/libc++/include/optional @@ -57,17 +57,17 @@ namespace std { // 23.6.8, comparison with T template constexpr bool operator==(const optional&, const U&); - template constexpr bool operator==(const U&, const optional&); + template constexpr bool operator==(const T&, const optional&); template constexpr bool operator!=(const optional&, const U&); - template constexpr bool operator!=(const U&, const optional&); + template constexpr bool operator!=(const T&, const optional&); template constexpr bool operator<(const optional&, const U&); - template constexpr bool operator<(const U&, const optional&); + template constexpr bool operator<(const T&, const optional&); template constexpr bool operator<=(const optional&, const U&); - template constexpr bool operator<=(const U&, const optional&); + template constexpr bool operator<=(const T&, const optional&); template constexpr bool operator>(const optional&, const U&); - template constexpr bool operator>(const U&, const optional&); + template constexpr bool operator>(const T&, const optional&); template constexpr bool operator>=(const optional&, const U&); - template constexpr bool operator>=(const U&, const optional&); + template constexpr bool operator>=(const T&, const optional&); // 23.6.9, specialized algorithms template void swap(optional&, optional&) noexcept(see below ); diff --git a/contrib/libc++/include/ostream b/contrib/libc++/include/ostream index 9bf8d3cdcfb5..f3250a7080dd 100644 --- a/contrib/libc++/include/ostream +++ b/contrib/libc++/include/ostream @@ -1071,6 +1071,20 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p) return __os << __p.get(); } +#ifndef _LIBCPP_HAS_NO_DECLTYPE +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same&>() << declval<_Yp>())>::type>::value, + basic_ostream<_CharT, _Traits>& +>::type +operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p) +{ + return __os << __p.get(); +} +#endif + template basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x) diff --git a/contrib/libc++/include/queue b/contrib/libc++/include/queue index feaae8920463..670fbb722ee2 100644 --- a/contrib/libc++/include/queue +++ b/contrib/libc++/include/queue @@ -268,7 +268,7 @@ public: #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} @@ -490,7 +490,7 @@ public: _Alloc>::value>::type* = 0); #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} diff --git a/contrib/libc++/include/random b/contrib/libc++/include/random index ba8a088dfcb1..9073a5285b1a 100644 --- a/contrib/libc++/include/random +++ b/contrib/libc++/include/random @@ -2308,6 +2308,7 @@ template ::seed(result_type __sd) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { // __w >= 2 __x_[0] = __sd & _Max; for (size_t __i = 1; __i < __n; ++__i) diff --git a/contrib/libc++/include/regex b/contrib/libc++/include/regex index 77ca648109b2..ff84b2738b78 100644 --- a/contrib/libc++/include/regex +++ b/contrib/libc++/include/regex @@ -773,6 +773,8 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> +#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 + _LIBCPP_BEGIN_NAMESPACE_STD namespace regex_constants @@ -2407,17 +2409,28 @@ __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const goto __exit; } } - if (!__neg_chars_.empty()) + // set of "__found" chars = + // union(complement(union(__neg_chars_, __neg_mask_)), + // other cases...) + // + // __neg_chars_ and __neg_mask_'d better be handled together, as there + // are no short circuit opportunities. + // + // In addition, when __neg_mask_/__neg_chars_ is empty, they should be + // treated as all ones/all chars. { - for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) - { - if (__ch == __neg_chars_[__i]) - goto __is_neg_char; - } + const bool __in_neg_mask = (__neg_mask_ == 0) || + __traits_.isctype(__ch, __neg_mask_); + const bool __in_neg_chars = + __neg_chars_.empty() || + std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != + __neg_chars_.end(); + if (!(__in_neg_mask || __in_neg_chars)) + { __found = true; goto __exit; + } } -__is_neg_char: if (!__ranges_.empty()) { string_type __s2 = __collate_ ? @@ -2449,11 +2462,6 @@ __is_neg_char: __found = true; goto __exit; } - if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) - { - __found = true; - goto __exit; - } } else __found = __negate_; // force reject @@ -4056,6 +4064,8 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; ++__first) { + if (__c >= std::numeric_limits::max() / 10) + __throw_regex_error(); __c *= 10; __c += __val; } @@ -4317,8 +4327,12 @@ basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, unsigned __v = *__first - '0'; for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; ++__first) + { + if (__v >= std::numeric_limits::max() / 10) + __throw_regex_error(); __v = 10 * __v + *__first - '0'; - if (__v > mark_count()) + } + if (__v == 0 || __v > mark_count()) __throw_regex_error(); __push_back_ref(__v); } @@ -5226,11 +5240,11 @@ public: // size: _LIBCPP_INLINE_VISIBILITY - size_type size() const {return __matches_.size();} + size_type size() const _NOEXCEPT {return __matches_.size();} _LIBCPP_INLINE_VISIBILITY - size_type max_size() const {return __matches_.max_size();} - _LIBCPP_INLINE_VISIBILITY - bool empty() const {return size() == 0;} + size_type max_size() const _NOEXCEPT {return __matches_.max_size();} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} // element access: _LIBCPP_INLINE_VISIBILITY @@ -5263,15 +5277,15 @@ public: // format: template _OutputIter - format(_OutputIter __output, const char_type* __fmt_first, + format(_OutputIter __output_iter, const char_type* __fmt_first, const char_type* __fmt_last, regex_constants::match_flag_type __flags = regex_constants::format_default) const; template _LIBCPP_INLINE_VISIBILITY _OutputIter - format(_OutputIter __output, const basic_string& __fmt, + format(_OutputIter __output_iter, const basic_string& __fmt, regex_constants::match_flag_type __flags = regex_constants::format_default) const - {return format(__output, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} + {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} template _LIBCPP_INLINE_VISIBILITY basic_string @@ -5383,7 +5397,7 @@ match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, template template _OutputIter -match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output, +match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, const char_type* __fmt_first, const char_type* __fmt_last, regex_constants::match_flag_type __flags) const { @@ -5392,27 +5406,27 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output, for (; __fmt_first != __fmt_last; ++__fmt_first) { if (*__fmt_first == '&') - __output = _VSTD::copy(__matches_[0].first, __matches_[0].second, - __output); + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) { ++__fmt_first; if ('0' <= *__fmt_first && *__fmt_first <= '9') { size_t __i = *__fmt_first - '0'; - __output = _VSTD::copy((*this)[__i].first, - (*this)[__i].second, __output); + __output_iter = _VSTD::copy((*this)[__i].first, + (*this)[__i].second, __output_iter); } else { - *__output = *__fmt_first; - ++__output; + *__output_iter = *__fmt_first; + ++__output_iter; } } else { - *__output = *__fmt_first; - ++__output; + *__output_iter = *__fmt_first; + ++__output_iter; } } } @@ -5425,52 +5439,54 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output, switch (__fmt_first[1]) { case '$': - *__output = *++__fmt_first; - ++__output; + *__output_iter = *++__fmt_first; + ++__output_iter; break; case '&': ++__fmt_first; - __output = _VSTD::copy(__matches_[0].first, __matches_[0].second, - __output); + __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, + __output_iter); break; case '`': ++__fmt_first; - __output = _VSTD::copy(__prefix_.first, __prefix_.second, __output); + __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); break; case '\'': ++__fmt_first; - __output = _VSTD::copy(__suffix_.first, __suffix_.second, __output); + __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); break; default: if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') { ++__fmt_first; - size_t __i = *__fmt_first - '0'; + size_t __idx = *__fmt_first - '0'; if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') { ++__fmt_first; - __i = 10 * __i + *__fmt_first - '0'; + if (__idx >= std::numeric_limits::max() / 10) + __throw_regex_error(); + __idx = 10 * __idx + *__fmt_first - '0'; } - __output = _VSTD::copy((*this)[__i].first, - (*this)[__i].second, __output); + __output_iter = _VSTD::copy((*this)[__idx].first, + (*this)[__idx].second, __output_iter); } else { - *__output = *__fmt_first; - ++__output; + *__output_iter = *__fmt_first; + ++__output_iter; } break; } } else { - *__output = *__fmt_first; - ++__output; + *__output_iter = *__fmt_first; + ++__output_iter; } } } - return __output; + return __output_iter; } template @@ -5552,8 +5568,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma( __states.back().__node_ = __st; __states.back().__flags_ = __flags; __states.back().__at_first_ = __at_first; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); @@ -5627,8 +5649,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( __states.back().__flags_ = __flags; __states.back().__at_first_ = __at_first; bool __matched = false; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); @@ -5724,8 +5752,14 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( __states.back().__at_first_ = __at_first; const _CharT* __current = __first; bool __matched = false; + int __counter = 0; + int __length = __last - __first; do { + ++__counter; + if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && + __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) + __throw_regex_error(); __state& __s = __states.back(); if (__s.__node_) __s.__node_->__exec(__s); @@ -6460,7 +6494,7 @@ typedef regex_token_iterator wsregex_token_iterator; template _OutputIterator -regex_replace(_OutputIterator __output, +regex_replace(_OutputIterator __output_iter, _BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, regex_constants::match_flag_type __flags = regex_constants::match_default) @@ -6471,7 +6505,7 @@ regex_replace(_OutputIterator __output, if (__i == __eof) { if (!(__flags & regex_constants::format_no_copy)) - __output = _VSTD::copy(__first, __last, __output); + __output_iter = _VSTD::copy(__first, __last, __output_iter); } else { @@ -6479,29 +6513,29 @@ regex_replace(_OutputIterator __output, for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) { if (!(__flags & regex_constants::format_no_copy)) - __output = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output); - __output = __i->format(__output, __fmt, __fmt + __len, __flags); + __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); + __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); __lm = __i->suffix(); if (__flags & regex_constants::format_first_only) break; } if (!(__flags & regex_constants::format_no_copy)) - __output = _VSTD::copy(__lm.first, __lm.second, __output); + __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); } - return __output; + return __output_iter; } template inline _LIBCPP_INLINE_VISIBILITY _OutputIterator -regex_replace(_OutputIterator __output, +regex_replace(_OutputIterator __output_iter, _BidirectionalIterator __first, _BidirectionalIterator __last, const basic_regex<_CharT, _Traits>& __e, const basic_string<_CharT, _ST, _SA>& __fmt, regex_constants::match_flag_type __flags = regex_constants::match_default) { - return _VSTD::regex_replace(__output, __first, __last, __e, __fmt.c_str(), __flags); + return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags); } template :: allocate(outer_allocator(), __n);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, const_void_pointer __hint) {return allocator_traits:: allocate(outer_allocator(), __n, __hint);} diff --git a/contrib/libc++/include/set b/contrib/libc++/include/set index 30f2fa88f256..b4c6b2ef8c53 100644 --- a/contrib/libc++/include/set +++ b/contrib/libc++/include/set @@ -575,7 +575,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} @@ -984,7 +984,7 @@ public: _LIBCPP_INLINE_VISIBILITY const_reverse_iterator crend() const _NOEXCEPT {return rend();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __tree_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __tree_.size();} diff --git a/contrib/libc++/include/sstream b/contrib/libc++/include/sstream index fe65fd7db53d..34b0014c14ad 100644 --- a/contrib/libc++/include/sstream +++ b/contrib/libc++/include/sstream @@ -243,7 +243,6 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode : __hm_(0), __mode_(__wch) { - str(string_type()); } template @@ -289,7 +288,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } __hm_ = __hm == -1 ? nullptr : __p + __hm; __p = const_cast(__rhs.__str_.data()); @@ -332,7 +331,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs) if (__bout != -1) { this->setp(__p + __bout, __p + __eout); - this->pbump(__nout); + this->__pbump(__nout); } else this->setp(nullptr, nullptr); @@ -403,7 +402,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) if (__rbout != -1) { this->setp(__p + __rbout, __p + __reout); - this->pbump(__rnout); + this->__pbump(__rnout); } else this->setp(nullptr, nullptr); @@ -416,7 +415,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs) if (__lbout != -1) { __rhs.setp(__p + __lbout, __p + __leout); - __rhs.pbump(__lnout); + __rhs.__pbump(__lnout); } else __rhs.setp(nullptr, nullptr); @@ -471,7 +470,15 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s) this->setp(const_cast(__str_.data()), const_cast(__str_.data()) + __str_.size()); if (__mode_ & (ios_base::app | ios_base::ate)) - this->pbump(__sz); + { + while (__sz > INT_MAX) + { + this->pbump(INT_MAX); + __sz -= INT_MAX; + } + if (__sz > 0) + this->pbump(__sz); + } } } @@ -536,7 +543,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) __str_.resize(__str_.capacity()); char_type* __p = const_cast(__str_.data()); this->setp(__p, __p + __str_.size()); - this->pbump(__nout); + this->__pbump(__nout); __hm_ = this->pbase() + __hm; #ifndef _LIBCPP_NO_EXCEPTIONS } diff --git a/contrib/libc++/include/stack b/contrib/libc++/include/stack index b2d4e2395017..0cb4c6ca925e 100644 --- a/contrib/libc++/include/stack +++ b/contrib/libc++/include/stack @@ -181,7 +181,7 @@ public: : c(_VSTD::move(__s.c), __a) {} #endif // _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const {return c.empty();} _LIBCPP_INLINE_VISIBILITY size_type size() const {return c.size();} diff --git a/contrib/libc++/include/streambuf b/contrib/libc++/include/streambuf index a10ce1bf5636..ea64f5780459 100644 --- a/contrib/libc++/include/streambuf +++ b/contrib/libc++/include/streambuf @@ -255,6 +255,9 @@ protected: inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void pbump(int __n) { __nout_ += __n; } + _LIBCPP_ALWAYS_INLINE + void __pbump(streamsize __n) { __nout_ += __n; } + inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY void setp(char_type* __pbeg, char_type* __pend) { __bout_ = __nout_ = __pbeg; @@ -404,7 +407,8 @@ basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n) { if (__ninp_ < __einp_) { - const streamsize __len = _VSTD::min(__einp_ - __ninp_, __n - __i); + const streamsize __len = _VSTD::min(static_cast(INT_MAX), + _VSTD::min(__einp_ - __ninp_, __n - __i)); traits_type::copy(__s, __ninp_, __len); __s += __len; __i += __len; diff --git a/contrib/libc++/include/string b/contrib/libc++/include/string index 7775587a42d9..f5d548965aae 100644 --- a/contrib/libc++/include/string +++ b/contrib/libc++/include/string @@ -301,6 +301,13 @@ public: int compare(size_type pos1, size_type n1, const value_type* s) const; int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; + bool starts_with(basic_string_view sv) const noexcept; // C++2a + bool starts_with(charT c) const noexcept; // C++2a + bool starts_with(const charT* s) const; // C++2a + bool ends_with(basic_string_view sv) const noexcept; // C++2a + bool ends_with(charT c) const noexcept; // C++2a + bool ends_with(const charT* s) const; // C++2a + bool __invariants() const; }; @@ -608,7 +615,7 @@ struct __libcpp_string_gets_noexcept_iterator template struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT( - ( is_convertible >::value && + ( is_convertible >::value && !is_convertible::value)) {}; #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT @@ -670,7 +677,7 @@ private: size_type __cap_; }; -#if _LIBCPP_BIG_ENDIAN +#ifdef _LIBCPP_BIG_ENDIAN static const size_type __short_mask = 0x01; static const size_type __long_mask = 0x1ul; #else // _LIBCPP_BIG_ENDIAN @@ -700,7 +707,7 @@ private: pointer __data_; }; -#if _LIBCPP_BIG_ENDIAN +#ifdef _LIBCPP_BIG_ENDIAN static const size_type __short_mask = 0x80; static const size_type __long_mask = ~(size_type(~0) >> 1); #else // _LIBCPP_BIG_ENDIAN @@ -901,7 +908,8 @@ public: void shrink_to_fit() _NOEXCEPT {reserve();} _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;} + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT {return size() == 0;} _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT; @@ -1127,7 +1135,7 @@ public: const value_type* c_str() const _NOEXCEPT {return data();} _LIBCPP_INLINE_VISIBILITY const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} -#if _LIBCPP_STD_VER > 14 +#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) _LIBCPP_INLINE_VISIBILITY value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} #endif @@ -1214,6 +1222,32 @@ public: int compare(size_type __pos1, size_type __n1, const value_type* __s) const; int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).starts_with(__sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(__self_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(__self_view __sv) const _NOEXCEPT + { return __self_view(data(), size()).ends_with( __sv); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(__self_view(__s)); } +#endif + _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY @@ -1241,7 +1275,7 @@ private: _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} # else {__r_.first().__s.__size_ = (unsigned char)(__s);} @@ -1249,7 +1283,7 @@ private: _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_ >> 1;} # else {return __r_.first().__s.__size_;} @@ -1259,7 +1293,7 @@ private: _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {__r_.first().__s.__size_ = (unsigned char)(__s);} # else {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} @@ -1267,7 +1301,7 @@ private: _LIBCPP_INLINE_VISIBILITY size_type __get_short_size() const _NOEXCEPT -# if _LIBCPP_BIG_ENDIAN +# ifdef _LIBCPP_BIG_ENDIAN {return __r_.first().__s.__size_;} # else {return __r_.first().__s.__size_ >> 1;} @@ -1756,10 +1790,10 @@ template template basic_string<_CharT, _Traits, _Allocator>::basic_string( const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a, - typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *) + typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *) : __r_(__second_tag(), __a) { - __self_view __sv = __self_view(__t).substr(__pos, __n); + __self_view __sv = __self_view(__t).substr(__pos, __n); __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); @@ -2145,7 +2179,7 @@ template typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, - basic_string<_CharT, _Traits, _Allocator>& + basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) { @@ -2493,7 +2527,7 @@ template typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, - basic_string<_CharT, _Traits, _Allocator>& + basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n) @@ -2682,8 +2716,8 @@ template template typename enable_if < - __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, - basic_string<_CharT, _Traits, _Allocator>& + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + basic_string<_CharT, _Traits, _Allocator>& >::type basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2) @@ -2870,7 +2904,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT { size_type __m = __alloc_traits::max_size(__alloc()); -#if _LIBCPP_BIG_ENDIAN +#ifdef _LIBCPP_BIG_ENDIAN return (__m <= ~__long_mask ? __m : __m/2) - __alignment; #else return __m - __alignment; @@ -3462,8 +3496,8 @@ template template typename enable_if < - __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, - int + __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, + int >::type basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, size_type __n1, diff --git a/contrib/libc++/include/string_view b/contrib/libc++/include/string_view index 4c759ab5daea..4d8358288f0c 100644 --- a/contrib/libc++/include/string_view +++ b/contrib/libc++/include/string_view @@ -143,6 +143,13 @@ namespace std { constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a + constexpr bool starts_with(charT c) const noexcept; // C++2a + constexpr bool starts_with(const charT* s) const; // C++2a + constexpr bool ends_with(basic_string_view s) const noexcept; // C++2a + constexpr bool ends_with(charT c) const noexcept; // C++2a + constexpr bool ends_with(const charT* s) const; // C++2a + private: const_pointer data_; // exposition only size_type size_; // exposition only @@ -155,10 +162,10 @@ namespace std { template <> struct hash; template <> struct hash; - constexpr basic_string operator "" s( const char *str, size_t len ); // C++17 - constexpr basic_string operator "" s( const wchar_t *str, size_t len ); // C++17 - constexpr basic_string operator "" s( const char16_t *str, size_t len ); // C++17 - constexpr basic_string operator "" s( const char32_t *str, size_t len ); // C++17 + constexpr basic_string_view operator "" sv( const char *str, size_t len ) noexcept; + constexpr basic_string_view operator "" sv( const wchar_t *str, size_t len ) noexcept; + constexpr basic_string_view operator "" sv( const char16_t *str, size_t len ) noexcept; + constexpr basic_string_view operator "" sv( const char32_t *str, size_t len ) noexcept; } // namespace std @@ -186,388 +193,414 @@ _LIBCPP_BEGIN_NAMESPACE_STD template > class _LIBCPP_TEMPLATE_VIS basic_string_view { public: - // types - typedef _Traits traits_type; - typedef _CharT value_type; - typedef const _CharT* pointer; - typedef const _CharT* const_pointer; - typedef const _CharT& reference; - typedef const _CharT& const_reference; - typedef const_pointer const_iterator; // See [string.view.iterators] - typedef const_iterator iterator; - typedef _VSTD::reverse_iterator const_reverse_iterator; - typedef const_reverse_iterator reverse_iterator; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); + // types + typedef _Traits traits_type; + typedef _CharT value_type; + typedef const _CharT* pointer; + typedef const _CharT* const_pointer; + typedef const _CharT& reference; + typedef const _CharT& const_reference; + typedef const_pointer const_iterator; // See [string.view.iterators] + typedef const_iterator iterator; + typedef _VSTD::reverse_iterator const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); static_assert(is_pod::value, "Character type of basic_string_view must be a POD"); static_assert((is_same<_CharT, typename traits_type::char_type>::value), "traits_type::char_type must be the same type as CharT"); - // [string.view.cons], construct/copy - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} + // [string.view.cons], construct/copy + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - basic_string_view(const basic_string_view&) _NOEXCEPT = default; + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const basic_string_view&) _NOEXCEPT = default; - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - basic_string_view(const _CharT* __s, size_type __len) - : __data(__s), __size(__len) - { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT + : __data(__s), __size(__len) + { // #if _LIBCPP_STD_VER > 11 // _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); // #endif - } + } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - basic_string_view(const _CharT* __s) - : __data(__s), __size(_Traits::length(__s)) {} + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view(const _CharT* __s) + : __data(__s), __size(_Traits::length(__s)) {} - // [string.view.iterators], iterators - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_iterator begin() const _NOEXCEPT { return cbegin(); } + // [string.view.iterators], iterators + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT { return cbegin(); } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_iterator end() const _NOEXCEPT { return cend(); } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT { return cend(); } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_iterator cbegin() const _NOEXCEPT { return __data; } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cbegin() const _NOEXCEPT { return __data; } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_iterator cend() const _NOEXCEPT { return __data + __size; } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_iterator cend() const _NOEXCEPT { return __data + __size; } - _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY - const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } - _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY - const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } - _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY - const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } - _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY - const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } + _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY + const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } - // [string.view.capacity], capacity - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - size_type size() const _NOEXCEPT { return __size; } + // [string.view.capacity], capacity + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type size() const _NOEXCEPT { return __size; } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - size_type length() const _NOEXCEPT { return __size; } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type length() const _NOEXCEPT { return __size; } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - size_type max_size() const _NOEXCEPT { return numeric_limits::max(); } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT { return numeric_limits::max(); } - _LIBCPP_CONSTEXPR bool _LIBCPP_INLINE_VISIBILITY - empty() const _NOEXCEPT { return __size == 0; } + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + bool empty() const _NOEXCEPT { return __size == 0; } - // [string.view.access], element access - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; } + // [string.view.access], element access + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference at(size_type __pos) const - { - return __pos >= size() - ? (__throw_out_of_range("string_view::at"), __data[0]) - : __data[__pos]; - } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference at(size_type __pos) const + { + return __pos >= size() + ? (__throw_out_of_range("string_view::at"), __data[0]) + : __data[__pos]; + } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference front() const - { - return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; - } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference front() const + { + return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; + } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference back() const - { - return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; - } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_reference back() const + { + return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; + } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_pointer data() const _NOEXCEPT { return __data; } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + const_pointer data() const _NOEXCEPT { return __data; } - // [string.view.modifiers], modifiers: - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - void remove_prefix(size_type __n) _NOEXCEPT - { - _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); - __data += __n; - __size -= __n; - } + // [string.view.modifiers], modifiers: + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_prefix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); + __data += __n; + __size -= __n; + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - void remove_suffix(size_type __n) _NOEXCEPT - { - _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); - __size -= __n; - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void remove_suffix(size_type __n) _NOEXCEPT + { + _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); + __size -= __n; + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - void swap(basic_string_view& __other) _NOEXCEPT - { - const value_type *__p = __data; - __data = __other.__data; - __other.__data = __p; + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + void swap(basic_string_view& __other) _NOEXCEPT + { + const value_type *__p = __data; + __data = __other.__data; + __other.__data = __p; - size_type __sz = __size; - __size = __other.__size; - __other.__size = __sz; - } + size_type __sz = __size; + __size = __other.__size; + __other.__size = __sz; + } - _LIBCPP_INLINE_VISIBILITY - size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const - { - if (__pos > size()) - __throw_out_of_range("string_view::copy"); - size_type __rlen = _VSTD::min(__n, size() - __pos); - _Traits::copy(__s, data() + __pos, __rlen); - return __rlen; - } + _LIBCPP_INLINE_VISIBILITY + size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const + { + if (__pos > size()) + __throw_out_of_range("string_view::copy"); + size_type __rlen = _VSTD::min(__n, size() - __pos); + _Traits::copy(__s, data() + __pos, __rlen); + return __rlen; + } - _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - basic_string_view substr(size_type __pos = 0, size_type __n = npos) const - { - return __pos > size() - ? (__throw_out_of_range("string_view::substr"), basic_string_view()) - : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); - } + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + basic_string_view substr(size_type __pos = 0, size_type __n = npos) const + { + return __pos > size() + ? (__throw_out_of_range("string_view::substr"), basic_string_view()) + : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT - { - size_type __rlen = _VSTD::min( size(), __sv.size()); - int __retval = _Traits::compare(data(), __sv.data(), __rlen); - if ( __retval == 0 ) // first __rlen chars matched - __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); - return __retval; - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT + { + size_type __rlen = _VSTD::min( size(), __sv.size()); + int __retval = _Traits::compare(data(), __sv.data(), __rlen); + if ( __retval == 0 ) // first __rlen chars matched + __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); + return __retval; + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const - { - return substr(__pos1, __n1).compare(__sv); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const + { + return substr(__pos1, __n1).compare(__sv); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare( size_type __pos1, size_type __n1, - basic_string_view __sv, size_type __pos2, size_type __n2) const - { - return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare( size_type __pos1, size_type __n1, + basic_string_view __sv, size_type __pos2, size_type __n2) const + { + return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare(const _CharT* __s) const _NOEXCEPT - { - return compare(basic_string_view(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(const _CharT* __s) const _NOEXCEPT + { + return compare(basic_string_view(__s)); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare(size_type __pos1, size_type __n1, const _CharT* __s) const - { - return substr(__pos1, __n1).compare(basic_string_view(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s)); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const - { - return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); + } - // find - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); - return __str_find - (data(), size(), __s.data(), __pos, __s.size()); - } + // find + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_find + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT - { - return __str_find - (data(), size(), __c, __pos); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { + return __str_find + (data(), size(), __c, __pos); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); - return __str_find - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); + return __str_find + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find(const _CharT* __s, size_type __pos = 0) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); - return __str_find - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find(const _CharT* __s, size_type __pos = 0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); + return __str_find + (data(), size(), __s, __pos, traits_type::length(__s)); + } - // rfind - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); - return __str_rfind - (data(), size(), __s.data(), __pos, __s.size()); - } + // rfind + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return __str_rfind + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT - { - return __str_rfind - (data(), size(), __c, __pos); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { + return __str_rfind + (data(), size(), __c, __pos); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); - return __str_rfind - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type rfind(const _CharT* __s, size_type __pos=npos) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); - return __str_rfind - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type rfind(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); + return __str_rfind + (data(), size(), __s, __pos, traits_type::length(__s)); + } - // find_first_of - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); - return __str_find_first_of - (data(), size(), __s.data(), __pos, __s.size()); - } + // find_first_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT - { return find(__c, __pos); } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT + { return find(__c, __pos); } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); - return __str_find_first_of - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_of(const _CharT* __s, size_type __pos=0) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); - return __str_find_first_of - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); + return __str_find_first_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } - // find_last_of - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); - return __str_find_last_of - (data(), size(), __s.data(), __pos, __s.size()); - } + // find_last_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT - { return rfind(__c, __pos); } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT + { return rfind(__c, __pos); } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); - return __str_find_last_of - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_of(const _CharT* __s, size_type __pos=npos) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); - return __str_find_last_of - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); + return __str_find_last_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } - // find_first_not_of - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); - return __str_find_first_not_of - (data(), size(), __s.data(), __pos, __s.size()); - } + // find_first_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT - { - return __str_find_first_not_of - (data(), size(), __c, __pos); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT + { + return __str_find_first_not_of + (data(), size(), __c, __pos); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); - return __str_find_first_not_of - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); - return __str_find_first_not_of - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return __str_find_first_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } - // find_last_not_of - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT - { - _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); - return __str_find_last_not_of - (data(), size(), __s.data(), __pos, __s.size()); - } + // find_last_not_of + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT + { + _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of + (data(), size(), __s.data(), __pos, __s.size()); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT - { - return __str_find_last_not_of - (data(), size(), __c, __pos); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT + { + return __str_find_last_not_of + (data(), size(), __c, __pos); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const - { - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); - return __str_find_last_not_of - (data(), size(), __s, __pos, __n); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of + (data(), size(), __s, __pos, __n); + } - _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const - { - _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); - return __str_find_last_not_of - (data(), size(), __s, __pos, traits_type::length(__s)); - } + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return __str_find_last_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(front(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool starts_with(const value_type* __s) const _NOEXCEPT + { return starts_with(basic_string_view(__s)); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(basic_string_view __s) const _NOEXCEPT + { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(value_type __c) const _NOEXCEPT + { return !empty() && _Traits::eq(back(), __c); } + + _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY + bool ends_with(const value_type* __s) const _NOEXCEPT + { return ends_with(basic_string_view(__s)); } +#endif private: - const value_type* __data; - size_type __size; + const value_type* __data; + size_type __size; }; @@ -576,28 +609,28 @@ private: template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator==(basic_string_view<_CharT, _Traits> __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) return false; - return __lhs.compare(__rhs) == 0; + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator==(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) return false; - return __lhs.compare(__rhs) == 0; + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator==(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) return false; - return __lhs.compare(__rhs) == 0; + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; } @@ -606,29 +639,29 @@ template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) - return true; - return __lhs.compare(__rhs) != 0; + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator!=(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) - return true; - return __lhs.compare(__rhs) != 0; + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator!=(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - if ( __lhs.size() != __rhs.size()) - return true; - return __lhs.compare(__rhs) != 0; + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; } @@ -637,23 +670,23 @@ template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) < 0; + return __lhs.compare(__rhs) < 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) < 0; + return __lhs.compare(__rhs) < 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) < 0; + return __lhs.compare(__rhs) < 0; } @@ -662,23 +695,23 @@ template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) > 0; + return __lhs.compare(__rhs) > 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator>(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) > 0; + return __lhs.compare(__rhs) > 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator>(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) > 0; + return __lhs.compare(__rhs) > 0; } @@ -687,23 +720,23 @@ template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) <= 0; + return __lhs.compare(__rhs) <= 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<=(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) <= 0; + return __lhs.compare(__rhs) <= 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator<=(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) <= 0; + return __lhs.compare(__rhs) <= 0; } @@ -712,24 +745,24 @@ template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) >= 0; + return __lhs.compare(__rhs) >= 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator>=(basic_string_view<_CharT, _Traits> __lhs, - typename common_type >::type __rhs) _NOEXCEPT + typename common_type >::type __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) >= 0; + return __lhs.compare(__rhs) >= 0; } template _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY bool operator>=(typename common_type >::type __lhs, - basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT + basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) >= 0; + return __lhs.compare(__rhs) >= 0; } typedef basic_string_view string_view; @@ -760,25 +793,25 @@ inline namespace literals inline namespace string_view_literals { inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - basic_string_view operator "" sv(const char *__str, size_t __len) + basic_string_view operator "" sv(const char *__str, size_t __len) _NOEXCEPT { return basic_string_view (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - basic_string_view operator "" sv(const wchar_t *__str, size_t __len) + basic_string_view operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT { return basic_string_view (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - basic_string_view operator "" sv(const char16_t *__str, size_t __len) + basic_string_view operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT { return basic_string_view (__str, __len); } inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR - basic_string_view operator "" sv(const char32_t *__str, size_t __len) + basic_string_view operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT { return basic_string_view (__str, __len); } diff --git a/contrib/libc++/include/system_error b/contrib/libc++/include/system_error index a29807db0d65..12745525f57f 100644 --- a/contrib/libc++/include/system_error +++ b/contrib/libc++/include/system_error @@ -230,6 +230,7 @@ template <> struct hash; #include #include #include <__functional_base> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/contrib/libc++/include/tuple b/contrib/libc++/include/tuple index a52b934aaca7..5e32b6dfe2ac 100644 --- a/contrib/libc++/include/tuple +++ b/contrib/libc++/include/tuple @@ -929,7 +929,7 @@ public: void swap(tuple&) _NOEXCEPT {} }; -#ifdef __cpp_deduction_guides +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES // NOTE: These are not yet standardized, but are required to simulate the // implicit deduction guide that should be generated had libc++ declared the // tuple-like constructors "correctly" @@ -1012,10 +1012,10 @@ constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { template struct __find_exactly_one_checked { - static constexpr bool __matches[] = {is_same<_T1, _Args>::value...}; + static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; static constexpr size_t value = __find_detail::__find_idx(0, __matches); - static_assert (value != __not_found, "type not found in type list" ); - static_assert(value != __ambiguous,"type occurs more than once in type list"); + static_assert(value != __not_found, "type not found in type list" ); + static_assert(value != __ambiguous, "type occurs more than once in type list"); }; template diff --git a/contrib/libc++/include/type_traits b/contrib/libc++/include/type_traits index 6c111abfd1e8..60b5dec5b839 100644 --- a/contrib/libc++/include/type_traits +++ b/contrib/libc++/include/type_traits @@ -137,25 +137,25 @@ namespace std template struct is_base_of; template struct is_convertible; - template struct is_callable; // not defined - template - struct is_callable; + template struct is_invocable; + template struct is_invocable_r; - template struct is_nothrow_callable; // not defined - template - struct is_nothrow_callable; + template struct is_nothrow_invocable; + template struct is_nothrow_invocable_r; // Alignment properties and transformations: template struct alignment_of; template struct aligned_storage; template struct aligned_union; + template struct remove_cvref; // C++20 template struct decay; template struct common_type; template struct underlying_type; template class result_of; // undefined template class result_of; + template struct invoke_result; // C++17 // const-volatile modifications: template @@ -202,6 +202,8 @@ namespace std using aligned_storage_t = typename aligned_storage::type; // C++14 template using aligned_union_t = typename aligned_union::type; // C++14 + template + using remove_cvref_t = typename remove_cvref::type; // C++20 template using decay_t = typename decay::type; // C++14 template @@ -212,8 +214,10 @@ namespace std using common_type_t = typename common_type::type; // C++14 template using underlying_type_t = typename underlying_type::type; // C++14 - template - using result_of_t = typename result_of::type; // C++14 + template + using result_of_t = typename result_of::type; // C++14 + template + using invoke_result_t = typename invoke_result::type; // C++17 template using void_t = void; // C++17 @@ -367,10 +371,14 @@ namespace std = is_base_of::value; // C++17 template constexpr bool is_convertible_v = is_convertible::value; // C++17 - template constexpr bool is_callable_v - = is_callable::value; // C++17 - template constexpr bool is_nothrow_callable_v - = is_nothrow_callable::value; // C++17 + template constexpr bool is_invocable_v + = is_invocable::value; // C++17 + template constexpr bool is_invocable_r_v + = is_invocable_r::value; // C++17 + template constexpr bool is_nothrow_invocable_v + = is_nothrow_invocable::value; // C++17 + template constexpr bool is_nothrow_invocable_r_v + = is_nothrow_invocable_r::value; // C++17 // [meta.logical], logical operator traits: template struct conjunction; // C++17 @@ -1141,6 +1149,17 @@ template struct __is_same_uncvref : is_same::type, typename __uncvref<_Up>::type> {}; +#if _LIBCPP_STD_VER > 17 +// aligned_union - same as __uncvref +template +struct remove_cvref { + using type = remove_cv_t>; +}; + +template using remove_cvref_t = typename remove_cvref<_Tp>::type; +#endif + + struct __any { __any(...); @@ -4387,6 +4406,13 @@ using __nothrow_invokable_r = _Ret, _Fp, _Args... >; +template +using __nothrow_invokable = + __nothrow_invokable_r_imp< + __invokable<_Fp, _Args...>::value, + true, void, _Fp, _Args... + >; + template struct __invoke_of : public enable_if< @@ -4409,30 +4435,48 @@ template using result_of_t = typename result_of<_Tp>::type; #if _LIBCPP_STD_VER > 14 -// is_callable +// invoke_result -template -struct _LIBCPP_TEMPLATE_VIS is_callable; +template +struct _LIBCPP_TEMPLATE_VIS invoke_result + : __invoke_of<_Fn, _Args...> +{ +}; -template -struct _LIBCPP_TEMPLATE_VIS is_callable<_Fn(_Args...), _Ret> +template +using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; + +// is_invocable + +template +struct _LIBCPP_TEMPLATE_VIS is_invocable + : integral_constant::value> {}; + +template +struct _LIBCPP_TEMPLATE_VIS is_invocable_r : integral_constant::value> {}; -template -constexpr bool is_callable_v = is_callable<_Fn, _Ret>::value; +template +constexpr bool is_invocable_v = is_invocable<_Fn, _Args...>::value; + +template +constexpr bool is_invocable_r_v = is_invocable_r<_Ret, _Fn, _Args...>::value; // is_nothrow_callable -template -struct _LIBCPP_TEMPLATE_VIS is_nothrow_callable; +template +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable + : integral_constant::value> {}; -template -struct _LIBCPP_TEMPLATE_VIS is_nothrow_callable<_Fn(_Args...), _Ret> - : integral_constant::value> -{}; +template +struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r + : integral_constant::value> {}; -template -constexpr bool is_nothrow_callable_v = is_nothrow_callable<_Fn, _Ret>::value; +template +constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value; + +template +constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value; #endif // _LIBCPP_STD_VER > 14 @@ -4638,6 +4682,11 @@ long long __convert_to_integral(long long __val) { return __val; } inline _LIBCPP_INLINE_VISIBILITY unsigned long long __convert_to_integral(unsigned long long __val) {return __val; } +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long long>::type + __convert_to_integral(_Fp __val) { return __val; } + #ifndef _LIBCPP_HAS_NO_INT128 inline _LIBCPP_INLINE_VISIBILITY __int128_t __convert_to_integral(__int128_t __val) { return __val; } @@ -4747,26 +4796,26 @@ namespace std // purposefully not versioned template constexpr typename enable_if, byte>::type & operator<<=(byte& __lhs, _Integer __shift) noexcept - { return __lhs = byte(static_cast(__lhs) << __shift); } + { return __lhs = __lhs << __shift; } template constexpr typename enable_if, byte>::type operator<< (byte __lhs, _Integer __shift) noexcept - { return byte(static_cast(__lhs) << __shift); } + { return static_cast(static_cast(static_cast(__lhs) << __shift)); } template constexpr typename enable_if, byte>::type & operator>>=(byte& __lhs, _Integer __shift) noexcept - { return __lhs = byte(static_cast(__lhs) >> __shift); } + { return __lhs = __lhs >> __shift; } template constexpr typename enable_if, byte>::type operator>> (byte __lhs, _Integer __shift) noexcept - { return byte(static_cast(__lhs) >> __shift); } + { return static_cast(static_cast(static_cast(__lhs) >> __shift)); } template constexpr typename enable_if, _Integer>::type - to_integer(byte __b) noexcept { return _Integer(__b); } + to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); } } #endif diff --git a/contrib/libc++/include/typeinfo b/contrib/libc++/include/typeinfo index 8624b349764a..7e8d3990ed98 100644 --- a/contrib/libc++/include/typeinfo +++ b/contrib/libc++/include/typeinfo @@ -69,18 +69,17 @@ public: #pragma GCC system_header #endif -#if defined(_LIBCPP_ABI_MICROSOFT) -#include -#elif defined(_LIBCPP_NONUNIQUE_RTTI_BIT) +#if !defined(_LIBCPP_ABI_MICROSOFT) +#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT) #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO #else #define _LIBCPP_HAS_UNIQUE_TYPEINFO #endif +#endif namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) class _LIBCPP_EXCEPTION_ABI type_info { type_info& operator=(const type_info&); @@ -92,7 +91,17 @@ class _LIBCPP_EXCEPTION_ABI type_info { return __builtin_strcmp(name(), __arg.name()); } #endif +#if defined(_LIBCPP_ABI_MICROSOFT) + mutable struct { + const char *__undecorated_name; + const char __decorated_name[1]; + } __data; + + int __compare(const type_info &__rhs) const _NOEXCEPT; +#endif // _LIBCPP_ABI_MICROSOFT + protected: +#if !defined(_LIBCPP_ABI_MICROSOFT) #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) // A const char* with the non-unique RTTI bit possibly set. uintptr_t __type_name; @@ -106,11 +115,27 @@ protected: _LIBCPP_INLINE_VISIBILITY explicit type_info(const char* __n) : __type_name(__n) {} #endif +#endif // ! _LIBCPP_ABI_MICROSOFT public: _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE virtual ~type_info(); +#if defined(_LIBCPP_ABI_MICROSOFT) + const char *name() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool before(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) < 0; + } + + size_t hash_code() const _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + bool operator==(const type_info& __arg) const _NOEXCEPT { + return __compare(__arg) == 0; + } +#else #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) _LIBCPP_INLINE_VISIBILITY const char* name() const _NOEXCEPT @@ -167,6 +192,7 @@ public: bool operator==(const type_info& __arg) const _NOEXCEPT { return __type_name == __arg.__type_name; } #endif +#endif // _LIBCPP_ABI_MICROSOFT _LIBCPP_INLINE_VISIBILITY bool operator!=(const type_info& __arg) const _NOEXCEPT @@ -191,8 +217,6 @@ public: virtual const char* what() const _NOEXCEPT; }; -#endif // !_LIBCPP_ABI_MICROSOFT - } // std _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/contrib/libc++/include/unordered_map b/contrib/libc++/include/unordered_map index 0546c0e2f9f2..725cb6af2759 100644 --- a/contrib/libc++/include/unordered_map +++ b/contrib/libc++/include/unordered_map @@ -885,7 +885,7 @@ public: allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -1634,7 +1634,7 @@ public: allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} diff --git a/contrib/libc++/include/unordered_set b/contrib/libc++/include/unordered_set index a14fb0004922..3ae024a45eed 100644 --- a/contrib/libc++/include/unordered_set +++ b/contrib/libc++/include/unordered_set @@ -450,7 +450,7 @@ public: allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} @@ -968,7 +968,7 @@ public: allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__table_.__node_alloc());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __table_.size() == 0;} _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __table_.size();} diff --git a/contrib/libc++/include/utility b/contrib/libc++/include/utility index 00e3cd208ecb..288c6e823c3b 100644 --- a/contrib/libc++/include/utility +++ b/contrib/libc++/include/utility @@ -545,6 +545,11 @@ private: #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template +pair(_T1, _T2) -> pair<_T1, _T2>; +#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES + template inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool diff --git a/contrib/libc++/include/variant b/contrib/libc++/include/variant index f8d3e28bae45..8a66add865ae 100644 --- a/contrib/libc++/include/variant +++ b/contrib/libc++/include/variant @@ -207,11 +207,15 @@ namespace std { #include #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + namespace std { // explicitly not using versioning namespace class _LIBCPP_EXCEPTION_ABI bad_variant_access : public exception { @@ -283,7 +287,28 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> { }; constexpr size_t variant_npos = static_cast(-1); -constexpr unsigned int __variant_npos = static_cast(-1); + +constexpr int __choose_index_type(unsigned int __num_elem) { + if (__num_elem < std::numeric_limits::max()) + return 0; + if (__num_elem < std::numeric_limits::max()) + return 1; + return 2; +} + +template +using __variant_index_t = +#ifndef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION + unsigned int; +#else + std::tuple_element_t< + __choose_index_type(_NumAlts), + std::tuple + >; +#endif + +template +constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1); namespace __find_detail { @@ -557,7 +582,7 @@ struct __variant { private: template static constexpr void __std_visit_exhaustive_visitor_check() { - static_assert(is_callable_v<_Visitor(_Values...)>, + static_assert(is_invocable_v<_Visitor, _Values...>, "`std::visit` requires the visitor to be exhaustive."); } @@ -647,9 +672,11 @@ _LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;); template <_Trait _DestructibleTrait, class... _Types> class _LIBCPP_TEMPLATE_VIS __base { public: + using __index_t = __variant_index_t; + inline _LIBCPP_INLINE_VISIBILITY explicit constexpr __base(__valueless_t tag) noexcept - : __data(tag), __index(__variant_npos) {} + : __data(tag), __index(__variant_npos<__index_t>) {} template inline _LIBCPP_INLINE_VISIBILITY @@ -665,7 +692,7 @@ public: inline _LIBCPP_INLINE_VISIBILITY constexpr size_t index() const noexcept { - return __index == __variant_npos ? variant_npos : __index; + return __index == __variant_npos<__index_t> ? variant_npos : __index; } protected: @@ -685,7 +712,7 @@ protected: static constexpr size_t __size() { return sizeof...(_Types); } __union<_DestructibleTrait, 0, _Types...> __data; - unsigned int __index; + __index_t __index; friend struct __access::__base; friend struct __visitation::__base; @@ -696,10 +723,11 @@ class _LIBCPP_TEMPLATE_VIS __destructor; #define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \ template \ - class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \ + class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \ destructible_trait> \ : public __base { \ using __base_type = __base; \ + using __index_t = typename __base_type::__index_t; \ \ public: \ using __base_type::__base_type; \ @@ -719,7 +747,7 @@ class _LIBCPP_TEMPLATE_VIS __destructor; _LIBCPP_VARIANT_DESTRUCTOR( _Trait::_TriviallyAvailable, ~__destructor() = default;, - void __destroy() noexcept { this->__index = __variant_npos; }); + void __destroy() noexcept { this->__index = __variant_npos<__index_t>; }); _LIBCPP_VARIANT_DESTRUCTOR( _Trait::_Available, @@ -733,7 +761,7 @@ _LIBCPP_VARIANT_DESTRUCTOR( }, *this); } - this->__index = __variant_npos; + this->__index = __variant_npos<__index_t>; }); _LIBCPP_VARIANT_DESTRUCTOR( @@ -1561,4 +1589,6 @@ struct _LIBCPP_TEMPLATE_VIS hash { _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_VARIANT diff --git a/contrib/libc++/include/vector b/contrib/libc++/include/vector index b2f8f092c63d..54b1e8831d5b 100644 --- a/contrib/libc++/include/vector +++ b/contrib/libc++/include/vector @@ -634,7 +634,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT {return __base::capacity();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return this->__begin_ == this->__end_;} size_type max_size() const _NOEXCEPT; @@ -2290,7 +2290,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT {return __size_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return __size_ == 0;} void reserve(size_type __n); diff --git a/contrib/libc++/include/wchar.h b/contrib/libc++/include/wchar.h index a5666e193a5b..f74fe6ddcff4 100644 --- a/contrib/libc++/include/wchar.h +++ b/contrib/libc++/include/wchar.h @@ -125,6 +125,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, # if __GLIBC_PREREQ(2, 10) # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 # endif +#elif defined(_LIBCPP_MSVCRT) +# if defined(_CRT_CONST_CORRECT_OVERLOADS) +# define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1 +# endif #endif #if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD) diff --git a/contrib/libc++/src/exception.cpp b/contrib/libc++/src/exception.cpp index 4359d126173a..3d2dcfd5b10e 100644 --- a/contrib/libc++/src/exception.cpp +++ b/contrib/libc++/src/exception.cpp @@ -31,6 +31,7 @@ #include "support/runtime/exception_glibcxx.ipp" #include "support/runtime/exception_pointer_glibcxx.ipp" #else +#include "include/atomic_support.h" #include "support/runtime/exception_fallback.ipp" #include "support/runtime/exception_pointer_unimplemented.ipp" #endif diff --git a/contrib/libc++/src/experimental/filesystem/directory_iterator.cpp b/contrib/libc++/src/experimental/filesystem/directory_iterator.cpp index 25135857d40c..a552fdc4461d 100644 --- a/contrib/libc++/src/experimental/filesystem/directory_iterator.cpp +++ b/contrib/libc++/src/experimental/filesystem/directory_iterator.cpp @@ -296,24 +296,43 @@ void recursive_directory_iterator::__advance(error_code* ec) { } bool recursive_directory_iterator::__try_recursion(error_code *ec) { - bool rec_sym = bool(options() & directory_options::follow_directory_symlink); + auto& curr_it = __imp_->__stack_.top(); - if (is_directory(curr_it.__entry_.status()) && - (!is_symlink(curr_it.__entry_.symlink_status()) || rec_sym)) - { - std::error_code m_ec; + bool skip_rec = false; + std::error_code m_ec; + if (!rec_sym) { + file_status st = curr_it.__entry_.symlink_status(m_ec); + if (m_ec && status_known(st)) + m_ec.clear(); + if (m_ec || is_symlink(st) || !is_directory(st)) + skip_rec = true; + } else { + file_status st = curr_it.__entry_.status(m_ec); + if (m_ec && status_known(st)) + m_ec.clear(); + if (m_ec || !is_directory(st)) + skip_rec = true; + } + + if (!skip_rec) { __dir_stream new_it(curr_it.__entry_.path(), __imp_->__options_, m_ec); if (new_it.good()) { __imp_->__stack_.push(_VSTD::move(new_it)); return true; } - if (m_ec) { - __imp_.reset(); - set_or_throw(m_ec, ec, - "recursive_directory_iterator::operator++()"); + } + if (m_ec) { + const bool allow_eacess = bool(__imp_->__options_ + & directory_options::skip_permission_denied); + if (m_ec.value() == EACCES && allow_eacess) { + if (ec) ec->clear(); + } else { + __imp_.reset(); + set_or_throw(m_ec, ec, + "recursive_directory_iterator::operator++()"); } } return false; diff --git a/contrib/libc++/src/experimental/filesystem/operations.cpp b/contrib/libc++/src/experimental/filesystem/operations.cpp index 641a3c53636d..1a514545cec5 100644 --- a/contrib/libc++/src/experimental/filesystem/operations.cpp +++ b/contrib/libc++/src/experimental/filesystem/operations.cpp @@ -182,20 +182,20 @@ void __copy(const path& from, const path& to, copy_options options, const bool sym_status2 = bool(options & copy_options::copy_symlinks); - std::error_code m_ec; + std::error_code m_ec1; struct ::stat f_st = {}; const file_status f = sym_status || sym_status2 - ? detail::posix_lstat(from, f_st, &m_ec) - : detail::posix_stat(from, f_st, &m_ec); - if (m_ec) - return set_or_throw(m_ec, ec, "copy", from, to); + ? detail::posix_lstat(from, f_st, &m_ec1) + : detail::posix_stat(from, f_st, &m_ec1); + if (m_ec1) + return set_or_throw(m_ec1, ec, "copy", from, to); struct ::stat t_st = {}; - const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec) - : detail::posix_stat(to, t_st, &m_ec); + const file_status t = sym_status ? detail::posix_lstat(to, t_st, &m_ec1) + : detail::posix_stat(to, t_st, &m_ec1); if (not status_known(t)) - return set_or_throw(m_ec, ec, "copy", from, to); + return set_or_throw(m_ec1, ec, "copy", from, to); if (!exists(f) || is_other(f) || is_other(t) || (is_directory(f) && is_regular_file(t)) @@ -249,9 +249,9 @@ void __copy(const path& from, const path& to, copy_options options, directory_iterator it = ec ? directory_iterator(from, *ec) : directory_iterator(from); if (ec && *ec) { return; } - std::error_code m_ec; - for (; it != directory_iterator(); it.increment(m_ec)) { - if (m_ec) return set_or_throw(m_ec, ec, "copy", from, to); + std::error_code m_ec2; + for (; it != directory_iterator(); it.increment(m_ec2)) { + if (m_ec2) return set_or_throw(m_ec2, ec, "copy", from, to); __copy(it->path(), to / it->path().filename(), options | copy_options::__in_recursive_copy, ec); if (ec && *ec) { return; } diff --git a/contrib/libc++/src/include/atomic_support.h b/contrib/libc++/src/include/atomic_support.h index 08847e630705..ccd8d78d3d71 100644 --- a/contrib/libc++/src/include/atomic_support.h +++ b/contrib/libc++/src/include/atomic_support.h @@ -16,6 +16,7 @@ #if defined(__clang__) && __has_builtin(__atomic_load_n) \ && __has_builtin(__atomic_store_n) \ && __has_builtin(__atomic_add_fetch) \ + && __has_builtin(__atomic_exchange_n) \ && __has_builtin(__atomic_compare_exchange_n) \ && defined(__ATOMIC_RELAXED) \ && defined(__ATOMIC_CONSUME) \ @@ -82,6 +83,14 @@ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a, return __atomic_add_fetch(__val, __a, __order); } +template +inline _LIBCPP_INLINE_VISIBILITY +_ValueType __libcpp_atomic_exchange(_ValueType* __target, + _ValueType __value, int __order = _AO_Seq) +{ + return __atomic_exchange_n(__target, __value, __order); +} + template inline _LIBCPP_INLINE_VISIBILITY bool __libcpp_atomic_compare_exchange(_ValueType* __val, @@ -135,6 +144,16 @@ _ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a, return *__val += __a; } +template +inline _LIBCPP_INLINE_VISIBILITY +_ValueType __libcpp_atomic_exchange(_ValueType* __target, + _ValueType __value, int __order = _AO_Seq) +{ + _ValueType old = *__target; + *__target = __value; + return old; +} + template inline _LIBCPP_INLINE_VISIBILITY bool __libcpp_atomic_compare_exchange(_ValueType* __val, diff --git a/contrib/libc++/src/include/config_elast.h b/contrib/libc++/src/include/config_elast.h index 8328978ef953..4c4d853c2a68 100644 --- a/contrib/libc++/src/include/config_elast.h +++ b/contrib/libc++/src/include/config_elast.h @@ -24,7 +24,7 @@ #define _LIBCPP_ELAST __ELASTERROR #elif defined(__Fuchsia__) // No _LIBCPP_ELAST needed on Fuchsia -#elif defined(__linux__) +#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_ELAST 4095 #elif defined(__APPLE__) // No _LIBCPP_ELAST needed on Apple diff --git a/contrib/libc++/src/include/refstring.h b/contrib/libc++/src/include/refstring.h index f0d5b4456da5..702f2b7388da 100644 --- a/contrib/libc++/src/include/refstring.h +++ b/contrib/libc++/src/include/refstring.h @@ -18,6 +18,7 @@ #include #include #endif +#include "atomic_support.h" _LIBCPP_BEGIN_NAMESPACE_STD @@ -83,7 +84,7 @@ __libcpp_refstring::__libcpp_refstring(const __libcpp_refstring &s) _NOEXCEPT : __imp_(s.__imp_) { if (__uses_refcount()) - __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1); + __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); } inline @@ -92,10 +93,10 @@ __libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _ struct _Rep_base *old_rep = rep_from_data(__imp_); __imp_ = s.__imp_; if (__uses_refcount()) - __sync_add_and_fetch(&rep_from_data(__imp_)->count, 1); + __libcpp_atomic_add(&rep_from_data(__imp_)->count, 1); if (adjust_old_count) { - if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0) + if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0) { ::operator delete(old_rep); } @@ -107,7 +108,7 @@ inline __libcpp_refstring::~__libcpp_refstring() { if (__uses_refcount()) { _Rep_base* rep = rep_from_data(__imp_); - if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) { + if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) { ::operator delete(rep); } } diff --git a/contrib/libc++/src/iostream.cpp b/contrib/libc++/src/iostream.cpp index 534b47a917d5..2b47cf25b640 100644 --- a/contrib/libc++/src/iostream.cpp +++ b/contrib/libc++/src/iostream.cpp @@ -11,19 +11,23 @@ #include "string" #include "new" +#define _str(s) #s +#define str(s) _str(s) +#define _LIBCPP_NAMESPACE_STR str(_LIBCPP_NAMESPACE) + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_STDIN _ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?cin@__1@std@@3V?$basic_istream@DU?$char_traits@D@__1@std@@@12@A") +__asm__("?cin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdinbuf ) static char __cin[sizeof(__stdinbuf )]; static mbstate_t mb_cin; _ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?wcin@__1@std@@3V?$basic_istream@_WU?$char_traits@_W@__1@std@@@12@A") +__asm__("?wcin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdinbuf ) static char __wcin[sizeof(__stdinbuf )]; @@ -33,14 +37,14 @@ static mbstate_t mb_wcin; #ifndef _LIBCPP_HAS_NO_STDOUT _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?cout@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") +__asm__("?cout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdoutbuf) static char __cout[sizeof(__stdoutbuf)]; static mbstate_t mb_cout; _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?wcout@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") +__asm__("?wcout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdoutbuf) static char __wcout[sizeof(__stdoutbuf)]; @@ -49,14 +53,14 @@ static mbstate_t mb_wcout; _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?cerr@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") +__asm__("?cerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdoutbuf) static char __cerr[sizeof(__stdoutbuf)]; static mbstate_t mb_cerr; _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?wcerr@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") +__asm__("?wcerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (__stdoutbuf) static char __wcerr[sizeof(__stdoutbuf)]; @@ -64,12 +68,12 @@ static mbstate_t mb_wcerr; _ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?clog@__1@std@@3V?$basic_ostream@DU?$char_traits@D@__1@std@@@12@A") +__asm__("?clog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; _ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)] #if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__) -__asm__("?wclog@__1@std@@3V?$basic_ostream@_WU?$char_traits@_W@__1@std@@@12@A") +__asm__("?wclog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A") #endif ; diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp index 3b4c83a09007..a6cb0e97d128 100644 --- a/contrib/libc++/src/locale.cpp +++ b/contrib/libc++/src/locale.cpp @@ -36,6 +36,7 @@ #endif #include #include +#include "include/atomic_support.h" #include "__undef_macros" // On Linux, wint_t and wchar_t have different signed-ness, and this causes @@ -667,7 +668,7 @@ locale::id::__get() void locale::id::__init() { - __id_ = __sync_add_and_fetch(&__next_id, 1); + __id_ = __libcpp_atomic_add(&__next_id, 1); } // template <> class collate_byname diff --git a/contrib/libc++/src/new.cpp b/contrib/libc++/src/new.cpp index 2b2682fa6617..e228a0d83d8e 100644 --- a/contrib/libc++/src/new.cpp +++ b/contrib/libc++/src/new.cpp @@ -12,9 +12,12 @@ #include #include "new" +#include "include/atomic_support.h" #if defined(_LIBCPP_ABI_MICROSOFT) -// nothing todo +#if defined(_LIBCPP_NO_VCRUNTIME) +#include "support/runtime/new_handler_fallback.ipp" +#endif #elif defined(LIBCXX_BUILDING_LIBCXXABI) #include #elif defined(LIBCXXRT) @@ -53,7 +56,8 @@ __throw_bad_alloc() } // std -#if !defined(__GLIBCXX__) && !defined(_LIBCPP_ABI_MICROSOFT) && \ +#if !defined(__GLIBCXX__) && \ + (!defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME)) && \ !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) // Implement all new and delete operators as weak definitions @@ -299,4 +303,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT } #endif // !_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -#endif // !__GLIBCXX__ && !_LIBCPP_ABI_MICROSOFT && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS +#endif // !__GLIBCXX__ && (!_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME) && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS diff --git a/contrib/libc++/src/random.cpp b/contrib/libc++/src/random.cpp index eb2510a48c85..4a2468368d06 100644 --- a/contrib/libc++/src/random.cpp +++ b/contrib/libc++/src/random.cpp @@ -25,7 +25,9 @@ #include #include -#if defined(_LIBCPP_USING_DEV_RANDOM) +#if defined(_LIBCPP_USING_GETENTROPY) +#include +#elif defined(_LIBCPP_USING_DEV_RANDOM) #include #include #elif defined(_LIBCPP_USING_NACL_RANDOM) @@ -35,7 +37,30 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if defined(_LIBCPP_USING_ARC4_RANDOM) +#if defined(_LIBCPP_USING_GETENTROPY) + +random_device::random_device(const string& __token) +{ + if (__token != "/dev/urandom") + __throw_system_error(ENOENT, ("random device not supported " + __token).c_str()); +} + +random_device::~random_device() +{ +} + +unsigned +random_device::operator()() +{ + unsigned r; + size_t n = sizeof(r); + int err = getentropy(&r, n); + if (err) + __throw_system_error(errno, "random_device getentropy failed"); + return r; +} + +#elif defined(_LIBCPP_USING_ARC4_RANDOM) random_device::random_device(const string& __token) { diff --git a/contrib/libc++/src/strstream.cpp b/contrib/libc++/src/strstream.cpp index 01523cf45462..8b8521f76af1 100644 --- a/contrib/libc++/src/strstream.cpp +++ b/contrib/libc++/src/strstream.cpp @@ -186,7 +186,7 @@ strstreambuf::overflow(int_type __c) } setg(buf, buf + ninp, buf + einp); setp(buf + einp, buf + new_size); - pbump(static_cast(nout)); + __pbump(nout); __strmode_ |= __allocated; } *pptr() = static_cast(__c); @@ -282,7 +282,7 @@ strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmod // min(pbase, newpos), newpos, epptr() __off = epptr() - newpos; setp(min(pbase(), newpos), epptr()); - pbump(static_cast((epptr() - pbase()) - __off)); + __pbump((epptr() - pbase()) - __off); } __p = newoff; } @@ -312,7 +312,7 @@ strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which) // min(pbase, newpos), newpos, epptr() off_type temp = epptr() - newpos; setp(min(pbase(), newpos), epptr()); - pbump(static_cast((epptr() - pbase()) - temp)); + __pbump((epptr() - pbase()) - temp); } __p = newoff; } diff --git a/contrib/libc++/src/support/runtime/exception_fallback.ipp b/contrib/libc++/src/support/runtime/exception_fallback.ipp index 69c06a9ce3a8..664e7f48c09a 100644 --- a/contrib/libc++/src/support/runtime/exception_fallback.ipp +++ b/contrib/libc++/src/support/runtime/exception_fallback.ipp @@ -20,13 +20,13 @@ _LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler; unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT { - return __sync_lock_test_and_set(&__unexpected_handler, func); + return __libcpp_atomic_exchange(&__unexpected_handler, func); } unexpected_handler get_unexpected() _NOEXCEPT { - return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); + return __libcpp_atomic_load(&__unexpected_handler); } @@ -41,14 +41,13 @@ void unexpected() terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { - return __sync_lock_test_and_set(&__terminate_handler, func); + return __libcpp_atomic_exchange(&__terminate_handler, func); } terminate_handler get_terminate() _NOEXCEPT { - return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); - + return __libcpp_atomic_load(&__terminate_handler); } #ifndef __EMSCRIPTEN__ // We provide this in JS diff --git a/contrib/libc++/src/support/runtime/exception_msvc.ipp b/contrib/libc++/src/support/runtime/exception_msvc.ipp index 950ec0cebfe7..d5bf5b726ea5 100644 --- a/contrib/libc++/src/support/runtime/exception_msvc.ipp +++ b/contrib/libc++/src/support/runtime/exception_msvc.ipp @@ -14,12 +14,35 @@ #include #include -#include -#include + +#if !defined(_ACRTIMP) +#define _ACRTIMP __declspec(dllimport) +#endif + +#if !defined(_VCRTIMP) +#define _VCRTIMP __declspec(dllimport) +#endif + +#if !defined(__CRTDECL) +#define __CRTDECL __cdecl +#endif + +extern "C" { +typedef void (__CRTDECL* terminate_handler)(); +_ACRTIMP terminate_handler __cdecl set_terminate( + terminate_handler _NewTerminateHandler) throw(); +_ACRTIMP terminate_handler __cdecl _get_terminate(); + +typedef void (__CRTDECL* unexpected_handler)(); +_VCRTIMP unexpected_handler __cdecl set_unexpected( + unexpected_handler _NewUnexpectedHandler) throw(); +_VCRTIMP unexpected_handler __cdecl _get_unexpected(); + +_VCRTIMP int __cdecl __uncaught_exceptions(); +} namespace std { -// libcxxrt provides implementations of these functions itself. unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT { return ::set_unexpected(func); @@ -86,4 +109,82 @@ bad_array_length::what() const _NOEXCEPT return "bad_array_length"; } +bad_cast::bad_cast() _NOEXCEPT +{ +} + +bad_cast::~bad_cast() _NOEXCEPT +{ +} + +const char * +bad_cast::what() const _NOEXCEPT +{ + return "std::bad_cast"; +} + +bad_typeid::bad_typeid() _NOEXCEPT +{ +} + +bad_typeid::~bad_typeid() _NOEXCEPT +{ +} + +const char * +bad_typeid::what() const _NOEXCEPT +{ + return "std::bad_typeid"; +} + +#if defined(_LIBCPP_NO_VCRUNTIME) +exception::~exception() _NOEXCEPT +{ +} + +const char* exception::what() const _NOEXCEPT +{ + return "std::exception"; +} + + +bad_exception::~bad_exception() _NOEXCEPT +{ +} + +const char* bad_exception::what() const _NOEXCEPT +{ + return "std::bad_exception"; +} + + +bad_alloc::bad_alloc() _NOEXCEPT +{ +} + +bad_alloc::~bad_alloc() _NOEXCEPT +{ +} + +const char* +bad_alloc::what() const _NOEXCEPT +{ + return "std::bad_alloc"; +} + +bad_array_new_length::bad_array_new_length() _NOEXCEPT +{ +} + +bad_array_new_length::~bad_array_new_length() _NOEXCEPT +{ +} + +const char* +bad_array_new_length::what() const _NOEXCEPT +{ + return "bad_array_new_length"; +} +#endif // _LIBCPP_NO_VCRUNTIME + } // namespace std diff --git a/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp b/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp index eab5d30a9487..5ca7519a6001 100644 --- a/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp +++ b/contrib/libc++/src/support/runtime/exception_pointer_msvc.ipp @@ -10,26 +10,32 @@ #include #include -#include // for _CRTIMP2_PURE -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(_Out_ void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(_Inout_ void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(_Out_ void*, - _In_ const void*); +#if !defined(_CRTIMP2_PURE) +#define _CRTIMP2_PURE __declspec(dllimport) +#endif + +#if !defined(__CLRCALL_PURE_OR_CDECL) +#define __CLRCALL_PURE_OR_CDECL __cdecl +#endif + +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCreate(void*); +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrDestroy(void*); +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrCopy(void*, + const void*); _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrAssign(_Inout_ void*, _In_ const void*); +__ExceptionPtrAssign(void*, const void*); _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL -__ExceptionPtrCompare(_In_ const void*, _In_ const void*); +__ExceptionPtrCompare(const void*, const void*); _CRTIMP2_PURE bool __CLRCALL_PURE_OR_CDECL -__ExceptionPtrToBool(_In_ const void*); -_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(_Inout_ void*, - _Inout_ void*); +__ExceptionPtrToBool(const void*); +_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL __ExceptionPtrSwap(void*, void*); _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrCurrentException(_Out_ void*); +__ExceptionPtrCurrentException(void*); [[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrRethrow(_In_ const void*); +__ExceptionPtrRethrow(const void*); _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL -__ExceptionPtrCopyException(_Inout_ void*, _In_ const void*, _In_ const void*); +__ExceptionPtrCopyException(void*, const void*, const void*); namespace std { diff --git a/contrib/libc++/src/support/runtime/new_handler_fallback.ipp b/contrib/libc++/src/support/runtime/new_handler_fallback.ipp index b7092d542d97..ec3f52354ca8 100644 --- a/contrib/libc++/src/support/runtime/new_handler_fallback.ipp +++ b/contrib/libc++/src/support/runtime/new_handler_fallback.ipp @@ -15,13 +15,13 @@ _LIBCPP_SAFE_STATIC static std::new_handler __new_handler; new_handler set_new_handler(new_handler handler) _NOEXCEPT { - return __sync_lock_test_and_set(&__new_handler, handler); + return __libcpp_atomic_exchange(&__new_handler, handler); } new_handler get_new_handler() _NOEXCEPT { - return __sync_fetch_and_add(&__new_handler, nullptr); + return __libcpp_atomic_load(&__new_handler); } } // namespace std diff --git a/contrib/libc++/src/system_error.cpp b/contrib/libc++/src/system_error.cpp index 17f2c9a5ba79..72623ea6bc81 100644 --- a/contrib/libc++/src/system_error.cpp +++ b/contrib/libc++/src/system_error.cpp @@ -73,39 +73,59 @@ string do_strerror_r(int ev) { std::snprintf(buffer, strerror_buff_size, "unknown error %d", ev); return string(buffer); } -#elif defined(__linux__) && !defined(_LIBCPP_HAS_MUSL_LIBC) && \ - (!defined(__ANDROID__) || __ANDROID_API__ >= 23) -// GNU Extended version -string do_strerror_r(int ev) { - char buffer[strerror_buff_size]; - char* ret = ::strerror_r(ev, buffer, strerror_buff_size); - return string(ret); -} #else -// POSIX version + +// Only one of the two following functions will be used, depending on +// the return type of strerror_r: + +// For the GNU variant, a char* return value: +__attribute__((unused)) const char * +handle_strerror_r_return(char *strerror_return, char *buffer) { + // GNU always returns a string pointer in its return value. The + // string might point to either the input buffer, or a static + // buffer, but we don't care which. + return strerror_return; +} + +// For the POSIX variant: an int return value. +__attribute__((unused)) const char * +handle_strerror_r_return(int strerror_return, char *buffer) { + // The POSIX variant either: + // - fills in the provided buffer and returns 0 + // - returns a positive error value, or + // - returns -1 and fills in errno with an error value. + if (strerror_return == 0) + return buffer; + + // Only handle EINVAL. Other errors abort. + int new_errno = strerror_return == -1 ? errno : strerror_return; + if (new_errno == EINVAL) + return ""; + + _LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerror_r"); + // FIXME maybe? 'strerror_buff_size' is likely to exceed the + // maximum error size so ERANGE shouldn't be returned. + std::abort(); +} + +// This function handles both GNU and POSIX variants, dispatching to +// one of the two above functions. string do_strerror_r(int ev) { char buffer[strerror_buff_size]; + // Preserve errno around the call. (The C++ standard requires that + // system_error functions not modify errno). const int old_errno = errno; - int ret; - if ((ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) { - // If `ret == -1` then the error is specified using `errno`, otherwise - // `ret` represents the error. - const int new_errno = ret == -1 ? errno : ret; - errno = old_errno; - if (new_errno == EINVAL) { - std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev); - return string(buffer); - } else { - _LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerr_r"); - // FIXME maybe? 'strerror_buff_size' is likely to exceed the - // maximum error size so ERANGE shouldn't be returned. - std::abort(); - } + const char *error_message = handle_strerror_r_return( + ::strerror_r(ev, buffer, strerror_buff_size), buffer); + // If we didn't get any message, print one now. + if (!error_message[0]) { + std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev); + error_message = buffer; } - return string(buffer); + errno = old_errno; + return string(error_message); } #endif - } // end namespace #endif diff --git a/contrib/libc++/src/typeinfo.cpp b/contrib/libc++/src/typeinfo.cpp index 02778f368704..0cb193b77d9e 100644 --- a/contrib/libc++/src/typeinfo.cpp +++ b/contrib/libc++/src/typeinfo.cpp @@ -9,11 +9,48 @@ #include "typeinfo" +#if defined(_LIBCPP_ABI_MICROSOFT) +#include + +int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT { + if (&__data == &__rhs.__data) + return 0; + return strcmp(&__data.__decorated_name[1], &__rhs.__data.__decorated_name[1]); +} + +const char *std::type_info::name() const _NOEXCEPT { + // TODO(compnerd) cache demangled &__data.__decorated_name[1] + return &__data.__decorated_name[1]; +} + +size_t std::type_info::hash_code() const _NOEXCEPT { +#if defined(_WIN64) + constexpr size_t fnv_offset_basis = 14695981039346656037ull; + constexpr size_t fnv_prime = 10995116282110ull; +#else + constexpr size_t fnv_offset_basis = 2166136261ull; + constexpr size_t fnv_prime = 16777619ull; +#endif + + size_t value = fnv_offset_basis; + for (const char* c = &__data.__decorated_name[1]; *c; ++c) { + value ^= static_cast(static_cast(*c)); + value *= fnv_prime; + } + +#if defined(_WIN64) + value ^= value >> 32; +#endif + + return value; +} +#endif // _LIBCPP_ABI_MICROSOFT + // FIXME: Remove __APPLE__ default here once buildit is gone. -#if (!defined(_LIBCPP_ABI_MICROSOFT) && !defined(LIBCXX_BUILDING_LIBCXXABI) && \ - !defined(LIBCXXRT) && !defined(__GLIBCXX__) && \ - !defined(__APPLE__)) || \ - defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) // FIXME: remove this configuration. +// FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration. +#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) && \ + !defined(__GLIBCXX__) && !defined(__APPLE__)) || \ + defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) std::type_info::~type_info() { }