From: Jonathan Wakely Date: Tue, 15 Feb 2022 12:47:39 +0000 (+0000) Subject: libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542] X-Git-Tag: upstream/12.2.0~1453 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6cfb7ffb659fd6b87a21312021ab023a06e8f6be;p=platform%2Fupstream%2Fgcc.git 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 --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index a3aa37d..d92dd1f 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 - 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 - 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 cd4497e..2dd0f81 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 0000000..f403cbe --- /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() );