From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 54EB43857806; Fri, 14 Jan 2022 10:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54EB43857806 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 r12-6572] libstdc++: Use std::construct_at in std::common_iterator [PR103992] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f390f11b445ee36cce5c5f1d5779baee817f0af X-Git-Newrev: d67ba1dce9796bff177e52e2bbb68bfa2c69a884 Message-Id: <20220114101444.54EB43857806@sourceware.org> Date: Fri, 14 Jan 2022 10:14:44 +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: Fri, 14 Jan 2022 10:14:44 -0000 https://gcc.gnu.org/g:d67ba1dce9796bff177e52e2bbb68bfa2c69a884 commit r12-6572-gd67ba1dce9796bff177e52e2bbb68bfa2c69a884 Author: Jonathan Wakely Date: Wed Jan 12 16:58:18 2022 +0000 libstdc++: Use std::construct_at in std::common_iterator [PR103992] This should have been done as part of the LWG 3574 changes. libstdc++-v3/ChangeLog: PR libstdc++/103992 * include/bits/stl_iterator.h (common_iterator): Use std::construct_at instead of placement new. * testsuite/24_iterators/common_iterator/1.cc: Check copy construction is usable in constant expressions. Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 8 ++++---- libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 24a71ea55af..24c106e0f70 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -1907,14 +1907,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if constexpr (is_trivially_default_constructible_v<_It>) _M_it = std::move(__x._M_it); else - ::new((void*)std::__addressof(_M_it)) _It(__x._M_it); + std::construct_at(std::__addressof(_M_it), __x._M_it); } else if (_M_index == 1) { if constexpr (is_trivially_default_constructible_v<_Sent>) _M_sent = std::move(__x._M_sent); else - ::new((void*)std::__addressof(_M_sent)) _Sent(__x._M_sent); + std::construct_at(std::__addressof(_M_sent), __x._M_sent); } } @@ -1928,14 +1928,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if constexpr (is_trivially_default_constructible_v<_It>) _M_it = std::move(__x._M_it); else - ::new((void*)std::__addressof(_M_it)) _It(__x._M_it); + std::construct_at(std::__addressof(_M_it), __x._M_it); } else if (_M_index == 1) { if constexpr (is_trivially_default_constructible_v<_Sent>) _M_sent = std::move(__x._M_sent); else - ::new((void*)std::__addressof(_M_sent)) _Sent(__x._M_sent); + std::construct_at(std::__addressof(_M_sent), __x._M_sent); } } diff --git a/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc b/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc index 484d0cc2301..365ee89c02e 100644 --- a/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc +++ b/libstdc++-v3/testsuite/24_iterators/common_iterator/1.cc @@ -157,6 +157,22 @@ test04() VERIFY( x.i == 2 ); } +constexpr bool +test_pr103992() +{ + using C1 = std::common_iterator, + std::unreachable_sentinel_t>; + using C2 = std::common_iterator, + std::unreachable_sentinel_t>; + C1 c1; + C2 c2 = c1; + C1 c3 = c1; + + return true; +} + +static_assert( test_pr103992() ); + int main() {