Commit Graph

11900 Commits

Author SHA1 Message Date
Jonathan Wakely
e0af865ab9 libstdc++: Define new C++17 std::search overload for Parallel Mode [PR 94971]
libstdc++-v3/ChangeLog:

	PR libstdc++/94971
	* include/bits/stl_algo.h (search(FIter, FIter, const Searcher):
	Adjust #if condition.
	* include/parallel/algo.h (search(FIter, FIter, const Searcher&):
	Define new overload for C++17.
2020-11-04 13:36:32 +00:00
Jonathan Wakely
3ef33e756a libstdc++: Document istreambuf_iterator base class change [PR 92285]
libstdc++-v3/ChangeLog:

	PR libstdc++/92285
	* doc/xml/manual/evolution.xml: Document change to base class.
	* doc/html/manual/api.html: Regenerate.
2020-11-04 12:46:52 +00:00
Jonathan Wakely
24366207b7 libstdc++: Fix constant expressions in std::uniform_int_distribution
Clang and EDG say the class member access expressions __urng.min() and
__urng.max() are not constant expressions, because the object expression
__urng is not usable in a constant expresion. Use a qualified-id to call
those static member functions instead.

Co-authored-by: Stephan Bergmann <sbergman@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/uniform_int_dist.h (uniform_int_distribution::_S_nd):
	Use qualified-id to refer to static member functions.
2020-11-04 10:36:45 +00:00
GCC Administrator
fd2325ea60 Daily bump. 2020-11-04 00:16:41 +00:00
Jonathan Wakely
e1276e3342 libstdc++: Ensure std::lock_guard is declared
libstdc++-v3/ChangeLog:

	* include/std/syncstream: Include <bits/std_mutex.h>
	unconditionally.
2020-11-03 21:56:44 +00:00
François Dumont
12d0512305 libstdc++: Add mising gnu-versioned-namespace symbols
libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu-versioned-namespace.ver:
	Add __istream_extract and _Safe_local_iterator_base::_M_attach_single
	symbols.
2020-11-03 22:01:55 +01:00
Jonathan Wakely
9f925f3b19 libstdc++: Refactor std::call_once internals
This separates the definition of std::__call_proxy into two funcions,
one for TLS and one for non-TLS, to make them easier to read. It also
replaces the __get_once_functor_lock_ptr() internal helper with a new
set_lock_ptr(unique_lock<mutex>*) function so that __once_proxy doesn't
need to call it twice.

libstdc++-v3/ChangeLog:

	* src/c++11/mutex.cc [_GLIBCXX_HAVE_TLS] (__once_proxy): Define
	separately for TLS targets.
	[!_GLIBCXX_HAVE_TLS] (__get_once_functor_lock_ptr): Replace with ...
	(set_lock_ptr): ... this. Set new value and return previous
	value.
	[!_GLIBCXX_HAVE_TLS] (__set_once_functor_lock_ptr): Adjust to
	use set_lock_ptr.
	[!_GLIBCXX_HAVE_TLS] (__once_proxy): Likewise.
2020-11-03 20:03:16 +00:00
Jonathan Wakely
93e79ed391 libstdc++: Rewrite std::call_once to use futexes [PR 66146]
The current implementation of std::call_once uses pthread_once, which
only meets the C++ requirements when compiled with support for
exceptions. For most glibc targets and all non-glibc targets,
pthread_once does not work correctly if the init_routine exits via an
exception. The pthread_once_t object is left in the "active" state, and
any later attempts to run another init_routine will block forever.

This change makes std::call_once work correctly for Linux targets, by
replacing the use of pthread_once with a futex, based on the code from
__cxa_guard_acquire. For both glibc and musl, the Linux implementation
of pthread_once is already based on futexes, and pthread_once_t is just
a typedef for int, so this change does not alter the layout of
std::once_flag. By choosing the values for the int appropriately, the
new code is even ABI compatible. Code that calls the old implementation
of std::call_once will use pthread_once to manipulate the int, while new
code will use the new std::once_flag members to manipulate it, but they
should interoperate correctly. In both cases, the int is initially zero,
has the lowest bit set when there is an active execution, and equals 2
after a successful returning execution. The difference with the new code
is that exceptional exceptions are correctly detected and the int is
reset to zero.

The __cxa_guard_acquire code (and musl's pthread_once) use an additional
state to say there are other threads waiting. This allows the futex wake
syscall to be skipped if there is no contention. Glibc doesn't use a
waiter bit, so we have to unconditionally issue the wake in order to be
compatible with code calling the old std::call_once that uses Glibc's
pthread_once. If we know that we're using musl (and musl's pthread_once
doesn't change) it would be possible to set a waiting state and check
for it in std::once_flag::_M_finish(bool), but this patch doesn't do
that.

This doesn't fix the bug for non-linux targets. A similar approach could
be used for targets where we know the definition of pthread_once_t is a
mutex and an integer. We could make once_flag._M_activate() use
pthread_mutex_lock on the mutex member within the pthread_once_t, and
then only set the integer if the execution finishes, and then unlock the
mutex. That would require careful study of each target's pthread_once
implementation and that work is left for a later date.

This also fixes PR 55394 because pthread_once is no longer needed, and
PR 84323 because the fast path is now just an atomic load.

As a consequence of the new implementation that doesn't use
pthread_once, we can also make std::call_once work for targets with no
gthreads support. The code for the single-threaded implementation
follows the same methods as on Linux, but with no need for atomics or
futexes.

libstdc++-v3/ChangeLog:

	PR libstdc++/55394
	PR libstdc++/66146
	PR libstdc++/84323
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): Add new symbols.
	* include/std/mutex [!_GLIBCXX_HAS_GTHREADS] (once_flag): Define
	even when gthreads is not supported.
	(once_flag::_M_once) [_GLIBCXX_HAVE_LINUX_FUTEX]: Change type
	from __gthread_once_t to int.
	(once_flag::_M_passive(), once_flag::_M_activate())
	(once_flag::_M_finish(bool), once_flag::_Active_execution):
	Define new members for futex and non-threaded implementation.
	[_GLIBCXX_HAS_GTHREADS] (once_flag::_Prepare_execution): New
	RAII helper type.
	(call_once): Use new members of once_flag.
	* src/c++11/mutex.cc (std::once_flag::_M_activate): Define.
	(std::once_flag::_M_finish): Define.
	* testsuite/30_threads/call_once/39909.cc: Do not require
	gthreads.
	* testsuite/30_threads/call_once/49668.cc: Likewise.
	* testsuite/30_threads/call_once/60497.cc: Likewise.
	* testsuite/30_threads/call_once/call_once1.cc: Likewise.
	* testsuite/30_threads/call_once/dr2442.cc: Likewise.
	* testsuite/30_threads/call_once/once_flag.cc: Add test for
	constexpr constructor.
	* testsuite/30_threads/call_once/66146.cc: New test.
	* testsuite/30_threads/call_once/constexpr.cc: Removed.
	* testsuite/30_threads/once_flag/cons/constexpr.cc: Removed.
2020-11-03 18:44:49 +00:00
Jonathan Yong
08fca4df1d libstdc++: use lt_host_flags for libstdc++.la
For platforms like Mingw and Cygwin, cygwin refuses to generate the
shared library without using -no-undefined.

Attached patch makes sure the right flags are used, since libtool is
already used to link libstdc++.

libstdc++-v3/ChangeLog:

	* src/Makefile.am (libstdc___la_LINK): Add lt_host_flags.
	* src/Makefile.in: Regenerate.
2020-11-03 08:22:53 +00:00
GCC Administrator
88ce3d5fbb Daily bump. 2020-11-02 20:53:00 +00:00
Thomas Rodgers
6bcbcea058 libstdc++: Add c++2a <syncstream>
libstdc++-v3/ChangeLog:
	* doc/doxygen/user.cfg.in (INPUT): Add new header.
	* include/Makefile.am (std_headers): Add new header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Include new header.
	* include/std/syncstream: New header.
	* include/std/version: Add __cpp_lib_syncbuf.
	* testsuite/27_io/basic_syncbuf/1.cc: New test.
	* testsuite/27_io/basic_syncbuf/2.cc: Likewise.
	* testsuite/27_io/basic_syncbuf/basic_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/requirements/types.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/sync_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncstream/1.cc: Likewise.
	* testsuite/27_io/basic_syncstream/2.cc: Likewise.
	* testsuite/27_io/basic_syncstream/basic_ops/1.cc:
	Likewise.
	* testsuite/27_io/basic_syncstream/requirements/types.cc:
	Likewise.
2020-11-02 10:41:32 -08:00
Jonathan Wakely
29e4184858 libstdc++: Define type traits for wchar_t even when libc support missing
This meets the requirement that std::is_integral_v<wchar_t> is true,
even when full library support for wchar_t via specializations of
char_traits etc. is not provided. This is done by checking
__WCHAR_TYPE__ to see if the compiler knows about the type, rather than
checking the library's own _GLIBCXX_USE_WCHAR_T autoconf macro.

This assumes that the C++ compiler correctly defines wchar_t as a
distinct type, not a typedef for one of the other integeral types. This
is always true for G++ and should be true for any supported non-GNU
compilers.

Similarly, the std::make_unsigned and std::make_signed traits and the
internal helpers std::__is_integer and std::__is_char are also changed
to depend on the same macro.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_integral<wchar_t>)
	(make_unsigned<wchar_t>, make_signed<wchar_t>): Define based
	on #ifdef __WCHAR_TYPE__ instead of _GLIBCXX_USE_WCHAR_T.
	* include/bits/cpp_type_traits.h (__is_integer<wchar_t>)
	(__is_char<wchar_t>): Likewise.
2020-11-01 11:39:07 +00:00
François Dumont
de77abee11 libstdc++: Fix gnu-version-namespace buid
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog

	* src/c++17/floating_from_chars.cc (_GLIBCXX_USE_CX11_ABI): Add define.
	(buffering_string): New.
	[!_GLIBCXX_USE_CXX11_ABI](reserve_string): New.
	(from_chars): Adapt.
	* src/c++20/sstream-inst.cc: Limit instantiations to
	_GLIBCXX_USE_CXX11_ABI.
2020-10-31 18:10:10 +01:00
Jonathan Wakely
60d9f25487 libstdc++: Prefer double to long double in std::shuffle_order_engine
The transition algorithm for std::shuffle_order_engine uses long double
to ensure that the value (max() - min() + 1) can be accurately
represented, to avoid bias in the shuffling. However, when the base
engine's range is small enough we can avoid slower long double
arithmetic by using double. For example, long double is unnecessary for
any base engine returning 32-bit values.

This makes std::knuth_b::operator() about 15% faster on x86_64, and
probably even more on targets where long double uses soft-float.

libstdc++-v3/ChangeLog:

	* include/bits/random.h (independent_bit_engine): Fix typo
	in comment.
	(shuffle_order_engine): Fix incorrect description in comment.
	* include/bits/random.tcc (__representable_as_double
	(__p1_representable_as_double): New helper functions.
	(shuffle_order_engine::operator()): Use double for calculation
	if (max() - min() + 1) is representable as double.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
2020-10-31 12:54:03 +00:00
Jonathan Wakely
943cc2a1b7 libstdc++: Use double for unordered container load factors [PR 96958]
My previous commit for this PR changed the types from long double to
double, but didn't change the uses of __builtin_ceill and
__builtin_floorl. It also failed to change the non-inline functions in
src/c++11/hashtable_c++0x.cc. This should fix it properly now.

libstdc++-v3/ChangeLog:

	PR libstdc++/96958
	* include/bits/hashtable_policy.h (_Prime_rehash_policy)
	(_Power2_rehash_policy): Use ceil and floor instead of ceill and
	floorl.
	* src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy): Likewise.
	Use double instead of long double.
2020-10-31 00:52:57 +00:00
Patrick Palka
afb8da7faa libstdc++: Don't initialize from *this inside some views [PR97600]
This works around a subtle issue where instantiating the begin()/end()
member of some views (as part of return type deduction) inadvertently
requires computing the satisfaction value of range<foo_view>.

This is problematic because the constraint range<foo_view> requires the
begin()/end() member to be callable.  But it's not callable until we've
deduced its return type, so evaluation of range<foo_view> yields false
at this point.  And if after both members are instantiated (and their
return types deduced) we evaluate range<foo_view> again, this time it
will yield true since the begin()/end() members are now both callable.
This makes the program ill-formed according to [temp.constr.atomic]/3:

  If, at different points in the program, the satisfaction result is
  different for identical atomic constraints and template arguments, the
  program is ill-formed, no diagnostic required.

The views affected by this issue are those whose begin()/end() member
has a placeholder return type and that member initializes an _Iterator
or _Sentinel object from a reference to *this.  The second condition is
relevant because it means explicit conversion functions are considered
during overload resolution (as per [over.match.copy], I think), and
therefore it causes g++ to check the constraints of the conversion
function view_interface<foo_view>::operator bool().  And this conversion
function's constraints indirectly require range<foo_view>.

This issue is observable on trunk only with basic_istream_view (as in
the testcase in the PR).  But a pending patch that makes g++ memoize
constraint satisfaction values indefinitely (it currently invalidates
the satisfaction cache on various events) causes many existing tests for
the other affected views to fail, because range<foo_view> then remains
false for the whole compilation.

This patch works around this issue by adjusting the constructors of the
_Iterator and _Sentinel types of the affected views to take their
foo_view argument by pointer instead of by reference, so that g++ no
longer considers explicit conversion functions when resolving the
direct-initialization inside these views' begin()/end() members.

libstdc++-v3/ChangeLog:

	PR libstdc++/97600
	* include/std/ranges (basic_istream_view::begin): Initialize
	_Iterator from 'this' instead of '*this'.
	(basic_istream_view::_Iterator::_Iterator): Adjust constructor
	accordingly.
	(filter_view::_Iterator::_Iterator): Take a filter_view*
	argument instead of a filter_view& argument.
	(filter_view::_Sentinel::_Sentinel): Likewise.
	(filter_view::begin): Initialize _Iterator from 'this' instead
	of '*this'.
	(filter_view::end): Likewise.
	(transform_view::_Iterator::_Iterator): Take a _Parent* instead
	of a _Parent&.
	(filter_view::_Iterator::operator+): Adjust accordingly.
	(filter_view::_Iterator::operator-): Likewise.
	(filter_view::begin): Initialize _Iterator from 'this' instead
	of '*this'.
	(filter_view::end): Likewise.
	(join_view::_Iterator): Take a _Parent* instead of a _Parent&.
	(join_view::_Sentinel): Likewise.
	(join_view::begin): Initialize _Iterator from 'this' instead of
	'*this'.
	(join_view::end): Initialize _Sentinel from 'this' instead of
	'*this'.
	(split_view::_OuterIter): Take a _Parent& instead of a _Parent*.
	(split_view::begin): Initialize _OuterIter from 'this' instead
	of '*this'.
	(split_view::end): Likewise.
	* testsuite/std/ranges/97600.cc: New test.
2020-10-30 20:33:19 -04:00
Jonathan Wakely
39bf4f14fc libstdc++: Implement P2017R1 "Conditionally borrowed ranges"
This makes some range adaptors model the borrowed_range concept if they
are adapting a borrowed range. This hasn't been added to the C++23
working paper yet, but it has been approved by LWG, and the
recommendation is to treat it as a defect report for C++20 as well.

libstdc++-v3/ChangeLog:

	* include/std/ranges (enable_borrowed_view<take_view<T>>)
	(enable_borrowed_view<drop_view<T>>)
	(enable_borrowed_view<drop_while_view<T>>)
	(enable_borrowed_view<reverse_view<T>>)
	(enable_borrowed_view<common_view<T>>)
	(enable_borrowed_view<elements_view<T>>): Add partial
	specializations as per P2017R1.
	* testsuite/std/ranges/adaptors/conditionally_borrowed.cc:
	New test.
2020-10-30 23:25:52 +00:00
Jonathan Wakely
a1343e5c74 libstdc++: Use double for unordered container load factors [PR 96958]
These calculations were changed to use long double nearly ten years ago
in order to get more precision than float:
https://gcc.gnu.org/pipermail/libstdc++/2011-September/036420.html

However, double should be sufficient, whlie being potentially faster
than long double, and not requiring soft FP calculations for targets
without native long double support.

libstdc++-v3/ChangeLog:

	PR libstdc++/96958
	* include/bits/hashtable_policy.h (_Prime_rehash_policy)
	(_Power2_rehash_policy): Use double instead of long double.
2020-10-30 20:58:08 +00:00
Jonathan Wakely
d1e5d82af8 libstdc++: Fix some more warnings in test
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc:
	Avoid -Wcatch-value warnings.
2020-10-30 20:58:08 +00:00
Patrick Palka
f3ced6772e libstdc++: Fix the default constructor of ranges::__detail::__box
The class template semiregular-box<T> of [range.semi.wrap] is specified
to value-initialize the underlying object whenever its type is default
initializable.  Our primary template for __detail::__box respects this
requirement, but the recently added partial specialization (for types
that are already semiregular) does not.

This patch fixes this issue, and additionally makes the corresponding in
place constructor explicit (as in the primary template).

libstdc++-v3/ChangeLog:

	* include/std/ranges (__detail::__box): For the partial
	specialization used by types that are already semiregular,
	make the default constructor value-initialize the underlying
	object instead of default-initializing it.  Make its in place
	constructor explicit.
	* testsuite/std/ranges/adaptors/detail/semiregular_box.cc:
	Augment test.
2020-10-30 12:33:13 -04:00
David Edelsohn
dec1eb4c27 libstdc++: AIX xfail for_overwrite.cc testcase
The 20_util/unique_ptr/creation/for_overwrite.cc testcase relies on
operator new, which requires special features on AIX.  This patch
disables the testcase.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: XFAIL on AIX.
2020-10-29 21:57:24 -04:00
GCC Administrator
4f0606fe4b Daily bump. 2020-10-30 00:16:29 +00:00
Jonathan Wakely
ffe6b41015 libstdc++: Fix linker script to remove conflicting patterns
This should fix a bootstrap error on Solaris, due to some of the new
symbols matching old patterns as well as new ones.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Tighten patterns
	for old <sstream> symbols some more.
2020-10-29 22:47:22 +00:00
Jonathan Wakely
a55cda891d libstdc++: Avoid narrowing conversion in subrange constructor
libstdc++-v3/ChangeLog:

	* include/bits/ranges_util.h (subrange::subrange(R&&)): Use
	direct-initialization instead of list-initialization, so a
	potential narrowing conversion from ranges::size(r) to the
	stored size isn't ill-formed.
2020-10-29 22:47:22 +00:00
Jonathan Wakely
d7aa21a3c7 libstdc++: Fix some warnings in headers
These are usually suppressed in system headers, but should be fixed
anyway.

libstdc++-v3/ChangeLog:

	* include/bits/parse_numbers.h (_Select_int_base): Avoid
	narrowing conversion in constant expression.
	* include/experimental/buffer (buffer_copy): Avoid narrowing
	conversion.
	* include/experimental/internet (hash<>::operator()): Do not
	use deprecated 'argument_type' member.
	* include/std/variant (variant::emplace): Use cast instead
	of implicit conversion from size_t to narrower unsigned type.
2020-10-29 22:47:22 +00:00
Jonathan Wakely
52ddf0d458 libstdc++: Prevent deprecation warnings from <tr1/shared_ptr>
libstdc++-v3/ChangeLog:

	* include/tr1/shared_ptr.h (__shared_count, __shared_ptr)
	(shared_ptr): Add diagnostic pragmas around uses of auto_ptr.
	* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc:
	Adust dg-error line numbers.
2020-10-29 22:47:22 +00:00
Jonathan Wakely
13feb0234b libstdc++: Avoid warnings in tests
This fixes some warnings emitted when testing with warning flags added.
Some of these are only necessary when testing with -Wsystem-headers, but
either way it cleans up the tests to be less noisy under non-default
flags.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/96817.cc: Avoid -Wunused warnings.
	* testsuite/20_util/any/assign/2.cc: Likewise.
	* testsuite/20_util/any/cons/2.cc: Likewise.
	* testsuite/20_util/align/1.cc: Avoid -Wsign-compare warning.
	* testsuite/20_util/function/65760.cc: Avoid -Wunused warning.
	* testsuite/20_util/function/1.cc: Avoid -Wcatch-value warning.
	* testsuite/20_util/function/cons/move_target.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/headers/memory/synopsis.cc: Add exception
	specification.
	* testsuite/20_util/monotonic_buffer_resource/allocate.cc: Avoid
	-Wsign-compare warning.
	* testsuite/20_util/tuple/cons/deduction.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/808590-cxx11.cc:
	Avoid -Wdeprecated-copy warning.
	* testsuite/21_strings/basic_string/56166.cc: Avoid
	-Wcatch-value warning.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Avoid -Wcatch-value warnings.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/nonnull.cc:
	Prune additional diagnostics.
	* testsuite/21_strings/basic_string_view/operations/find/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/headers/string/synopsis.cc: Add exception
	specifications.
	* testsuite/22_locale/locale/cons/12352.cc: Define sized
	delete operators to avoid warnings.
	* testsuite/23_containers/deque/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/23_containers/forward_list/cons/11.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/headers/bitset/synopsis.cc: Add
	exception specification.
	* testsuite/23_containers/headers/deque/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/forward_list/synopsis.cc:
	Likewise.
	* testsuite/23_containers/headers/list/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/map/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/queue/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/set/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/vector/synopsis.cc: Likewise.
	* testsuite/23_containers/list/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/map/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/multiset/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/set/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/unordered_set/56267-2.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/vector/bool/23632.cc: Avoid
	-Wempty-body warning.
	* testsuite/23_containers/vector/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/25_algorithms/heap/moveable2.cc: Fix misplaced
	parentheses around arguments.
	* testsuite/25_algorithms/sample/1.cc: Use return value.
	* testsuite/25_algorithms/search/searcher.cc: Avoid -Wunused
	warnings.
	* testsuite/27_io/basic_ostream/exceptions/char/9561.cc:
	Likewise.
	* testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc:
	Likewise.
	* testsuite/27_io/filesystem/operations/remove_all.cc: Avoid
	-Wsign-compare warning.
	* testsuite/experimental/any/assign/2.cc: Avoid -Wunused warnings.
	* testsuite/experimental/any/cons/2.cc: Likewise.
	* testsuite/experimental/filesystem/operations/remove_all.cc:
	Avoid -Wign-compare warning.
	* testsuite/experimental/memory/observer_ptr/cons/cons.cc:
	Likewise.
	* testsuite/experimental/memory_resource/null_memory_resource.cc:
	Likewise.
	* testsuite/experimental/source_location/1.cc: Avoid -Waddress
	warning.
	* testsuite/ext/pod_char_traits.cc: Avoid -Wunused warning.
	* testsuite/ext/vstring/modifiers/clear/56166.cc: Avoid
	-Wcatch-value.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc:
	Avoid -Wunused warning.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc:
	Likewise.
	* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc:
	Prune additional warnings.
	* testsuite/tr1/3_function_objects/function/1.cc: Avoid
	-Wcatch-value warning.
	* testsuite/util/replacement_memory_operators.h: Define sized
	delete to avoid warnings.
	* testsuite/util/testsuite_api.h (_NonDefaultConstructible): Add
	user-declared assignment operator to stop -Wdeprecated-copy
	warnings.
	* testsuite/util/testsuite_containers.h: Avoid -Wunused warning.
	* testsuite/util/testsuite_iterators.h: Avoid -Wsign-compare
	warnings.
	* testsuite/util/testsuite_new_operators.h: Define sized deleted.
2020-10-29 22:47:21 +00:00
Jonathan Wakely
8c84486bba libstdc++: Improve tests for constexpr algorithms
These tests just return true without checking that the results of the
algorithms. Although it should be safe to assume that the algorithms
behave the same at compile-time as at run-time, we can use these tests
to verify it.

This replaces each 'return true' statement with a condition that depends
on the basic functionality of the algorithm, such as returning an
iterator to the right position.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/all_of/constexpr.cc: Check result of
	the algorithm.
	* testsuite/25_algorithms/any_of/constexpr.cc: Likewise.
	* testsuite/25_algorithms/binary_search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: Likewise.
	* testsuite/25_algorithms/count/constexpr.cc: Likewise.
	* testsuite/25_algorithms/equal/constexpr.cc: Likewise.
	* testsuite/25_algorithms/equal_range/constexpr.cc: Likewise.
	* testsuite/25_algorithms/fill/constexpr.cc: Likewise.
	* testsuite/25_algorithms/find_end/constexpr.cc: Likewise.
	* testsuite/25_algorithms/find_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: Likewise.
	* testsuite/25_algorithms/merge/constexpr.cc: Likewise.
	* testsuite/25_algorithms/mismatch/constexpr.cc: Likewise.
	* testsuite/25_algorithms/none_of/constexpr.cc: Likewise.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/replace_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/reverse/constexpr.cc: Likewise.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_difference/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_intersection/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_union/constexpr.cc: Likewise.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: Likewise.
2020-10-29 14:47:18 +00:00
Jonathan Wakely
822c1d21a3 libstdc++: Allow Lemire's algorithm to be used in more cases
This extends the fast path to also work when the URBG's range of
possible values is not the entire range of its result_type. Previously,
the slow path would be used for engines with a uint_fast32_t result type
if that type is actually a typedef for uint64_t rather than uint32_t.
After this change, the generator's result_type is not important, only
the range of possible value that generator can produce. If the
generator's range is exactly UINT64_MAX then the calculation will be
done using 128-bit and 64-bit integers, and if the range is UINT32_MAX
it will be done using 64-bit and 32-bit integers.

In practice, this benefits most of the engines and engine adaptors
defined in [rand.predef] on x86_64-linux and other 64-bit targets. This
is because std::minstd_rand0 and std::mt19937 and others use
uint_fast32_t, which is a typedef for uint64_t.

The code now makes use of the recently-clarified requirement that the
generator's min() and max() functions are usable in constant
expressions (see LWG 2154).

libstdc++-v3/ChangeLog:

	* include/bits/uniform_int_dist.h (_Power_of_two): Add
	constexpr.
	(uniform_int_distribution::_S_nd): Add static_assert to ensure
	the wider type is twice as wide as the result type.
	(uniform_int_distribution::__generate_impl): Add static_assert
	and declare variables as constexpr where appropriate.
	(uniform_int_distribution:operator()): Likewise. Only consider
	the uniform random bit generator's range of possible results
	when deciding whether _S_nd can be used, not the __uctype type.
2020-10-29 14:47:18 +00:00
Jonathan Wakely
d067bd7293 libstdc++: Do not use volatile for __gnu_cxx::rope reference counting
The rope extension uses a volatile variable for its reference count.
This is not only unnecessary for correctness (volatile provides neither
atomicity nor memory visibility, and the variable is only modified while
a lock is held) but it now causes deprecated warnings with
-Wsystem-headers due to the use of ++ and -- operators.

It would be possible to use __gnu_cxx::__exchange_and_add in _M_incr and
_M_decr when __atomic_is_lock_free(sizeof(_RC_t), &_M_ref_count) is
true, rather than locking a mutex. That would probably be a significant
improvement for multi-threaded and single-threaded code (because
__exchange_and_add will use non-atomic ops when possible, and even in MT
code it should be faster than the mutex lock/unlock pair). However,
mixing objects compiled with the old and new code would result in
inconsistent synchronization being used for the reference count.

libstdc++-v3/ChangeLog:

	* include/ext/rope (_Refcount_Base::_M_ref_count): Remove
	volatile qualifier.
	(_Refcount_Base::_M_decr()): Likewise.
2020-10-29 14:47:17 +00:00
Jonathan Wakely
3c9b99ef71 libstdc++: Make std::function work better with -fno-rtti
This change allows std::function::target<F>() to work even without RTTI,
using the same approach as std::any. Because we know what the manager
function would be for a given type, we can check if the stored pointer
has the expected address. If it does, we don't need to use RTTI. If it
isn't equal, we still need to do the RTTI check (when RTTI is enabled)
to handle the case where the same function has different addresses in
different shared objects.

This also changes the implementation of the manager function to return a
null pointer result when asked for the type_info of the target object.
This not only avoids a warning with -Wswitch -Wsystem-headers, but also
avoids prevents std::function::target_type() from dereferencing an
uninitialized pointer when the linker keeps an instantiation of the
manager function that was compiled without RTTI.

Finally, this fixes a bug in the non-const overload of function::target
where calling it with a function type F was ill-formed, due to
attempting to use const_cast<F*>(ptr). The standard only allows
const_cast<T*> when T is an object type.  The solution is to use
*const_cast<F**>(&ptr) instead, because F* is an object type even if F
isn't. I've also used _GLIBCXX17_CONSTEXPR in function::target so that
it doesn't bother instantiating anything for types that can never be a
valid target.

libstdc++-v3/ChangeLog:

	* include/bits/std_function.h (_Function_handler<void, void>):
	Define explicit specialization used for invalid target types.
	(_Base_manager::_M_manager) [!__cpp_rtti]: Return null.
	(function::target_type()): Check for null pointer.
	(function::target()): Define unconditionall. Fix bug with
	const_cast of function pointer type.
	(function::target() const): Define unconditionally, but
	only use RTTI if enabled.
	* testsuite/20_util/function/target_no_rtti.cc: New test.
2020-10-29 14:47:17 +00:00
Patrick Palka
2e0216f9c4 libstdc++: Fix memory issue in ranges::lexicographical_compare testcase
libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/lexicographical_compare/constrained.cc:
	(test03): Fix initializing the vector vy with the array y of size 4.
2020-10-29 10:11:12 -04:00
Patrick Palka
64817472be libstdc++: Correct PR number in ChangeLog entry 2020-10-29 09:28:43 -04:00
Jonathan Wakely
eb6b71b83c libstdc++: Fix some warnings in headers
These are usually suppressed without -Wsystem-headers.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (_Local_iterator_base): Cast
	value to avoid -Wsign-compare warnings.
	* include/bits/regex.h (sub_match::_M_str): Avoid narrowing
	conversion.
	* include/bits/regex_compiler.tcc (_Compiler::_M_quantifier):
	Initialize variable to avoid -Wmaybe-uninitialized warning.
	* include/bits/shared_ptr_base.h (_Sp_counted_deleter::_Impl):
	Reorder mem-initializer-list to avoid -Wreorder warning.
	* include/bits/stl_tree.h (_Rb_tree_impl): Explicitly
	initialize base class in copy constructor.
	* include/debug/safe_iterator.h (_Safe_iterator): Likewise.
	* include/ext/debug_allocator.h: Reorder mem-initializer-list
	to avoid -Wreorder warning.
	* include/ext/throw_allocator.h (throw_allocator_limit)
	(throw_allocator_random): Add user-declared assignment operators
	to avoid -Wdeprecated-copy warnings.
2020-10-29 11:43:55 +00:00
Jonathan Wakely
68990ed13d libstdc++: Rename _UniformRandomNumberGenerator parameters
The paper P0346R1 renamed uniform random number generators to
uniform random bit generators, to describe their purpose more
accurately. This makes that same change in one of the relevant
files (but not the others).

libstdc++-v3/ChangeLog:

	* include/bits/uniform_int_dist.h (uniform_int_distribution):
	Rename _UniformRandomNumberGenerator template parameters to
	_UniformRandomBitGenerator, as per P0346R1.
2020-10-29 09:09:44 +00:00
Jonathan Wakely
c6bfc4eb3c libstdc++: Fix new basic_stringbuf constructor
libstdc++-v3/ChangeLog:

	* include/std/sstream (basic_stringbuf(__string_type&&, openmode)):
	Call _M_init_syncbuf to set up get/put areas. Also qualify
	std::move.
2020-10-29 01:28:12 +00:00
GCC Administrator
e93aae4a49 Daily bump. 2020-10-29 00:16:50 +00:00
Jonathan Wakely
f4f9364d20 libstdc++: Fix linker script
libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): Remove duplicate
	patterns.
	(CXXABI_1.3.13): Restore missing piece.
2020-10-28 23:52:12 +00:00
Thomas Rodgers
a0e4d7b44c libstdc++: Implement C++20 features for <sstream>
New ctors and ::view() accessor for -
  * basic_stingbuf
  * basic_istringstream
  * basic_ostringstream
  * basic_stringstreamm

New ::get_allocator() accessor for basic_stringbuf.

libstdc++-v3/ChangeLog:
	* acinclude.m4 (glibcxx_SUBDIRS): Add src/c++20.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): New symbols.
	* configure: Regenerate.
	* include/std/sstream:
	(basic_stringbuf::basic_stringbuf(allocator const&)): New constructor.
	(basic_stringbuf::basic_stringbuf(openmode, allocator const&)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_string&&, openmode)): Likewise.
	(basic_stringbuf::basic_stringbuf(basic_stringbuf&&, allocator const&)):
	Likewise.
	(basic_stringbuf::get_allocator()): New method.
	(basic_stringbuf::view()): Likewise.
	(basic_istringstream::basic_istringstream(basic_string&&, openmode)):
	New constructor.
	(basic_istringstream::basic_istringstream(openmode, allocator const&)):
	Likewise
	(basic_istringstream::view()): New method.
	(basic_ostringstream::basic_ostringstream(basic_string&&, openmode)):
	New constructor.
	(basic_ostringstream::basic_ostringstream(openmode, allocator const&)):
	Likewise
	(basic_ostringstream::view()): New method.
	(basic_stringstream::basic_stringstream(basic_string&&, openmode)):
	New constructor.
	(basic_stringstream::basic_stringstream(openmode, allocator const&)):
	Likewise
	(basic_stringstream::view()): New method.
	* src/Makefile.in: Add c++20 directory.
	* src/Makefile.am: Regenerate.
	* src/c++20/Makefile.am: Add makefile for new sub-directory.
	* src/c++20/Makefile.in: Generate.
	* src/c++20/sstream-inst.cc: New file defining explicit
	instantiations for basic_stringbuf, basic_istringstream,
	basic_ostringstream, and basic_stringstream member functions
	added in C++20.
	* testsuite/27_io/basic_stringbuf/cons/char/2.cc: New test.
	* testsuite/27_io/basic_stringbuf/cons/wchar_t/2.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/view/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_istringstream/view/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_ostringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/view/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.
	* testsuite/27_io/basic_stringstream/view/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/view/wchar_t/1.cc: Likewise.
2020-10-28 11:56:06 -07:00
Patrick Palka
8572edc828 libstdc++: Fix arithmetic bug in year_month_weekday conversion [PR96713]
The conversion function year_month_weekday::operator sys_days computes
the offset in days from the first weekday of the month with:

 days{(index()-1)*7}
      ^~~~~~~~~~~~~  type 'unsigned'

We want the above to yield -7d when index() is 0u, but our 'days' alias
is based on long instead of int, so the conversion from unsigned to the
underlying type of 'days' instead yields a large positive value.

This patch fixes this by casting the result of index() to int so that
the initializer is sign-extended in the conversion to long.

The added testcase also verifies we do the right thing when index() == 5.

libstdc++-v3/ChangeLog:

	PR libstdc++/96713
	* include/std/chrono (year_month_weekday::operator sys_days):
	Cast the result of index() to int so that the initializer for
	days{} is sign-extended when it's converted to the underlying
	type.
	* testsuite/std/time/year_month_weekday/3.cc: New test.
2020-10-28 12:28:08 -04:00
Jonathan Wakely
c227d96feb libstdc++: Add comment to nothrow new explaining catch (...)
The decision to not rethrow a __forced_unwind exception is deliberate,
so add a comment explaining it.

libstdc++-v3/ChangeLog:

	* libsupc++/new_opnt.cc (new): Add comment about forced unwind
	exceptions.
2020-10-28 13:19:21 +00:00
Jonathan Wakely
0bc199fc5d libstdc++: Override BUFSIZ for Windows targets [PR 94268]
This replaces uses of BUFSIZ with a new _GLIBCXX_BUFSIZ macro that can
be overridden in target-specific config headers.

That allows the mingw and mingw-w64 targets to override it, because
BUFSIZ is apparently defined to 512, resulting in poor performance. The
MSVCRT stdio apparently uses 4096, so we use that too.

libstdc++-v3/ChangeLog:

	PR libstdc++/94268
	* config/os/mingw32-w64/os_defines.h (_GLIBCXX_BUFSIZ):
	Define.
	* config/os/mingw32/os_defines.h (_GLIBCXX_BUFSIZ):
	Define.
	* include/bits/fstream.tcc: Use _GLIBCXX_BUFSIZ instead
	of BUFSIZ.
	* include/ext/stdio_filebuf.h: Likewise.
	* include/std/fstream (_GLIBCXX_BUFSIZ): Define.
2020-10-28 13:19:21 +00:00
Jonathan Wakely
72a87d82e0 libstdc++: Fix name clash with _Cosh in QNX headers [PR 95592]
This replaces unqualified names like _Cosh with struct std::_Cosh to
ensure there is no ambiguity with other entities with the same name.

libstdc++-v3/ChangeLog:

	PR libstdc++/95592
	* include/bits/valarray_after.h (_DEFINE_EXPR_UNARY_OPERATOR)
	(_DEFINE_EXPR_BINARY_OPERATOR, _DEFINE_EXPR_BINARY_FUNCTION):
	Use elaborated-type-specifier and qualified-id to avoid
	ambiguities with QNX system headers.
	* testsuite/26_numerics/valarray/95592.cc: New test.
2020-10-28 12:35:44 +00:00
Jonathan Wakely
0f7cd5e573 libstdc++: Make std::span layout-compatible with struct iovec [PR 95609]
This change reorders the data members of std::span so that span<byte> is
layout-compatible with common implementations of struct iovec. This will
allow span<byte> to be used directly in places that use a struct iovec
to do scatter-gather I/O.

It's important to note that POSIX doesn't specify the order of members
in iovec. Also the equivalent type on Windows has members in the other
order, and uses type ULONG (which is always 32-bit whereas size_t is
64-bit for Win64). So this change will only help for certain targets and
an indirection between std::span and I/O system calls will still be
needed for the general case.

libstdc++-v3/ChangeLog:

	PR libstdc++/95609
	* include/std/span (span): Reorder data members to match common
	implementations of struct iovec.
	* testsuite/23_containers/span/layout_compat.cc: New test.
2020-10-28 12:07:40 +00:00
GCC Administrator
89bb01e7cb Daily bump. 2020-10-28 00:16:38 +00:00
Jonathan Wakely
d4fd8638be libstdc++: Fix ODR violations caused by <tr1/functional>
The placeholders for std::tr1::bind are defined in an anonymous
namespace, which means they have internal linkage. This will cause ODR
violations when used in function templates (such as std::tr1::bind) from
multiple translation units. Although probably harmless (every definition
will generate identical code, even if technically ill-formed) we can
avoid the ODR violations by reusing the std::placeholder objects as the
std::tr1::placeholder objects.

To make this work, the std::_Placeholder type needs to be defined for
C++98 mode, so that <tr1/functional> can use it. The members of the
std::placeholder namespace must not be defined by <functional> in C++98
mode, because "placeholders", "_1", "_2" etc. are not reserved names in
C++98. Instead they can be declared in <tr1/functional>, because those
names *are* reserved in that header. With the std::placeholders objects
declared, a simple using-directive suffices to redeclare them in
namespace std::tr1::placeholders. This means any use of the TR1
placeholders actually refers to the C++11 placeholders, which are
defined with external linkage and exported from the library, so don't
cause ODR violations.

libstdc++-v3/ChangeLog:

	* include/std/functional (std::_Placeholder): Define for C++98
	as well as later standards.
	* include/tr1/functional (std::placeholders::_1 etc): Declare
	for C++98.
	(tr1::_Placeholder): Replace with using-declaration for
	std::_Placeholder.
	(tr1::placeholders::_1 etc.): Replace with using-directive for
	std::placeholders.
2020-10-27 16:32:53 +00:00
Jonathan Wakely
86558afc09 libstdc++: Remove unused variables in special functions
libstdc++-v3/ChangeLog:

	* include/tr1/ell_integral.tcc (__ellint_rf, __ellint_rd)
	(__ellint_rc, __ellint_rj): Remove unused variables.
	* include/tr1/modified_bessel_func.tcc (__airy): Likewise.
2020-10-27 16:32:53 +00:00
Jonathan Wakely
2232b61368 libstdc++: Fix -Wsign-compare warnings in headers
libstdc++-v3/ChangeLog:

	* include/bits/locale_conv.h (__str_codecvt_out_all):
	Add cast to compare operands of the same signedness.
	* include/bits/locale_facets_nonio.tcc
	(time_get::_M_extract_wday_or_month): Likewise.
	* include/bits/sstream.tcc (basic_stringbuf::overflow):
	Likewise.
	* include/tr1/legendre_function.tcc (__sph_legendre): Use
	unsigned for loop variable.
2020-10-27 16:32:53 +00:00
Jonathan Wakely
e579f66c3c libstdc++: Add missing noexcept to std::from_chars declarations
libstdc++-v3/ChangeLog:

	* include/std/charconv (from_chars): Add noexcept to match
	definitions in src/c++17/floating_from_chars.cc
2020-10-27 14:50:38 +00:00
Jonathan Wakely
044b04348c libstdc++: Fix directory_iterator exception specification
libstdc++-v3/ChangeLog:

	* src/c++17/fs_dir.cc (fs::directory_iterator::operator*):
	Add noexcept. Do not throw on precondition violation.
2020-10-27 14:50:37 +00:00