From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 511203858C36; Thu, 27 Apr 2023 23:04:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 511203858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682636648; bh=A6pxq/APFrUF5gDomvurQIqiicfbaCR3kszrWzyhNIw=; h=From:To:Subject:Date:From; b=l83xm6SbVolHkRSkbn9z0IMUhd3hu9dBMwzLy4SBrs2z4MozcKaXdyXlSIdN+4X7q dR0zc8yhMfJL7yVwGP2iQDl0qC2J6un15oyF12ocdmojaOdnyOLrx0vcOzKwuf3mL3 6zlNcn0nezbATseb9/ZRDzYtGj/Jcr9E/6mxuBRs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-11316] libstdc++: Fix minor bugs in std::common_iterator X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 5d572ffe2e05dbe44edaf19fa10ef2ca3ae8227c X-Git-Newrev: 3cf551240fcbc7a5e0f5ba07a9164e237e6c097b Message-Id: <20230427230408.511203858C36@sourceware.org> Date: Thu, 27 Apr 2023 23:04:08 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3cf551240fcbc7a5e0f5ba07a9164e237e6c097b commit r10-11316-g3cf551240fcbc7a5e0f5ba07a9164e237e6c097b Author: Jonathan Wakely Date: Wed Jul 20 12:49:28 2022 +0100 libstdc++: Fix minor bugs in std::common_iterator The noexcept-specifier for some std::common_iterator constructors was incorrectly using an rvalue as the first argument of std::is_nothrow_assignable_v. This gave the wrong answer for some types, e.g. std::common_iterator, because an rvalue of scalar type cannot be assigned to. Also fix the friend declaration to use the same constraints as on the definition of the class template. G++ fails to diagnose this error, due to PR c++/96830. Finally, the copy constructor was using std::move for its argument in some cases, which should be removed. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (common_iterator): Fix incorrect uses of is_nothrow_assignable_v. Fix inconsistent constraints on friend declaration. Do not move argument in copy constructor. * testsuite/24_iterators/common_iterator/1.cc: Check for noexcept constructibnle/assignable. (cherry picked from commit 3b5567c3ec7e5759bdecc6a6fc0be2b65a93636e) Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 11 ++++++----- .../testsuite/24_iterators/common_iterator/1.cc | 23 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index a46872fc3c2..ca15fb46cf2 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1683,7 +1683,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_noexcept1() { if constexpr (is_trivially_default_constructible_v<_Tp>) - return is_nothrow_assignable_v<_Tp, _Up>; + return is_nothrow_assignable_v<_Tp&, _Up>; else return is_nothrow_constructible_v<_Tp, _Up>; } @@ -1777,14 +1777,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (_M_index == 0) { if constexpr (is_trivially_default_constructible_v<_It>) - _M_it = std::move(__x._M_it); + _M_it = __x._M_it; else ::new((void*)std::__addressof(_M_it)) _It(__x._M_it); } else if (_M_index == 1) { if constexpr (is_trivially_default_constructible_v<_Sent>) - _M_sent = std::move(__x._M_sent); + _M_sent = __x._M_sent; else ::new((void*)std::__addressof(_M_sent)) _Sent(__x._M_sent); } @@ -1809,8 +1809,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator=(const common_iterator<_It2, _Sent2>& __x) noexcept(is_nothrow_constructible_v<_It, const _It2&> && is_nothrow_constructible_v<_Sent, const _Sent2&> - && is_nothrow_assignable_v<_It, const _It2&> - && is_nothrow_assignable_v<_Sent, const _Sent2&>) + && is_nothrow_assignable_v<_It&, const _It2&> + && is_nothrow_assignable_v<_Sent&, const _Sent2&>) { switch(_M_index << 2 | __x._M_index) { @@ -2004,6 +2004,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: template _Sent2> + requires (!same_as<_It2, _Sent2>) && copyable<_It2> friend class common_iterator; bool _M_has_value() const noexcept { return _M_index < 2; } diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc b/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc index 576c4d818a4..8b69ecd54fe 100644 --- a/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc +++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc @@ -27,15 +27,30 @@ test01() using I = std::common_iterator; static_assert( std::is_default_constructible_v ); static_assert( std::is_copy_constructible_v ); + static_assert( std::is_move_constructible_v ); static_assert( std::is_copy_assignable_v ); + static_assert( std::is_move_assignable_v ); static_assert( std::is_constructible_v ); static_assert( std::is_constructible_v ); - struct sentinel { operator int*() const { return nullptr; } }; + static_assert( std::is_nothrow_copy_constructible_v ); // GCC extension + static_assert( std::is_nothrow_move_constructible_v ); // GCC extension + static_assert( std::is_nothrow_copy_assignable_v ); // GCC extension + static_assert( std::is_nothrow_move_assignable_v ); // GCC extension + + struct sentinel { operator int*() const noexcept { return nullptr; } }; using K = std::common_iterator; static_assert( std::is_constructible_v ); static_assert( std::is_assignable_v ); + static_assert( std::is_nothrow_assignable_v ); // GCC extension + + struct sentinel_throwing { operator int*() const { return nullptr; } }; + using K_throwing = std::common_iterator; + // Conversion is noexcept(false) + static_assert( ! std::is_nothrow_assignable_v ); + + struct sentinel2 { const int* p; @@ -46,6 +61,12 @@ test01() using J = std::common_iterator; static_assert( std::is_constructible_v ); static_assert( std::is_convertible_v ); + + static_assert( std::is_constructible_v ); + static_assert( std::is_convertible_v ); + + // Constructor is noexcept(false) + static_assert( ! std::is_nothrow_constructible_v ); } void