From 30236791e04a08c3a7edc49f00af4c63c4cb6a9d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 5 Jul 2018 18:03:05 +0100 Subject: [PATCH] PR libstdc++/58265 add noexcept to basic_string::assign(basic_string&&) PR libstdc++/58265 * include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI] (basic_string::assign(basic_string&&)): Add conditional noexcept depending on the allocator's is_always_equal property (LWG 2063). * testsuite/21_strings/basic_string/modifiers/assign/char/ move_assign.cc: Check for non-throwing exception specification. * testsuite/21_strings/basic_string/modifiers/assign/wchar_t/ move_assign.cc: Likewise. From-SVN: r262447 --- libstdc++-v3/ChangeLog | 9 +++++++++ libstdc++-v3/include/bits/basic_string.h | 3 +-- .../basic_string/modifiers/assign/char/move_assign.cc | 3 +++ .../basic_string/modifiers/assign/wchar_t/move_assign.cc | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 39b94917a2e..c8b4ce4a629 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,14 @@ 2018-07-05 Jonathan Wakely + PR libstdc++/58265 + * include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI] + (basic_string::assign(basic_string&&)): Add conditional noexcept + depending on the allocator's is_always_equal property (LWG 2063). + * testsuite/21_strings/basic_string/modifiers/assign/char/ + move_assign.cc: Check for non-throwing exception specification. + * testsuite/21_strings/basic_string/modifiers/assign/wchar_t/ + move_assign.cc: Likewise. + PR libstdc++/58265 * include/bits/basic_string.h [!_GLIBCXX_USE_CXX11_ABI] [_GLIBCXX_FULLY_DYNAMIC_STRING==0] (basic_string::basic_string()): diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index baad58682b6..2d1b9dc6c29 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -725,7 +725,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 * The contents of @a str are moved into this string (without copying). * @a str is a valid, but unspecified string. **/ - // PR 58265, this should be noexcept. // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2063. Contradictory requirements for string move assignment basic_string& @@ -4275,9 +4274,9 @@ _GLIBCXX_END_NAMESPACE_CXX11 * This function sets this string to the exact contents of @a __str. * @a __str is a valid, but unspecified string. */ - // PR 58265, this should be noexcept. basic_string& assign(basic_string&& __str) + noexcept(allocator_traits<_Alloc>::is_always_equal::value) { this->swap(__str); return *this; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/char/move_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/char/move_assign.cc index e9116b9c0e0..7089fea04c2 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/char/move_assign.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/char/move_assign.cc @@ -32,6 +32,9 @@ void test01() a.push_back('1'); b.assign(std::move(a)); VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 ); + + // True for std::allocator because is_always_equal, but not true in general: + static_assert(noexcept(a.assign(std::move(b))), "lwg 2063"); } int main() diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/wchar_t/move_assign.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/wchar_t/move_assign.cc index 74e342a8ef4..8d394602a9f 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/wchar_t/move_assign.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/wchar_t/move_assign.cc @@ -32,6 +32,9 @@ void test01() a.push_back(L'1'); b.assign(std::move(a)); VERIFY( b.size() == 1 && b[0] == '1' && a.size() == 0 ); + + // True for std::allocator because is_always_equal, but not true in general: + static_assert(noexcept(a.assign(std::move(b))), "lwg 2063"); } int main() -- 2.30.2