public inbox for libstdc++-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 r13-3312] libstdc++: Fix uses_allocator_construction args for cv pair (LWG 3677) Date: Sat, 15 Oct 2022 20:21:30 +0000 (GMT) [thread overview] Message-ID: <20221015202130.7CB4B3858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:e24b430f1ea60205162fd9b327ac6a4dfc57f37c commit r13-3312-ge24b430f1ea60205162fd9b327ac6a4dfc57f37c Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Oct 14 14:25:48 2022 +0100 libstdc++: Fix uses_allocator_construction args for cv pair (LWG 3677) The _Std_pair concept uses in <bits/uses_allocator_args.h> handles const qualified pairs, but not volatile qualified. That's because it just uses __is_pair which is specialized for const pairs. This removes the partial specialization __is_pair<const pair<T,U>>, so that __is_pair is now only true for cv-unqualified pairs. Then _Std_pair needs to explicitly use remove_cv_t for the argument to __is_pair. The other use of __is_pair is in map::insert(Pair&&) which doesn't want to handle volatile so should just use remove_const_t. libstdc++-v3/ChangeLog: * include/bits/stl_map.h (map::insert(Pair&&)): Use remove_const_t on argument to __is_pair. * include/bits/stl_pair.h (__is_pair<const pair<T,U>>): Remove partial specialization. * include/bits/uses_allocator_args.h (_Std_pair): Use remove_cv_t as per LWG 3677. * testsuite/20_util/uses_allocator/lwg3677.cc: New test. Diff: --- libstdc++-v3/include/bits/stl_map.h | 2 +- libstdc++-v3/include/bits/stl_pair.h | 3 -- libstdc++-v3/include/bits/uses_allocator_args.h | 2 +- .../testsuite/20_util/uses_allocator/lwg3677.cc | 52 ++++++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index 9c2b0745673..83c579aaedc 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -847,7 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { #if __cplusplus >= 201703L using _P2 = remove_reference_t<_Pair>; - if constexpr (__is_pair<_P2>) + if constexpr (__is_pair<remove_const_t<_P2>>) if constexpr (is_same_v<allocator_type, allocator<value_type>>) if constexpr (__usable_key<typename _P2::first_type>) { diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index d0f07b09d34..195167019b7 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -889,9 +889,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename _Up> inline constexpr bool __is_pair<pair<_Tp, _Up>> = true; - - template<typename _Tp, typename _Up> - inline constexpr bool __is_pair<const pair<_Tp, _Up>> = true; #endif /// @cond undocumented diff --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index ef5c4fffb70..77e48602aac 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -44,7 +44,7 @@ namespace std _GLIBCXX_VISIBILITY(default) _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp> - concept _Std_pair = __is_pair<_Tp>; + concept _Std_pair = __is_pair<remove_cv_t<_Tp>>; /** @addtogroup allocators * @{ diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc new file mode 100644 index 00000000000..649b98d3922 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc @@ -0,0 +1,52 @@ +// { dg-options "-std=gnu++23" } +// { dg-do run { target c++20 } } + +#include <memory> +#include <testsuite_hooks.h> + +struct UsesAlloc +{ + using allocator_type = std::allocator<int>; + + bool passed_alloc; + + UsesAlloc(int) : passed_alloc(false) { } + + UsesAlloc(int, std::allocator<int>) : passed_alloc(true) { } +}; + +using Pair = std::pair<UsesAlloc, int>; + +void +test_const() +{ + std::allocator<int> a; + int i = 0; + auto p = std::make_obj_using_allocator<const Pair>(a, i, i); + VERIFY( p.first.passed_alloc ); +} + +void +test_volatile() +{ + std::allocator<int> a; + int i = 0; + auto p = std::make_obj_using_allocator<volatile Pair>(a, i, i); + VERIFY( p.first.passed_alloc ); +} + +void +test_const_volatile() +{ + std::allocator<int> a; + int i = 0; + auto p = std::make_obj_using_allocator<volatile Pair>(a, i, i); + VERIFY( p.first.passed_alloc ); +} + +int main() +{ + test_const(); + test_volatile(); + test_const_volatile(); +}
reply other threads:[~2022-10-15 20:21 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=20221015202130.7CB4B3858D1E@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).