9a0b518a82
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. |
||
---|---|---|
.. | ||
config | ||
doc | ||
include | ||
libsupc++ | ||
po | ||
python | ||
scripts | ||
src | ||
testsuite | ||
ChangeLog | ||
ChangeLog-1998 | ||
ChangeLog-1999 | ||
ChangeLog-2000 | ||
ChangeLog-2001 | ||
ChangeLog-2002 | ||
ChangeLog-2003 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
ChangeLog-2020 | ||
ChangeLog-2021 | ||
Makefile.am | ||
Makefile.in | ||
README | ||
acinclude.m4 | ||
aclocal.m4 | ||
config.h.in | ||
configure | ||
configure.ac | ||
configure.host | ||
crossconfig.m4 | ||
fragment.am | ||
linkage.m4 |
README
file: libstdc++-v3/README New users may wish to point their web browsers to the file index.html in the 'doc/html' subdirectory. It contains brief building instructions and notes on how to configure the library in interesting ways.