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 r12-7244] libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542] Date: Tue, 15 Feb 2022 14:28:35 +0000 (GMT) [thread overview] Message-ID: <20220215142835.7BE033858D20@sourceware.org> (raw) https://gcc.gnu.org/g:6cfb7ffb659fd6b87a21312021ab023a06e8f6be commit r12-7244-g6cfb7ffb659fd6b87a21312021ab023a06e8f6be Author: Jonathan Wakely <jwakely@redhat.com> Date: Tue Feb 15 12:47:39 2022 +0000 libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542] libstdc++-v3/ChangeLog: PR libstdc++/104542 * include/bits/uses_allocator_args.h (make_obj_using_allocator) (uninitialized_construct_using_allocator): Add constexpr. * testsuite/20_util/uses_allocator/make_obj.cc: Check constexpr. * testsuite/20_util/uses_allocator/uninitialized_construct.cc: New test. Diff: --- libstdc++-v3/include/bits/uses_allocator_args.h | 4 +-- .../testsuite/20_util/uses_allocator/make_obj.cc | 30 +++++++++++++++++++++- .../uses_allocator/uninitialized_construct.cc | 17 ++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index a3aa37d8e78..d92dd1f0901 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -196,7 +196,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, typename _Alloc, typename... _Args> - inline _Tp + constexpr _Tp make_obj_using_allocator(const _Alloc& __a, _Args&&... __args) { return std::make_from_tuple<_Tp>( @@ -205,7 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, typename _Alloc, typename... _Args> - inline _Tp* + constexpr _Tp* uninitialized_construct_using_allocator(_Tp* __p, const _Alloc& __a, _Args&&... __args) { diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/make_obj.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/make_obj.cc index cd4497e8410..2dd0f819657 100644 --- a/libstdc++-v3/testsuite/20_util/uses_allocator/make_obj.cc +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/make_obj.cc @@ -142,7 +142,7 @@ test01() VERIFY( c2.alloc_id == 1 ); } -void +void test02() { decltype(auto) b @@ -389,6 +389,34 @@ test08() std::make_obj_using_allocator<X>(a); } +constexpr bool +test_pr104542() +{ + // PR libstdc++/104542 - missing constexpr + std::allocator<void> a; + int i = std::make_obj_using_allocator<int>(a, 1); + + struct X { + using allocator_type = std::allocator<long>; + constexpr X(std::allocator_arg_t, std::allocator<int>, int i) : i(i+1) { } + int i; + }; + + X x = std::make_obj_using_allocator<X>(a, i); + + struct Y { + using allocator_type = std::allocator<char>; + constexpr Y(X x, std::allocator<int>) : i(x.i+1) { } + int i; + }; + + Y y = std::make_obj_using_allocator<Y>(a, x); + + return y.i == 3; +} + +static_assert( test_pr104542() ); + int main() { diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/uninitialized_construct.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/uninitialized_construct.cc new file mode 100644 index 00000000000..f403cbe99cc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/uninitialized_construct.cc @@ -0,0 +1,17 @@ +// { dg-options "-std=gnu++20" } +// { dg-do compile { target c++20 } } + +#include <memory> + +constexpr bool +test_pr104542() +{ + // PR libstdc++/104542 - missing constexpr + std::allocator<int> a; + int* p = a.allocate(1); + int i = *std::uninitialized_construct_using_allocator<int>(p, a, 999); + a.deallocate(p, 1); + return i == 999; +} + +static_assert( test_pr104542() );
reply other threads:[~2022-02-15 14:28 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=20220215142835.7BE033858D20@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).