Commit Graph

13014 Commits

Author SHA1 Message Date
GCC Administrator 40fa651e60 Daily bump. 2021-12-02 00:16:33 +00:00
Jonathan Wakely 056551414a libstdc++: Clear RB tree after moving elements [PR103501]
If the allocator-extended move constructor move-constructs each element
into the new container, the contents of the old container are left in
moved-from states. We cannot know if those states preserve the
container's ordering and uniqueness guarantees, so just erase all
moved-from elements.

libstdc++-v3/ChangeLog:

	PR libstdc++/103501
	* include/bits/stl_tree.h (_Rb_tree(_Rb_tree&&, false_type)):
	Clear container if elements have been moved-from.
	* testsuite/23_containers/map/allocator/move_cons.cc: Expect
	moved-from container to be empty.
	* testsuite/23_containers/multimap/allocator/move_cons.cc:
	Likewise.
	* testsuite/23_containers/multiset/allocator/103501.cc: New test.
	* testsuite/23_containers/set/allocator/103501.cc: New test.
2021-12-01 15:00:33 +00:00
Jonathan Wakely 74d14778e7 libstdc++: Define std::__is_constant_evaluated() for internal use
This adds std::__is_constant_evaluated() as a C++11 wrapper for
__builtin_is_constant_evaluated, but just returning false if the
built-in isn't supported by the compiler. This allows us to use it
throughout the library without checking __has_builtin every time.

Some uses in std::vector and std::string can only be constexpr when the
std::is_constant_evaluated() function actually works, so we might as
well guard them with a relevant macro and call that function directly,
rather than the built-in or std::__is_constant_evaluated().

The remaining checks of the __cpp_lib_is_constant_evaluated macro could
now be replaced by checking __cplusplus >= 202002 instead, but there's
no practical difference. We still need some kind of preprocessor check
there anyway.

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in (PREDEFINED): Change macro name.
	* include/bits/allocator.h (allocate, deallocate): Use
	std::__is_constant_evaluated() unconditionally, instead of
	checking whether std::is_constant_evaluated() (or the built-in)
	can be used.
	* include/bits/basic_string.h: Check new macro. call
	std::is_constant_evaluated() directly in C++20-only code that is
	guarded by a suitable macro.
	* include/bits/basic_string.tcc: Likewise.
	* include/bits/c++config (__is_constant_evaluated): Define.
	(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Replace with ...
	(_GLIBCXX_HAVE_IS_CONSTANT_EVALUATED): New macro.
	* include/bits/char_traits.h (char_traits): Replace conditional
	calls to std::is_constant_evaluated with unconditional calls to
	std::__is_constant_evaluated.
	* include/bits/cow_string.h: Use new macro.
	* include/bits/ranges_algobase.h (__copy_or_move): Replace
	conditional calls to std::is_constant_evaluated with unconditional
	calls to std::__is_constant_evaluated.
	(__copy_or_move_backward, __fill_n_fn): Likewise.
	* include/bits/ranges_cmp.h (ranges::less): Likewise.
	* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Likewise.
	* include/bits/stl_bvector.h: Call std::is_constant_evaluated
	directly in C++20-only code that is guarded by a suitable macro.
	* include/bits/stl_construct.h (_Construct, _Destroy, _Destroy_n):
	Replace is_constant_evaluated with __is_constant_evaluated.
	* include/bits/stl_function.h (greater, less, greater_equal)
	(less_equal): Replace __builtin_is_constant_evaluated and
	__builtin_constant_p with __is_constant_evaluated.
	* include/bits/stl_vector.h: Call std::is_constant_evaluated()
	in C++20-only code.
	* include/debug/helper_functions.h (__check_singular): Use
	__is_constant_evaluated instead of built-in, or remove check
	entirely.
	* include/std/array (operator<=>): Use __is_constant_evaluated
	unconditionally.
	* include/std/bit (__bit_ceil): Likewise.
	* include/std/type_traits (is_constant_evaluated): Define using
	'if consteval' if possible.
	* include/std/version: Use new macro.
	* libsupc++/compare: Use __is_constant_evaluated instead of
	__builtin_is_constant_evaluated.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error lines.
2021-12-01 15:00:33 +00:00
Jonathan Wakely 2b83bc6097 libstdc++: Optimize ref-count updates in COW std::string
Most ref-count updates in the COW string are done via the functions in
<ext/atomicity.h>, which will use non-atomic ops when the program is
known to be single-threaded. The _M_is_leaked() and _M_is_shared()
functions use __atomic_load_n directly, because <ext/atomicity.h>
doesn't provide a load operation. Those functions can check the
__is_single_threaded() predicate to avoid using __atomic_load_n when not
needed.

The move constructor for the fully-dynamic-string increments the
ref-count by either 2 or 1, for leaked or non-leaked strings
respectively. That can be changed to use a non-atomic store of 1 for all
non-shared strings. It can be non-atomic because even if the program is
multi-threaded, conflicting access to the rvalue object while it's being
moved from would be data race anyway. It can store 1 directly for all
non-shared strings because it doesn't matter whether the initial
refcount was -1 or 0, it should be 1 after the move constructor creates
a second owner.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_is_leaked): Use
	non-atomic load when __is_single_threaded() is true.
	(basic_string::_M_is_shared): Likewise.
	(basic_string::(basic_string&&)) [_GLIBCXX_FULLY_DYNAMIC_STRING]:
	Use non-atomic store when rvalue is not shared.
2021-12-01 15:00:33 +00:00
Jonathan Wakely e9089e4fa9 libstdc++: Avoid unwanted allocations in filesystem::path
When using COW strings, accessing _M_pathname[0] and similar non-const
accessors can cause the string to "leak", meaning it reallocates itself
if it shares ownership with another string object.

This causes test failures for --enable-fully-dynamic-string builds:
/home/jwakely/src/gcc/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90634.cc:62: void test01(): Assertion 'bytes_allocated == 0' failed.
FAIL: experimental/filesystem/path/construct/90634.cc execution test

This FAIL happens because the fully-dynamic move constructor results in
shared ownership, so for path(std::move(std::string("foo"))) the
_M_pathname member shares ownership with the temporary, and the
non-const accesses in _M_split_cmpts() cause a new copy of the string to
be allocated. This un-sharing is wasteful, and entirely unnecessary when
sharing ownership with an rvalue that is about to release its ownership
anyway. Even for lvalues, sharing ownership is not a problem and
reallocating a unique copy of the string is wasteful.

This removes non-const accesses of _M_pathname in the
path::_M_split_cmpts() members.

libstdc++-v3/ChangeLog:

	* src/c++17/fs_path.cc (path::_M_split_cmpts()): Remove
	micro-optimization for "/" path.
	* src/filesystem/path.cc (path::_M_split_cmpts()): Only access
	the contents of _M_pathname using const member functions.
2021-12-01 15:00:32 +00:00
GCC Administrator c177e80609 Daily bump. 2021-12-01 00:17:04 +00:00
Jonathan Wakely be30fc4ce0 libstdc++: Fix tests that fail with fully-dynamic-string
Fix some tests that assume that a moved-from string is empty, or that
default constructing a string doesn't allocate.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/cons/char/moveable.cc: Allow
	moved-from string to be non-empty.
	* testsuite/21_strings/basic_string/cons/char/moveable2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/moveable2_c++17.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable2_c++17.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/87749.cc:
	Construct empty string before setting oom flag.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/87749.cc:
	Likewise.
2021-11-30 23:10:04 +00:00
Jonathan Wakely 675afa2124 libstdc++: Fix fully-dynamic-string build
My last change to the fully-dynamic-string actually broke it. This fixes
the move constructor so it builds, and simplifies it slightly so that
more code is common between the fully-dynamic enabled/disabled cases.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string(basic_string&&)): Fix
	mem-initializer for _GLIBCXX_FULLY_DYNAMIC_STRING==0 case.
	* testsuite/21_strings/basic_string/cons/char/noexcept_move_construct.cc:
	Remove outdated comment.
	* testsuite/21_strings/basic_string/cons/wchar_t/noexcept_move_construct.cc:
	Likewise.
2021-11-30 23:10:03 +00:00
Jonathan Wakely 56b07badf0 libstdc++: Ensure C++20 std::stringstream definitions use correct ABI
The definitions of the new C++20 members of std::stringstream etc are
missing when --with-default-libstdcxx-abi=gcc4-compatible is used,
because all the explicit instantiations in src/c++20/sstream-inst.cc are
skipped.

This ensures the contents of that file are compiled with the new ABI, so
the same set of symbols are exported regardless of which ABI is active
by default.

libstdc++-v3/ChangeLog:

	* src/c++20/sstream-inst.cc (_GLIBCXX_USE_CXX11_ABI): Define to
	select new ABI.
2021-11-30 23:10:03 +00:00
Jonathan Wakely 91c2600403 libstdc++: Skip tag dispatching for _S_relocate in C++17
In C++17 mode all callers of _S_relocate have already done:

  if constexpr (_S_use_relocate())

so we don't need to repeat that check and use tag dispatching to avoid
ill-formed instantiations.

libstdc++-v3/ChangeLog:

	* include/bits/stl_vector.h (vector::_S_do_relocate): Remove
	C++20 constexpr specifier.
	(vector::_S_relocate) [__cpp_if_constexpr]: Call __relocate_a
	directly without tag dispatching.
2021-11-30 20:10:19 +00:00
Jonathan Wakely cca6090b13 libstdc++: Make Asan detection work for Clang [PR103453]
Clang doesn't define __SANITIZE_ADDRESS__ so use its __has_feature check
to detect Asan instead.

libstdc++-v3/ChangeLog:

	PR libstdc++/103453
	* config/allocator/malloc_allocator_base.h
	(_GLIBCXX_SANITIZE_STD_ALLOCATOR): Define for Clang.
	* config/allocator/new_allocator_base.h
	(_GLIBCXX_SANITIZE_STD_ALLOCATOR): Likewise.
2021-11-30 20:10:19 +00:00
Jonathan Wakely 67013a2f71 libstdc++: Use gender-agnostic pronoun in docs
libstdc++-v3/ChangeLog:

	* doc/xml/manual/debug_mode.xml: Replace "his or her" with "they".
	* doc/html/manual/debug_mode_design.html: Regenerate.
2021-11-30 13:08:50 +00:00
Jakub Jelinek 92084a6dcd libstdc++: Add [[nodiscard]] to std::byteswap
This patch adds [[nodiscard]] to std::byteswap, because the function
template doesn't do anything useful if the result isn't used.

2021-11-30  Jakub Jelinek  <jakub@redhat.com>

	* include/std/bit (byteswap): Add [[nodiscard]].
2021-11-30 13:30:27 +01:00
GCC Administrator 2f0dd172bc Daily bump. 2021-11-29 00:16:16 +00:00
Jakub Jelinek 7393fa8b1d libstdc++: Implement std::byteswap for C++23
This patch attempts to implement P1272R4 (except for the std::bit_cast
changes in there which seem quite unrelated to this and will need to be
fixed on the compiler side).
While at least for GCC __builtin_bswap{16,32,64,128} should work fine
in constant expressions, I wonder about other compilers, so I'm using
a fallback implementation for constexpr evaluation always.
If you think that is unnecessary, I can drop the
__cpp_if_consteval >= 202106L &&
if !consteval
  {
and
  }
and reformat.
The fallback implementation is an attempt to make it work even for integral
types that don't have number of bytes divisible by 2 or when __CHAR_BIT__
is e.g. 16.

2021-11-28  Jakub Jelinek  <jakub@redhat.com>

	* include/std/bit (__cpp_lib_byteswap, byteswap): Define.
	* include/std/version (__cpp_lib_byteswap): Define.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: New test.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: New test.
2021-11-28 16:33:33 +01:00
GCC Administrator f4ed2e3ae7 Daily bump. 2021-11-27 00:16:19 +00:00
Jonathan Wakely 52b769437a libstdc++: Fix test that fails in C++20 mode
This test was written to verify that the LWG 3265 changes work. But
those changes were superseded by LWG 3435, and the test is now incorrect
according to the current draft. The assignment operator is now
constrained to also require convertibility, which makes the test fail.

Change the Iter type to be convertible from int*, but make it throw an
exception if that conversion is used. Change the test from compile-only
to run, so we verify that the exception isn't thrown.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/move_iterator/dr3265.cc: Fix test to
	account for LWG 3435 resolution.
2021-11-26 22:56:51 +00:00
Jonathan Wakely 33adfd0d42 libstdc++: Fix trivial relocation for constexpr std::vector
When implementing constexpr std::vector I added a check for constant
evaluation in vector::_S_use_relocate(), so that we would not try to relocate
trivial objects by using memmove. But I put it in the constexpr function
that decides whether to relocate or not, and calls to that function are
always constant evaluated. This had the effect of disabling relocation
entirely, even in non-constexpr vectors.

This removes the check in _S_use_relocate() and modifies the actual
relocation algorithm, __relocate_a_1, to use the non-trivial
implementation instead of memmove when called during constant
evaluation.

libstdc++-v3/ChangeLog:

	* include/bits/stl_uninitialized.h (__relocate_a_1): Do not use
	memmove during constant evaluation.
	* include/bits/stl_vector.h (vector::_S_use_relocate()): Do not
	check is_constant_evaluated in always-constexpr function.
2021-11-26 22:28:48 +00:00
Jonathan Wakely 76c6be48b7 libstdc++: Remove workaround for FE bug in std::tuple [PR96592]
The FE bug was fixed, so we don't need this workaround now.

libstdc++-v3/ChangeLog:

	PR libstdc++/96592
	* include/std/tuple (tuple::is_constructible): Remove.
2021-11-26 22:26:08 +00:00
Jonathan Wakely 665f726b8a libstdc++: Ensure dg-add-options comes after dg-options
This is what the docs say is required.

libstdc++-v3/ChangeLog:

	* testsuite/29_atomics/atomic_float/1.cc: Reorder directives.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 0a12bd92d1 libstdc++: Fix dg-do directive for tests supposed to be run
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/unordered_map/modifiers/move_assign.cc:
	Change dg-do compile to run.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499.cc:
	Likewise.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 1ecc9ba578 libstdc++: Remove redundant xfail selectors in dg-do compile tests
An 'xfail' selector means the test is expected to fail at runtime, so is
ignored for a compile-only test. The way to mark a compile-only test as
failing is with dg-error (which these already do).

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
	Remove xfail selector.
	* testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc:
	Likewise.
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc:
	Likewise.
	* testsuite/23_containers/span/101411.cc: Likewise.
	* testsuite/25_algorithms/copy/debug/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/copy_backward/debug/constexpr_neg.cc:
	Likewise.
	* testsuite/25_algorithms/equal/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/equal/debug/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc:
	Likewise.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 0178b73a02 libstdc++: Move std::to_address tests to more appropriate place
Some of the checks in 20_util/pointer_traits/lwg3545.cc really belong in
20_util/to_address/lwg3545 instead.

This also fixes the ordering of the dg-options and dg-do directives.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/pointer_traits/lwg3545.cc: Move to_address
	tests to ...
	* testsuite/20_util/to_address/lwg3545.cc: ... here. Add -std
	option before checking effective target.
2021-11-26 12:38:35 +00:00
GCC Administrator 091ccc066d Daily bump. 2021-11-26 00:16:26 +00:00
Jonathan Wakely 9664c46545 libstdc++: Remove dg-error that no longer happens
There was a c++11_only dg-error in this testcase, for a "body of
constexpr function is not a return statement" diagnostic that was bogus,
but happened because the return statement was ill-formed. A change to
G++ earlier this month means that diagnostic is no longer emitted, so
remove the dg-error.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/tuple/comparison_operators/overloaded2.cc:
	Remove dg-error for C++11_only error.
2021-11-25 23:12:15 +00:00
Jonathan Wakely b8018e5c5e libstdc++: Make std::pointer_traits SFINAE-friendly [PR96416]
This implements the resolution I'm proposing for LWG 3545, to avoid hard
errors when using std::to_address for types that make pointer_traits
ill-formed.

Consistent with std::iterator_traits, instantiating std::pointer_traits
for a non-pointer type will be well-formed, but give an empty type with
no member types. This avoids the problematic cases for std::to_address.
Additionally, the pointer_to member is now only declared when the
element type is not cv void (and for C++20, when the function body would
be well-formed). The rebind member was already SFINAE-friendly in our
implementation.

libstdc++-v3/ChangeLog:

	PR libstdc++/96416
	* include/bits/ptr_traits.h (pointer_traits): Reimplement to be
	SFINAE-friendly (LWG 3545).
	* testsuite/20_util/pointer_traits/lwg3545.cc: New test.
	* testsuite/20_util/to_address/1_neg.cc: Adjust dg-error line.
	* testsuite/20_util/to_address/lwg3545.cc: New test.
2021-11-25 23:12:14 +00:00
Jonathan Wakely 82c3657dd7 libstdc++: Do not use memset in constexpr calls to ranges::fill_n [PR101608]
libstdc++-v3/ChangeLog:

	PR libstdc++/101608
	* include/bits/ranges_algobase.h (__fill_n_fn): Check for
	constant evaluation before using memset.
	* testsuite/25_algorithms/fill_n/constrained.cc: Check
	byte-sized values as well.
2021-11-25 20:03:13 +00:00
GCC Administrator d9ca4b45bd Daily bump. 2021-11-25 00:16:29 +00:00
Jonathan Wakely 3b2337831a libstdc++: Add xfail to some printer tests for debug mode
The type printers are not substituting std::string for
std::basic_string<char> in debug mode, mark some tests as xfail.

libstdc++-v3/ChangeLog:

	* testsuite/libstdc++-prettyprinters/80276.cc: Add xfail for
	debug mode.
	* testsuite/libstdc++-prettyprinters/libfundts.cc: Likewise.
2021-11-24 13:20:26 +00:00
Jonathan Wakely a04b73e15b libstdc++: Replace hyphens in effective target keywords
An effective target like foo-bar-baz will match a target selector of
*-*-* and cause problems in the testsuite. Several libstdc++ et keywords
are of the form foo-bar, which could still be a problem for *-*
selectors.

Replace hyphens with underscores in the et keywords "debug-mode",
"cxx11-abi", etc.

libstdc++-v3/ChangeLog:

	* testsuite/lib/libstdc++.exp: Rename effective target keywords
	to avoid dashes in the name.
	* testsuite/*: Update effective targe keywords.
2021-11-24 13:20:26 +00:00
GCC Administrator e1d4359264 Daily bump. 2021-11-24 00:16:29 +00:00
Jonathan Wakely c59ec55c34 libstdc++: Add another testcase for std::unique_ptr printer [PR103086]
libstdc++-v3/ChangeLog:

	PR libstdc++/103086
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Check unique_ptr
	with non-empty pointer and non-empty deleter.
2021-11-23 21:39:46 +00:00
Jonathan Wakely 39de0e5411 libstdc++: Add effective-target for std::allocator implementation
This allows tests to be skipped if the std::allocator implementation is
not __gnu_cxx::new_allocator.

The 20_util/allocator/overaligned.cc test requires either C++17 or
new_allocator, otherwise we can't guarantee to return overaligned
memory.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/50594.cc: Check effective target.
	* testsuite/20_util/allocator/1.cc: Likewise.
	* testsuite/20_util/allocator/overaligned.cc: Likewise.
	* testsuite/23_containers/unordered_map/96088.cc: Likewise.
	* testsuite/23_containers/unordered_multimap/96088.cc: Likewise.
	* testsuite/23_containers/unordered_multiset/96088.cc: Likewise.
	* testsuite/23_containers/unordered_set/96088.cc: Likewise.
	* testsuite/ext/throw_allocator/check_delete.cc: Likewise.
	* testsuite/ext/throw_allocator/check_new.cc: Likewise.
	* testsuite/lib/libstdc++.exp (check_effective_target_std_allocator_new):
	Define new proc.
2021-11-23 21:23:24 +00:00
Jonathan Wakely 5459fa132a libstdc++: Fix circular dependency for bitmap_allocator [PR103381]
<ext/bitmap_allocator.h> includes <function>, and since C++17 that
includes <unordered_map>. If std::allocator is defined in terms of
__gnu_cxx::bitmap_allocator then you get a circular reference and
bootstrap fails when compiling src/c++17/*.cc.

libstdc++-v3/ChangeLog:

	PR libstdc++/103381
	* include/ext/bitmap_allocator.h: Include <bits/stl_function.h>
	instead of <functional>.
2021-11-23 12:30:57 +00:00
GCC Administrator 06be28f64a Daily bump. 2021-11-23 00:16:27 +00:00
Jonathan Wakely d7376862b6 libstdc++: Fix condition for definition of _GLIBCXX14_DEPRECATED
The check for C++14 was using the wrong date.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX14_DEPRECATED): Fix condition
	checking for C++14.
2021-11-22 14:57:17 +00:00
GCC Administrator f658f1d7a2 Daily bump. 2021-11-21 00:16:32 +00:00
François Dumont 5f40d34b6d libstdc++: [_GLIBCXX_DEBUG] Reduce performance impact on std::erase_if
Bypass the _GLIBCXX_DEBUG additional checks in std::__detail::__erase_node_if used
by all implementations of std::erase_if for node based containers.

libstdc++-v3/ChangeLog:

	* include/bits/erase_if.h (__erase_nodes_if): Add _UnsafeContainer template
	parameter. Use it to get iterators to work with.
	* include/debug/macros.h (__glibcxx_check_erase2): New.
	* include/debug/map.h (map<>::erase(_Base_const_iterator)): New.
	(map<>::erase(const_iterator)): Use latter.
	* include/debug/multimap.h (multimap<>::erase(_Base_const_iterator)): New.
	(multimap<>::erase(const_iterator)): Use latter.
	* include/debug/multiset.h (multiset<>::erase(_Base_const_iterator)): New.
	(multiset<>::erase(const_iterator)): Use latter.
	* include/debug/set.h (set<>::erase(_Base_const_iterator)): New.
	(set<>::erase(const_iterator)): Use latter.
	* include/debug/unordered_map (unordered_map<>::erase(_Base_const_iterator)): New.
	(unordered_multimap<>::erase(const_iterator)): New.
	* include/debug/unordered_set (unordered_set<>::erase(_Base_const_iterator)): New.
	(unordered_multiset<>::erase(const_iterator)): New.
	* include/experimental/map (erase_if): Adapt.
	* include/experimental/set (erase_if): Adapt.
	* include/experimental/unordered_map (erase_if): Adapt.
	* include/experimental/unordered_set (erase_if): Adapt.
	* include/std/map (erase_if): Adapt.
	* include/std/set (erase_if): Adapt.
	* include/std/unordered_map (erase_if): Adapt.
	* include/std/unordered_set (erase_if): Adapt.
2021-11-20 16:11:22 +01:00
GCC Administrator 9c0773984c Daily bump. 2021-11-20 00:16:35 +00:00
Jonathan Wakely be08d57317 libstdc++: Improve tests for stringstream constructors in C++20
This ensures all constructors are checked.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Check all
	constructors.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc:
	Likewise.
2021-11-19 20:23:50 +00:00
Jonathan Wakely 5faf1c8c7a libstdc++: Use __is_single_threaded in locale initialization
This replaces a __gthread_active_p() check with __is_single_threaded()
so that std::locale initialization doesn't use __gthread_once if it
happens before the first thread is created.

This means that _S_initialize_once() might now be called twice instead
of only once, because if __is_single_threaded() changes to false then we
will do the __gthread_once call even if _S_initialize_once() was already
called. Add a check to _S_initialize_once() and return immediately if
it is the second call.

Also use __builtin_expect to _S_initialize, as the branch will be taken
at most once in the lifetime of the program.

libstdc++-v3/ChangeLog:

	* src/c++98/locale_init.cc (_S_initialize_once): Check if
	initialization has already been done.
	(_S_initialize): Replace __gthread_active_p with
	__is_single_threaded. Use __builtin_expect.
2021-11-19 20:22:52 +00:00
Jonathan Wakely 1f8d01eb14 libstdc++: One more change for Clang to support constexpr std::string [PR103295]
All writes into the allocated buffer need to be via traits_type::assign
to begin lifetimes.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.tcc (_M_construct): Use the
	traits assign member to write into allcoated memory.
2021-11-19 20:17:52 +00:00
Iain Sandoe c7b782d847 libstdc++, testsuite: Add a prune expression for external tool bug.
Depending on the permutation of CPU, OS version and shared/non-
shared library inclusion, we get can get warnings from the external
tools (ld64, dsymutil) which are not actually libstdc++ issues but
relate to the external tools themselves.  This is already pruned
in the main testsuite, this adds it to the library.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libstdc++-v3/ChangeLog:

	* testsuite/lib/prune.exp: Prune dsymutil (ld64) warning.
2021-11-19 19:52:03 +00:00
Jonathan Wakely b8f2efaed0 libstdc++: Suppress -Wstringop warnings [PR103332]
libstdc++-v3/ChangeLog:

	PR libstdc++/103332
	PR libstdc++/102958
	* testsuite/21_strings/basic_string/capacity/char/1.cc: Add
	-Wno-stringop-overflow.
	* testsuite/21_strings/basic_string/operators/char/1.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/factory/u8path-char8_t.cc:
	Add -Wno-stringop-overread.
2021-11-19 18:15:52 +00:00
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
Tamar Christina 0e510ab534 libstdc++: Fix ctype changed after newlib update.
Newlib changed ctype.h recently[1] by moving the short labels from ctype.h intro
the private namespace in ctype_.h.  This broke embedded builds due to them no
longer being found.  Instead they now expose the long names to match glibc.

This patch now uses the short or long names depending on is the short ones are
defined or not.

[1] 3ba1bd0d9d

libstdc++-v3/ChangeLog:

	PR libstdc++/103305
	* config/os/newlib/ctype_base.h (upper, lower, alpha, digit, xdigit,
	space, print, graph, cntrl, punct, alnum, blank): Use short or long
	names depending on if short ones are defined.
2021-11-19 08:48:11 +00:00
GCC Administrator 483092d3d9 Daily bump. 2021-11-19 00:16:34 +00:00
Jonathan Wakely ca243ada71 libstdc++: Fix std::char_traits<C>::move for constexpr
The constexpr branch in __gnu_cxx::char_traits::move compares the string
arguments to see if they overlap, but relational comparisons between
unrelated pointers are not core constant expressions.

I want to replace the comparisons with a loop using pointer equality to
determine whether the end of the source string is in the destination
string. However, that doesn't work with GCC, due to PR c++/89074 so
allocate a temporary buffer instead and copy out into that first, so
that overlapping source and destination don't matter. The allocation
isn't supported by the current Intel icc so use the loop as a fallback.

libstdc++-v3/ChangeLog:

	* include/bits/char_traits.h (__gnu_cxx::char_traits::move):
	Do not compare unrelated pointers during constant evaluation.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
	Improve tests for char_traits::move.
2021-11-18 16:14:15 +00:00
Jonathan Wakely 9646a3229b libstdc++: Replace AC_CACHE_VAL with AC_CACHE_CHECK
This replaces most uses of AC_CACHE_VAL with AC_CACHE_CHECK, which means
we don't need separate AC_MSG_CHECKING and AC_MSG_RESULT macros.

There are a few trivial bugs fixed as a side effect, where an
AC_MSG_RESULT was printed out even if the actual checks hadn't been
done. That didn't affect the results, only the content of config.log.

libstdc++-v3/ChangeLog:

	* acinclude.m4: Replace AC_CACHE_VAL with AC_CACHE_CHECK.
	* configure: Regenerate.
2021-11-18 13:56:33 +00:00
GCC Administrator 280d2838c1 Daily bump. 2021-11-18 00:16:34 +00:00