Commit Graph

12979 Commits

Author SHA1 Message Date
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
Jonathan Wakely 0e4a8656e8 libstdc++: Fix author name in ChangeLog
The constexpr std::string commit was my own work, but the commit still
had the author name from an earlier cherry-pick that eventually got
entirely reverted. This fixes the name in the ChangeLog file.
2021-11-17 22:41:49 +00:00
Jonathan Wakely 5ea8803e65 libstdc++: Use std::construct_at in net::ip::address
Using placement-new isn't valid in constant expressions, so this
replaces it with std::construct_at (via the std::_Construct function
that is usable before C++20).

libstdc++-v3/ChangeLog:

	* include/experimental/internet (address): Use std::_Construct
	to initialize union members.
2021-11-17 17:28:52 +00:00
Jonathan Wakely 5a9572e486 libstdc++: Simplify std::string constructors
Several std::basic_string constructors dispatch to one of the
two-argument overloads of _M_construct, which then dispatches again to
_M_construct_aux to detect whether the arguments are iterators or not.
That then dispatches to one of _M_construct(size_type, char_type) or
_M_construct(Iter, Iter, iterator_traits<Iter>::iterator_category{}).

For most of those constructors this is a waste of time, because we know
the arguments are already iterators. For basic_string(const CharT*) and
basic_string(initializer_list<C>) we know that we call _M_construct with
two pointers, and for basic_string(const basic_string&) we call it with
two const_iterators.  Those constructors can call the three-argument
overload of _M_construct with the iterator category tag right away,
without the intermediate dispatching.

The case where this doesn't apply is basic_string(InputIter, InputIter),
but for C++11 and later this is constrained so we know it's an iterator
here as well. We can restrict the dispatching in this constructor to
only be done for C++98 and to call _M_construct_aux directly, which
allows us to remove the two-argument _M_construct(InputIter, InputIter)
overload entirely.

N.B. When calling the three-arg _M_construct with pointers or string
iterators, we pass forward_iterator_tag not random_access_iterator_tag.
This is because it makes no difference which overload gets called, and
simplifies overload resolution to not have to do a base-to-derived
check. If we ever add a new overload of M_construct for random access
iterators we would have to revisit this, but that seems unlikely.

This patch also moves the __is_null_pointer checks from the three-arg
_M_construct into the constructors where a null pointer argument is
actually possible. This avoids redundant checks where we know we have a
non-null pointer, or don't have a pointer at all.

Finally, this patch replaces some try-blocks with an RAII type, so that
memory is deallocated during unwinding. This avoids the overhead of
catching and rethrowing an exception.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (_M_construct_aux): Only define
	for C++98. Remove constexpr.
	(_M_construct_aux_2): Likewise.
	(_M_construct(InputIter, InputIter)): Remove.
	(basic_string(const basic_string&)): Call _M_construct with
	iterator category argument.
	(basic_string(const basic_string&, size_type, const Alloc&)):
	Likewise.
	(basic_string(const basic_string&, size_type, size_type)):
	Likewise.
	(basic_string(const charT*, size_type, const Alloc&)): Likewise.
	Check for null pointer.
	(basic_string(const charT*, const Alloc&)): Likewise.
	(basic_string(initializer_list<charT>, const Alloc&)): Call
	_M_construct with iterator category argument.
	(basic_string(const basic_string&, const Alloc&)): Likewise.
	(basic_string(basic_string&&, const Alloc&)): Likewise.
	(basic_string(_InputIter, _InputIter, const Alloc&)): Likewise
	for C++11 and later, call _M_construct_aux for C++98.
	* include/bits/basic_string.tcc
	(_M_construct(I, I, input_iterator_tag)): Replace try-block with
	RAII type.
	(_M_construct(I, I, forward_iterator_tag)): Likewise. Remove
	__is_null_pointer check.
2021-11-17 17:28:44 +00:00
Jonathan Wakely 6afa1083c6 libstdc++: Set active member of union in std::string [PR103295]
Clang diagnoses that the new constexpr std::string constructors are not
usable in constant expressions, because they start to write to members
of the union without setting an active member.

This adds a new helper function which returns the address of the local
buffer after making it the active member.

This doesn't fix all problems with Clang, because it still refuses to
write to memory returned by the allocator.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.h (_M_use_local_data()): New
	member function to make local buffer the active member.
	(assign(const basic_string&)): Use it.
	* include/bits/basic_string.tcc (_M_construct, reserve()):
	Likewise.
2021-11-17 17:21:25 +00:00
Jonathan Wakely 054bf99841 libstdc++: Fix std::type_info::before for ARM [PR103240]
The r179236 fix for std::type_info::operator== should also have been
applied to std::type_info::before. Otherwise two distinct types can
compare equivalent due to using a string comparison, when they should do
a pointer comparison.

libstdc++-v3/ChangeLog:

	PR libstdc++/103240
	* libsupc++/tinfo2.cc (type_info::before): Use unadjusted name
	to check for the '*' prefix.
	* testsuite/util/testsuite_shared.cc: Add type_info object for
	use in new test.
	* testsuite/18_support/type_info/103240.cc: New test.
2021-11-17 17:21:24 +00:00
GCC Administrator 6b1695f4a0 Daily bump. 2021-11-17 00:16:29 +00:00
Jonathan Wakely 73e4d9f175 libstdc++: Fix tests for constexpr std::string
Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (operator<=>): Use constexpr
	unconditionally.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc:
	Require cxx11-abit effective target.
	* testsuite/21_strings/headers/string/synopsis.cc: Add
	conditional constexpr to declarations, and adjust relational
	operators for C++20.
2021-11-16 22:48:15 +00:00
Patrick Palka 7461b58131 libstdc++: Merge latest Ryu sources
libstdc++-v3/ChangeLog:

	* src/c++17/ryu/MERGE: Update the commit hash.
	* src/c++17/ryu/d2s_intrinsics.h: Merge from Ryu's master
	branch.

Signed-off-by: Patrick Palka <ppalka@redhat.com>
2021-11-16 12:23:27 -05:00
Michael de Lang b96e2ff9d8 libstdc++: Implement constexpr std::basic_string for C++20
This is only supported for the cxx11 ABI, not for COW strings.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string, operator""s): Add
	constexpr for C++20.
	(basic_string::basic_string(basic_string&&)): Only copy
	initialized portion of the buffer.
	(basic_string::basic_string(basic_string&&, const Alloc&)):
	Likewise.
	* include/bits/basic_string.tcc (basic_string): Add constexpr
	for C++20.
	(basic_string::swap(basic_string&)): Only copy initialized
	portions of the buffers.
	(basic_string::_M_replace): Add constexpr implementation that
	doesn't depend on pointer comparisons.
	* include/bits/cow_string.h: Adjust comment.
	* include/ext/type_traits.h (__is_null_pointer): Add constexpr.
	* include/std/string (erase, erase_if): Add constexpr.
	* include/std/version (__cpp_lib_constexpr_string): Update
	value.
	* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/literals/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc: New test.
	* testsuite/21_strings/basic_string/modifiers/swap/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/swap/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/version.cc: New test.
2021-11-16 16:43:20 +00:00
Jonathan Wakely 59434931fb libstdc++: Use hidden friends for vector<bool>::reference swap overloads
These swap overloads are non-standard, but are needed to make swap work
for vector<bool>::reference rvalues. They don't need to be called
explicitly, only via ADL, so hide them from normal lookup. This is what
I've proposed as the resolution to LWG 3638.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (swap(_Bit_reference, _Bit_reference))
	(swap(_Bit_reference, bool&), swap(bool&, _Bit_reference)):
	Define as hidden friends of _Bit_reference.
2021-11-16 16:42:59 +00:00
Jonathan Wakely 8d8e8f3ad5 libstdc++: Fix out-of-bound array accesses in testsuite
I fixed some undefined behaviour in string tests in r238609, but I only
fixed the narrow char versions. This applies the same fixes to the
wchar_t ones. These problems were found when testing a patch to make
std::basic_string usable in constexpr.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc:
	Fix reads past the end of strings.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/experimental/string_view/operations/compare/wchar_t/1.cc:
	Likewise.
2021-11-16 14:09:00 +00:00
Jonathan Wakely 9719769471 libstdc++: Fix typos in tests
libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/allocator/71964.cc: Fix
	typo.
	* testsuite/23_containers/set/allocator/71964.cc: Likewise.
2021-11-16 14:08:42 +00:00
GCC Administrator e2b57363fc Daily bump. 2021-11-16 00:16:31 +00:00
Jason Merrill 87c2080b05 c++: Add -fimplicit-constexpr
With each successive C++ standard the restrictions on the use of the
constexpr keyword for functions get weaker and weaker; it recently occurred
to me that it is heading toward the same fate as the C register keyword,
which was once useful for optimization but became obsolete.  Similarly, it
seems to me that we should be able to just treat inlines as constexpr
functions and not make people add the extra keyword everywhere.

There were a lot of testcase changes needed; many disabling errors about
non-constexpr functions that are now constexpr, and many disabling implicit
constexpr so that the tests can check the same thing as before, whether
that's mangling or whatever.

gcc/c-family/ChangeLog:

	* c.opt: Add -fimplicit-constexpr.
	* c-cppbuiltin.c: Define __cpp_implicit_constexpr.
	* c-opts.c (c_common_post_options): Disable below C++14.

gcc/cp/ChangeLog:

	* cp-tree.h (struct lang_decl_fn): Add implicit_constexpr.
	(decl_implicit_constexpr_p): New.
	* class.c (type_maybe_constexpr_destructor): Use
	TYPE_HAS_TRIVIAL_DESTRUCTOR and maybe_constexpr_fn.
	(finalize_literal_type_property): Simplify.
	* constexpr.c (is_valid_constexpr_fn): Check for dtor.
	(maybe_save_constexpr_fundef): Try to set DECL_DECLARED_CONSTEXPR_P
	on inlines.
	(cxx_eval_call_expression): Use maybe_constexpr_fn.
	(maybe_constexpr_fn): Handle flag_implicit_constexpr.
	(var_in_maybe_constexpr_fn): Use maybe_constexpr_fn.
	(potential_constant_expression_1): Likewise.
	(decl_implicit_constexpr_p): New.
	* decl.c (validate_constexpr_redeclaration): Allow change with
	-fimplicit-constexpr.
	(grok_special_member_properties): Use maybe_constexpr_fn.
	* error.c (dump_function_decl): Don't print 'constexpr'
	if it's implicit.
	* Make-lang.in (check-c++-all): Update.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/to_address/1_neg.cc: Adjust error.
	* testsuite/26_numerics/random/concept.cc: Adjust asserts.

gcc/testsuite/ChangeLog:

	* lib/g++-dg.exp: Handle "impcx".
	* lib/target-supports.exp
	(check_effective_target_implicit_constexpr): New.
	* g++.dg/abi/abi-tag16.C:
	* g++.dg/abi/abi-tag18a.C:
	* g++.dg/abi/guard4.C:
	* g++.dg/abi/lambda-defarg1.C:
	* g++.dg/abi/mangle26.C:
	* g++.dg/cpp0x/constexpr-diag3.C:
	* g++.dg/cpp0x/constexpr-ex1.C:
	* g++.dg/cpp0x/constexpr-ice5.C:
	* g++.dg/cpp0x/constexpr-incomplete2.C:
	* g++.dg/cpp0x/constexpr-memfn1.C:
	* g++.dg/cpp0x/constexpr-neg3.C:
	* g++.dg/cpp0x/constexpr-specialization.C:
	* g++.dg/cpp0x/inh-ctor19.C:
	* g++.dg/cpp0x/inh-ctor30.C:
	* g++.dg/cpp0x/lambda/lambda-mangle3.C:
	* g++.dg/cpp0x/lambda/lambda-mangle5.C:
	* g++.dg/cpp1y/auto-fn12.C:
	* g++.dg/cpp1y/constexpr-loop5.C:
	* g++.dg/cpp1z/constexpr-lambda7.C:
	* g++.dg/cpp2a/constexpr-dtor3.C:
	* g++.dg/cpp2a/constexpr-new13.C:
	* g++.dg/cpp2a/constinit11.C:
	* g++.dg/cpp2a/constinit12.C:
	* g++.dg/cpp2a/constinit14.C:
	* g++.dg/cpp2a/constinit15.C:
	* g++.dg/cpp2a/spaceship-constexpr1.C:
	* g++.dg/cpp2a/spaceship-eq3.C:
	* g++.dg/cpp2a/udlit-class-nttp-neg2.C:
	* g++.dg/debug/dwarf2/auto1.C:
	* g++.dg/debug/dwarf2/cdtor-1.C:
	* g++.dg/debug/dwarf2/lambda1.C:
	* g++.dg/debug/dwarf2/pr54508.C:
	* g++.dg/debug/dwarf2/pubnames-2.C:
	* g++.dg/debug/dwarf2/pubnames-3.C:
	* g++.dg/ext/is_literal_type3.C:
	* g++.dg/ext/visibility/template7.C:
	* g++.dg/gcov/gcov-12.C:
	* g++.dg/gcov/gcov-2.C:
	* g++.dg/ipa/devirt-35.C:
	* g++.dg/ipa/devirt-36.C:
	* g++.dg/ipa/devirt-37.C:
	* g++.dg/ipa/devirt-44.C:
	* g++.dg/ipa/imm-devirt-1.C:
	* g++.dg/lookup/builtin5.C:
	* g++.dg/lto/inline-crossmodule-1_0.C:
	* g++.dg/modules/enum-1_a.C:
	* g++.dg/modules/fn-inline-1_c.C:
	* g++.dg/modules/pmf-1_b.C:
	* g++.dg/modules/used-1_c.C:
	* g++.dg/tls/thread_local11.C:
	* g++.dg/tls/thread_local11a.C:
	* g++.dg/tm/pr46653.C:
	* g++.dg/ubsan/pr70035.C:
	* g++.old-deja/g++.other/delete6.C:
	* g++.dg/modules/pmf-1_a.H:
	Adjust for implicit constexpr.
2021-11-15 18:50:07 -05:00
François Dumont d10b863fa3 libstdc++: Unordered containers merge re-use hash code
When merging 2 unordered containers with same hasher we can re-use the hash code from
the cache if any.

Also in the context of the merge operation on multi-container use previous insert iterator as a hint
for the next insert.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h:
	(_Hash_code_base<>::_M_hash_code(const _Hash&, const _Hash_node_value<_Value, true>&)): New.
	(_Hash_code_base<>::_M_hash_code<_H2>(const _H2&, const _Hash_node_value<>&)): New.
	* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Use latter.
	(_Hashtable<>::_M_merge_multi): Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/merge.cc (test05): New test.
	* testsuite/23_containers/unordered_set/modifiers/merge.cc (test04): New test.
2021-11-15 18:52:07 +01:00
Jason Merrill 37326651b4 c++: check constexpr constructor body
The implicit constexpr patch revealed that our checks for constexpr
constructors that could possibly produce a constant value (which
otherwise are IFNDR) was failing to look at most of the function body.
Fixing that required some library tweaks.

gcc/cp/ChangeLog:

	* constexpr.c (maybe_save_constexpr_fundef): Also check whether the
	body of a constructor is potentially constant.

libstdc++-v3/ChangeLog:

	* src/c++17/memory_resource.cc: Add missing constexpr.
	* include/experimental/internet: Only mark copy constructor
	as constexpr with __cpp_constexpr_dynamic_alloc.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/constexpr-89285-2.C: Expect error.
	* g++.dg/cpp1y/constexpr-89285.C: Adjust error.
2021-11-15 02:50:45 -05:00
GCC Administrator b85a03ae11 Daily bump. 2021-11-15 00:16:20 +00:00
François Dumont e9a53a4f76 libstdc++: [_GLIBCXX_DEBUG] Remove _Safe_container<>::_M_safe()
_GLIBCXX_DEBUG container code cleanup to get rid of _Safe_container<>::_M_safe() and just
use _Safe:: calls which use normal inheritance. Also remove several usages of _M_base()
which can be most of the time ommitted and sometimes replace with explicit _Base::
calls.

libstdc++-v3/ChangeLog:

	* include/debug/safe_container.h (_Safe_container<>::_M_safe): Remove.
	* include/debug/deque (deque::operator=(initializer_list<>)): Replace
	_M_base() call with _Base:: call.
	(deque::operator[](size_type)): Likewise.
	* include/debug/forward_list (forward_list(forward_list&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(forward_list::operator=(initializer_list<>)): Remove _M_base() calls.
	(forward_list::splice_after, forward_list::merge): Likewise.
	* include/debug/list (list(list&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(list::operator=(initializer_list<>)): Remove _M_base() calls.
	(list::splice, list::merge): Likewise.
	* include/debug/map.h (map(map&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(map::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/multimap.h (multimap(multimap&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(multimap::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/set.h (set(set&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(set::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/multiset.h (multiset(multiset&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(multiset::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/string (basic_string(basic_string&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(basic_string::operator=(initializer_list<>)): Remove _M_base() call.
	(basic_string::operator=(const _CharT*), basic_string::operator=(_CharT)): Likewise.
	(basic_string::operator[](size_type), basic_string::operator+=(const basic_string&)):
	Likewise.
	(basic_string::operator+=(const _Char*), basic_string::operator+=(_CharT)): Likewise.
	* include/debug/unordered_map (unordered_map(unordered_map&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_map::operator=(initializer_list<>), unordered_map::merge):
	Remove _M_base() calls.
	(unordered_multimap(unordered_multimap&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_multimap::operator=(initializer_list<>), unordered_multimap::merge):
	Remove _M_base() calls.
	* include/debug/unordered_set (unordered_set(unordered_set&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_set::operator=(initializer_list<>), unordered_set::merge):
	Remove _M_base() calls.
	(unordered_multiset(unordered_multiset&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_multiset::operator=(initializer_list<>), unordered_multiset::merge):
	Remove _M_base() calls.
	* include/debug/vector (vector(vector&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(vector::operator=(initializer_list<>)): Remove _M_base() calls.
	(vector::operator[](size_type)): Likewise.
2021-11-14 21:55:01 +01:00
GCC Administrator a8029add30 Daily bump. 2021-11-14 00:16:23 +00:00
Jonathan Wakely a30a2e43e4 libstdc++: Implement std::spanstream for C++23
This implements the <spanstream> header, as proposed for C++23 by P0448R4.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add spanstream header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Add spanstream header.
	* include/std/version (__cpp_lib_spanstream): Define.
	* include/std/spanstream: New file.
	* testsuite/27_io/spanstream/1.cc: New test.
	* testsuite/27_io/spanstream/version.cc: New test.
2021-11-13 11:45:31 +00:00
Hans-Peter Nilsson 60f761c7e5 libstdc++: Use GCC_TRY_COMPILE_OR_LINK for getentropy, arc4random
Since r12-5056-g3439657b0286, there has been a regression in
test results; an additional 100 FAILs running the g++ and
libstdc++ testsuite on cris-elf, a newlib target.  The
failures are linker errors, not finding a definition for
getentropy.  It appears newlib has since 2017-12-03
declarations of getentropy and arc4random, and provides an
implementation of arc4random using getentropy, but provides no
definition of getentropy, not even a stub yielding ENOSYS.
This is similar to what it does for many other functions too.

While fixing newlib (like adding said stub) would likely help,
it still leaves older newlib releases hanging.  Thankfully,
the libstdc++ configury test can be improved to try linking
where possible; using the bespoke GCC_TRY_COMPILE_OR_LINK
instead of AC_TRY_COMPILE.  BTW, I see a lack of consistency;
some tests use AC_TRY_COMPILE and some GCC_TRY_COMPILE_OR_LINK
for no apparent reason, but this commit just amends
r12-5056-g3439657b0286.

libstdc++-v3:
	PR libstdc++/103166
	* acinclude.m4 (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM):
	Use GCC_TRY_COMPILE_OR_LINK instead of AC_TRY_COMPILE.
	* configure: Regenerate.
2021-11-13 01:45:06 +01:00
GCC Administrator af2852b9dc Daily bump. 2021-11-13 00:16:39 +00:00
Jonathan Wakely a54ce8865a libstdc++: Print assertion messages to stderr [PR59675]
This replaces the printf used by failed debug assertions with fprintf,
so we can write to stderr.

To avoid including <stdio.h> the assert function is moved into the
library. To avoid programs using a vague linkage definition of the old
inline function, the function is renamed. Code compiled with old
versions of GCC might still call the old function, but code compiled
with the newer GCC will call the new function and write to stderr.

libstdc++-v3/ChangeLog:

	PR libstdc++/59675
	* acinclude.m4 (libtool_VERSION): Bump version.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Add version and
	export new symbol.
	* configure: Regenerate.
	* include/bits/c++config (__replacement_assert): Remove, declare
	__glibcxx_assert_fail instead.
	* src/c++11/debug.cc (__glibcxx_assert_fail): New function to
	replace __replacement_assert, writing to stderr instead of
	stdout.
	* testsuite/util/testsuite_abi.cc: Update latest version.
2021-11-12 12:23:10 +00:00
Jonathan Wakely 1ae8edf5f7 libstdc++: Implement constexpr std::vector for C++20
This implements P1004R2 ("Making std::vector constexpr") for C++20.

For now, debug mode vectors are not supported in constant expressions.
To make that work we might need to disable all attaching/detaching of
safe iterators. That can be fixed later.

Co-authored-by: Josh Marshall <joshua.r.marshall.1991@gmail.com>

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (_Destroy): Make constexpr for
	C++20 mode.
	* include/bits/allocator.h (__shrink_to_fit::_S_do_it):
	Likewise.
	* include/bits/stl_algobase.h (__fill_a1): Declare _Bit_iterator
	overload constexpr for C++20.
	* include/bits/stl_bvector.h (_Bit_type, _S_word_bit): Move out
	of inline namespace.
	(_Bit_reference, _Bit_iterator_base, _Bit_iterator)
	(_Bit_const_iterator, _Bvector_impl_data, _Bvector_base)
	(vector<bool, A>>): Add constexpr to every member function.
	(_Bvector_base::_M_allocate): Initialize storage during constant
	evaluation.
	(vector<bool, A>::_M_initialize_value): Use __fill_bvector_n
	instead of memset.
	(__fill_bvector_n): New helper function to replace memset during
	constant evaluation.
	* include/bits/stl_uninitialized.h (__uninitialized_copy<false>):
	Move logic to ...
	(__do_uninit_copy): New function.
	(__uninitialized_fill<false>): Move logic to ...
	(__do_uninit_fill): New function.
	(__uninitialized_fill_n<false>): Move logic to ...
	(__do_uninit_fill_n): New function.
	(__uninitialized_copy_a): Add constexpr. Use __do_uninit_copy.
	(__uninitialized_move_a, __uninitialized_move_if_noexcept_a):
	Add constexpr.
	(__uninitialized_fill_a): Add constexpr. Use __do_uninit_fill.
	(__uninitialized_fill_n_a): Add constexpr. Use
	__do_uninit_fill_n.
	(__uninitialized_default_n, __uninitialized_default_n_a)
	(__relocate_a_1, __relocate_a): Add constexpr.
	* include/bits/stl_vector.h (_Vector_impl_data, _Vector_impl)
	(_Vector_base, vector): Add constexpr to every member function.
	(_Vector_impl::_S_adjust): Disable ASan annotation during
	constant evaluation.
	(_Vector_base::_S_use_relocate): Disable bitwise-relocation
	during constant evaluation.
	(vector::_Temporary_value): Use a union for storage.
	* include/bits/vector.tcc (vector, vector<bool>): Add constexpr
	to every member function.
	* include/std/vector (erase_if, erase): Add constexpr.
	* testsuite/23_containers/headers/vector/synopsis.cc: Add
	constexpr for C++20 mode.
	* testsuite/23_containers/vector/bool/cmp_c++20.cc: Change to
	compile-only test using constant expressions.
	* testsuite/23_containers/vector/bool/capacity/29134.cc: Adjust
	namespace for _S_word_bit.
	* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc:
	Likewise.
	* testsuite/23_containers/vector/cmp_c++20.cc: Likewise.
	* testsuite/23_containers/vector/cons/89164.cc: Adjust errors
	for C++20 and move C++17 test to ...
	* testsuite/23_containers/vector/cons/89164_c++17.cc: ... here.
	* testsuite/23_containers/vector/bool/capacity/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/cons/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/element_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc: New test.
	* testsuite/23_containers/vector/capacity/constexpr.cc: New test.
	* testsuite/23_containers/vector/cons/constexpr.cc: New test.
	* testsuite/23_containers/vector/data_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/element_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/assign/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/swap/constexpr.cc: New test.
2021-11-12 00:42:39 +00:00
GCC Administrator b39265d4fe Daily bump. 2021-11-12 00:16:32 +00:00
Jonathan Wakely 4a407d358e libstdc++: Fix debug containers for C++98 mode
Since r12-5072 made _Safe_container::operator=(const _Safe_container&)
protected, the debug containers no longer compile in C++98 mode. They
have user-provided copy assignment operators in C++98 mode, and they
assign each base class in turn. The 'this->_M_safe() = __x' expressions
fail, because calling a protected member function is only allowed via
'this'. They could be fixed by using this->_Safe::operator=(__x) but a
simpler solution is to just remove the user-provided assignment
operators and let the compiler define them (as we do for C++11 and
later, by defining them as defaulted).

The only change needed for that to work is to define the _Safe_vector
copy assignment operator in C++98 mode, so that the implicit
__gnu_debug::vector::operator= definition will call it, instead of
needing to call _M_update_guaranteed_capacity() manually.

libstdc++-v3/ChangeLog:

	* include/debug/deque (deque::operator=(const deque&)): Remove
	definition.
	* include/debug/list (list::operator=(const list&)): Likewise.
	* include/debug/map.h (map::operator=(const map&)): Likewise.
	* include/debug/multimap.h (multimap::operator=(const multimap&)):
	Likewise.
	* include/debug/multiset.h (multiset::operator=(const multiset&)):
	Likewise.
	* include/debug/set.h (set::operator=(const set&)): Likewise.
	* include/debug/string (basic_string::operator=(const basic_string&)):
	Likewise.
	* include/debug/vector (vector::operator=(const vector&)):
	Likewise.
	(_Safe_vector::operator=(const _Safe_vector&)): Define for
	C++98 as well.
2021-11-11 21:55:11 +00:00
Jonathan Wakely 083fd73202 libstdc++: Make pmr::memory_resource::allocate implicitly create objects
Calling the placement version of ::operator new "implicitly creates
objects in the returned region of storage" as per [intro.object]. This
allows the returned memory to be used as storage for implicit-lifetime
types (including arrays) without additional action by the caller. This
is required by the proposed resolution of LWG 3147.

libstdc++-v3/ChangeLog:

	* include/std/memory_resource (memory_resource::allocate):
	Implicitly create objects in the returned storage.
2021-11-11 18:16:17 +00:00
Jonathan Wakely ef0e100f58 libstdc++: Remove public std::vector<bool>::data() member
This function only exists to avoid an error in the debug mode vector, so
doesn't need to be public.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (vector<bool>::data()): Give
	protected access, and delete for C++11 and later.
2021-11-11 18:16:17 +00:00
GCC Administrator 8d36a0d288 Daily bump. 2021-11-11 00:16:28 +00:00
Jonathan Wakely 77963796ae libstdc++: Fix test for libstdc++ not including <unistd.h> [PR100117]
The <cxxx> headers for the C library are not under our control, so we
can't prevent them from including <unistd.h>. Change the PR 49745 test
to only include the C++ library headers, not the <cxxx> ones.

To ensure <bits/stdc++.h> isn't included automatically we need to use
no_pch to disable PCH.

libstdc++-v3/ChangeLog:

	PR libstdc++/100117
	* testsuite/17_intro/headers/c++1998/49745.cc: Explicitly list
	all C++ headers instead of including <bits/stdc++.h>
2021-11-10 12:03:29 +00:00
Jonathan Wakely 80fe172ba9 libstdc++: Disable gthreads weak symbols for glibc 2.34 [PR103133]
Since Glibc 2.34 all pthreads symbols are defined directly in libc not
libpthread, and since Glibc 2.32 we have used __libc_single_threaded to
avoid unnecessary locking in single-threaded programs. This means there
is no reason to avoid linking to libpthread now, and so no reason to use
weak symbols defined in gthr-posix.h for all the pthread_xxx functions.

libstdc++-v3/ChangeLog:

	PR libstdc++/100748
	PR libstdc++/103133
	* config/os/gnu-linux/os_defines.h (_GLIBCXX_GTHREAD_USE_WEAK):
	Define for glibc 2.34 and later.
2021-11-10 12:01:27 +00:00
GCC Administrator c9b1334eec Daily bump. 2021-11-10 00:16:28 +00:00
François Dumont f4b4ce152a libstdc++: [_GLIBCXX_DEBUG] Implement unordered container merge
The _GLIBCXX_DEBUG unordered containers need a dedicated merge implementation
so that any existing iterator on the transfered nodes is properly invalidated.

Add typedef/using declarations for everything used as-is from normal implementation.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (__distance_fw): Replace class keyword with
	typename.
	* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Remove noexcept
	qualification. Use const_iterator for node extraction/reinsert.
	(_Hashtable<>::_M_merge_multi): Likewise. Compute new hash code before extract.
	* include/debug/safe_container.h (_Safe_container<>): Make all methods
	protected.
	* include/debug/safe_unordered_container.h
	(_Safe_unordered_container<>::_UContInvalidatePred<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_UMContInvalidatePred<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_UContMergeGuard<_Source, _InvalidatePred>): New.
	(_Safe_unordered_container<>::_S_uc_guard<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_S_umc_guard<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_M_invalide_all): Make public.
	(_Safe_unordered_container<>::_M_invalide_if): Likewise.
	(_Safe_unordered_container<>::_M_invalide_local_if): Likewise.
	* include/debug/unordered_map
	(unordered_map<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_map<>::reference, const_reference, difference_type): New typedef.
	(unordered_map<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_map<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_map<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_map<>::operator[], at, rehash, reserve): Add usings.
	(unordered_map<>::merge): New.
	(unordered_multimap<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_multimap<>::reference, const_reference, difference_type): New typedef.
	(unordered_multimap<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_multimap<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_multimap<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_multimap<>::rehash, reserve): Add usings.
	(unordered_multimap<>::merge): New.
	* include/debug/unordered_set
	(unordered_set<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_set<>::reference, const_reference, difference_type): New typedef.
	(unordered_set<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_set<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_set<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_set<>::rehash, reserve): Add usings.
	(unordered_set<>::merge): New.
	(unordered_multiset<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_multiset<>::reference, const_reference, difference_type): New typedef.
	(unordered_multiset<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_multiset<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_multiset<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_multiset<>::rehash, reserve): Add usings.
	(unordered_multiset<>::merge): New.
	* testsuite/23_containers/unordered_map/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge4_neg.cc: New test.
	* testsuite/util/testsuite_abi.h: [_GLIBCXX_DEBUG] Use normal unordered
	container implementation.
2021-11-09 21:50:17 +01:00
Jonathan Wakely 95e8fcd3d5 libstdc++: Make test print which random_device tokens work
libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/random_device/cons/token.cc:
	Print results of random_device_available checks.
2021-11-09 15:12:29 +00:00
Jonathan Wakely d9ebf0ce08 libstdc++: Do not use 64-bit DARN on 32-bit powerpc [PR103146]
We need to use the 64-bit DARN to detect failure without bias, but it's
not available in 32-bit mode.

libstdc++-v3/ChangeLog:

	PR libstdc++/103146
	* src/c++11/random.cc: Check __powerpc64__ not __powerpc__.
2021-11-09 14:40:33 +00:00