public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10656] libstdc++: Fix uses_allocator_construction_args for pair<T&&, U&&> [PR108952] Date: Thu, 27 Apr 2023 22:01:01 +0000 (GMT) [thread overview] Message-ID: <20230427220101.50F09385842D@sourceware.org> (raw) https://gcc.gnu.org/g:6930165acd05c8eef88a99b9546742b108e0c84e commit r11-10656-g6930165acd05c8eef88a99b9546742b108e0c84e Author: Jonathan Wakely <jwakely@redhat.com> Date: Mon Feb 27 22:34:57 2023 +0000 libstdc++: Fix uses_allocator_construction_args for pair<T&&, U&&> [PR108952] This implements LWG 3527 which fixes the handling of pair<T&&, U&&> 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. (cherry picked from commit 8e342c04550466ab088c33746091ce7f3498ee44) Diff: --- libstdc++-v3/include/bits/uses_allocator_args.h | 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/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index 044494aab05..40ef6843945 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -180,11 +180,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)))); } template<typename _Tp, typename _Alloc, typename... _Args> 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 <utility> + +template<int N, typename T, typename Pair> +constexpr bool +check() +{ + return std::is_same<decltype(std::get<N>(std::declval<Pair>())), T>::value; +} + +void +test_value_category() +{ + using P = std::pair<int, long>; + static_assert( check<0, int&, P&>(), + "get<0>(pair<T1, T2>&)" ); + static_assert( check<1, long&, P&>(), + "get<1>(pair<T1, T2>&)" ); + static_assert( check<0, int&&, P&&>(), + "get<0>(pair<T1, T2>&&)" ); + static_assert( check<1, long&&, P&&>(), + "get<1>(pair<T1, T2>&&)" ); + static_assert( check<0, const int&, const P&>(), + "get<0>(const pair<T1, T2>&)" ); + static_assert( check<1, const long&, const P&>(), + "get<1>(const pair<T1, T2>&)" ); + static_assert( check<0, const int&&, const P&&>(), + "get<0>(const pair<T1, T2>&&)" ); + static_assert( check<1, const long&&, const P&&>(), + "get<1>(const pair<T1, T2>&&)" ); + + using PL = std::pair<int&, long&>; + static_assert( check<0, int&, PL&>(), + "get<0>(pair<T1&, T2&>&)" ); + static_assert( check<1, long&, PL&>(), + "get<1>(pair<T1&, T2&>&)" ); + static_assert( check<0, int&, PL&&>(), + "get<0>(pair<T1&, T2&>&&)" ); + static_assert( check<1, long&, PL&&>(), + "get<1>(pair<T1&, T2&>&&)" ); + static_assert( check<0, int&, const PL&>(), + "get<0>(const pair<T1&, T2&>&)" ); + static_assert( check<1, long&, const PL&>(), + "get<1>(const pair<T1&, T2&>&)" ); + static_assert( check<0, int&, const PL&&>(), + "get<0>(const pair<T1&, T2&>&&)" ); + static_assert( check<1, long&, const PL&&>(), + "get<1>(const pair<T1&, T2&>&&)" ); + + using PR = std::pair<int&&, long&&>; + static_assert( check<0, int&, P&>(), + "get<0>(pair<T1&&, T2&&>&)" ); + static_assert( check<1, long&, P&>(), + "get<1>(pair<T1&&, T2&&>&)" ); + static_assert( check<0, int&&, PR&&>(), + "get<0>(pair<T1&&, T2&&>&&)" ); + static_assert( check<1, long&&, PR&&>(), + "get<1>(pair<T1&&, T2&&>&&)" ); + static_assert( check<0, int&, const PR&>(), + "get<0>(const pair<T1&&, T2&&>&)" ); + static_assert( check<1, long&, const PR&>(), + "get<1>(const pair<T1&&, T2&&>&)" ); + static_assert( check<0, int&&, const PR&&>(), + "get<0>(const pair<T1&&, T2&&>&&)" ); + static_assert( check<1, long&&, const PR&&>(), + "get<1>(const pair<T1&&, T2&&>&&)" ); +} 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 <scoped_allocator> + +struct move_only +{ + move_only(move_only&&); +}; + +using P = std::pair<move_only, move_only>; + +void +test_pr108952(std::pair<move_only&&, move_only&&> 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<std::allocator<P>> 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 <memory> + +struct move_only +{ + move_only(move_only&&); +}; + +using P = std::pair<move_only, move_only>; + +void +test_lwg3527(std::pair<move_only&&, move_only&&> 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<move_only> a; + (void) std::uses_allocator_construction_args<P>(a, std::move(rvals)); +}
reply other threads:[~2023-04-27 22:01 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230427220101.50F09385842D@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).