diff --git a/libcxx/include/__debug b/libcxx/include/__debug --- a/libcxx/include/__debug +++ b/libcxx/include/__debug @@ -226,6 +226,37 @@ #endif } +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_erase_c(_Tp* __c) { +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) + __get_db()->__erase_c(__c); +#else + (void)(__c); +#endif +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_swap(_Tp* __lhs, _Tp* __rhs) { +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) + __get_db()->swap(__lhs, __rhs); +#else + (void)(__lhs); + (void)(__rhs); +#endif +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 inline void __debug_db_invalidate_all(_Tp* __c) { +#if _LIBCPP_DEBUG_LEVEL == 2 + if (!__libcpp_is_constant_evaluated()) + __get_db()->__invalidate_all(__c); +#else + (void)(__c); +#endif +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___DEBUG diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -1512,9 +1512,7 @@ #endif __deallocate_node(__p1_.first().__next_); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__erase_c(this); -#endif + std::__debug_db_erase_c(this); } template @@ -1617,9 +1615,7 @@ __u.__p1_.first().__next_ = nullptr; __u.size() = 0; } -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -2321,9 +2317,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc) { -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); __pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc(); __bucket_list_.reset(__nbc > 0 ? __pointer_alloc_traits::allocate(__npa, __nbc) : nullptr); @@ -2729,9 +2723,7 @@ if (__u.size() > 0) __u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = __u.__p1_.first().__ptr(); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -682,9 +682,7 @@ _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators() { -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); } }; @@ -727,9 +725,7 @@ template __list_imp<_Tp, _Alloc>::~__list_imp() { clear(); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__erase_c(this); -#endif + std::__debug_db_erase_c(this); } template @@ -1373,9 +1369,7 @@ insert(__e, __f, __l); else erase(__i, __e); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); } template @@ -1390,9 +1384,7 @@ insert(__e, __n, __x); else erase(__i, __e); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); } template diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1865,10 +1865,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() { -#if _LIBCPP_DEBUG_LEVEL == 2 - if (!__libcpp_is_constant_evaluated()) - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); } template @@ -2077,10 +2074,8 @@ { __str.__default_init(); std::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - if (!__libcpp_is_constant_evaluated() && __is_long()) - __get_db()->swap(this, &__str); -#endif + if (__is_long()) + std::__debug_db_swap(this, &__str); } template @@ -2101,10 +2096,8 @@ __str.__default_init(); } std::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - if (!__libcpp_is_constant_evaluated() && __is_long()) - __get_db()->swap(this, &__str); -#endif + if (__is_long()) + std::__debug_db_swap(this, &__str); } #endif // _LIBCPP_CXX03_LANG @@ -2342,10 +2335,7 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string<_CharT, _Traits, _Allocator>::~basic_string() { -#if _LIBCPP_DEBUG_LEVEL == 2 - if (!__libcpp_is_constant_evaluated()) - __get_db()->__erase_c(this); -#endif + std::__debug_db_erase_c(this); if (__is_long()) __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); } @@ -3600,15 +3590,12 @@ __is_nothrow_swappable::value) #endif { -#if _LIBCPP_DEBUG_LEVEL == 2 - if (!__libcpp_is_constant_evaluated()) { - if (!__is_long()) - __get_db()->__invalidate_all(this); - if (!__str.__is_long()) - __get_db()->__invalidate_all(&__str); - __get_db()->swap(this, &__str); - } -#endif + if (!__is_long()) + std::__debug_db_invalidate_all(this); + if (!__str.__is_long()) + std::__debug_db_invalidate_all(&__str); + std::__debug_db_swap(this, &__str); + _LIBCPP_ASSERT( __alloc_traits::propagate_on_container_swap::value || __alloc_traits::is_always_equal::value || diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -1693,9 +1693,7 @@ : __table_(_VSTD::move(__u.__table_)) { _VSTD::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -1712,10 +1710,8 @@ __u.__table_.remove((__i++).__i_)->__value_.__move()); } } -#if _LIBCPP_DEBUG_LEVEL == 2 else - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -2469,9 +2465,7 @@ : __table_(_VSTD::move(__u.__table_)) { _VSTD::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -2489,10 +2483,8 @@ __u.__table_.remove((__i++).__i_)->__value_.__move()); } } -#if _LIBCPP_DEBUG_LEVEL == 2 else - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -1006,9 +1006,7 @@ : __table_(_VSTD::move(__u.__table_)) { _VSTD::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -1023,10 +1021,8 @@ while (__u.size() != 0) __table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_)); } -#if _LIBCPP_DEBUG_LEVEL == 2 else - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -1647,9 +1643,7 @@ : __table_(_VSTD::move(__u.__table_)) { _VSTD::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template @@ -1664,10 +1658,8 @@ while (__u.size() != 0) __table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_)); } -#if _LIBCPP_DEBUG_LEVEL == 2 else - __get_db()->swap(this, _VSTD::addressof(__u)); -#endif + std::__debug_db_swap(this, std::addressof(__u)); } template diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -413,9 +413,7 @@ ~vector() { __annotate_delete(); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__erase_c(this); -#endif + std::__debug_db_erase_c(this); if (this->__begin_ != nullptr) { @@ -1206,9 +1204,7 @@ : __end_cap_(nullptr, _VSTD::move(__x.__alloc())) { _VSTD::__debug_db_insert_c(this); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__x)); -#endif + std::__debug_db_swap(this, std::addressof(__x)); this->__begin_ = __x.__begin_; this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); @@ -1227,9 +1223,7 @@ this->__end_ = __x.__end_; this->__end_cap() = __x.__end_cap(); __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__x)); -#endif + std::__debug_db_swap(this, std::addressof(__x)); } else { @@ -1299,9 +1293,7 @@ this->__end_ = __c.__end_; this->__end_cap() = __c.__end_cap(); __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__c)); -#endif + std::__debug_db_swap(this, std::addressof(__c)); } #endif // !_LIBCPP_CXX03_LANG @@ -1946,9 +1938,7 @@ _VSTD::swap(this->__end_cap(), __x.__end_cap()); _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), integral_constant()); -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->swap(this, _VSTD::addressof(__x)); -#endif + std::__debug_db_swap(this, std::addressof(__x)); } template @@ -2011,12 +2001,9 @@ void vector<_Tp, _Allocator>::__invalidate_all_iterators() { -#if _LIBCPP_DEBUG_LEVEL == 2 - __get_db()->__invalidate_all(this); -#endif + std::__debug_db_invalidate_all(this); } - template inline _LIBCPP_INLINE_VISIBILITY void