From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DAA103858C30; Thu, 27 Apr 2023 23:04:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAA103858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682636663; bh=Ig1T7Wq7JjqqgojPE+yCrzWbdR5mRBrOixhZ9Vbqdkk=; h=From:To:Subject:Date:From; b=a0CFcWe+oz4Z47Lb33Y9+FLoZKVRXKksywbl/tYA1pcx9SN6aspHI9B8xD1H6yd/x Xr5wjszc8eaE2ZbGgqTmin69VeqG8rXZ+0Qo/GCVfve2H1dXxyI84FtOA89hjxjVLs PK7lSSw8HmlUFK57DoYso4NboRt0hDnESIj0i2qc= 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-11319] libstdc++: Fix uses_allocator_construction_args for pair [PR108952] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 497094c9d61c20643c93b8a5960b1b498ac5685e X-Git-Newrev: bd0179f31dfb9b009cb561d336f3f1c6fbdd4ceb Message-Id: <20230427230423.DAA103858C30@sourceware.org> Date: Thu, 27 Apr 2023 23:04:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bd0179f31dfb9b009cb561d336f3f1c6fbdd4ceb commit r10-11319-gbd0179f31dfb9b009cb561d336f3f1c6fbdd4ceb Author: Jonathan Wakely Date: Mon Feb 27 22:34:57 2023 +0000 libstdc++: Fix uses_allocator_construction_args for pair [PR108952] This implements LWG 3527 which fixes the handling of pair in std::uses_allocator_construction_args. libstdc++-v3/ChangeLog: PR libstdc++/108952 * include/std/memory (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. (cherry picked from commit 8e342c04550466ab088c33746091ce7f3498ee44) Diff: --- libstdc++-v3/include/std/memory | 7 ++- .../testsuite/20_util/pair/astuple/get-2.cc | 68 ++++++++++++++++++++++ .../testsuite/20_util/scoped_allocator/108952.cc | 23 ++++++++ .../testsuite/20_util/uses_allocator/lwg3527.cc | 22 +++++++ 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory index eea472e8600..ce54f260257 100644 --- a/libstdc++-v3/include/std/memory +++ b/libstdc++-v3/include/std/memory @@ -378,11 +378,14 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; } 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)))); } template 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)); +}