diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -284,6 +284,7 @@ // TODO(hardening): Don't enable uncategorized assertions in the hardened mode. # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) // Disabled checks. +# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) @@ -294,6 +295,7 @@ // All checks enabled. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) +# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) @@ -305,6 +307,7 @@ // All checks disabled. # define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) +# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -1109,7 +1109,7 @@ local_iterator begin(size_type __n) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n < bucket_count(), + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < bucket_count(), "unordered container::begin(n) called with n >= bucket_count()"); return local_iterator(__bucket_list_[__n], __n, bucket_count()); } @@ -1118,7 +1118,7 @@ local_iterator end(size_type __n) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n < bucket_count(), + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < bucket_count(), "unordered container::end(n) called with n >= bucket_count()"); return local_iterator(nullptr, __n, bucket_count()); } @@ -1127,7 +1127,7 @@ const_local_iterator cbegin(size_type __n) const { - _LIBCPP_ASSERT_UNCATEGORIZED(__n < bucket_count(), + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < bucket_count(), "unordered container::cbegin(n) called with n >= bucket_count()"); return const_local_iterator(__bucket_list_[__n], __n, bucket_count()); } @@ -1136,7 +1136,7 @@ const_local_iterator cend(size_type __n) const { - _LIBCPP_ASSERT_UNCATEGORIZED(__n < bucket_count(), + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < bucket_count(), "unordered container::cend(n) called with n >= bucket_count()"); return const_local_iterator(nullptr, __n, bucket_count()); } @@ -2223,8 +2223,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p) { __next_pointer __np = __p.__node_; - _LIBCPP_ASSERT_UNCATEGORIZED(__p != end(), - "unordered container erase(iterator) called with a non-dereferenceable iterator"); + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p != end(), + "unordered container::erase(iterator) called with a non-dereferenceable iterator"); iterator __r(__np); ++__r; remove(__p); @@ -2423,10 +2423,10 @@ _NOEXCEPT_(__is_nothrow_swappable::value && __is_nothrow_swappable::value) #endif { - _LIBCPP_ASSERT_UNCATEGORIZED(__node_traits::propagate_on_container_swap::value || - this->__node_alloc() == __u.__node_alloc(), - "list::swap: Either propagate_on_container_swap must be true" - " or the allocators must compare equal"); + _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__node_traits::propagate_on_container_swap::value || + this->__node_alloc() == __u.__node_alloc(), + "unordered container::swap: Either propagate_on_container_swap " + "must be true or the allocators must compare equal"); { __node_pointer_pointer __npp = __bucket_list_.release(); __bucket_list_.reset(__u.__bucket_list_.release()); @@ -2451,7 +2451,7 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const { - _LIBCPP_ASSERT_UNCATEGORIZED(__n < bucket_count(), + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < bucket_count(), "unordered container::bucket_size(n) called with n >= bucket_count()"); __next_pointer __np = __bucket_list_[__n]; size_type __bc = bucket_count(); diff --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h --- a/libcxx/include/__memory/construct_at.h +++ b/libcxx/include/__memory/construct_at.h @@ -37,7 +37,7 @@ template ()) _Tp(std::declval<_Args>()...))> _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) { - _LIBCPP_ASSERT_UNCATEGORIZED(__location != nullptr, "null pointer given to construct_at"); + _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"); return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); } @@ -48,7 +48,7 @@ #if _LIBCPP_STD_VER >= 20 return std::construct_at(__location, std::forward<_Args>(__args)...); #else - return _LIBCPP_ASSERT_UNCATEGORIZED(__location != nullptr, "null pointer given to construct_at"), + return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"), ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); #endif } @@ -65,7 +65,7 @@ template ::value, int>::type = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT_UNCATEGORIZED(__loc != nullptr, "null pointer given to destroy_at"); + _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at"); __loc->~_Tp(); } @@ -73,7 +73,7 @@ template ::value, int>::type = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __destroy_at(_Tp* __loc) { - _LIBCPP_ASSERT_UNCATEGORIZED(__loc != nullptr, "null pointer given to destroy_at"); + _LIBCPP_ASSERT_NON_NULL(__loc != nullptr, "null pointer given to destroy_at"); std::__destroy(std::begin(*__loc), std::end(*__loc)); } #endif diff --git a/libcxx/include/__node_handle b/libcxx/include/__node_handle --- a/libcxx/include/__node_handle +++ b/libcxx/include/__node_handle @@ -149,7 +149,7 @@ _LIBCPP_INLINE_VISIBILITY __basic_node_handle& operator=(__basic_node_handle&& __other) { - _LIBCPP_ASSERT_UNCATEGORIZED( + _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( __alloc_ == _VSTD::nullopt || __alloc_traits::propagate_on_container_move_assignment::value || __alloc_ == __other.__alloc_, diff --git a/libcxx/include/__stop_token/intrusive_list_view.h b/libcxx/include/__stop_token/intrusive_list_view.h --- a/libcxx/include/__stop_token/intrusive_list_view.h +++ b/libcxx/include/__stop_token/intrusive_list_view.h @@ -67,7 +67,7 @@ __node->__next_->__prev_ = __node->__prev_; } } else { - _LIBCPP_ASSERT_UNCATEGORIZED(__node == __head_, "Node to be removed has no prev node, so it has to be the head"); + _LIBCPP_ASSERT_INTERNAL(__node == __head_, "Node to be removed has no prev node, so it has to be the head"); __pop_front(); } } diff --git a/libcxx/include/__string/char_traits.h b/libcxx/include/__string/char_traits.h --- a/libcxx/include/__string/char_traits.h +++ b/libcxx/include/__string/char_traits.h @@ -142,7 +142,7 @@ static _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) { if (!__libcpp_is_constant_evaluated()) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); } char_type* __r = __s1; for (; __n; --__n, ++__s1, ++__s2) @@ -236,7 +236,7 @@ static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { if (!__libcpp_is_constant_evaluated()) - _LIBCPP_ASSERT_UNCATEGORIZED(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); std::copy_n(__s2, __n, __s1); return __s1; } @@ -307,7 +307,7 @@ static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { if (!__libcpp_is_constant_evaluated()) - _LIBCPP_ASSERT_UNCATEGORIZED(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); std::copy_n(__s2, __n, __s1); return __s1; } @@ -371,7 +371,7 @@ static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { if (!__libcpp_is_constant_evaluated()) - _LIBCPP_ASSERT_UNCATEGORIZED(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); std::copy_n(__s2, __n, __s1); return __s1; } @@ -455,7 +455,7 @@ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT { if (!__libcpp_is_constant_evaluated()) - _LIBCPP_ASSERT_UNCATEGORIZED(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range"); std::copy_n(__s2, __n, __s1); return __s1; } diff --git a/libcxx/include/__tree b/libcxx/include/__tree --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -168,7 +168,7 @@ _NodePtr __tree_min(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "Root node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Root node shouldn't be null"); while (__x->__left_ != nullptr) __x = __x->__left_; return __x; @@ -180,7 +180,7 @@ _NodePtr __tree_max(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "Root node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Root node shouldn't be null"); while (__x->__right_ != nullptr) __x = __x->__right_; return __x; @@ -191,7 +191,7 @@ _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_next(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__right_ != nullptr) return _VSTD::__tree_min(__x->__right_); while (!_VSTD::__tree_is_left_child(__x)) @@ -204,7 +204,7 @@ _EndNodePtr __tree_next_iter(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__right_ != nullptr) return static_cast<_EndNodePtr>(_VSTD::__tree_min(__x->__right_)); while (!_VSTD::__tree_is_left_child(__x)) @@ -219,7 +219,7 @@ _NodePtr __tree_prev_iter(_EndNodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); if (__x->__left_ != nullptr) return _VSTD::__tree_max(__x->__left_); _NodePtr __xx = static_cast<_NodePtr>(__x); @@ -233,7 +233,7 @@ _LIBCPP_HIDE_FROM_ABI _NodePtr __tree_leaf(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); while (true) { if (__x->__left_ != nullptr) @@ -257,8 +257,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree_left_rotate(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); - _LIBCPP_ASSERT_UNCATEGORIZED(__x->__right_ != nullptr, "node should have a right child"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x->__right_ != nullptr, "node should have a right child"); _NodePtr __y = __x->__right_; __x->__right_ = __y->__left_; if (__x->__right_ != nullptr) @@ -278,8 +278,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree_right_rotate(_NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "node shouldn't be null"); - _LIBCPP_ASSERT_UNCATEGORIZED(__x->__left_ != nullptr, "node should have a left child"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "node shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x->__left_ != nullptr, "node should have a left child"); _NodePtr __y = __x->__left_; __x->__left_ = __y->__right_; if (__x->__left_ != nullptr) @@ -304,8 +304,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__root != nullptr, "Root of the tree shouldn't be null"); - _LIBCPP_ASSERT_UNCATEGORIZED(__x != nullptr, "Can't attach null node to a leaf"); + _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root of the tree shouldn't be null"); + _LIBCPP_ASSERT_INTERNAL(__x != nullptr, "Can't attach null node to a leaf"); __x->__is_black_ = __x == __root; while (__x != __root && !__x->__parent_unsafe()->__is_black_) { @@ -374,8 +374,8 @@ _LIBCPP_HIDE_FROM_ABI void __tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__root != nullptr, "Root node should not be null"); - _LIBCPP_ASSERT_UNCATEGORIZED(__z != nullptr, "The node to remove should not be null"); + _LIBCPP_ASSERT_INTERNAL(__root != nullptr, "Root node should not be null"); + _LIBCPP_ASSERT_INTERNAL(__z != nullptr, "The node to remove should not be null"); _LIBCPP_ASSERT_INTERNAL(std::__tree_invariant(__root), "The tree invariants should hold"); // __z will be removed from the tree. Client still needs to destruct/deallocate it // __y is either __z, or if __z has two children, __tree_next(__z). diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -936,14 +936,14 @@ template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "basic_string(const char*) detected nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); } template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); } @@ -953,15 +953,15 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) : __r_(__default_init_tag(), __default_init_tag()) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) : __r_(__default_init_tag(), __a) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, - "basic_string(const char*, n, allocator) detected nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, + "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); } @@ -2438,7 +2438,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::assign received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::assign received nullptr"); return (__builtin_constant_p(__n) && __fits_in_sso(__n)) ? __assign_short(__s, __n) : __assign_external(__s, __n); @@ -2643,7 +2643,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::assign received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::assign received nullptr"); return __builtin_constant_p(*__s) ? (__fits_in_sso(traits_type::length(__s)) ? __assign_short(__s, traits_type::length(__s)) @@ -2657,7 +2657,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::append received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::append received nullptr"); size_type __cap = capacity(); size_type __sz = size(); if (__cap - __sz >= __n) @@ -2812,7 +2812,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::append received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::append received nullptr"); return append(__s, traits_type::length(__s)); } @@ -2823,7 +2823,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::insert received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::insert received nullptr"); size_type __sz = size(); if (__pos > __sz) __throw_out_of_range(); @@ -2960,7 +2960,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::insert received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::insert received nullptr"); return insert(__pos, __s, traits_type::length(__s)); } @@ -2999,7 +2999,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { - _LIBCPP_ASSERT_UNCATEGORIZED(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); size_type __sz = size(); if (__pos > __sz) __throw_out_of_range(); @@ -3115,7 +3115,7 @@ basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::replace received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::replace received nullptr"); return replace(__pos, __n1, __s, traits_type::length(__s)); } @@ -3395,7 +3395,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find(): received nullptr"); return std::__str_find (data(), size(), __s, __pos, __n); } @@ -3427,7 +3427,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find(): received nullptr"); return std::__str_find (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3451,7 +3451,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); return std::__str_rfind (data(), size(), __s, __pos, __n); } @@ -3483,7 +3483,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::rfind(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::rfind(): received nullptr"); return std::__str_rfind (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3507,7 +3507,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); return std::__str_find_first_of (data(), size(), __s, __pos, __n); } @@ -3539,7 +3539,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_first_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_of(): received nullptr"); return std::__str_find_first_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3562,7 +3562,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); return std::__str_find_last_of (data(), size(), __s, __pos, __n); } @@ -3594,7 +3594,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_last_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_of(): received nullptr"); return std::__str_find_last_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3617,7 +3617,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); return std::__str_find_first_not_of (data(), size(), __s, __pos, __n); } @@ -3649,7 +3649,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_first_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_first_not_of(): received nullptr"); return std::__str_find_first_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3673,7 +3673,7 @@ size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); return std::__str_find_last_not_of (data(), size(), __s, __pos, __n); } @@ -3705,7 +3705,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, size_type __pos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_last_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::find_last_not_of(): received nullptr"); return std::__str_find_last_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -3757,7 +3757,7 @@ const value_type* __s, size_type __n2) const { - _LIBCPP_ASSERT_UNCATEGORIZED(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); size_type __sz = size(); if (__pos1 > __sz || __n2 == npos) __throw_out_of_range(); @@ -3822,7 +3822,7 @@ int basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::compare(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr"); return compare(0, npos, __s, traits_type::length(__s)); } @@ -3833,7 +3833,7 @@ size_type __n1, const value_type* __s) const { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::compare(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string::compare(): received nullptr"); return compare(__pos1, __n1, __s, traits_type::length(__s)); } @@ -3915,7 +3915,7 @@ const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { typedef basic_string<_CharT, _Traits, _Allocator> _String; - _LIBCPP_ASSERT_UNCATEGORIZED(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); size_t __lhs_len = _Traits::length(__lhs); if (__lhs_len != __rhs.size()) return false; return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; @@ -3932,7 +3932,7 @@ return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); #else typedef basic_string<_CharT, _Traits, _Allocator> _String; - _LIBCPP_ASSERT_UNCATEGORIZED(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); size_t __rhs_len = _Traits::length(__rhs); if (__rhs_len != __lhs.size()) return false; return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -261,8 +261,8 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT { // This needs to be a single statement for C++11 constexpr - return _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, - "null pointer passed to non-null argument of char_traits<...>::length"), + return _LIBCPP_ASSERT_NON_NULL(__s != nullptr, + "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s); } @@ -312,8 +312,8 @@ _LIBCPP_ASSERT_UNCATEGORIZED( __len <= static_cast(numeric_limits::max()), "string_view::string_view(_CharT *, size_t): length does not fit in difference_type"); - _LIBCPP_ASSERT_UNCATEGORIZED(__len == 0 || __s != nullptr, - "string_view::string_view(_CharT *, size_t): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__len == 0 || __s != nullptr, + "string_view::string_view(_CharT *, size_t): received nullptr"); #endif } @@ -522,7 +522,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); return std::__str_find (data(), size(), __s.data(), __pos, __s.size()); } @@ -537,7 +537,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); return std::__str_find (data(), size(), __s, __pos, __n); } @@ -545,7 +545,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr"); return std::__str_find (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -554,7 +554,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); return std::__str_rfind (data(), size(), __s.data(), __pos, __s.size()); } @@ -569,7 +569,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); return std::__str_rfind (data(), size(), __s, __pos, __n); } @@ -577,7 +577,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::rfind(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr"); return std::__str_rfind (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -586,8 +586,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, - "string_view::find_first_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, + "string_view::find_first_of(): received nullptr"); return std::__str_find_first_of (data(), size(), __s.data(), __pos, __s.size()); } @@ -599,7 +599,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); return std::__str_find_first_of (data(), size(), __s, __pos, __n); } @@ -607,7 +607,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_first_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr"); return std::__str_find_first_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -616,8 +616,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, - "string_view::find_last_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, + "string_view::find_last_of(): received nullptr"); return std::__str_find_last_of (data(), size(), __s.data(), __pos, __s.size()); } @@ -629,7 +629,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); return std::__str_find_last_of (data(), size(), __s, __pos, __n); } @@ -637,7 +637,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_last_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr"); return std::__str_find_last_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -646,8 +646,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, - "string_view::find_first_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, + "string_view::find_first_not_of(): received nullptr"); return std::__str_find_first_not_of (data(), size(), __s.data(), __pos, __s.size()); } @@ -662,7 +662,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); return std::__str_find_first_not_of (data(), size(), __s, __pos, __n); } @@ -670,7 +670,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); return std::__str_find_first_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } @@ -679,8 +679,8 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, - "string_view::find_last_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, + "string_view::find_last_not_of(): received nullptr"); return std::__str_find_last_not_of (data(), size(), __s.data(), __pos, __s.size()); } @@ -695,7 +695,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); return std::__str_find_last_not_of (data(), size(), __s, __pos, __n); } @@ -703,7 +703,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT { - _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); + _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); return std::__str_find_last_not_of (data(), size(), __s, __pos, traits_type::length(__s)); } diff --git a/libcxx/src/string.cpp b/libcxx/src/string.cpp --- a/libcxx/src/string.cpp +++ b/libcxx/src/string.cpp @@ -346,7 +346,7 @@ constexpr size_t bufsize = numeric_limits::digits10 + 2; // +1 for minus, +1 for digits10 char buf[bufsize]; const auto res = to_chars(buf, buf + bufsize, v); - _LIBCPP_ASSERT_UNCATEGORIZED(res.ec == errc(), "bufsize must be large enough to accomodate the value"); + _LIBCPP_ASSERT_INTERNAL(res.ec == errc(), "bufsize must be large enough to accomodate the value"); return S(buf, res.ptr); }