gcc/libstdc++-v3
Jonathan Wakely 9a0b518a82 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.
2022-01-14 10:14:25 +00:00
..
config libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760] 2022-01-10 15:38:47 +01:00
doc libstdc++: Document new std::random_device tokens 2022-01-14 10:14:24 +00:00
include libstdc++: Add C++20 std::make_shared enhancements (P0674R1) 2022-01-14 10:14:25 +00:00
libsupc++ libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
po libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
python libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
scripts Update copyright years. 2022-01-03 10:42:10 +01:00
src libstdc++: Avoid overflow in bounds checks [PR103955] 2022-01-12 09:10:24 -05:00
testsuite libstdc++: Add C++20 std::make_shared enhancements (P0674R1) 2022-01-14 10:14:25 +00:00
ChangeLog Daily bump. 2022-01-13 00:16:21 +00:00
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 Rotate ChangeLog files - part 1 - add ChangeLog-2021. 2022-01-03 10:18:16 +01:00
Makefile.am Update copyright years. 2022-01-03 10:42:10 +01:00
Makefile.in libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
README
acinclude.m4 libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
aclocal.m4
config.h.in libstdc++: Fix definition of _GLIBCXX_NO_SLEEP config macro 2021-12-10 14:05:46 +00:00
configure libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
configure.ac libstdc++: Fix and simplify freestanding configuration [PR103866] 2022-01-10 12:18:14 +00:00
configure.host
crossconfig.m4 libstdc++: Check for TLS support on mingw cross-compilers 2021-09-15 09:49:33 +01:00
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.