Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates.
llvm-svn: 242056
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: e3fbe1433b02d52a833b06219184ee4f4852b50a
diff --git a/include/string b/include/string
index ac7b30a..6be2195 100644
--- a/include/string
+++ b/include/string
@@ -220,8 +220,8 @@
basic_string substr(size_type pos = 0, size_type n = npos) const;
void swap(basic_string& str)
- noexcept(!allocator_type::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
+ noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
+ allocator_traits<allocator_type>::is_always_equal::value); // C++17
const value_type* c_str() const noexcept;
const value_type* data() const noexcept;
@@ -1604,8 +1604,12 @@
_LIBCPP_INLINE_VISIBILITY
void swap(basic_string& __str)
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value);
+#if _LIBCPP_STD_VER >= 14
+ _NOEXCEPT;
+#else
+ _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
+ __is_nothrow_swappable<allocator_type>::value);
+#endif
_LIBCPP_INLINE_VISIBILITY
const value_type* c_str() const _NOEXCEPT {return data();}
@@ -1868,24 +1872,6 @@
_NOEXCEPT
{}
- _LIBCPP_INLINE_VISIBILITY
- static void __swap_alloc(allocator_type& __x, allocator_type& __y)
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
- {__swap_alloc(__x, __y, integral_constant<bool,
- __alloc_traits::propagate_on_container_swap::value>());}
-
- _LIBCPP_INLINE_VISIBILITY
- static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
- _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
- {
- using _VSTD::swap;
- swap(__x, __y);
- }
- _LIBCPP_INLINE_VISIBILITY
- static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
- {}
-
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
@@ -3366,8 +3352,12 @@
inline _LIBCPP_INLINE_VISIBILITY
void
basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
- __is_nothrow_swappable<allocator_type>::value)
+#if _LIBCPP_STD_VER >= 14
+ _NOEXCEPT
+#else
+ _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
+ __is_nothrow_swappable<allocator_type>::value)
+#endif
{
#if _LIBCPP_DEBUG_LEVEL >= 2
if (!__is_long())
@@ -3377,7 +3367,7 @@
__get_db()->swap(this, &__str);
#endif
_VSTD::swap(__r_.first(), __str.__r_.first());
- __swap_alloc(__alloc(), __str.__alloc());
+ __swap_allocator(__alloc(), __str.__alloc());
}
// find