From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id E88E43858016; Mon, 4 Apr 2022 11:46:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E88E43858016 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 r11-9760] libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 94525b91df8ed598b086c35a55a89200422df14c X-Git-Newrev: fe76adc667b4e521705540b30b68ab988c6abbec Message-Id: <20220404114634.E88E43858016@sourceware.org> Date: Mon, 4 Apr 2022 11:46:34 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 11:46:35 -0000 https://gcc.gnu.org/g:fe76adc667b4e521705540b30b68ab988c6abbec commit r11-9760-gfe76adc667b4e521705540b30b68ab988c6abbec Author: Jonathan Wakely 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. (cherry picked from commit 6cfb7ffb659fd6b87a21312021ab023a06e8f6be) 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 70e750f15aa..044494aab05 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -188,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - inline _Tp + constexpr _Tp make_obj_using_allocator(const _Alloc& __a, _Args&&... __args) { return std::make_from_tuple<_Tp>( @@ -197,7 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template - 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 b45d96cd359..f0a17969822 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(a); } +constexpr bool +test_pr104542() +{ + // PR libstdc++/104542 - missing constexpr + std::allocator a; + int i = std::make_obj_using_allocator(a, 1); + + struct X { + using allocator_type = std::allocator; + constexpr X(std::allocator_arg_t, std::allocator, int i) : i(i+1) { } + int i; + }; + + X x = std::make_obj_using_allocator(a, i); + + struct Y { + using allocator_type = std::allocator; + constexpr Y(X x, std::allocator) : i(x.i+1) { } + int i; + }; + + Y y = std::make_obj_using_allocator(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 + +constexpr bool +test_pr104542() +{ + // PR libstdc++/104542 - missing constexpr + std::allocator a; + int* p = a.allocate(1); + int i = *std::uninitialized_construct_using_allocator(p, a, 999); + a.deallocate(p, 1); + return i == 999; +} + +static_assert( test_pr104542() );