From patchwork Fri Jan 14 10:15:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 50016 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AC583857C7E for ; Fri, 14 Jan 2022 10:17:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AC583857C7E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642155455; bh=b502P62rqBM+8RepoyvIL57seJEY8b20bmZllbHrEQU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=V/YC5+p2SpQzRuLA8ClvYZFcwqu/K6hAWEd/qqFmRJZfdQgYcYjgRFpzjFmfyv8qP cirkTzJe76SIXx26y86f6gZFMoUlr/pH2sXhvt5lCOTpzpZ3jg1yFiGRLYVtIxg509 mjbl8LfvDgv5o8shBhHJrXAq58F8YkZqnx34+XLI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 92B443857C6E for ; Fri, 14 Jan 2022 10:15:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92B443857C6E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-msIX91sEMB69kwQ99kO-IQ-1; Fri, 14 Jan 2022 05:15:15 -0500 X-MC-Unique: msIX91sEMB69kwQ99kO-IQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3BD681CCBF; Fri, 14 Jan 2022 10:15:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id A543E7B9D4; Fri, 14 Jan 2022 10:15:14 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Use std::construct_at in std::common_iterator [PR103992] Date: Fri, 14 Jan 2022 10:15:13 +0000 Message-Id: <20220114101513.2975259-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested powerpc64le-linux, pushed to trunk. 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. --- libstdc++-v3/include/bits/stl_iterator.h | 8 ++++---- .../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() {