Commit Graph

9508 Commits

Author SHA1 Message Date
Patrick Palka
f316994199 libstdc++: P1243R4 Rangify new algorithms
This adds rangified overloads for for_each_n, sample and clamp as per P1243R4.

libstdc++-v3/ChangeLog:

	P1243R4 Rangify new algorithms
	* include/bits/ranges_algo.h (for_each_n_result, __for_each_n_fn,
	for_each_n, __sample_fn, sample, __clamp_fn, clamp): New.
	* testsuite/25_algorithms/clamp/constrained.cc: New test.
	* testsuite/25_algorithms/for_each/constrained.cc: Augment test.
	* testsuite/25_algorithms/sample/constrained.cc: New test.
2020-02-18 11:06:49 -05:00
Jonathan Wakely
c5e1c1d3ab libstdc++: P1964R2 Wording for boolean-testable
This removes the complicated std::boolean concept, as agreed in Prague.

	* include/bits/ranges_algo.h (__find_fn, __find_first_of_fn)
	(__adjacent_find_fn): Cast result of predicate to bool.
	* include/std/concepts (__boolean): Remove.
	(__detail::__boolean_testable_impl, __detail::__boolean_testable): Add
	new helper concepts.
	(__detail::__weakly_eq_cmp_with, totally_ordered, totally_ordered_with)
	(predicate): Use __boolean_testable instead of boolean.
	* libsupc++/compare (__detail::__partially_ordered, _Synth3way):
	Likewise.
2020-02-17 18:22:05 +00:00
Jonathan Wakely
7ab36231a1 libstdc++: P1970R2 Consistency for size() functions: Add ranges::ssize
This defines ranges::ssize as approved in Prague. It's unclear what is
supposed to happen for types for which range_difference_t is not a valid
type. I've assumed they are not meant to be usable with ranges::ssize,
despite being usable with ranges::size.

	* include/bits/range_access.h (_SSize, ssize): Define for C++20.
	* testsuite/std/ranges/access/ssize.cc: New test.
2020-02-17 18:15:41 +00:00
Jonathan Wakely
9866abe31e libstdc++ P1956R1 On the names of low-level bit manipulation functions
Implement this change for C++20 that was just approved in Prague.

	P1956R1 On the names of low-level bit manipulation functions
	* include/bits/hashtable_policy.h: Update comment.
	* include/std/bit (__ispow2, __ceil2, __floor2, __log2p1): Rename.
	(ispow2, ceil2, floor2, log2p1): Likewise.
	(__cpp_lib_int_pow2): Add feature test macro.
	* include/std/charconv (__to_chars_len_2): Adjust use of __log2p1.
	* include/std/memory (assume_aligned): Adjust use of ispow2.
	* include/std/version (__cpp_lib_int_pow2): Add.
	* libsupc++/new_opa.cc: Adjust use of __ispow2.
	* src/c++17/memory_resource.cc: Likewise, and for __ceil2 and __log2p1.
	* testsuite/17_intro/freestanding.cc: Adjust use of ispow2.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil_neg.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_width.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc: ... here.
2020-02-17 17:09:18 +00:00
Jonathan Wakely
cfbc8fbb37 libstdc++: Add comment to <charconv> explaining C++14 status
This header is intentionally valid in C++14 mode, because no conforming
C++14 program will try to include <charconv> and so it's OK to add new
(non-reserved in C++14) names to namespace std. However, other headers
must not include <charconv> transitively prior to C++17, so that we
don't add those non-reserved names without the user requesting it.

This adds a comment to the header explaining that.

	* include/std/charconv: Add comment.
2020-02-17 15:44:03 +00:00
Jonathan Wakely
9cd4eeefcc libstdc++: Reduce header dependencies for C++20 (PR 92546)
In C++20 <memory> depends on <bits/ranges_unitialized.h> which
depends on <bits/random.h> just for a single concept. Including
<bits/random.h> also requires including <cmath>, which is huge due to
the C++17 special functions.

This change moves the concept to the <bits/uniform_int_dist.h> internal
header that exists so that <bits/stl_algobase.h> doesn't need to include
<bits/random.h>.

	PR libstdc++/92546 (partial)
	* include/bits/random.h (uniform_random_bit_generator): Move definition
	to <bits/uniform_int_dist.h>.
	* include/bits/ranges_algo.h: Include <bits/uniform_int_dist.h> instead
	of <bits/random.h>.
	* include/bits/ranges_algobase.h: Do not include <cmath>.
	* include/bits/uniform_int_dist.h (uniform_random_bit_generator):
	Move here.
	* include/std/ranges: Do not include <limits>.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
2020-02-17 15:43:43 +00:00
Jonathan Wakely
c03b53da91 libstdc++: Add lightweight replacement for std::numeric_limits (PR 92546)
Many uses of std::numeric_limits in C++17 and C++20 features only really
need the min(), max() and digits constants for integral types. By adding
__detail::__int_limits we can avoid including the whole <limits> header.

The <limits> header isn't especially large, but avoiding it still gives
small savings in compilation time and memory usage for the compiler.

There are also C++11 features that could benefit from this change (e.g.
<bits/hashtable_policy.h> and <bits/uniform_int_dist.h>) but I won't
change those until stage 1.

The implementation of __int_limits assumes two's complement integers,
which is true for all targets supported by GCC.

	PR libstdc++/92546 (partial)
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/int_limits.h: New header.
	* include/bits/parse_numbers.h (__select_int::_Select_int): Replace
	numeric_limits with __detail::__int_limits.
	* include/std/bit (__rotl, __rotr, __countl_zero, __countl_one)
	(__countr_zero, __countr_one, __popcount, __ceil2, __floor2, __log2p1):
	Likewise.
	* include/std/charconv (__to_chars_8, __from_chars_binary)
	(__from_chars_alpha_to_num, from_chars): Likewise.
	* include/std/memory_resource (polymorphic_allocator::allocate)
	(polymorphic_allocator::allocate_object): Likewise.
	* include/std/string_view (basic_string_view::_S_compare): Likewise.
	* include/std/utility (in_range): Likewise.
	* testsuite/20_util/integer_comparisons/in_range_neg.cc: Adjust for
	extra error about incomplete type __int_limits<bool>.
	* testsuite/26_numerics/bit/bit.count/countl_one.cc: Include <limits>.
	* testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Likewise.
	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.
	* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
2020-02-17 15:11:04 +00:00
Jonathan Wakely
4540ef781b libstdc++: Fix regression in libstdc++-prettyprinters/cxx20.cc
* python/libstdcxx/v6/printers.py (StdCmpCatPrinter.to_string): Update
	value for partial_ordering::unordered.
2020-02-17 13:20:57 +00:00
Jonathan Wakely
d6dfa3dafc libstdc++: Make "implicit expression variants" more explicit (P2102R0)
* include/bits/iterator_concepts.h (indirectly_copyable_storable): Add
	const-qualified expression variations.
	* include/std/concepts (copyable): Likewise.
2020-02-17 13:20:57 +00:00
Jonathan Wakely
98cf2c2659 libstdc++: Implement "Safe Integral Comparisons" (P0586R2)
* include/std/type_traits (__is_standard_integer): New helper trait.
	* include/std/utility (cmp_equal, cmp_not_equal, cmp_less, cmp_greater)
	(cmp_less_equal, cmp_greater_equal, in_range): Define for C++20.
	* include/std/version (__cpp_lib_integer_comparison_functions): Define.
	* testsuite/20_util/integer_comparisons/1.cc: New test.
	* testsuite/20_util/integer_comparisons/2.cc: New test.
	* testsuite/20_util/integer_comparisons/equal.cc: New test.
	* testsuite/20_util/integer_comparisons/equal_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/greater_equal.cc: New test.
	* testsuite/20_util/integer_comparisons/greater_equal_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/greater_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/in_range.cc: New test.
	* testsuite/20_util/integer_comparisons/in_range_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/less.cc: New test.
	* testsuite/20_util/integer_comparisons/less_equal.cc: New test.
	* testsuite/20_util/integer_comparisons/less_equal_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/less_neg.cc: New test.
	* testsuite/20_util/integer_comparisons/not_equal.cc: New test.
	* testsuite/20_util/integer_comparisons/not_equal_neg.cc: New test.
2020-02-17 13:20:57 +00:00
Patrick Palka
93b8cfce27 libstdc++: Move code after an early exit constexpr if to under an else branch
This avoids instantiating dead code when the true branch of the constexpr if is
taken.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
	Move code after an early exit constexpr if to under an else branch.
	* include/bits/ranges_algobase.h (__equal_fn::operator()): Likewise.
2020-02-15 21:16:00 -05:00
Patrick Palka
5599262661 libstdc++: Whitespace and formatting adjustments
libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h: Adjust whitespace and formatting.
	* include/bits/ranges_algobase.h: Likewise.
	* include/bits/ranges_uninitialized.h: Likewise.
2020-02-15 10:57:02 -05:00
Patrick Palka
b40c57bdd2 libstdc++: Convert the ranges algorithm entities into function objects
This is the standard way to inhibit ADL for these entities, which is required as
per [algorithms.requirements] p2 and [specialized.algorithms] p4.  The
conversion was done mostly mechanically with a custom Vim macro.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h: (adjacent_find, all_of, any_of,
	binary_search, copy_if, count, count_if, equal_range, find, find_end,
	find_first_of, find_if, find_if_not, for_each, generate, generate_n,
	includes, inplace_merge, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, lexicographical_compare,
	lower_bound, make_heap, max, max_element, merge, min, min_element,
	minmax, minmax_element, mismatch, next_permutation, none_of,
	nth_element, partial_sort, partial_sort_copy, partition, partition_copy,
	partition_point, pop_heap, prev_permutation, push_heap, remove,
	remove_copy, remove_copy_if, remove_if, replace, replace_copy,
	replace_copy_if, replace_if, reverse, reverse_copy, rotate, rotate_copy,
	search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, shuffle, sort, sort_heap,
	stable_partition, stable_sort, swap_ranges, transform, unique,
	unique_copy, upper_bound): Convert into function objects.
	* include/bits/ranges_algobase.h: (equal, copy, move, copy_n, fill_n,
	fill, move_backward, copy_backward): Likewise.
	* include/bits/ranges_uninitialized.h (uninitialized_default_construct,
	uninitialized_default_construct_n, uninitialized_value_construct,
	uninitialized_value_construct_n, uninitialized_copy,
	uninitialized_copy_n, uninitialized_move, uninitialized_move_n,
	uninitialized_fill, uninitialized_fill_n, construct_at, destroy_at,
	destroy, destroy_n): Likewise.
2020-02-15 10:56:10 -05:00
Patrick Palka
90b7eb6539 libstdc++: Fold some ranges algo subroutines into their only caller
These subroutines have only a single call site, so it might be best and simplest
to eliminate them before we convert the algos into function objects.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (ranges::__find_end): Fold into ...
	(ranges::find_end): ... here.
	(ranges::__lexicographical_compare): Fold into ...
	(ranges::lexicographical_compare): ... here.
	* include/bits/ranges_algobase.h (ranges::__equal): Fold into ...
	(ranges::equal): ... here.
2020-02-15 10:55:25 -05:00
Jonathan Wakely
55b00d14f4 libstdc++: Update __cpp_lib_erase_if macro (P1115R3)
Now that this feature has been approved for C++20 we can define the
macro to the official value.

	* include/bits/erase_if.h (__cpp_lib_erase_if): Define to 202002L.
	* include/std/deque: Likewise.
	* include/std/forward_list: Likewise.
	* include/std/list: Likewise.
	* include/std/string: Likewise.
	* include/std/vector: Likewise.
	* include/std/version: Likewise.
	* testsuite/23_containers/deque/erasure.cc: Test for new value.
	* testsuite/23_containers/forward_list/erasure.cc: Likewise.
	* testsuite/23_containers/list/erasure.cc: Likewise.
	* testsuite/23_containers/map/erasure.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.
2020-02-15 10:25:23 +00:00
Jonathan Wakely
5b1d588509 libstdc++: Implement LWG 3150 for std::uniform_random_bit_generator
* include/bits/random.h (uniform_random_bit_generator): Require min()
	and max() to be constant expressions and min() to be less than max().
	* testsuite/26_numerics/random/concept.cc: Check additional cases.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error lineno.
2020-02-15 10:24:57 +00:00
Patrick Palka
613c932f5e libstdc++: Implement ranges [specialized.algorithms]
This implements all the ranges members defined in [specialized.algorithms]:

  ranges::uninitialized_default_construct
  ranges::uninitialized_value_construct
  ranges::uninitialized_copy
  ranges::uninitialized_copy_n
  ranges::uninitialized_move
  ranges::uninitialized_move_n
  ranges::uninitialized_fill
  ranges::uninitialized_fill_n
  ranges::construct_at
  ranges::destroy_at
  ranges::destroy

It also implements (hopefully correctly) the "obvious" optimizations for these
algos, namely that if the output range has a trivial value type and if the
appropriate operation won't throw then we can dispatch to the standard ranges
version of the algorithm which will then potentially enable further
optimizations.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add <bits/ranges_uninitialized.h>.
	* include/Makefile.in: Regenerate.
	* include/bits/ranges_uninitialized.h: New header.
	* include/std/memory: Include it.
	* testsuite/20_util/specialized_algorithms/destroy/constrained.cc: New
	test.
	* .../uninitialized_copy/constrained.cc: New test.
	* .../uninitialized_default_construct/constrained.cc: New test.
	* .../uninitialized_fill/constrained.cc: New test.
	* .../uninitialized_move/constrained.cc: New test.
	* .../uninitialized_value_construct/constrained.cc: New test.
2020-02-13 15:22:28 -05:00
Patrick Palka
90fc7b3ce0 libstdc++: Move some ranges algos to a new header <bits/ranges_algobase.h>
This roughly mirrors the existing split between <bits/stl_algo.h> and
<bits/stl_algobase.h>.  The ranges [specialized.algorithms] will use this new
header to avoid including all of of <bits/ranges_algo.h>.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add bits/ranges_algobase.h
	* include/Makefile.in: Regenerate.
	* bits/ranges_algo.h: Include <bits/ranges_algobase.h> and refactor
	existing #includes.
	(__detail::__is_normal_iterator, __detail::is_reverse_iterator,
	__detail::__is_move_iterator, copy_result, move_result,
	__equal, equal, copy_result, move_result, move_backward_result,
	copy_backward_result, __copy_or_move_backward, __copy_or_move, copy,
	move, copy_backward, move_backward, copy_n_result, copy_n, fill_n,
	fill): Split out into ...
	* bits/range_algobase.h: ... this new header.
2020-02-13 15:20:49 -05:00
Patrick Palka
99bbab9f77 libstdc++: Fix LWG issues 3389 and 3390
libstdc++-v3/ChangeLog:

	LWG 3389 and LWG 3390
	* include/bits/stl_iterator.h (move_move_iterator): Use std::move when
	constructing the move_iterator with __i.
	(counted_iterator::counted_iterator): Use std::move when initializing
	M_current with __i.
	* testsuite/24_iterators/counted_iterator/lwg3389.cc: New test.
	* testsuite/24_iterators/move_iterator/lwg3390.cc: New test.
2020-02-12 16:30:19 -05:00
Sandra Loosemore
02ce382cd3 Use a non-empty test program to test ability to link.
On bare-metal targets, I/O support is typically provided by a BSP and
requires a linker script and/or hosting library to be specified on the
linker command line.  Linking an empty program with the default linker
script may succeed, however, which confuses libstdc++ configuration
when programs that probe for the presence of various I/O features fail
with link errors.

2020-02-12  Sandra Loosemore  <sandra@codesourcery.com>

	PR libstdc++/79193
	PR libstdc++/88999

	config/
	* no-executables.m4: Use a non-empty program to test for linker
	support.

	libgcc/
	* configure: Regenerated.

	libgfortran/
	* configure: Regenerated.

	libiberty/
	* configure: Regenerated.

	libitm/
	* configure: Regenerated.

	libobjc/
	* configure: Regenerated.

	libquadmath/
	* configure: Regenerated.

	libssp/
	* configure: Regenerated.

	libstdc++v-3/
	* configure: Regenerated.
2020-02-12 13:22:07 -08:00
François Dumont
b32a3f3243 libstdc++: Add missing std:: qualification of a forward call
* include/bits/hashtable.h
	(_Hashtable<>(_Hashtable&&, std::allocator_type&)): Add
	missing std namespace qualification to forward call.
2020-02-12 22:09:41 +01:00
Jonathan Wakely
38660e87f0 libstdc++: Fix names of types in comment
* testsuite/20_util/function_objects/range.cmp/equal_to.cc: Fix
	comment.
	* testsuite/20_util/function_objects/range.cmp/less.ccL Likewise.
2020-02-09 14:00:23 +00:00
Jonathan Wakely
97a7c22955 libstdc++: Fix non-ASCII characters in comment
* include/std/ranges: Fix non-ASCII characters in comment.
2020-02-09 13:54:32 +00:00
Jonathan Wakely
dcda050e6c libstdc++: Fix BUILTIN-PTR-CMP helpers
The helpers that implement BUILTIN-PTR-CMP do not currently check if the
arguments are actually comparable, so the concept is true when it
shouldn't be.

Since we're trying to test for an unambiguous conversion to pointers, we
can also require that it returns bool, because the built-in comparisons
for pointers do return bool.

	* include/bits/range_cmp.h (__detail::__eq_builtin_ptr_cmp): Require
	equality comparison to be valid and return bool.
	(__detail::__less_builtin_ptr_cmp): Likewise for less-than comparison.
	* testsuite/20_util/function_objects/range.cmp/equal_to.cc: Check
	type with ambiguous conversion to fundamental types.
	* testsuite/20_util/function_objects/range.cmp/less.cc: Likewise.
2020-02-09 13:37:43 +00:00
Jonathan Wakely
c8dd2446f5 libstdc++: Implement P1878R1 "Constraining Readable Types"
* include/bits/iterator_concepts.h (iter_difference_t, iter_value_t):
	Use remove_cvref_t.
	(readable_traits): Rename to indirectly_readable_traits.
	(readable): Rename to indirectly_readable.
	(writable): Rename to indirectly_writable.
	(__detail::__iter_exchange_move): Do not use remove_reference_t.
	(indirectly_swappable): Adjust requires expression parameter types.
	expression.
	* include/bits/ranges_algo.h (ranges::transform, ranges::replace)
	(ranges::replace_if, ranges::generate_n, ranges::generate)
	(ranges::remove): Use new name for writable.
	* include/bits/stl_iterator.h (__detail::__common_iter_has_arrow):
	Use new name for readable.
	* include/ext/pointer.h (readable_traits<_Pointer_adapter<P>>): Use
	new name for readable_traits.
	* testsuite/24_iterators/associated_types/readable.traits.cc: Likewise.
	* testsuite/24_iterators/indirect_callable/projected.cc: Adjust for
	new definition of indirectly_readable.
2020-02-07 16:58:43 +00:00
Jonathan Wakely
d222d8ec3c libstdc++: Fix bug in iterator_traits<common_iterator<S,I>>
The wrong type was being used in the __common_iter_has_arrow constraint,
creating a circular dependency where the iterator_traits specialization
was needed before it was complete. The correct parameter for the
__common_iter_has_arrow concept is the first template argument of  the
common_iterator, not the common_iterator itself.

	* include/bits/stl_iterator.h (__detail::__common_iter_ptr): Change
	to take parameters of common_iterator, instead of the common_iterator
	type itself. Fix argument for __common_iter_has_arrow constraint.
	(iterator_traits<common_iterator<I, S>>::pointer): Adjust.
2020-02-07 16:54:54 +00:00
Jonathan Wakely
572992c892 libstdc++ Fix missing return in istream_view iterator
* include/std/ranges (iota_view): Add braces to prevent -Wempty-body
	warning.
	(basic_istream_view::_Iterator::operator++()): Add missing return.
2020-02-07 16:06:43 +00:00
Patrick Palka
a04f635d1e libstdc++: Remove extraneous && 2020-02-07 10:09:30 -05:00
Patrick Palka
b7903d9f5b libstdc++: Add [range.istream]
This patch adds ranges::basic_istream_view and ranges::istream_view.  This seems
to be the last missing part of the ranges header.

libstdc++-v3/ChangeLog:

	* include/std/ranges (ranges::__detail::__stream_extractable,
	ranges::basic_istream_view, ranges::istream_view): Define.
	* testsuite/std/ranges/istream_view: New test.
2020-02-07 09:44:53 -05:00
Patrick Palka
55d4cbcba8 Fix ChangeLog for previous commit 2020-02-07 09:31:17 -05:00
Patrick Palka
cba9ef069e libstdc++: Implement C++20 range adaptors
This patch implements [range.adaptors].  It also includes the changes from P3280
and P3278 and P3323, without which many standard examples won't work.

The implementation is mostly dictated by the spec and there was not much room
for implementation discretion.  The most interesting part that was not specified
by the spec is the design of the range adaptors and range adaptor closures,
which I tried to design in a way that minimizes boilerplate and statefulness (so
that e.g. the composition of two stateless closures is stateless).

What is left unimplemented is caching of calls to begin() in filter_view,
drop_view and reverse_view, which is required to guarantee that begin() has
amortized constant time complexity.  I can implement this in a subsequent patch.

"Interesting" parts of the patch are marked with XXX comments.

libstdc++-v3/ChangeLog:

	Implement C++20 range adaptors
	* include/std/ranges: Include <bits/refwrap.h> and <tuple>.
	(subrange::_S_store_size): Mark as const instead of constexpr to
	avoid what seems to be a bug in GCC.
	(__detail::__box): Give it defaulted copy and move constructors.
	(views::_Single::operator()): Mark constexpr.
	(views::_Iota::operator()): Mark constexpr.
	(__detail::Empty): Define.
	(views::_RangeAdaptor, views::_RangeAdaptorClosure, ref_view, all_view,
	views::all, filter_view, views::filter, transform_view,
	views::transform, take_view, views::take, take_while_view,
	views::take_while, drop_view, views::drop, join_view, views::join,
	__detail::require_constant, __detail::tiny_range, split_view,
	views::split, views::_Counted, views::counted, common_view,
	views::common, reverse_view, views::reverse,
	views::__detail::__is_reversible_subrange,
	views::__detail::__is_reverse_view, reverse_view, views::reverse,
	__detail::__has_tuple_element, elements_view, views::elements,
	views::keys, views::values): Define.
	* testsuite/std/ranges/adaptors/all.cc: New test.
	* testsuite/std/ranges/adaptors/common.cc: Likewise.
	* testsuite/std/ranges/adaptors/counted.cc: Likewise.
	* testsuite/std/ranges/adaptors/drop.cc: Likewise.
	* testsuite/std/ranges/adaptors/drop_while.cc: Likewise.
	* testsuite/std/ranges/adaptors/elements.cc: Likewise.
	* testsuite/std/ranges/adaptors/filter.cc: Likewise.
	* testsuite/std/ranges/adaptors/join.cc: Likewise.
	* testsuite/std/ranges/adaptors/reverse.cc: Likewise.
	* testsuite/std/ranges/adaptors/split.cc: Likewise.
	* testsuite/std/ranges/adaptors/take.cc: Likewise.
	* testsuite/std/ranges/adaptors/take_while.cc: Likewise.
	* testsuite/std/ranges/adaptors/transform.cc: Likewise.
2020-02-07 09:24:43 -05:00
Jonathan Wakely
0d57370c9c libstdc++: Optimize C++20 comparison category types
This reduces the size and alignment of all three comparison category
types to a single byte. The partial_ordering::_M_is_ordered flag is
replaced by the value 0x02 in the _M_value member.

This also optimizes conversion and comparison operators to avoid
conditional branches where possible, by comparing _M_value to constants
or using bitwise operations to correctly handle the unordered state.

	* libsupc++/compare (__cmp_cat::type): Define typedef for underlying
	type of enumerations and comparison category types.
	(__cmp_cat::_Ord, __cmp_cat::_Ncmp): Add underlying type.
	(__cmp_cat::_Ncmp::unordered): Change value to 2.
	(partial_ordering::_M_value, weak_ordering::_M_value)
	(strong_ordering::_M_value): Change type to __cmp_cat::type.
	(partial_ordering::_M_is_ordered): Remove data member.
	(partial_ordering): Use second bit of _M_value for unordered. Adjust
	comparison operators.
	(weak_ordering::operator partial_ordering): Simplify to remove
	branches.
	(operator<=>(unspecified, weak_ordering)): Likewise.
	(strong_ordering::operator partial_ordering): Likewise.
	(strong_ordering::operator weak_ordering): Likewise.
	(operator<=>(unspecified, strong_ordering)): Likewise.
	* testsuite/18_support/comparisons/categories/partialord.cc: New test.
	* testsuite/18_support/comparisons/categories/strongord.cc: New test.
	* testsuite/18_support/comparisons/categories/weakord.cc: New test.
2020-02-07 14:09:03 +00:00
Jonathan Wakely
5713834e4b libstdc++: Enable three-way comparison for iota_view iterators
The declaration of operator<=> was disabled due to a typo in the macro.
The declaration was also ill-formed when three_way_comparable<_Winc> is
not satisfied, which is a defect in the C++20 draft.

	* include/std/ranges (iota_view::_Iterator): Fix typo in name of
	__cpp_lib_three_way_comparison macro and use deduced return type for
	operator<=>.
	* testsuite/std/ranges/iota/iterator.cc: New test.
2020-02-07 11:39:12 +00:00
Patrick Palka
bc4646410a libstdc++: Implement C++20 constrained algorithms
This patch implements the C++20 ranges overloads for the algorithms in
[algorithms].  Most of the algorithms were reimplemented, with each of their
implementations very closely following the existing implementation in
bits/stl_algo.h and bits/stl_algobase.h.  The reason for reimplementing most of
the algorithms instead of forwarding to their STL-style overload is because
forwarding cannot be conformantly and efficiently performed for algorithms that
operate on non-random-access iterators.  But algorithms that operate on random
access iterators can safely and efficiently be forwarded to the STL-style
implementation, and this patch does so for push_heap, pop_heap, make_heap,
sort_heap, sort, stable_sort, nth_element, inplace_merge and stable_partition.

What's missing from this patch is debug-iterator and container specializations
that are present for some of the STL-style algorithms that need to be ported
over to the ranges algos.  I marked them missing at TODO comments.  There are
also some other minor outstanding TODOs.

The code that could use the most thorough review is ranges::__copy_or_move,
ranges::__copy_or_move_backward, ranges::__equal and
ranges::__lexicographical_compare.  In the tests, I tried to test the interface
of each new overload, as well as the correctness of the new implementation.

libstdc++-v3/ChangeLog:

	Implement C++20 constrained algorithms
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/std/algorithm: Include <bits/ranges_algo.h>.
	* include/bits/ranges_algo.h: New file.
	* testsuite/25_algorithms/adjacent_find/constrained.cc: New test.
	* testsuite/25_algorithms/all_of/constrained.cc: New test.
	* testsuite/25_algorithms/any_of/constrained.cc: New test.
	* testsuite/25_algorithms/binary_search/constrained.cc: New test.
	* testsuite/25_algorithms/copy/constrained.cc: New test.
	* testsuite/25_algorithms/copy_backward/constrained.cc: New test.
	* testsuite/25_algorithms/copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/copy_n/constrained.cc: New test.
	* testsuite/25_algorithms/count/constrained.cc: New test.
	* testsuite/25_algorithms/count_if/constrained.cc: New test.
	* testsuite/25_algorithms/equal/constrained.cc: New test.
	* testsuite/25_algorithms/equal_range/constrained.cc: New test.
	* testsuite/25_algorithms/fill/constrained.cc: New test.
	* testsuite/25_algorithms/fill_n/constrained.cc: New test.
	* testsuite/25_algorithms/find/constrained.cc: New test.
	* testsuite/25_algorithms/find_end/constrained.cc: New test.
	* testsuite/25_algorithms/find_first_of/constrained.cc: New test.
	* testsuite/25_algorithms/find_if/constrained.cc: New test.
	* testsuite/25_algorithms/find_if_not/constrained.cc: New test.
	* testsuite/25_algorithms/for_each/constrained.cc: New test.
	* testsuite/25_algorithms/generate/constrained.cc: New test.
	* testsuite/25_algorithms/generate_n/constrained.cc: New test.
	* testsuite/25_algorithms/heap/constrained.cc: New test.
	* testsuite/25_algorithms/includes/constrained.cc: New test.
	* testsuite/25_algorithms/inplace_merge/constrained.cc: New test.
	* testsuite/25_algorithms/is_partitioned/constrained.cc: New test.
	* testsuite/25_algorithms/is_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/is_sorted/constrained.cc: New test.
	* testsuite/25_algorithms/is_sorted_until/constrained.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/constrained.cc: New
	test.
	* testsuite/25_algorithms/lower_bound/constrained.cc: New test.
	* testsuite/25_algorithms/max/constrained.cc: New test.
	* testsuite/25_algorithms/max_element/constrained.cc: New test.
	* testsuite/25_algorithms/merge/constrained.cc: New test.
	* testsuite/25_algorithms/min/constrained.cc: New test.
	* testsuite/25_algorithms/min_element/constrained.cc: New test.
	* testsuite/25_algorithms/minmax/constrained.cc: New test.
	* testsuite/25_algorithms/minmax_element/constrained.cc: New test.
	* testsuite/25_algorithms/mismatch/constrained.cc: New test.
	* testsuite/25_algorithms/move/constrained.cc: New test.
	* testsuite/25_algorithms/move_backward/constrained.cc: New test.
	* testsuite/25_algorithms/next_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/none_of/constrained.cc: New test.
	* testsuite/25_algorithms/nth_element/constrained.cc: New test.
	* testsuite/25_algorithms/partial_sort/constrained.cc: New test.
	* testsuite/25_algorithms/partial_sort_copy/constrained.cc: New test.
	* testsuite/25_algorithms/partition/constrained.cc: New test.
	* testsuite/25_algorithms/partition_copy/constrained.cc: New test.
	* testsuite/25_algorithms/partition_point/constrained.cc: New test.
	* testsuite/25_algorithms/prev_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/remove/constrained.cc: New test.
	* testsuite/25_algorithms/remove_copy/constrained.cc: New test.
	* testsuite/25_algorithms/remove_copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/remove_if/constrained.cc: New test.
	* testsuite/25_algorithms/replace/constrained.cc: New test.
	* testsuite/25_algorithms/replace_copy/constrained.cc: New test.
	* testsuite/25_algorithms/replace_copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/replace_if/constrained.cc: New test.
	* testsuite/25_algorithms/reverse/constrained.cc: New test.
	* testsuite/25_algorithms/reverse_copy/constrained.cc: New test.
	* testsuite/25_algorithms/rotate/constrained.cc: New test.
	* testsuite/25_algorithms/rotate_copy/constrained.cc: New test.
	* testsuite/25_algorithms/search/constrained.cc: New test.
	* testsuite/25_algorithms/search_n/constrained.cc: New test.
	* testsuite/25_algorithms/set_difference/constrained.cc: New test.
	* testsuite/25_algorithms/set_intersection/constrained.cc: New test.
	* testsuite/25_algorithms/set_symmetric_difference/constrained.cc: New
	test.
	* testsuite/25_algorithms/set_union/constrained.cc: New test.
	* testsuite/25_algorithms/shuffle/constrained.cc: New test.
	* testsuite/25_algorithms/sort/constrained.cc: New test.
	* testsuite/25_algorithms/stable_partition/constrained.cc: New test.
	* testsuite/25_algorithms/stable_sort/constrained.cc: New test.
	* testsuite/25_algorithms/swap_ranges/constrained.cc: New test.
	* testsuite/25_algorithms/transform/constrained.cc: New test.
	* testsuite/25_algorithms/unique/constrained.cc: New test.
	* testsuite/25_algorithms/unique_copy/constrained.cc: New test.
	* testsuite/25_algorithms/upper_bound/constrained.cc: New test.
2020-02-06 20:08:34 -05:00
Jonathan Wakely
bd630df033 libstdc++: Fix comment to refer to correct PR
* include/bits/stl_iterator.h (__detail::__common_iter_ptr): Fix PR
	number in comment. Fix indentation.
2020-02-06 13:32:48 +00:00
Jonathan Wakely
26eae9ac2b libstdc++: decay in viewable_range should be remove_cvref (LWG 3375)
* include/bits/stl_algobase.h (__iter_swap, __iter_swap<true>): Remove
	redundant _GLIBCXX20_CONSTEXPR.
2020-02-06 13:32:48 +00:00
Jonathan Wakely
d1aa7705d5 libstdc++: Remove redundant macro that is always empty
The __iter_swap class template and explicit specialization are only
declared (and used) for C++03 so _GLIBCXX20_CONSTEXPR does nothing here.

	* include/bits/stl_algobase.h (__iter_swap, __iter_swap<true>): Remove
	redundant _GLIBCXX20_CONSTEXPR.
2020-02-06 10:48:17 +00:00
Jonathan Wakely
269e8130b7 libstdc++: Remove workarounds for constraints on alias templates
The G++ bug has been fixed for a couple of months so we can remove these
workarounds that define alias templates in terms of constrained class
templates. We can just apply constraints directly to alias templates as
specified in the C++20 working draft.

	* include/bits/iterator_concepts.h (iter_reference_t)
	(iter_rvalue_reference_t, iter_common_reference_t, indirect_result_t):
	Remove workarounds for PR c++/67704.
	* testsuite/24_iterators/aliases.cc: New test.
2020-02-05 15:09:23 +00:00
Patrick Palka
7db12d155d libstdc++: Apply the move_iterator changes described in P1207R4
These changes are needed for some of the tests in the constrained algorithm
patch, because they use move_iterator with an uncopyable output_iterator.  The
other changes described in the paper are already applied, it seems.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (move_iterator::move_iterator): Move __i
	when initializing _M_current.
	(move_iterator::base): Split into two overloads differing in
	ref-qualifiers as in P1207R4 for C++20.
2020-02-04 22:19:47 -05:00
Jonathan Wakely
9bc5bea1f3 libstdc++: Fix name of macro in #undef directive
The macro that is defined is _GLIBCXX_NOT_FN_CALL_OP but the macro that
was named in the #undef directive was _GLIBCXX_NOT_FN_CALL. This fixes
the #undef.

	* include/std/functional (_GLIBCXX_NOT_FN_CALL_OP): Un-define after
	use.
2020-02-04 13:30:57 +00:00
Jonathan Wakely
9962493ca2 libstdc++: Fix regressions in unique_ptr::swap (PR 93562)
The requirements for this function are only that the deleter is
swappable, but we incorrectly require that the element type is complete
and that the deleter can be swapped using std::swap (which requires it
to be move cosntructible and move assignable).

The fix is to add __uniq_ptr_impl::swap which swaps the pointer and
deleter individually, instead of using the generic std::swap on the
tuple containing them.

	PR libstdc++/93562
	* include/bits/unique_ptr.h (__uniq_ptr_impl::swap): Define.
	(unique_ptr::swap, unique_ptr<T[], D>::swap): Call it.
	* testsuite/20_util/unique_ptr/modifiers/93562.cc: New test.
2020-02-04 13:02:37 +00:00
Andrew Burgess
20fa702b32 Fixes after recent configure changes relating to static libraries
This commit:

  commit e7c26e04b2 (tjteru/master)
  Date:   Wed Jan 22 14:54:26 2020 +0000

      gcc: Add new configure options to allow static libraries to be selected

contains a couple of issues.  First I failed to correctly regenerate
all of the configure files it should have done.  Second, there was a
mistake in lib-link.m4, one of the conditions didn't use pure sh
syntax, I wrote this:

  if x$lib_type = xauto || x$lib_type = xshared; then

When I should have written this:

  if test "x$lib_type" = "xauto" || test "x$lib_type" = "xshared"; then

These issues were raised on the mailing list in these messages:

  https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01827.html
  https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01921.html

config/ChangeLog:

	* lib-link.m4 (AC_LIB_LINKFLAGS_BODY): Update shell syntax.

gcc/ChangeLog:

	* configure: Regenerate.

intl/ChangeLog:

	* configure: Regenerate.

libcpp/ChangeLog:

	* configure: Regenerate.

libstdc++-v3/ChangeLog:

	* configure: Regenerate.
2020-02-01 00:34:28 +00:00
Patrick Palka
6e5a196399 libstdc++: Always return a sentinel<I> from __gnu_test::test_range::end()
It seems that in practice std::sentinel_for<I, I> is always true, and so the
test_range container doesn't help us detect bugs in ranges code in which we
wrongly assume that a sentinel can be manipulated like an iterator.  Make the
test_range range more strict by having end() unconditionally return a
sentinel<I>, and adjust some tests accordingly.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/range_operations/distance.cc: Do not assume
	test_range::end() returns the same type as test_range::begin().
	* testsuite/24_iterators/range_operations/next.cc: Likewise.
	* testsuite/24_iterators/range_operations/prev.cc: Likewise.
	* testsuite/util/testsuite_iterators.h (__gnu_test::test_range::end):
	Always return a sentinel<I>.
2020-01-31 12:17:10 -05:00
Jonathan Wakely
0a8f4febf7 libstdc++: Fix conformance issues in <stop_token> (PR92895)
Fix synchronization issues in <stop_token>. Replace shared_ptr with
_Stop_state_ref and a reference count embedded in the shared state.
Replace std::mutex with spinlock using one bit of a std::atomic<> that
also tracks whether a stop request has been made and how many
stop_source objects share ownership of the state.

	PR libstdc++/92895
	* include/std/stop_token (stop_token::stop_possible()): Call new
	_M_stop_possible() function.
	(stop_token::stop_requested()): Do not use stop_possible().
	(stop_token::binary_semaphore): New class, as temporary stand-in for
	std::binary_semaphore.
	(stop_token::_Stop_cb::_M_callback): Add noexcept to type.
	(stop_token::_Stop_cb::_M_destroyed, stop_token::_Stop_cb::_M_done):
	New data members for symchronization with stop_callback destruction.
	(stop_token::_Stop_cb::_Stop_cb): Make non-template.
	(stop_token::_Stop_cb::_M_linked, stop_token::_Stop_cb::_S_execute):
	Remove.
	(stop_token::_Stop_cb::_M_run): New member function.
	(stop_token::_Stop_state::_M_stopped, stop_token::_Stop_state::_M_mtx):
	Remove.
	(stop_token::_Stop_state::_M_owners): New data member to track
	reference count for ownership.
	(stop_token::_Stop_state::_M_value): New data member combining a
	spinlock, the stop requested flag, and the reference count for
	associated stop_source objects.
	(stop_token::_Stop_state::_M_requester): New data member for
	synchronization with stop_callback destruction.
	(stop_token::_Stop_state::_M_stop_possible()): New member function.
	(stop_token::_Stop_state::_M_stop_requested()): Inspect relevant bit
	of _M_value.
	(stop_token::_Stop_state::_M_add_owner)
	(stop_token::_Stop_state::_M_release_ownership)
	(stop_token::_Stop_state::_M_add_ssrc)
	(stop_token::_Stop_state::_M_sub_ssrc): New member functions for
	updating reference counts.
	(stop_token::_Stop_state::_M_lock, stop_token::_Stop_state::_M_unlock)
	(stop_token::_Stop_state::_M_lock, stop_token::_Stop_state::_M_unlock)
	(stop_token::_Stop_state::_M_try_lock)
	(stop_token::_Stop_state::_M_try_lock_and_stop)
	(stop_token::_Stop_state::_M_do_try_lock): New member functions for
	managing spinlock.
	(stop_token::_Stop_state::_M_request_stop): Use atomic operations to
	read and update state. Release lock while running callbacks. Use new
	data members to synchronize with callback destruction.
	(stop_token::_Stop_state::_M_remove_callback): Likewise.
	(stop_token::_Stop_state::_M_register_callback): Use atomic operations
	to read and update state.
	(stop_token::_Stop_state_ref): Handle type to manage _Stop_state,
	replacing shared_ptr.
	(stop_source::stop_source(const stop_source&)): Update reference count.
	(stop_source::operator=(const stop_source&)): Likewise.
	(stop_source::~stop_source()): Likewise.
	(stop_source::stop_source(stop_source&&)): Define as defaulted.
	(stop_source::operator=(stop_source&&)): Establish postcondition on
	parameter.
	(stop_callback): Enforce preconditions on template parameter. Replace
	base class with data member of new _Cb_impl type.
	(stop_callback::stop_callback(const stop_token&, Cb&&))
	(stop_callback::stop_callback(stop_token&&, Cb&&)): Fix TOCTTOU race.
	(stop_callback::_Cb_impl): New type wrapping _Callback member and
	defining the _S_execute member function.
	* testsuite/30_threads/stop_token/stop_callback/deadlock-mt.cc: New
	test.
	* testsuite/30_threads/stop_token/stop_callback/deadlock.cc: New test.
	* testsuite/30_threads/stop_token/stop_callback/destroy.cc: New test.
	* testsuite/30_threads/stop_token/stop_callback/destructible_neg.cc:
	New test.
	* testsuite/30_threads/stop_token/stop_callback/invocable_neg.cc: New
	test.
	* testsuite/30_threads/stop_token/stop_callback/invoke.cc: New test.
	* testsuite/30_threads/stop_token/stop_source/assign.cc: New test.
	* testsuite/30_threads/stop_token/stop_token/stop_possible.cc: New
	test.
2020-01-29 15:52:08 +00:00
Jonathan Wakely
f214ffb336 libstdc++: Simplify constraints on std::compare_three_way
The __3way_builtin_ptr_cmp concept can use three_way_comparable_with to
check whether <=> is valid. Doing that makes it obvious that the
disjunction on compare_three_way::operator() is redundant, because
the second constraint subsumes the first.

The workaround for PR c++/91073 can also be removed as that bug is fixed
now.

	* libsupc++/compare (__detail::__3way_builtin_ptr_cmp): Use
	three_way_comparable_with.
	(__detail::__3way_cmp_with): Remove workaround for fixed bug.
	(compare_three_way::operator()): Remove redundant constraint from
	requires-clause.
	(__detail::_Synth3way::operator()): Use three_way_comparable_with
	instead of workaround.
	* testsuite/18_support/comparisons/object/93479.cc: Prune extra
	output due to simplified constraints on compare_three_way::operator().
2020-01-29 13:56:49 +00:00
Jonathan Wakely
83b0201035 libstdc++: Make std::compare_three_way check if <=> is valid (PR 93479)
Currently types that cannot be compared using <=> but which are
convertible to pointers will be compared by converting to pointers
first. They should not be comparable.

	PR libstdc++/93479
	* libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid.
	* testsuite/18_support/comparisons/object/93479.cc: New test.
2020-01-29 13:36:15 +00:00
Jonathan Wakely
5cd2e126f5 libstdc++: Make tests for std::ranges access functions more robust
* testsuite/std/ranges/access/end.cc: Do not assume test_range::end()
	returns the same type as test_range::begin(). Add comments.
	* testsuite/std/ranges/access/rbegin.cc: Likewise.
	* testsuite/std/ranges/access/rend.cc: Likewise.
	* testsuite/std/ranges/range.cc: Do not assume the sentinel for
	test_range is the same as its iterator type.
	* testsuite/util/testsuite_iterators.h (test_range::sentinel): Add
	operator- overloads to satisfy sized_sentinel_for when the iterator
	satisfies random_access_iterator.
2020-01-29 13:36:15 +00:00
Jonathan Wakely
a5d81aaab6 libstdc++: Fix order of changelog entries
Rebasing my last two commits put the changelog entries at the wrong
place in the file. Fixed by this change.
2020-01-28 15:20:23 +00:00
Jonathan Wakely
72a9fd209b libstdc++: Avoid using sizeof with function types (PR 93470)
PR libstdc++/93470
	* include/bits/refwrap.h (reference_wrapper::operator()): Restrict
	static assertion to object types.
2020-01-28 13:24:09 +00:00
Jonathan Wakely
759812fddc libstdc++: Replace glibc-specific check for clock_gettime (PR 93325)
It's wrong to assume that clock_gettime is unavailable on any *-*-linux*
target that doesn't have glibc 2.17 or later. Use a generic test instead
of using __GLIBC_PREREQ. Only do that test when is_hosted=yes so that we
don't get an error for cross targets without a working linker.

This ensures that C library's clock_gettime will be used on non-glibc
targets, instead of an incorrect syscall to SYS_clock_gettime.

	PR libstdc++/93325
	* acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Use AC_SEARCH_LIBS for
	clock_gettime instead of explicit glibc version check.
	* configure: Regenerate.
2020-01-28 13:24:09 +00:00