From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 89310385701D; Wed, 20 Jul 2022 22:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89310385701D 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 r13-1771] libstdc++: Fix std::common_iterator triviality [PR100823] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 56c999860bbbb2fd5091ba0985e2e5eaa90c6478 X-Git-Newrev: 87a9bfe86d8a87d09de5d60e430d14bfa6c816f0 Message-Id: <20220720225919.89310385701D@sourceware.org> Date: Wed, 20 Jul 2022 22:59:19 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jul 2022 22:59:19 -0000 https://gcc.gnu.org/g:87a9bfe86d8a87d09de5d60e430d14bfa6c816f0 commit r13-1771-g87a9bfe86d8a87d09de5d60e430d14bfa6c816f0 Author: Jonathan Wakely Date: Wed Jul 20 16:51:44 2022 +0100 libstdc++: Fix std::common_iterator triviality [PR100823] This fixes the remaining problem reported in the PR, that the special members should be trivial. This can be done by constraining the non-trivial versions and adding defaulted overloads that will be used when the union members are trivial. Making these members trivial alters the argument passing ABI and so isn't suitable for backporting to release branches. libstdc++-v3/ChangeLog: PR libstdc++/100823 * include/bits/stl_iterator.h (common_iterator): Define destructor, copy constructor and move constructor as trivial when the underlying types allow. * testsuite/24_iterators/common_iterator/100823.cc: Check triviality of special members. Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 15 +++++++++++++++ .../testsuite/24_iterators/common_iterator/100823.cc | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index a913c04deaa..9cd262cd1d9 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1925,9 +1925,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + common_iterator(const common_iterator&) = default; + constexpr common_iterator(const common_iterator& __x) noexcept(_S_noexcept()) + requires (!is_trivially_copyable_v<_It> || !is_trivially_copyable_v<_Sent>) : _M_valueless(), _M_index(__x._M_index) { if (_M_index == 0) @@ -1946,9 +1949,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } + common_iterator(common_iterator&&) = default; + constexpr common_iterator(common_iterator&& __x) noexcept(_S_noexcept<_It, _Sent>()) + requires (!is_trivially_copyable_v<_It> || !is_trivially_copyable_v<_Sent>) : _M_valueless(), _M_index(__x._M_index) { if (_M_index == 0) @@ -2017,8 +2023,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } +#if __cpp_concepts >= 202002L // Constrained special member functions + ~common_iterator() = default; + constexpr ~common_iterator() + requires (!is_trivially_destructible_v<_It> + || !is_trivially_destructible_v<_Sent>) +#else + constexpr + ~common_iterator() +#endif { if (_M_index == 0) _M_it.~_It(); diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc index 4f2b23de8cc..b42dd087ab2 100644 --- a/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc +++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/100823.cc @@ -4,6 +4,21 @@ #include #include +void +test_triviality() +{ + using I = std::common_iterator; + + // Cannot be trivial, because it has to initialize members. + static_assert( ! std::is_trivially_default_constructible_v ); + + static_assert( std::is_trivially_destructible_v ); + static_assert( std::is_trivially_copy_constructible_v ); + static_assert( std::is_trivially_copy_assignable_v ); + static_assert( std::is_trivially_move_constructible_v ); + static_assert( std::is_trivially_move_assignable_v ); +} + void test_valueless_assignment() {