diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-01-13 22:08:43 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-01-14 10:14:25 +0000 |
commit | 9a0b518a82db68c5cbd9ea8ccc47c2ff45182519 (patch) | |
tree | 6fce64cd7aacd03b1f14e5cb0282f4d917d49d23 /libstdc++-v3/include/std/version | |
parent | fc6f1128ae603164aea6303ce2b3ed0b57e6a378 (diff) | |
download | gcc-9a0b518a82db68c5cbd9ea8ccc47c2ff45182519.zip gcc-9a0b518a82db68c5cbd9ea8ccc47c2ff45182519.tar.gz gcc-9a0b518a82db68c5cbd9ea8ccc47c2ff45182519.tar.bz2 |
libstdc++: Add C++20 std::make_shared enhancements (P0674R1)
This adds the overloads of std::make_shared and std::allocate_shared for
creating arrays, added to C++20 by P0674R1.
It also adds std::make_shared_for_overwrite, added to C++20 by P1020R1
(and renamed by P1973R1). The std::make_unique_for_overwite overloads
are already supported.
The original std::make_shared overload is changed to construct a
shared_ptr directly instead of calling std::allocate_shared. This
removes a function call at runtime, and avoids having to do overload
resolution for std::allocate_shared, now that there are five overloads
of it.
Allocating a shared array is done by a new __shared_count constructor.
An array is allocated with space for additional elements at the end and
an instance of new _Sp_counted_array class template is constructed in
that unused capacity.
The non-array form of std::make_shared_for_overwrite uses the same
__shared_count constructor as the original std::make_shared overload,
but a new partial specialization of _Sp_counted_ptr_inplace is selected
when the allocator's value_type is the new _Sp_overwrite_tag type. That
new partial specialization default-initializes its contained object and
destroys it with a destructor call rather than using the allocator.
Despite being C++20 features, this implementation only uses concepts
conditionally, with workarounds when they are not supported. This allows
it to work with older non-GCC compilers (Clang 9 and icc 2021). At some
point we can simplify the code by removing the workarounds.
libstdc++-v3/ChangeLog:
* include/bits/shared_ptr.h (__cpp_lib_shared_ptr_weak_type):
Correct type of macro value.
(shared_ptr): Add additional friend declarations.
(make_shared, allocate_shared): Constrain existing overloads and
remove static_assert.
* include/bits/shared_ptr_base.h (__cpp_lib_smart_ptr_for_overwrite):
New macro.
(_Sp_counted_ptr_inplace<T, Alloc, Lp>): New partial
specialization for use with make_shared_for_overwrite.
(__cpp_lib_shared_ptr_arrays): Update value for C++20.
(_Sp_counted_array_base): New class template.
(_Sp_counted_array): New class template.
(__shared_count(_Tp*&, const _Sp_counted_array_base&, _Init)):
New constructor for allocating shared arrays.
(__shared_ptr(const _Sp_counted_array_base&, _Init)): Likewise.
* include/std/version (__cpp_lib_shared_ptr_weak_type): Correct
type.
(__cpp_lib_shared_ptr_arrays): Update value for C++20.
(__cpp_lib_smart_ptr_for_overwrite): New macro.
* testsuite/20_util/shared_ptr/creation/99006.cc: Adjust
expected errors.
* testsuite/20_util/shared_ptr/creation/array.cc: New test.
* testsuite/20_util/shared_ptr/creation/overwrite.cc: New test.
* testsuite/20_util/shared_ptr/creation/version.cc: New test.
* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Check
feature test macro. Test non-trivial default-initialization.
Diffstat (limited to 'libstdc++-v3/include/std/version')
-rw-r--r-- | libstdc++-v3/include/std/version | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index c5d5efb..a8b792e 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -51,8 +51,10 @@ #if _GLIBCXX_HOSTED # define __cpp_lib_allocator_traits_is_always_equal 201411 +#if __cplusplus < 201703L // N.B. updated value in C++20 # define __cpp_lib_shared_ptr_arrays 201611L #endif +#endif #if !defined(__STRICT_ANSI__) // gnu++11 @@ -167,7 +169,7 @@ # define __cpp_lib_scoped_lock 201703 # define __cpp_lib_shared_mutex 201505L #endif -#define __cpp_lib_shared_ptr_weak_type 201606 +#define __cpp_lib_shared_ptr_weak_type 201606L #define __cpp_lib_string_view 201803L #if _GLIBCXX_HAVE_USELOCALE # define __cpp_lib_to_chars 201611L @@ -275,7 +277,9 @@ #if __cpp_lib_atomic_wait || _GLIBCXX_HAVE_POSIX_SEMAPHORE # define __cpp_lib_semaphore 201907L #endif +#define __cpp_lib_shared_ptr_arrays 201707L #define __cpp_lib_shift 201806L +#define __cpp_lib_smart_ptr_for_overwrite 202002L #if __cpp_lib_concepts # define __cpp_lib_span 202002L #endif |