Commit Graph

6893 Commits

Author SHA1 Message Date
Jonathan Wakely
0789600c59 libstdc++: Fix deleted overload of __absu(bool)
libstdc++-v3/ChangeLog:

	* include/std/numeric (__detail::__absu(bool)): Make deleted
	function a function template, so it will be chosen for calls
	with an explicit template argument list.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Add dg-prune-output.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
2020-08-29 18:24:08 +01:00
Jonathan Wakely
f2f48b68a6 libstdc++: Fix common_type specializations for duration
My recent change to implement P0548 ("common_type and duration") was not
correct. The result of common_type_t<duration<R,P>, duration<R,P>>
should be duration<common_type_t<R>, P::type>, not duration<R, P::type>.
The common_type specialization for two different duration types was
correct, but the specializations for a single duration type (which only
exist to optimize compilation time) were wrong.

This fixes the partial specializations of common_type for a single
duration type, and also the return types of duration::operator+ and
duration::operator- which are supposed to use common_type_t<duration>.

libstdc++-v3/ChangeLog:

	* include/std/chrono (common_type): Fix partial specializations
	for a single duration type to use the common_type of the rep.
	(duration::operator+, duration::operator-): Fix return types
	to also use the common_type of the rep.
	* testsuite/20_util/duration/requirements/reduced_period.cc:
	Check duration using a rep that has common_type specialized.
2020-08-28 23:41:13 +01:00
Jonathan Wakely
82db1a42e9 libstdc++: Fix std::gcd and std::lcm for unsigned integers [PR 92978]
This fixes a bug with mixed signed and unsigned types, where converting
a negative value to the unsigned result type alters the value. The
solution is to obtain the absolute values of the arguments immediately
and to perform the actual GCD or LCM algorithm on two arguments of the
same type.

In order to operate on the most negative number without overflow when
taking its absolute, use an unsigned type for the result of the abs
operation. For example, -INT_MIN will overflow, but -(unsigned)INT_MIN
is (unsigned)INT_MAX+1U which is the correct value.

libstdc++-v3/ChangeLog:

	PR libstdc++/92978
	* include/std/numeric (__abs_integral): Replace with ...
	(__detail::__absu): New function template that returns an
	unsigned type, guaranteeing it can represent the most
	negative signed value.
	(__detail::__gcd, __detail::__lcm): Require arguments to
	be unsigned and therefore already non-negative.
	(gcd, lcm): Convert arguments to absolute value as unsigned
	type before calling __detail::__gcd or __detail::__lcm.
	* include/experimental/numeric (gcd, lcm): Likewise.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Adjust expected
	errors.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
	* testsuite/26_numerics/gcd/92978.cc: New test.
	* testsuite/26_numerics/lcm/92978.cc: New test.
	* testsuite/experimental/numeric/92978.cc: New test.
2020-08-28 23:03:28 +01:00
Jonathan Wakely
82030d5101 libstdc++: Make std::chrono::duration use reduced ratio for period
This implements the changes from P0548 "common_type and duration". That
was a change for C++17, but as it corrects some issues introduced by DRs
I'm also treating it as a DR and changing it for all modes from C++11
up.

The main change is that duration<R,P>::period no longer denotes P, but
rather P::type, the reduced ratio. The unary operator+ and operator-
members of duration should now return a duration using that reduced
ratio.

The requirement that common_type<T>::type is the same type as
common_type<T, T>::type (rather than simply T) was already implemented
for PR 89102.

The standard says that duration::operator+() and duration::operator-()
should return common_type_t<duration>, but that seems unnecessarily
expensive to compute. This change just uses duration<rep, period> which
is the same type, so we don't need to instantiate common_type.

As an optimization, this also adds partial specializations of
common_type for two durations of the same type, a single duration, two
time_points of the same type, and a single time_point. These
specializations avoid instantiating other specializations of common_type
and one or both of __duration_common_type or __timepoint_common_type for
the cases where the answer is trivial to obtain.

libstdc++-v3/ChangeLog:

	* include/std/chrono (__duration_common_type): Ensure the
	reduced ratio is used. Remove unused partial specialization
	using __failure_type.
	(common_type): Pass reduced ratios to __duration_common_type.
	Add partial specializations for simple cases involving a single
	duration or time_point type.
	(duration::period): Use reduced ratio.
	(duration::operator+(), duration::operator-()): Return duration
	type using the reduced ratio.
	* testsuite/20_util/duration/requirements/typedefs_neg2.cc:
	Adjust expected errors.
	* testsuite/20_util/duration/requirements/reduced_period.cc: New test.
2020-08-27 22:36:03 +01:00
Patrick Palka
71e9716137 libstdc++: Fix arithmetic bug in chrono::year_month::operator+
This fixes the months-based addition for year_month when the
year_month's month component is 0.

libstdc++-v3/ChangeLog:

	* include/std/chrono (year_month::operator+): Properly handle a
	month value of 0 by casting the month value to int before
	subtracting 1 from it so that the difference is sign-extended in
	the subsequent addition.
	* testsuite/std/time/year_month/1.cc: Test adding months to a
	year_month whose month component is below or above the
	normalized range of [1,12].
2020-08-27 14:11:24 -04:00
Patrick Palka
7b743c67f0 libstdc++: Fix operator overload ambiguity with calendar types
We currently don't enforce a constraint on some of the calendar types'
addition/subtraction operator overloads that take a 'months' arguments:

  Constraints: If the argument supplied by the caller for the months
  parameter is convertible to years, its implicit conversion sequence to
  years is worse than its implicit conversion sequence to months.

This constraint is relevant when adding/subtracting a duration to/from,
say, a year_month where the given duration is convertible to both
'months' and to 'years' (as in the new testcases below).  The correct
behavior here in light of this constraint is to perform the operation
through the (more efficient) 'years'-based overload, but we currently
emit an ambiguous overload error.

This patch templatizes the 'months'-based addition/subtraction operator
overloads so that in the event of an implicit-conversion tie, we select
the non-template 'years'-based overload.  This is the same approach
that the date library takes for enforcing this constraint.

libstdc++-v3/ChangeLog:

	* include/std/chrono
	(__detail::__months_years_conversion_disambiguator): Define.
	(year_month::operator+=): Templatize the 'months'-based overload
	so that the 'years'-based overload is selected in case of
	equally-ranked implicit conversion sequences to both 'months'
	and 'years' from the supplied argument.
	(year_month::operator-=): Likewise.
	(year_month::operator+): Likewise.
	(year_month::operator-): Likewise.
	(year_month_day::operator+=): Likewise.
	(year_month_day::operator-=): Likewise.
	(year_month_day::operator+): Likewise.
	(year_month_day::operator-): Likewise.
	(year_month_day_last::operator+=): Likewise.
	(year_month_day_last::operator-=): Likewise.
	(year_month_day_last::operator+): Likewise
	(year_month_day_last::operator-): Likewise.
	(year_month_day_weekday::operator+=): Likewise
	(year_month_day_weekday::operator-=): Likewise.
	(year_month_day_weekday::operator+): Likewise.
	(year_month_day_weekday::operator-): Likewise.
	(year_month_day_weekday_last::operator+=): Likewise
	(year_month_day_weekday_last::operator-=): Likewise.
	(year_month_day_weekday_last::operator+): Likewise.
	(year_month_day_weekday_last::operator-): Likewise.
	(testsuite/std/time/year_month/2.cc): New test.
	(testsuite/std/time/year_month_day/2.cc): New test.
	(testsuite/std/time/year_month_day_last/2.cc): New test.
	(testsuite/std/time/year_month_weekday/2.cc): New test.
	(testsuite/std/time/year_month_weekday_last/2.cc): New test.
2020-08-27 14:09:52 -04:00
Patrick Palka
3ae0cd94ab libstdc++: Implement remaining piece of LWG 3448
Almost all of the proposed resolution for LWG 3448 is already
implemented; the only part left is to adjust the return type of
transform_view::sentinel::operator-.

libstdc++-v3/ChangeLog:

	PR libstdc++/95322
	* include/std/ranges (transform_view::sentinel::__distance_from):
	Give this a deduced return type.
	(transform_view::sentinel::operator-): Adjust the return type so
	that it's based on the constness of the iterator rather than
	that of the sentinel.
	* testsuite/std/ranges/adaptors/95322.cc: Refer to LWG 3488.
2020-08-26 21:53:04 -04:00
Patrick Palka
4be16d1c1c libstdc++: elements_view's sentinel and iterator not comparable [LWG 3406]
This implements the proposed resolution for LWG 3406, and adds a
testcase for the example from P1994R1.

libstdc++-v3/ChangeLog:

	* include/std/ranges (elements_view::begin): Adjust constraints.
	(elements_view::end): Likewise.
	(elements_view::_Sentinel::operator==): Templatize to take both
	_Iterator<true> and _Iterator<false>.
	(elements_view::_Sentinel::operator-): Likewise.
	* testsuite/std/ranges/adaptors/elements.cc: Add testcase for
	the example from P1994R1.
	* testsuite/std/ranges/adaptors/lwg3406.cc: New test.
2020-08-26 21:52:58 -04:00
Patrick Palka
97ab5daa6c libstdc++: Implement P1994R1 changes to ranges::elements_view
The example from the paper doesn't compile without the proposed
resolution for LWG 3406, so we'll add a testcase for this once the
proposed resolution is implemented.

libstdc++-v3/ChangeLog:

	* include/std/ranges (elements_view::end): Replace these two
	overloads with four new overloads.
	(elements_view::_Iterator::operator==): Remove.
	(elements_view::_Iterator::operator-): Likewise.
	(elements_view::_Sentinel): Define.
2020-08-26 21:49:51 -04:00
Jonathan Wakely
af06acfc8d libstdc++: Whitespace changes in <tuple>
libstdc++-v3/ChangeLog:

	* include/std/tuple (_Tuple_impl): Whitespaces changes for
	consistent indentation. Also use __enable_if_t alias template.
2020-08-26 19:32:30 +01:00
Jonathan Wakely
5494edae83 libstdc++: Use correct argument type for __use_alloc [PR 96803]
The _Tuple_impl constructor for allocator-extended construction from a
different tuple type uses the _Tuple_impl's own _Head type in the
__use_alloc test. That is incorrect, because the argument tuple could
have a different type. Using the wrong type might select the
leading-allocator convention when it should use the trailing-allocator
convention, or vice versa.

libstdc++-v3/ChangeLog:

	PR libstdc++/96803
	* include/std/tuple
	(_Tuple_impl(allocator_arg_t, Alloc, const _Tuple_impl<U...>&)):
	Replace parameter pack with a type parameter and a pack and pass
	the first type to __use_alloc.
	* testsuite/20_util/tuple/cons/96803.cc: New test.
2020-08-26 19:32:30 +01:00
Patrick Palka
0c5df67ffc libstdc++: Fix typo in chrono::year_month_weekday::operator==
libstdc++-v3/ChangeLog:

	* include/std/chrono (year_month_weekday::operator==): Compare
	weekday_indexed instead of weekday.
	* testsuite/std/time/year_month_weekday/1.cc: Augment testcase.
2020-08-26 12:58:37 -04:00
Jonathan Wakely
9f9c0549dd libstdc++: Fix regression in hash containers
A recent change altered the layout of EBO-helper base classes, resulting
in an ambiguity when the hash function and equality predicate are the
same type.

This modifies the type of one of the base classes, so that we don't get
two base classes of the same type.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (_Hash_code_base): Change
	index of _Hashtable_ebo_helper base class.
	* testsuite/23_containers/unordered_map/dup_types.cc: New test.
2020-08-26 17:44:23 +01:00
Jonathan Wakely
3eefb302d2 libstdc++: Enable assertions in constexpr string_view members [PR 71960]
Since GCC 6.1 there is no reason we can't just use __glibcxx_assert in
constexpr functions in string_view. As long as the condition is true,
there will be no call to std::__replacement_assert that would make the
function ineligible for constant evaluation.

	PR libstdc++/71960
	* include/experimental/string_view (basic_string_view):
	Enable debug assertions.
	* include/std/string_view (basic_string_view):
	Likewise.
2020-08-26 14:48:49 +01:00
François Dumont
4797a61cc5 libstdc++: Rename _Hashtable _H1, _H2 and _Hash template parameters
Limit our _Hashtable implementation to ranged hash. _H1 is now rename
to _Hash matching the _Hash functor used for unordered containers. _H2
is now renamed to _RangeHash. Former _Hash simply becomes _Unused. Remove
_ExtractKey storage.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (_Hashtable<>): Rename _H1 into _Hash
	_H2 into _RangeHash and _Hash into _Unused.
	(_Hastable_base<>): Likewise.
	(_Map_base<>): Likewise.
	(_Insert_base<>): Likewise.
	(_Insert<>): Likewise.
	(_Rehash_base<>): Likewise.
	(_Local_iterator_base<>): Likewise.
	(_Hash_code_base<>): Likewise.
	(_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, false>):
	Remove.
	(_Hash_code_base<_Key, _Value, _ExtractKey, _H1, _H2, _Hash, true>):
	Remove.
	(_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHas, _Unused,
	bool>): Remove _Hashtable_ebo_helper<2, _RangeHash> base type..
	(_Hash_code_base<>::_M_bucket_index(const _Key&, __hash_code, size_t)):
	Replace by...
	(_Hash_code_base<>::_M_bucket_index(__hash_code, size_t)): ...this.
	(_Local_iterator<>): Remove _H1 and _H2 template parameters.
	(_Local_const_iterator<>): Likewise.
	(_Equality<>): Likewise.
	(_Map_base<>::operator[](const key_type&): Adapt.
	(_Map_base<>::operator[](key_type&&): Adapt.
	(_Identity::operator()): Add noexcept.
	(_Select1st::operator()): Likewise.
	(_Hash_code_base<>): Remove _Hashtable_ebo_helper<0, _ExtractKey> base
	type.
	(_Hash_code_base::_M_extract): Remove.
	* include/bits/hashtable.h (_Hashtable<>): Remove _H1 and _H2 template
	parameters. Remove _ExtractKey from constructors.
	(_Hashtable<>::_M_insert_unique_node(const key_type&, size_t,
	__hash_code, __node_type*, size_t)): Replace by...
	(_Hashtable<>::_M_insert_unique_node(size_t, __hash_code,
	 __node_type*, size_t)): ...this.
	(_Hashtable<>::_M_insert_muti_node(__node_type*, const key_type&,
	__hash_code, __node_type*)): Replace by...
	(_Hashtable<>::_M_insert_multi_node(__node_type*, __hash_code,
	__node_type*)): ...this.
	(_Hashtable<>::__key_extract): Remove.
	* include/bits/node_handle.h: Adapt.
2020-08-26 07:58:46 +02:00
Patrick Palka
1007170df8 libstdc++: Fix debug-mode build failure in <chrono>
libstdc++-v3/ChangeLog:

	* include/std/chrono (year_month_weekday::ok): Fix assert.
2020-08-25 11:23:36 -04:00
Jonathan Wakely
71ed3c0c9a libstdc++: Adjust static assertions in futures and promises [LWG 3466]
Add a static_assertions to check the result type is destructible, as in
the proposed resolution for LWG 3466 (which supersedes 3458).

libstdc++-v3/ChangeLog:

	* include/std/future (future, shared_future. promise): Add
	is_destructible assertion (LWG 3466). Adjust string-literal for
	!is_array and !is_function assertions.
	* testsuite/30_threads/future/requirements/lwg3458.cc: Check
	types with no accessible destructor. Adjust expected errors.
	* testsuite/30_threads/promise/requirements/lwg3466.cc:
	Likewise.
	* testsuite/30_threads/shared_future/requirements/lwg3458.cc:
	Likewise.
2020-08-25 15:52:57 +01:00
Patrick Palka
03d5044b31 libstdc++: Add more C++20 additions to <chrono>
This patch adds the C++20 calendar types and their methods as defined in
[time.cal] (modulo the parsing/printing support).  This patch also
implements [time.hms] and [time.12], and a few more bits of
[time.clock].  The remaining C++20 additions to <chrono> from P0355 and
P1466 depend on [time.zone] and <format>, so they will come later, as
will more optimized versions of some of the algorithms added here.

The non-member operator overloads for the calendar types are defined as
namespace-scope functions in the standard, but here we instead define
these operator overloads as hidden friends.  This simplifies the
implementation somewhat and lets us reap the benefits of hidden friends
for these overloads.

The bulk of this work is based on a patch from Ed Smith-Rowland, which can
be found at the Git branch users/redi/heads/calendar.

Co-authored-by: Ed Smith-Rowland <3dw4rd@verizon.net>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* include/std/chrono (time_point::operator++)
	(time_point::operator--): Define.
	(utc_clock, tai_clock, gps_clock): Forward declare.
	(utc_time, utc_seconds, tai_time, tai_seconds, gps_time)
	(gps_seconds): Define.
	(is_clock<utc_clock>, is_clock<tai_clock>, is_clock<gps_clock>)
	(is_clock_v<utc_clock>, is_clock_v<tai_clock>)
	(is_clock_v<gps_clock>): Define these specializations.
	(leap_second_info): Define.
	(day, month, year, weekday, weekday_indexed)
	(weekday_last, month_day, month_day_last, month_weekday)
	(month_weekday_last, year_month, year_month_day)
	(year_month_day_last, year_month_weekday, year_month_weekday_last):
	Declare and later define.
	(last_spec, last, __detail::__days_per_month)
	(__detail::__days_per_month, __detail::__last_day): Define.
	(January, February, March, April, May, June, July, August)
	(September, October, November, December, Sunday, Monday, Tuesday)
	(Wednesday, Thursday, Friday, Saturday): Define.
	(weekday::operator[]): Define out-of-line.
	(year_month_day::_S_from_days, year_month_day::M_days_since_epoch):
	Likewise.
	(year_month_day::year_month_day, year_month_day::ok): Likewise.
	(__detail::__pow10, hh_mm_ss): Define.
	(literals::chrono_literals::operator""d)
	(literals::chrono_literals::operator""y): Define.
	(is_am, is_pm, make12, make24): Define.
	* testsuite/20_util/time_point/4.cc: New test.
	* testsuite/std/time/day/1.cc: New test.
	* testsuite/std/time/hh_mm_ss/1.cc: New test.
	* testsuite/std/time/is_am/1.cc: New test.
	* testsuite/std/time/is_pm/1.cc: New test.
	* testsuite/std/time/make12/1.cc: New test.
	* testsuite/std/time/make24/1.cc: New test.
	* testsuite/std/time/month/1.cc: New test.
	* testsuite/std/time/month_day/1.cc: New test.
	* testsuite/std/time/month_day_last/1.cc: New test.
	* testsuite/std/time/month_weekday/1.cc: New test.
	* testsuite/std/time/month_weekday_last/1.cc: New test.
	* testsuite/std/time/weekday/1.cc: New test.
	* testsuite/std/time/weekday_indexed/1.cc: New test.
	* testsuite/std/time/weekday_last/1.cc: New test.
	* testsuite/std/time/year/1.cc: New test.
	* testsuite/std/time/year_month/1.cc: New test.
	* testsuite/std/time/year_month_day/1.cc: New test.
	* testsuite/std/time/year_month_day_last/1.cc: New test.
	* testsuite/std/time/year_month_weekday/1.cc: New test.
	* testsuite/std/time/year_month_weekday_last/1.cc: New test.
2020-08-25 10:23:59 -04:00
Jonathan Wakely
ef275d1f20 libstdc++: Add deduction guide for std::ranges::join_view [LWG 3474]
This implements the proposed resolution for LWG 3474.

libstdc++-v3/ChangeLog:

	* include/std/ranges (join_view): Add deduction guide (LWG 3474).
	* testsuite/std/ranges/adaptors/join_lwg3474.cc: New test.
2020-08-24 16:18:32 +01:00
Jonathan Wakely
186aa63045 libstdc++: Fix std::indirectly_readable ambiguity [LWG 3446]
This implements the proposed resolution of LWG 3446. I'm also adding
another new constrained specialization which isn't proposed by 3446, to
resolve the ambiguity when a type has both value_type and element_type
but denoting different types.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (indirectly_readable): Add
	partial specializations to resolve ambiguities (LWG 3446).
	* testsuite/24_iterators/associated_types/readable.traits.cc:
	Check types with both value_type and element_type.
2020-08-24 16:18:31 +01:00
Jonathan Wakely
a0e6f05d26 libstdc++: Fix iota_view::size() to avoid overflow
This avoids the overflow that occurs when negating the most negative
value of an integral type.

Also prevent returning signed int when the values have lower rank and
promote to int.

libstdc++-v3/ChangeLog:

	* include/std/ranges (ranges::iota_view::size()): Perform all
	calculations in the right unsigned types.
	* testsuite/std/ranges/iota/size.cc: New test.
2020-08-24 16:17:04 +01:00
Jonathan Wakely
074436cf8c libstdc++: Make variant_npos conversions explicit [PR 96766]
libstdc++-v3/ChangeLog:

	PR libstdc++/96766
	* include/std/variant (_Variant_storage): Replace implicit
	conversions from size_t to __index_type with explicit casts.
2020-08-24 16:10:07 +01:00
Jonathan Wakely
5e9ad288eb libstdc++: Make incrementable<__int128> satisfied in strict mode
This adds specializations of std::incrementable_traits so that 128-bit
integers are always considered incrementable (and therefore usable with
std::ranges::iota_view) even when they don't satisfy std::integral.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h [__STRICT_ANSI__]
	(incrementable_traits<__int128>): Define specialization.
	(incrementable_traits<unsigned __int128>): Likewise.
	* testsuite/std/ranges/iota/96042.cc: Test iota_view with
	__int128.
2020-08-20 19:42:02 +01:00
Jonathan Wakely
e6e01618e8 libstdc++: Make make-unsigned-like-t<__int128> work [PR 96042]
As well as ensuring that numeric_limits<__int128> is defined, we need to
ensure that make-unsigned-like-t and to-unsigned-like work correctly for
128-bit integers in strict mode. This ensures that a subrange created
from an iota_view's iterator and sentinel can represent its size.

Co-authored-by: Patrick Palka  <ppalka@redhat.com>

libstdc++-v3/ChangeLog:

2020-08-19  Jonathan Wakely  <jwakely@redhat.com>
	    Patrick Palka  <ppalka@redhat.com>

	PR libstdc++/96042
	* include/bits/range_access.h (__detail::__to_unsigned_like):
	Do not use make_unsigned_t<T> in the return type, as it can
	result in an error before the integral<T> constraint is checked.
	[__STRICT_ANSI__]: Add overloads for 128-bit integer types.
	(__detail::__make_unsigned_like_t): Define as the return type
	of __to_unsigned_like.
	* testsuite/std/ranges/subrange/96042.cc: New test.
2020-08-19 20:36:10 +01:00
Jonathan Wakely
5abc821556 libstdc++: Remove deprecated comparison operators for RB trees
These functions were deprecated in GCC 9.1.0 because they are never used
by the library. This patch removes them for GCC 11.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tree.h (operator!=, operator>, operator<=)
	(operator>=): Remove deprecated functions.
2020-08-19 17:04:49 +01:00
Jonathan Wakely
386fd16c55 libstdc++: Make __int128 meet integer-class requirements [PR 96042]
Because __int128 can be used as the difference type for iota_view, we
need to ensure that it meets the requirements of an integer-class type.
The requirements in [iterator.concept.winc] p10 include numeric_limits
being specialized and giving meaningful answers. Currently we only
specialize numeric_limits for non-standard integer types in non-strict
modes.  However, nothing prevents us from defining an explicit
specialization for any implementation-defined type, so it doesn't matter
whether std::is_integral<__int128> is true or not.

This patch ensures that the numeric_limits specializations for signed
and unsigned __int128 are defined whenever __int128 is available. It
also makes the __numeric_traits and __int_limits helpers work for
__int128, via a new __gnu_cxx::__is_integer_nonstrict trait.

libstdc++-v3/ChangeLog:

	PR libstdc++/96042
	* include/ext/numeric_traits.h (__is_integer_nonstrict): New
	trait which is true for 128-bit integers even in strict modes.
	(__numeric_traits_integer, __numeric_traits): Use
	__is_integer_nonstrict instead of __is_integer.
	* include/std/limits [__STRICT_ANSI__ && __SIZEOF_INT128__]
	(numeric_limits<__int128>, (numeric_limits<unsigned __int128>):
	Define.
	* testsuite/std/ranges/iota/96042.cc: New test.
2020-08-19 16:49:07 +01:00
Jonathan Wakely
1e235788bb libstdc++: Mention new macros in comments
libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_DEPRECATED_SUGGEST)
	(_GLIBCXX11_DEPRECATED, _GLIBCXX11_DEPRECATED_SUGGEST)
	(_GLIBCXX17_DEPRECATED_SUGGEST, _GLIBCXX20_DEPRECATED_SUGGEST):
	Add new macros to comment.
2020-08-19 14:51:32 +01:00
Patrick Palka
e6c76f0d33 libstdc++: integer-class types as per [iterator.concept.winc]
This implements signed and unsigned integer-class types, whose width is
one bit larger than the widest supported signed and unsigned integral
type respectively.  In our case this is either __int128 and unsigned
__int128, or long long and unsigned long long.

Internally, the two integer-class types are represented as a largest
supported unsigned integral type plus one extra bit.  The signed
integer-class type is represented in two's complement form with the
extra bit acting as the sign bit.

libstdc++-v3/ChangeLog:

	* include/Makefile.am (bits_headers): Add new header
	<bits/max_size_type.h>.
	* include/Makefile.in: Regenerate.
	* include/bits/iterator_concepts.h
	(ranges::__detail::__max_diff_type): Remove definition, replace
	with forward declaration of class __max_diff_type.
	(__detail::__max_size_type): Remove definition, replace with
	forward declaration of class __max_size_type.
	(__detail::__is_unsigned_int128, __is_signed_int128)
	(__is_int128): New concepts.
	(__detail::__is_integer_like): Accept __int128 and unsigned
	__int128.
	(__detail::__is_signed_integer_like): Accept __int128.
	* include/bits/max_size_type.h: New header.
	* include/bits/range_access.h: Include <bits/max_size_type.h>.
	(__detail::__to_unsigned_like): Two new overloads.
	* testsuite/std/ranges/iota/difference_type.cc: New test.
	* testsuite/std/ranges/iota/max_size_type.cc: New test.
2020-08-19 09:12:55 -04:00
Jonathan Wakely
eef9bf4ca8 libstdc++: Add deprecated attributes to old iostream members
Back in 2017 I removed these prehistoric members (which were deprecated
since C++98) for C++17 mode. But I didn't add deprecated attributes to
most of them, so users didn't get any warning they would be going away.
Apparently some poor souls do actually use some of these names, and so
now that GCC 11 defaults to -std=gnu++17 some code has stopped
compiling.

This adds deprecated attributes to them, so that C++98/03/11/14 code
will get a warning if it uses them. I'll also backport this to the
release branches so that users can find out about the deprecation before
they start using C++17.

In order to give deprecated warnings even in C++98 mode this patch makes
_GLIBCXX_DEPRECATED work even for C++98, adds _GLIBCXX11_DEPRECATED for
the old meaning of _GLIBCXX_DEPRECATED, and adds new macros such as
_GLIBCXX_DEPRECATED_SUGGEST for suggesting alternatives to deprecated
features.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_DEPRECATED): Define for all
	standard modes.
	(_GLIBCXX_DEPRECATED_SUGGEST): New macro for "use 'foo' instead"
	message in deprecated warnings.
	(_GLIBCXX11_DEPRECATED, _GLIBCXX11_DEPRECATED_SUGGEST): New
	macros for marking features derpecated in C++11.
	(_GLIBCXX17_DEPRECATED_SUGGEST, _GLIBCXX20_DEPRECATED_SUGGEST):
	New macros.
	* include/backward/auto_ptr.h (auto_ptr_ref, auto_ptr<void>):
	Use _GLIBCXX11_DEPRECATED instead of _GLIBCXX_DEPRECATED.
	(auto_ptr): Use _GLIBCXX11_DEPRECATED_SUGGEST.
	* include/backward/binders.h (binder1st, binder2nd): Likewise.
	* include/bits/ios_base.h (io_state, open_mode, seek_dir)
	(streampos, streamoff): Use _GLIBCXX_DEPRECATED_SUGGEST.
	* include/std/streambuf (stossc): Replace C++11 attribute
	with _GLIBCXX_DEPRECATED_SUGGEST.
	* include/std/type_traits (__is_nullptr_t): Use
	_GLIBCXX_DEPRECATED_SUGGEST instead of _GLIBCXX_DEPRECATED.
	* testsuite/27_io/types/1.cc: Check for deprecated warnings.
	Also check for io_state, open_mode and seek_dir typedefs.
2020-08-19 12:13:23 +01:00
Antony Polukhin
69f571ffc5 libstdc++: assert that type traits are not misused with incomplete types [PR 71579]
libstdc++-v3/ChangeLog:

2020-08-19  Antony Polukhin  <antoshkka@gmail.com>

	PR libstdc++/71579
	* include/std/type_traits (invoke_result, is_nothrow_invocable_r)
	Add static_asserts to make sure that the argument of the type
	trait is not misused with incomplete types.
	(is_swappable_with, is_nothrow_swappable_with): Add static_asserts
	to make sure that the first and second arguments of the type trait
	are not misused with incomplete types.
	* testsuite/20_util/invoke_result/incomplete_neg.cc: New test.
	* testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: New test.
	* testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc: New test.
	* testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc: New
	test.
	* testsuite/20_util/is_swappable_with/incomplete_neg.cc: New test.
2020-08-19 12:12:40 +01:00
Jonathan Wakely
bb1b7f087b libstdc++: Remove redundant copying of std::async arguments [PR 69724]
As was previously done for std::thread, this removes an unnecessary copy
of an rvalue of type thread::_Invoker. Instead of creating the rvalue
and then moving that into the shared state, the member of the shared
state is initialized directly from the forwarded callable and bound
arguments.

This also slightly simplifies std::thread creation to remove the
_S_make_state helper function.

libstdc++-v3/ChangeLog:

	PR libstdc++/69724
	* include/std/future (__future_base::_S_make_deferred_state)
	(__future_base::_S_make_async_state): Remove.
	(__future_base::_Deferred_state): Change constructor to accept a
	parameter pack of arguments and forward them to the call
	wrapper.
	(__future_base::_Async_state_impl): Likewise. Replace lambda
	expression with a named member function.
	(async): Construct state object directly from the arguments,
	instead of using thread::__make_invoker, _S_make_deferred_state
	and _S_make_async_state. Move shared state into the returned
	future.
	* include/std/thread (thread::_Call_wrapper): New alias
	template for use by constructor and std::async.
	(thread::thread(Callable&&, Args&&...)): Create state object
	directly instead of using _S_make_state.
	(thread::__make_invoker, thread::__decayed_tuple)
	(thread::_S_make_state): Remove.
	* testsuite/30_threads/async/69724.cc: New test.
2020-08-18 14:28:38 +01:00
Jonathan Wakely
91e6226f88 libstdc++: Remove inheritance from elements in std::tuple
This fixes a number of std::tuple bugs by no longer making use of the
empty base-class optimization. By using the C++20 [[no_unique_address]]
attribute we can always store the element as a data member, while still
compressing the layout of tuples containing empty types.

Since we no longer use inheritance we could also apply the compression
optimization for final types and for tuples of tuples, but doing so
would be an ABI break.

Using [[no_unique_address]] more liberally for the unstable std::__8
configuration is left for a later date. There may be reasons not to
apply the attribute unconditionally, e.g. see the discussion about
guaranteed elision in PR 94062.

libstdc++-v3/ChangeLog:

	PR libstdc++/55713
	PR libstdc++/71096
	PR libstdc++/93147
	* include/std/tuple [__has_cpp_attribute(no_unique_address)]
	(_Head_base<Idx, Head, true>): New definition of the partial
	specialization, using [[no_unique_address]] instead of
	inheritance.
	* testsuite/libstdc++-prettyprinters/48362.cc: Adjust expected
	output.
	* testsuite/20_util/tuple/comparison_operators/93147.cc: New test.
	* testsuite/20_util/tuple/creation_functions/55713.cc: New test.
	* testsuite/20_util/tuple/element_access/71096.cc: New test.
2020-08-17 15:27:51 +01:00
Jonathan Wakely
c2fb0a1a2e libstdc++: Make self-move well-defined for containers [PR 85828]
The C++ LWG recently confirmed that self-move assignment should not have
undefined behaviour for standard containers (see the proposed resolution
of LWG 2839). The result should be a valid but unspecified value, just
like other times when a container is moved from.

Our std::list, std::__cxx11::basic_string and unordered containers all
have bugs which result in undefined behaviour.

For std::list the problem is that we clear the previous contents using
_M_clear() instead of clear(). This means the _M_next, _M_prev and
_M_size members are not zeroed, and so after we "update" them (with
their existing values), we are left with dangling pointers and a
non-zero size, but no elements.

For the unordered containers the problem is similar. _Hashtable first
deallocates the existing contents, then takes ownership of the pointers
from the RHS object (which has just had its contents deallocated so the
pointers are dangling).

For std::basic_string it's a little more subtle. When the string is
local (i.e. fits in the SSO buffer) we use char_traits::copy to copy the
contents from this->data() to __rhs.data(). When &__rhs == this that
copy violates the precondition that the ranges don't overlap. We only
need to check for self-move for this case where it's local, because the
only other case that can be true for self-move is that it's non-local
but the allocators compare equal. In that case the data pointer is
neither deallocated nor leaked, so the result is well-defined.

This patch also makes a small optimization for std::deque move
assignment, to use the efficient move when is_always_equal is false, but
the allocators compare equal at runtime.

Finally, we need to remove all the Debug Mode checks which abort the
program when a self-move is detected, because it's not undefined to do
that.

Before PR 85828 can be closed we should also look into fixing
std::shuffle so it doesn't do any redundant self-swaps.

libstdc++-v3/ChangeLog:

	PR libstdc++/85828
	* include/bits/basic_string.h (operator=(basic_string&&)): Check
	for self-move before copying with char_traits::copy.
	* include/bits/hashtable.h (operator=(_Hashtable&&)): Check for
	self-move.
	* include/bits/stl_deque.h (_M_move_assign1(deque&&, false_type)):
	Check for equal allocators.
	* include/bits/stl_list.h (_M_move_assign(list&&, true_type)):
	Call clear() instead of _M_clear().
	* include/debug/formatter.h (__msg_self_move_assign): Change
	comment.
	* include/debug/macros.h (__glibcxx_check_self_move_assign):
	(_GLIBCXX_DEBUG_VERIFY): Remove.
	* include/debug/safe_container.h (operator=(_Safe_container&&)):
	Remove assertion check for safe move and make it well-defined.
	* include/debug/safe_iterator.h (operator=(_Safe_iterator&&)):
	Remove assertion check for self-move.
	* include/debug/safe_local_iterator.h
	(operator=(_Safe_local_iterator&&)): Likewise.
	* testsuite/21_strings/basic_string/cons/char/self_move.cc: New test.
	* testsuite/23_containers/deque/cons/self_move.cc: New test.
	* testsuite/23_containers/forward_list/cons/self_move.cc: New test.
	* testsuite/23_containers/list/cons/self_move.cc: New test.
	* testsuite/23_containers/set/cons/self_move.cc: New test.
	* testsuite/23_containers/unordered_set/cons/self_move.cc: New test.
	* testsuite/23_containers/vector/cons/self_move.cc: New test.
2020-08-12 20:36:00 +01:00
François Dumont
8b7af071b0 libstdc++: Implement DR 526 on [forward_]list remove_if/unique [PR 91620]
Respect DR 526 in implementation of std::[forward_]list remove/remove_if/unique.
[forward_]list::remove was already implementing it but the implementation has
been modified to generalize the following pattern. All nodes to remove are
collected in an intermediate [forward_]list which purpose is just to be
detroyed once out of scope.

libstdc++-v3/ChangeLog:

	PR libstdc++/91620
	* include/bits/forward_list.tcc (forward_list<>::remove): Collect nodes
	to destroy in an intermediate forward_list.
	(forward_list<>::remove_if, forward_list<>::unique): Likewise.
	* include/bits/list.tcc (list<>::remove, list<>::unique): Likewise.
	(list<>::remove_if): Likewise.
	* include/debug/forward_list (forward_list<>::_M_erase_after): Remove.
	(forward_list<>::erase_after): Adapt.
	(forward_list<>::remove, forward_list<>::remove_if): Collect nodes to
	destroy in an intermediate forward_list.
	(forward_list<>::unique): Likewise.
	* include/debug/list (list<>::remove, list<>::unique): Likewise.
	(list<>::remove_if): Likewise.
	* testsuite/23_containers/forward_list/operations/91620.cc: New test.
	* testsuite/23_containers/list/operations/91620.cc: New test.
2020-08-11 21:30:05 +02:00
Jonathan Wakely
18095be170 libstdc++: Make Networking TS work without gthreads [PR 89760]
Make the experimental Networking TS code work without std::mutex and
std::condition_variable.

libstdc++-v3/ChangeLog:

	PR libstdc++/89760
	* include/experimental/executor [!_GLIBCXX_HAS_GTHREADS]:
	(execution_context::mutex_type): Define dummy mutex type.
	(system_context): Use execution_context::mutex_type.
	(system_context) [!_GLIBCXX_HAS_GTHREADS]: Define dummy
	thread and condition variable types.
	[!_GLIBCXX_HAS_GTHREADS] (system_context::_M_run()): Do not
	define.
	(system_context::_M_post) [!_GLIBCXX_HAS_GTHREADS]: Throw
	an exception when threads aren't available.
	(strand::running_in_this_thread()): Defer to _M_state.
	(strand::_State::running_in_this_thread()): New function.
	(use_future_t): Do not depend on _GLIBCXX_USE_C99_STDINT_TR1.
	* include/experimental/io_context (io_context): Use the
	execution_context::mutex_type alias. Replace stack of thread
	IDs with counter.
	* testsuite/experimental/net/execution_context/use_service.cc:
	Enable test for non-pthread targets.
2020-08-11 16:16:22 +01:00
Jonathan Wakely
2a6918e4fa libstdc++: Make net::system_context tag type constructor explicit
libstdc++-v3/ChangeLog:

	* include/experimental/executor (system_context::a__tag): Make
	default constructor explicit.
2020-08-11 16:16:21 +01:00
Jonathan Wakely
61759518ad libstdc++: Fix net::system_context stop condition
libstdc++-v3/ChangeLog:

	* include/experimental/executor (system_context::_M_run()):
	Fix predicate.
	* testsuite/experimental/net/system_context/1.cc: New test.
2020-08-11 16:16:21 +01:00
Jonathan Wakely
35e5294c4b libstdc++: Fix <stop_token> to compile without gthreads
libstdc++-v3/ChangeLog:

	* include/std/stop_token: Check _GLIBCXX_HAS_GTHREADS using
	#ifdef instead of #if.
	(stop_token::_S_yield()): Check _GLIBCXX_HAS_GTHREADS before
	using __gthread_yield.
2020-08-11 16:16:21 +01:00
Jonathan Wakely
5bbb1f3000 libstdc++: Make std::this_thread functions work without gthreads
The only function in namespace std::this_thread that actually depends on
thread support being present is this_thread::get_id(). The other
functions (yield, sleep_for and sleep_until) can be defined for targets
without gthreads.

A small change is needed in std::this_thread::sleep_for which currently
uses the __gthread_time_t typedef. Since it just calls nanosleep
directly, it should use timespec directly instead of the typedef.

Even std::this_thread::get_id() could be made to work, the only
difficulty is that it returns a value of type std:🧵:id and
std::thread is only defined when gthreads support exists.

libstdc++-v3/ChangeLog:

	* include/std/thread [!_GLIBCXX_HAS_GTHREADS] (this_thread::yield)
	(this_thread::sleep_until): Define.
	[!_GLIBCXX_HAS_GTHREADS] (this_thread::sleep_for): Define. Replace
	use of __gthread_time_t typedef with timespec.
	* src/c++11/thread.cc [!_GLIBCXX_HAS_GTHREADS] (__sleep_for):
	Likewise.
	* testsuite/30_threads/this_thread/2.cc: Moved to...
	* testsuite/30_threads/this_thread/yield.cc: ...here.
	* testsuite/30_threads/this_thread/3.cc: Moved to...
	* testsuite/30_threads/this_thread/sleep_for-mt.cc: ...here.
	* testsuite/30_threads/this_thread/4.cc: Moved to...
	* testsuite/30_threads/this_thread/sleep_until-mt.cc: ...here.
	* testsuite/30_threads/this_thread/58038.cc: Add
	dg-require-sleep.
	* testsuite/30_threads/this_thread/60421.cc: Likewise.
	* testsuite/30_threads/this_thread/sleep_for.cc: New test.
	* testsuite/30_threads/this_thread/sleep_until.cc: New test.
2020-08-11 16:16:21 +01:00
Jonathan Wakely
2203a80a72 libstdc++: Implement LWG 561 for std::inserter
libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (inserter): Do not deduce
	iterator type (LWG 561).
	* testsuite/24_iterators/insert_iterator/dr561.cc: New test.
2020-08-10 12:09:59 +01:00
Jonathan Wakely
8bd92d8097 libstdc++: Check __cpp_exceptions in basic_string::reserve()
If exceptions are disabled then reallocating could abort, so ignore
shrink-to-fit requests.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI=0]
	(basic_string::reserve()): Do nothing if exceptions are not
	enabled.
2020-08-10 12:02:18 +01:00
Jonathan Wakely
de1e3b8795 libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303]
With -pedantic the debug mode bitset has an ambiguous equality
comparison operator, because it tries to compare the non-debug base to
the debug object. The base object can be converted to another debug
bitset, making the same operator== a candidate again.

The fix is to do the comparison on both base objects, so the operator
for the derived type isn't a candidate.

For the inequality operator the same change should be done, but that
operator can be removed entirely for C++20 because it can be synthesized
by the compiler.

I don't think either equality or inequality operators are really needed,
because the public _GLIBCXX_STD_C::bitset base class cam always be
compared using its own comparison operators. I'm not changing that here
though.

libstdc++-v3/ChangeLog:

	PR libstdc++/96303
	* include/debug/bitset (bitset::operator==): Call _M_base() on
	right operand.
	(bitset::operator!=): Likewise, but don't define it at all when
	default comparisons are supported by the compiler.
	* testsuite/23_containers/bitset/operations/96303.cc: New test.
2020-08-07 20:29:11 +01:00
Andrew Luo
140cf935cd libstdc++: Implement P0966 std::string::reserve should not shrink
Remove ability for reserve(n) to reduce a string's capacity. Add a new
reserve() overload that makes a shrink-to-fit request, and make
shrink_to_fit() use that.

libstdc++-v3/ChangeLog:

2020-07-30  Andrew Luo  <andrewluotechnologies@outlook.com>
	    Jonathan Wakely  <jwakely@redhat.com>

	* config/abi/pre/gnu.ver (GLIBCXX_3.4): Use less greedy
	patterns for basic_string members.
	(GLIBCXX_3.4.29): Export new basic_string::reserve symbols.
	* doc/xml/manual/status_cxx2020.xml: Update P0966 status.
	* include/bits/basic_string.h (shrink_to_fit()): Call reserve().
	(reserve(size_type)): Remove default argument.
	(reserve()): Declare new overload.
	[!_GLIBCXX_USE_CXX11_ABI] (shrink_to_fit, reserve): Likewise.
	* include/bits/basic_string.tcc (reserve(size_type)): Remove
	support for shrinking capacity.
	(reserve()): Perform shrink-to-fit operation.
	[!_GLIBCXX_USE_CXX11_ABI] (reserve): Likewise.
	* testsuite/21_strings/basic_string/capacity/1.cc: Adjust to
	reflect new behavior.
	* testsuite/21_strings/basic_string/capacity/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string/capacity/char/18654.cc:
	Likewise.
	* testsuite/21_strings/basic_string/capacity/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/capacity/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc:
	Likewise.
	* testsuite/21_strings/basic_string/capacity/wchar_t/2.cc:
	Likewise.
2020-08-06 19:49:07 +01:00
Jonathan Wakely
4e39f563c0 libstdc++: Do not set eofbit eagerly in operator>>(istream&, char(&)[N])
Similar to the bugs I fixed recently in istream::ignore, we incorrectly
set eofbit too often in operator>>(istream&, string&) and
operator>>(istream&.  char(&)[N]).

We should only set eofbit if we reach EOF but would have kept going
otherwise. If we've already extracted the maximum number of characters
(whether that's because of the buffer size or the istream's width())
then we should not set eofbit.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.tcc
	(operator>>(basic_istream&, basic_string&)): Do not set eofbit
	if extraction stopped after in.width() characters.
	* src/c++98/istream-string.cc (operator>>(istream&, string&)):
	Likewise.
	* include/bits/istream.tcc (__istream_extract): Do not set
	eofbit if extraction stopped after n-1 characters.
	* src/c++98/istream.cc (__istream_extract): Likewise.
	* testsuite/21_strings/basic_string/inserters_extractors/char/13.cc: New test.
	* testsuite/21_strings/basic_string/inserters_extractors/wchar_t/13.cc: New test.
	* testsuite/27_io/basic_istream/extractors_character/char/5.cc: New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/5.cc: New test.
2020-08-06 19:23:14 +01:00
Jonathan Wakely
6251ea15f5 libstdc++: Adjust overflow prevention to operator>>
This adjusts the overflow prevention added to operator>> so that we can
distinguish "unknown size" from "zero size", and avoid writing anything
at all in to zero sized buffers.

This also removes the incorrect comment saying extraction stops at a
null byte.

libstdc++-v3/ChangeLog:

	* include/std/istream (operator>>(istream&, char*)): Add
	attributes to get warnings for pointers that are null or known
	to point to the end of a buffer. Request upper bound from
	__builtin_object_size check and handle zero-sized buffer case.
	(operator>>(istream&, signed char))
	(operator>>(istream&, unsigned char*)): Add attributes.
	* testsuite/27_io/basic_istream/extractors_character/char/overflow.cc:
	Check extracting into the middle of a buffer.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/overflow.cc: New test.
2020-08-06 18:26:45 +01:00
Jonathan Wakely
b2d4ba65dc libstdc++: Break long lines to fit in 80 columns
libstdc++-v3/ChangeLog:

	* include/std/atomic (atomic<T>::store): Reformat.
2020-08-05 22:48:17 +01:00
Jonathan Wakely
17abcc7734 libstdc++: Replace operator>>(istream&, char*) [LWG 2499]
P0487R1 resolved LWG 2499 for C++20 by removing the operator>> overloads
that have high risk of buffer overflows. They were replaced by
equivalents that only accept a reference to an array, and so can
guarantee not to write past the end of the array.

In order to support both the old and new functionality, this patch
introduces a new overloaded __istream_extract function which takes a
maximum length. The new operator>> overloads use the array size as the
maximum length. The old overloads now use __builtin_object_size to
determine the available buffer size if available (which requires -O2) or
use numeric_limits<streamsize>::max()/sizeof(char_type) otherwise. This
is a change in behaviour, as the old overloads previously always used
numeric_limits<streamsize>::max(), without considering sizeof(char_type)
and without attempting to prevent overflows.

Because they now do little more than call __istream_extract, the old
operator>> overloads are very small inline functions. This means there
is no advantage to explicitly instantiating them in the library (in fact
that would prevent the __builtin_object_size checks from ever working).
As a result, the explicit instantiation declarations can be removed from
the header. The explicit instantiation definitions are still needed, for
backwards compatibility with existing code that expects to link to the
definitions in the library.

While working on this change I noticed that src/c++11/istream-inst.cc
has the following explicit instantiation definition:
  template istream& operator>>(istream&, char*);
This had no effect (and so should not have been present in that file),
because there was an explicit specialization declared in <istream> and
defined in src/++98/istream.cc. However, this change removes the
explicit specialization, and now the explicit instantiation definition
is necessary to ensure the symbol gets defined in the library.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.29): Export new symbols.
	* include/bits/istream.tcc (__istream_extract): New function
	template implementing both of operator>>(istream&, char*) and
	operator>>(istream&, char(&)[N]). Add explicit instantiation
	declaration for it. Remove explicit instantiation declarations
	for old function templates.
	* include/std/istream (__istream_extract): Declare.
	(operator>>(basic_istream<C,T>&, C*)): Define inline and simply
	call __istream_extract.
	(operator>>(basic_istream<char,T>&, signed char*)): Likewise.
	(operator>>(basic_istream<char,T>&, unsigned char*)): Likewise.
	(operator>>(basic_istream<C,T>&, C(7)[N])): Define for LWG 2499.
	(operator>>(basic_istream<char,T>&, signed char(&)[N])):
	Likewise.
	(operator>>(basic_istream<char,T>&, unsigned char(&)[N])):
	Likewise.
	* include/std/streambuf (basic_streambuf): Declare char overload
	of __istream_extract as a friend.
	* src/c++11/istream-inst.cc: Add explicit instantiation
	definition for wchar_t overload of __istream_extract. Remove
	explicit instantiation definitions of old operator>> overloads
	for versioned-namespace build.
	* src/c++98/istream.cc (operator>>(istream&, char*)): Replace
	with __istream_extract(istream&, char*, streamsize).
	* testsuite/27_io/basic_istream/extractors_character/char/3.cc:
	Do not use variable-length array.
	* testsuite/27_io/basic_istream/extractors_character/char/4.cc:
	Do not run test for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/9555-ic.cc:
	Do not test writing to pointers for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/9826.cc:
	Use array instead of pointer.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/3.cc:
	Do not use variable-length array.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc:
	Do not run test for C++20.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/9555-ic.cc:
	Do not test writing to pointers for C++20.
	* testsuite/27_io/basic_istream/extractors_character/char/lwg2499.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/char/lwg2499_neg.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/char/overflow.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499.cc:
	New test.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499_neg.cc:
	New test.
2020-08-05 22:17:18 +01:00
François Dumont
6f00ccbad3 libstdc++: Fix and improve std::vector<bool> implementation.
Do not consider allocator noexcept qualification for vector<bool> move
constructor.
Improve swap performance using TBAA like in main vector implementation. Bypass
_M_initialize_dispatch/_M_assign_dispatch in post-c++11 modes.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h
	[_GLIBCXX_INLINE_VERSION](_Bvector_impl_data::_M_start): Define as
	_Bit_type*.
	(_Bvector_impl_data(const _Bvector_impl_data&)): Default.
	(_Bvector_impl_data(_Bvector_impl_data&&)): Delegate to latter.
	(_Bvector_impl_data::operator=(const _Bvector_impl_data&)): Default.
	(_Bvector_impl_data::_M_move_data(_Bvector_impl_data&&)): Use latter.
	(_Bvector_impl_data::_M_reset()): Likewise.
	(_Bvector_impl_data::_M_swap_data): New.
	(_Bvector_impl::_Bvector_impl(_Bvector_impl&&)): Implement explicitely.
	(_Bvector_impl::_Bvector_impl(_Bit_alloc_type&&, _Bvector_impl&&)): New.
	(_Bvector_base::_Bvector_base(_Bvector_base&&, const allocator_type&)):
	New, use latter.
	(vector::vector(vector&&, const allocator_type&, true_type)): New, use
	latter.
	(vector::vector(vector&&, const allocator_type&, false_type)): New.
	(vector::vector(vector&&, const allocator_type&)): Use latters.
	(vector::vector(const vector&, const allocator_type&)): Adapt.
	[__cplusplus >= 201103](vector::vector(_InputIt, _InputIt,
	const allocator_type&)): Use _M_initialize_range.
	(vector::operator[](size_type)): Use iterator operator[].
	(vector::operator[](size_type) const): Use const_iterator operator[].
	(vector::swap(vector&)): Add assertions on allocators. Use _M_swap_data.
	[__cplusplus >= 201103](vector::insert(const_iterator, _InputIt,
	_InputIt)): Use _M_insert_range.
	(vector::_M_initialize(size_type)): Adapt.
	[__cplusplus >= 201103](vector::_M_initialize_dispatch): Remove.
	[__cplusplus >= 201103](vector::_M_insert_dispatch): Remove.
	* python/libstdcxx/v6/printers.py (StdVectorPrinter._iterator): Stop
	using start _M_offset.
	(StdVectorPrinter.to_string): Likewise.
	* testsuite/23_containers/vector/bool/allocator/swap.cc: Adapt.
	* testsuite/23_containers/vector/bool/cons/noexcept_move_construct.cc:
	Add check.
2020-07-31 23:18:51 +02:00
Jonathan Wakely
8abab28bb5 libstdc++: Remove condition around friend declaration (PR 96382)
libstdc++-v3/ChangeLog:

	PR libstdc++/96382
	* include/bits/stl_iterator.h (reverse_iterator): Friend
	declaration should not depend on __cplusplus.
2020-07-31 19:55:46 +01:00
Jonathan Wakely
684d6ee140 libstdc++: Make COW string use allocator_traits for nested types
When compiled as C++20 the COW std::string fails due to assuming that
the allocator always defines size_type and difference_type. That has
been incorrect since C++11, but we got away with it for specializations
using std::allocator until those members were removed in C++20.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (size_type, difference_type):
	Use allocator_traits to obtain the allocator's size_type and
	difference_type.
2020-07-30 20:58:09 +01:00