From patchwork Tue Feb 28 09:50:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1749387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=rSfSdaga; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PQt1f39sVz1yWy for ; Tue, 28 Feb 2023 20:51:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF3C9384B80F for ; Tue, 28 Feb 2023 09:51:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF3C9384B80F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677577907; bh=DZrEiZG0qlNVNz3ACHtY9HQaYUsIXSsvFP+r0zcWBvc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rSfSdaga6TlmfxpaUZxcP9Y8UTsOMyDuuXrFF/Lnz3kQLAyB8GTIHDYJtJtVgiqcm RHfdAi93cNAb+c6DeHUV6HfxWlzw0CY1WqvixEJAHUIbUyzlY1gWcfXoZQSOKDTNtU sVeXKXbLYSmuNtaGDNEqBU3nR5mtpKmS008dGsKI= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id E10F0385B515 for ; Tue, 28 Feb 2023 09:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E10F0385B515 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-435-8y2GfMfTND2-ydavV6bNKg-1; Tue, 28 Feb 2023 04:50:54 -0500 X-MC-Unique: 8y2GfMfTND2-ydavV6bNKg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 192D33C0F425; Tue, 28 Feb 2023 09:50:54 +0000 (UTC) Received: from localhost (unknown [10.33.36.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4695492B14; Tue, 28 Feb 2023 09:50:53 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix uses_allocator_construction_args for pair [PR108952] Date: Tue, 28 Feb 2023 09:50:53 +0000 Message-Id: <20230228095053.1193118-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Tested powerpc64le-linux. Pushed to trunk. -- >8 -- This implements LWG 3527 which fixes the handling of pair in std::uses_allocator_construction_args. libstdc++-v3/ChangeLog: PR libstdc++/108952 * include/bits/uses_allocator_args.h (uses_allocator_construction_args): Implement LWG 3527. * testsuite/20_util/pair/astuple/get-2.cc: New test. * testsuite/20_util/scoped_allocator/108952.cc: New test. * testsuite/20_util/uses_allocator/lwg3527.cc: New test. --- .../include/bits/uses_allocator_args.h | 11 +-- .../testsuite/20_util/pair/astuple/get-2.cc | 68 +++++++++++++++++++ .../20_util/scoped_allocator/108952.cc | 23 +++++++ .../20_util/uses_allocator/lwg3527.cc | 22 ++++++ 4 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/pair/astuple/get-2.cc create mode 100644 libstdc++-v3/testsuite/20_util/scoped_allocator/108952.cc create mode 100644 libstdc++-v3/testsuite/20_util/uses_allocator/lwg3527.cc diff --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index e7849abfc91..bc038f03458 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -185,11 +185,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using _Tp1 = typename _Tp::first_type; using _Tp2 = typename _Tp::second_type; + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3527. uses_allocator_construction_args handles rvalue pairs + // of rvalue references incorrectly return std::make_tuple(piecewise_construct, std::uses_allocator_construction_args<_Tp1>(__a, - std::move(__pr).first), + std::get<0>(std::move(__pr))), std::uses_allocator_construction_args<_Tp2>(__a, - std::move(__pr).second)); + std::get<1>(std::move(__pr)))); } #if __cplusplus > 202002L @@ -216,9 +219,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return std::make_tuple(piecewise_construct, std::uses_allocator_construction_args<_Tp1>(__a, - std::move(__pr).first), + std::get<0>(std::move(__pr))), std::uses_allocator_construction_args<_Tp2>(__a, - std::move(__pr).second)); + std::get<1>(std::move(__pr)))); } #endif // C++23 diff --git a/libstdc++-v3/testsuite/20_util/pair/astuple/get-2.cc b/libstdc++-v3/testsuite/20_util/pair/astuple/get-2.cc new file mode 100644 index 00000000000..573d239effa --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/astuple/get-2.cc @@ -0,0 +1,68 @@ +// { dg-do compile { target c++11 } } + +#include + +template +constexpr bool +check() +{ + return std::is_same(std::declval())), T>::value; +} + +void +test_value_category() +{ + using P = std::pair; + static_assert( check<0, int&, P&>(), + "get<0>(pair&)" ); + static_assert( check<1, long&, P&>(), + "get<1>(pair&)" ); + static_assert( check<0, int&&, P&&>(), + "get<0>(pair&&)" ); + static_assert( check<1, long&&, P&&>(), + "get<1>(pair&&)" ); + static_assert( check<0, const int&, const P&>(), + "get<0>(const pair&)" ); + static_assert( check<1, const long&, const P&>(), + "get<1>(const pair&)" ); + static_assert( check<0, const int&&, const P&&>(), + "get<0>(const pair&&)" ); + static_assert( check<1, const long&&, const P&&>(), + "get<1>(const pair&&)" ); + + using PL = std::pair; + static_assert( check<0, int&, PL&>(), + "get<0>(pair&)" ); + static_assert( check<1, long&, PL&>(), + "get<1>(pair&)" ); + static_assert( check<0, int&, PL&&>(), + "get<0>(pair&&)" ); + static_assert( check<1, long&, PL&&>(), + "get<1>(pair&&)" ); + static_assert( check<0, int&, const PL&>(), + "get<0>(const pair&)" ); + static_assert( check<1, long&, const PL&>(), + "get<1>(const pair&)" ); + static_assert( check<0, int&, const PL&&>(), + "get<0>(const pair&&)" ); + static_assert( check<1, long&, const PL&&>(), + "get<1>(const pair&&)" ); + + using PR = std::pair; + static_assert( check<0, int&, P&>(), + "get<0>(pair&)" ); + static_assert( check<1, long&, P&>(), + "get<1>(pair&)" ); + static_assert( check<0, int&&, PR&&>(), + "get<0>(pair&&)" ); + static_assert( check<1, long&&, PR&&>(), + "get<1>(pair&&)" ); + static_assert( check<0, int&, const PR&>(), + "get<0>(const pair&)" ); + static_assert( check<1, long&, const PR&>(), + "get<1>(const pair&)" ); + static_assert( check<0, int&&, const PR&&>(), + "get<0>(const pair&&)" ); + static_assert( check<1, long&&, const PR&&>(), + "get<1>(const pair&&)" ); +} diff --git a/libstdc++-v3/testsuite/20_util/scoped_allocator/108952.cc b/libstdc++-v3/testsuite/20_util/scoped_allocator/108952.cc new file mode 100644 index 00000000000..a6b9c67498c --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/scoped_allocator/108952.cc @@ -0,0 +1,23 @@ +// { dg-do compile { target c++11 } } + +#include + +struct move_only +{ + move_only(move_only&&); +}; + +using P = std::pair; + +void +test_pr108952(std::pair rvals) +{ + // LWG 3527. uses_allocator_construction_args handles rvalue pairs of + // rvalue references incorrectly. + // PR libstdc++/108952 Regression in uses_allocator_construction_args + // for pair of rvalue references + std::scoped_allocator_adaptor> a; + auto p = a.allocate(1); + a.construct(p, std::move(rvals)); + a.deallocate(p, 1); +} diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3527.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3527.cc new file mode 100644 index 00000000000..ae377f4b5a3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3527.cc @@ -0,0 +1,22 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include + +struct move_only +{ + move_only(move_only&&); +}; + +using P = std::pair; + +void +test_lwg3527(std::pair rvals) +{ + // LWG 3527. uses_allocator_construction_args handles rvalue pairs of + // rvalue references incorrectly. + // PR libstdc++/108952 Regression in uses_allocator_construction_args + // for pair of rvalue references + std::allocator a; + (void) std::uses_allocator_construction_args

(a, std::move(rvals)); +}