gcc/libstdc++-v3/include/ext
Jonathan Wakely 2d76292bd6 libstdc++: Begin lifetime of chars in constexpr std::string [PR103295]
Clang gives errors for constexpr std::string because the memory returned
by std::allocator<T>::allocate does not contain any objects yet, and
attempting to set them using char_traits::assign or char_traits::copy
fails with:

assignment to object outside its lifetime is not allowed in a constant expression
              *__result = *__first;
                        ^
This adds code to std::char_traits to use std::construct_at to begin
lifetimes when called during constant evaluation. To support
specializations of std::basic_string that don't use std::char_traits
there is now another layer of wrapper around the allocator_traits, so
that the lifetime of characters is begun as soon as the memory is
allocated. By doing it in the char traits and allocator traits, the rest
of basic_string can ignore the problem.

While modifying char_traits::copy and char_traits::assign to begin
lifetimes for the constexpr cases, I also replaced their uses of
std::copy and std::fill_n respectively. That means we don't need
<bits/stl_algobase.h> for char_traits.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.h (_Alloc_traits): Replace typedef
	with struct for C++20 mode.
	* include/bits/basic_string.tcc (_M_replace): Use _Alloc_traits
	for allocation.
	* include/bits/char_traits.h (__gnu_cxx::char_traits::assign):
	Use std::_Construct during constant evaluation.
	(__gnu_cxx::char_traits::assign(CharT*, const CharT*, size_t)):
	Likewise. Replace std::fill_n with memset or manual loop.
	(__gnu_cxx::char_traits::copy): Likewise, replacing std::copy
	with memcpy.
	* include/ext/vstring.h: Include <bits/stl_algobase.h> for
	std::min.
	* include/std/string_view: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
	Add constexpr test.
2021-11-19 18:15:15 +00:00
..
pb_ds libstdc++: Fix null dereference in pb_ds containers 2021-05-04 22:34:20 +01:00
algorithm Update copyright years. 2021-01-04 10:26:59 +01:00
aligned_buffer.h Update copyright years. 2021-01-04 10:26:59 +01:00
alloc_traits.h Update copyright years. 2021-01-04 10:26:59 +01:00
atomicity.h Update copyright years. 2021-01-04 10:26:59 +01:00
bitmap_allocator.h Update copyright years. 2021-01-04 10:26:59 +01:00
cast.h Update copyright years. 2021-01-04 10:26:59 +01:00
cmath Update copyright years. 2021-01-04 10:26:59 +01:00
codecvt_specializations.h Update copyright years. 2021-01-04 10:26:59 +01:00
concurrence.h Update copyright years. 2021-01-04 10:26:59 +01:00
debug_allocator.h Update copyright years. 2021-01-04 10:26:59 +01:00
enc_filebuf.h Update copyright years. 2021-01-04 10:26:59 +01:00
extptr_allocator.h libstdc++: Fix std::allocator<void> for versioned namespace 2021-08-28 14:37:19 +01:00
functional Update copyright years. 2021-01-04 10:26:59 +01:00
iterator Update copyright years. 2021-01-04 10:26:59 +01:00
malloc_allocator.h libstdc++: Fix missing members in std::allocator<void> 2021-05-11 16:11:01 +01:00
memory Update copyright years. 2021-01-04 10:26:59 +01:00
mt_allocator.h Update copyright years. 2021-01-04 10:26:59 +01:00
new_allocator.h libstdc++: Use __builtin_operator_new when available [PR94295] 2021-07-22 14:38:34 +01:00
numeric Update copyright years. 2021-01-04 10:26:59 +01:00
numeric_traits.h libstdc++: Use __extension__ instead of diagnostic pragmas 2021-07-16 15:03:03 +01:00
pod_char_traits.h Update copyright years. 2021-01-04 10:26:59 +01:00
pointer.h Update copyright years. 2021-01-04 10:26:59 +01:00
pool_allocator.h Update copyright years. 2021-01-04 10:26:59 +01:00
random libstdc++: Fix doxygen markup for group close commands 2021-04-06 16:43:24 +01:00
random.tcc Update copyright years. 2021-01-04 10:26:59 +01:00
rb_tree Update copyright years. 2021-01-04 10:26:59 +01:00
rc_string_base.h libstdc++: Enable vstring for wchar_t unconditionally [PR98725] 2021-10-09 00:57:49 +01:00
rope libstdc++: Remove __gnu_cxx::rope::erase(size_type) [PR102048] 2021-08-25 22:28:46 +01:00
ropeimpl.h Update copyright years. 2021-01-04 10:26:59 +01:00
slist Update copyright years. 2021-01-04 10:26:59 +01:00
sso_string_base.h Update copyright years. 2021-01-04 10:26:59 +01:00
stdio_filebuf.h Update copyright years. 2021-01-04 10:26:59 +01:00
stdio_sync_filebuf.h libstdc++: Fix build failure for targets without unistd.h 2021-02-09 12:31:52 +00:00
string_conversions.h Update copyright years. 2021-01-04 10:26:59 +01:00
throw_allocator.h libstdc++: Improvements to Doxygen markup 2021-07-01 18:45:48 +01:00
type_traits.h libstdc++: Implement constexpr std::basic_string for C++20 2021-11-16 16:43:20 +00:00
typelist.h Update copyright years. 2021-01-04 10:26:59 +01:00
vstring_fwd.h libstdc++: Enable vstring for wchar_t unconditionally [PR98725] 2021-10-09 00:57:49 +01:00
vstring_util.h Update copyright years. 2021-01-04 10:26:59 +01:00
vstring.h libstdc++: Begin lifetime of chars in constexpr std::string [PR103295] 2021-11-19 18:15:15 +00:00
vstring.tcc Update copyright years. 2021-01-04 10:26:59 +01:00