Commit Graph

6444 Commits

Author SHA1 Message Date
Jonathan Wakely 6fd4b25b50 Add noexcept-specifier to std::apply and std::make_from_tuple
When unpacking a std::tuple we know that the std::get calls are
noexcept, so only the invocation (for std::apply) and construction (for
std::make_from_tuple) can throw.

We also know the std::get calls won't throw for a std::array, but this
patch doesn't specialize the variable template for std::array. For an
arbitrary tuple-like type we don't know if the std::get calls will
throw, and so just use a potentially-throwing noexcept-specifier.

	* include/std/tuple (__unpack_std_tuple): New variable template and
	partial specializations.
	(apply, make_from_tuple): Add noexcept-specifier.
	* testsuite/20_util/tuple/apply/2.cc: New test.
	* testsuite/20_util/tuple/make_from_tuple/2.cc: New test.

From-SVN: r274312
2019-08-12 15:54:12 +01:00
Alexandre Oliva c787deb012 skip Cholesky decomposition in is>>n_mv_dist
normal_mv_distribution maintains the variance-covariance matrix param
in Cholesky-decomposed form.  Existing param_type constructors, when
taking a full or lower-triangle varcov matrix, perform Cholesky
decomposition to convert it to the internal representation.  This
internal representation is visible both in the varcov() result, and in
the streamed-out representation of a normal_mv_distribution object.

The problem is that when that representation is streamed back in, the
read-back decomposed varcov matrix is used as a lower-triangle
non-decomposed varcov matrix, and it undergoes Cholesky decomposition
again.  So, each cycle of stream-out/stream-in changes the varcov
matrix to its "square root", instead of restoring the original
params.

This patch includes Corentin's changes that introduce verification in
testsuite/ext/random/normal_mv_distribution/operators/serialize.cc and
other similar tests that the object read back in compares equal to the
written-out object: the modified tests pass only if (u == v).

This patch also fixes the error exposed by his change, introducing an
alternate private constructor for param_type, used only by operator>>.


for  libstdc++-v3/ChangeLog

	* include/ext/random
	(normal_mv_distribution::param_type::param_type): New private
	ctor taking a decomposed varcov matrix, for use by...
	(operator>>): ... this, befriended.
	* include/ext/random.tcc (operator>>): Use it.
	(normal_mv_distribution::param_type::_M_init_lower): Adjust
	member function name in exception message.

for  libstdc++-v3/ChangeLog
from  Corentin Gay  <gay@adacore.com>

	* testsuite/ext/random/beta_distribution/operators/serialize.cc,
	testsuite/ext/random/hypergeometric_distribution/operators/serialize.cc,
	testsuite/ext/random/normal_mv_distribution/operators/serialize.cc,
	testsuite/ext/random/triangular_distribution/operators/serialize.cc,
	testsuite/ext/random/von_mises_distribution/operators/serialize.cc:
	Add call to `VERIFY`.

From-SVN: r274233
2019-08-09 09:20:58 +00:00
Jonathan Wakely cb0de9b60c P0325R4 to_array from LFTS with updates
As an extension to what the standard requires, this also adds
conditional noexcept-specifiers to the std::to_array functions.

	P0325R4 to_array from LFTS with updates
	* include/experimental/array (to_array): Qualify call to __to_array.
	* include/std/array (__cpp_lib_to_array, to_array): Define for C++20.
	* include/std/version (__cpp_lib_to_array): Likewise.
	* testsuite/23_containers/array/creation/1.cc: New test.
	* testsuite/23_containers/array/creation/2.cc: New test.
	* testsuite/23_containers/array/creation/3_neg.cc: New test.
	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
	Use zero for dg-error line number.

From-SVN: r274209
2019-08-08 11:18:53 +01:00
Jonathan Wakely ffc500dd41 P1651R0 bind_front should not unwrap reference_wrapper
P1651R0 bind_front should not unwrap reference_wrapper
	* include/std/functional (bind_front): Don't unwrap reference_wrapper.
	* include/std/version (__cpp_lib_bind_front): Update value.
	* testsuite/20_util/function_objects/bind_front/1.cc: Fix test for
	feature test macro.
	* testsuite/20_util/function_objects/bind_front/2.cc: New test.

From-SVN: r274146
2019-08-06 16:57:55 +01:00
Jonathan Wakely a38b51bc3a Specialize std::numbers constants for __float128
* include/std/numbers [!__STRICT_ANSI__ && _GLIBCXX_USE_FLOAT128]
	(e_v, log2e_v, log10e_v, pi_v, inv_pi_v, inv_sqrtpi_v, ln2_v, ln10_v)
	(sqrt2_v, sqrt3_v, inv_sqrt3, egamma_v, phi_v): Add explicit
	specializations for __float128.
	* testsuite/26_numerics/numbers/float128.cc: New test.

From-SVN: r274145
2019-08-06 16:57:51 +01:00
Edward Smith-Rowland 3a66e68ad9 Implement C++20 p0202 - Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers.
2019-08-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement C++20 p0202 - Add Constexpr Modifiers to Functions
	in <algorithm> and <utility> Headers.
	Implement C++20 p1023 - constexpr comparison operators for std::array.
	* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
	copy_backward, copy_if, copy_n, equal_range, fill, find_end,
	find_if_not, includes, is_heap, is_heap_until, is_partitioned,
	is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
	none_of, partition_copy, partition_point, remove, remove_if,
	remove_copy, remove_copy_if, replace_copy, replace_copy_if,
	reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
	count_if, equal, find, find_first_of, find_if, for_each, generate,
	generate_n, lexicographical_compare, merge, mismatch, replace,
	replace_if, search, search_n, set_difference, set_intersection,
	set_symmetric_difference, set_union, transform, unique_copy):
	Mark constexpr.
	* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
	* include/bits/predefined_ops.h (_Iter_less_val::operator(),
	_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
	_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
	 Use const ref instead of ref arg;
	(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
	__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
	_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
	_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
	_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
	__iter_comp_iter): Mark constexpr.
	* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
	__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
	none_of, any_of, find_if_not, is_partitioned, partition_point,
	__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
	copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
	__unique, unique, __unique_copy, reverse_copy, rotate_copy,
	__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
	__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
	__equal_range, equal_range, binary_search, __includes, includes,
	__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
	replace_copy_if, __count_if, is_sorted, __is_sorted_until,
	is_sorted_until, __is_permutation, is_permutation, for_each, find,
	find_if, find_first_of, adjacent_find, count, count_if, search,
	search_n, transform, replace, replace_if, generate, generate_n,
	unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
	set_intersection, __set_difference, set_difference,
	__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
	* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
	wrappers around __builtin_memmove and __builtin_memcmp
	respectively;
	(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
	copy, move, __copy_move_b, __copy_move_backward_a,
	__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
	__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
	__lexicographical_compare_impl, __lexicographical_compare,
	__lexicographical_compare<true>::__lc, __lexicographical_compare_aux,
	__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
	__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
	is_heap): Mark constexpr.
	* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark constexpr.
	* include/std/array: Make comparison ops constexpr.
	* include/std/utility: Make exchange constexpr.
	* include/std/version (__cpp_lib_constexpr_algorithms): New macro.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_neg.cc: Adjust.
	* testsuite/20_util/exchange/constexpr.cc: New.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
	* testsuite/25_algorithms/constexpr_macro.cc: New.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
	* testsuite/25_algorithms/all_of/constexpr.cc: New.
	* testsuite/25_algorithms/any_of/constexpr.cc: New.
	* testsuite/25_algorithms/binary_search/constexpr.cc: New.
	* testsuite/25_algorithms/copy/constexpr.cc: New.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
	* testsuite/25_algorithms/copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/copy_n/constexpr.cc: New.
	* testsuite/25_algorithms/count/constexpr.cc: New.
	* testsuite/25_algorithms/count_if/constexpr.cc: New.
	* testsuite/25_algorithms/equal/constexpr.cc: New.
	* testsuite/25_algorithms/equal_range/constexpr.cc: New.
	* testsuite/25_algorithms/fill/constexpr.cc: New.
	* testsuite/25_algorithms/fill_n/constexpr.cc: New.
	* testsuite/25_algorithms/find/constexpr.cc: New.
	* testsuite/25_algorithms/find_end/constexpr.cc: New.
	* testsuite/25_algorithms/find_first_of/constexpr.cc: New.
	* testsuite/25_algorithms/find_if/constexpr.cc: New.
	* testsuite/25_algorithms/find_if_not/constexpr.cc: New.
	* testsuite/25_algorithms/for_each/constexpr.cc: New.
	* testsuite/25_algorithms/generate/constexpr.cc: New.
	* testsuite/25_algorithms/generate_n/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap/constexpr.cc: New.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: New.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: New.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: New.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: New.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: New.
	* testsuite/25_algorithms/merge/constexpr.cc: New.
	* testsuite/25_algorithms/mismatch/constexpr.cc: New.
	* testsuite/25_algorithms/none_of/constexpr.cc: New.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: New.
	* testsuite/25_algorithms/partition_point/constexpr.cc: New.
	* testsuite/25_algorithms/remove/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: New.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/remove_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy/constexpr.cc: New.
	* testsuite/25_algorithms/replace_copy_if/constexpr.cc: New.
	* testsuite/25_algorithms/replace_if/constexpr.cc: New.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: New.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: New.
	* testsuite/25_algorithms/search/constexpr.cc: New.
	* testsuite/25_algorithms/search_n/constexpr.cc: New.
	* testsuite/25_algorithms/set_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_intersection/constexpr.cc: New.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: New.
	* testsuite/25_algorithms/set_union/constexpr.cc: New.
	* testsuite/25_algorithms/transform/constexpr.cc: New.
	* testsuite/25_algorithms/unique/constexpr.cc: New.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: New.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: New.

From-SVN: r273975
2019-08-01 15:25:42 +00:00
Jonathan Wakely 3090082cbe Qualify call to prevent ADL
* include/std/memory (make_obj_using_allocator): Qualify call to
	uses_allocator_construction_args.

From-SVN: r273945
2019-07-31 20:08:56 +01:00
Jonathan Wakely 960b9ae05a Implement "P0631R4 Math Constants" for C++20
The values of the constants are taken from Glibc where the equivalent
constant exists, or by rounding the actual constant to the same number
of digits as the Glibc constants have.

	P0631R4 Math Constants
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Include new header.
	* include/std/numbers: New header.
	* include/std/version (__cpp_lib_math_constants): Define.
	* testsuite/26_numerics/numbers/1.cc: New test.
	* testsuite/26_numerics/numbers/2.cc: New test.
	* testsuite/26_numerics/numbers/3.cc: New test.
	* testsuite/26_numerics/numbers/nonfloat_neg.cc: New test.

From-SVN: r273940
2019-07-31 17:40:39 +01:00
Jonathan Wakely 27e6c1f406 Add Doxygen comments to <bit> header
* include/std/bit: Add Doxygen comments.

From-SVN: r273938
2019-07-31 15:38:50 +01:00
Jonathan Wakely 949fdadb9d PR libstdc++/91308 fix constraints on unique_ptr assignment
PR libstdc++/91308
	* include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove
	constraints on deleter that should only apply to the constructor.
	(unique_ptr<T[], D>::__safe_conversion_up): Likewise.
	(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
	constraints on deleter here.
	* testsuite/20_util/unique_ptr/assign/91308.cc: New test.

From-SVN: r273937
2019-07-31 15:38:26 +01:00
Jonathan Wakely a5378f9b60 Define __cpp_lib_endian feature test macro
This macro was added as part of moving std::endian from <type_traits> to
<bit>.

	* include/std/bit (__cpp_lib_endian): Define.
	* include/std/version (__cpp_lib_endian): Define.
	* testsuite/26_numerics/endian/2.cc: New.
	* testsuite/26_numerics/endian/3.cc: New.
	* testsuite/26_numerics/endian/4.cc: New.

From-SVN: r273828
2019-07-26 14:30:42 +01:00
Jonathan Wakely 45c7215c1e Relocate std::endian from <type_traits> to <bit>
This change to an early C++2a feature was just approved (P1612R1).

	* include/std/bit (endian): Move definition here as per P1612R1.
	* include/std/type_traits (endian): Remove definition from here.
	* testsuite/20_util/endian/1.cc: Rename to ...
	* testsuite/26_numerics/endian/1.cc: ... here. Adjust header.

From-SVN: r273816
2019-07-25 21:30:25 +01:00
Jonathan Wakely f35da524a2 Adjust std::rotl, std::rotr etc to match final P0553R4 proposal
This proposal has now been accepted for C++20, with a few changes. This
patch adjusts std::rotl and std::rotr to match the final specification
and declares the additions for C++2a mode even when __STRICT_ANSI__ is
defined.

	* include/std/bit (__rotl, __rotr): Change second parameter from
	unsigned int to int and handle negative values.
	(rotl, rotr): Remove check for __STRICT_ANSI__. Change second
	parameter from unsigned int to int. Add nodiscard attribute.
	* testsuite/26_numerics/bit/bitops.rot/rotl.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Here. Test negative
	shifts.
	* testsuite/26_numerics/bit/bitops.rot/rotr.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Here. Test negative
	shifts.

From-SVN: r273706
2019-07-22 17:53:36 +01:00
Jonathan Wakely 281ab2fbff Change std::ceil2 to be undefined if the result can't be represented
* include/std/bit (__ceil2): Make unrepresentable results undefined,
	as per P1355R2. Add debug assertion. Perform one left shift, not two,
	so that out of range values cause undefined behaviour. Ensure that
	shift will still be undefined if left operand is promoted.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Replace checks for
	unrepresentable values with checks that they are not core constant
	expressions.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: New test.

From-SVN: r273705
2019-07-22 17:53:27 +01:00
François Dumont 2be3193b82 stl_tempbuf.h (__detail::__return_temporary_buffer): Fix sized deallocation size computation.
2019-07-19  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/stl_tempbuf.h (__detail::__return_temporary_buffer): Fix
	sized deallocation size computation.

From-SVN: r273609
2019-07-19 21:14:41 +00:00
François Dumont f48d9d19dd stl_tempbuf.h (__detail::__return_temporary_buffer): New.
2019-07-18  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/stl_tempbuf.h (__detail::__return_temporary_buffer): New.
	(~_Temporary_buffer()): Use latter.
	(_Temporary_buffer(_FIterator, size_type)): Likewise.

From-SVN: r273586
2019-07-18 21:52:35 +00:00
Jason Merrill e6c847fb8f Add parens around constraint in <memory>.
C++20 concepts require parens around atomic constraints that are not
primary-expressions.

	* include/std/memory (uses_allocator_construction_args): Add parens
	around constraint.

From-SVN: r273515
2019-07-16 04:54:47 -04:00
Jonathan Wakely 0d67cd380d Define __type_identity_t alias and use for string_view
This defines the equivalent of C++2a's std::type_identity_t alias but
for use in C++11 and later. This can be used to replace __detail::__idt
in the string_view headers, which previously used common_type_t because
the one argument specialization of common_type_t was simply the identity
transform (which is no longer true).

	* include/experimental/string_view (__detail::__idt): Remove.
	(operator==, operator!=, operator<, operator>, operator<=, operator>=):
	Use __type_identity_t instead of __detail::__idt;
	* include/std/string_view (__detail::__idt): Remove.
	(operator==, operator!=, operator<, operator>, operator<=, operator>=):
	Use __type_identity_t instead of __detail::__idt;
	* include/std/type_traits (__type_identity_t): New alias template.

From-SVN: r273442
2019-07-12 12:43:22 +01:00
Jonathan Wakely a90fe12c80 Define std::atomic_ref and std::atomic<floating-point> for C++20
This adds the new atomic types from C++2a, as proposed by P0019 and
P0020. To reduce duplication the calls to the compiler's atomic
built-ins are wrapped in new functions in the __atomic_impl namespace.
These functions are currently only used by std::atomic<floating-point>
and std::atomic_ref but could also be used for all other specializations
of std::atomic.

	* include/bits/atomic_base.h (__atomic_impl): New namespace for
	wrappers around atomic built-ins.
	(__atomic_float, __atomic_ref): New class templates for use as base
	classes.
	* include/std/atomic (atomic<float>, atomic<double>)
	(atomic<long double>): New explicit specializations.
	(atomic_ref): New class template.
	(__cpp_lib_atomic_ref): Define.
	* include/std/version (__cpp_lib_atomic_ref): Define.
	* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error.
    	* testsuite/29_atomics/atomic_float/1.cc: New test.
    	* testsuite/29_atomics/atomic_float/requirements.cc: New test.
    	* testsuite/29_atomics/atomic_ref/deduction.cc: New test.
    	* testsuite/29_atomics/atomic_ref/float.cc: New test.
    	* testsuite/29_atomics/atomic_ref/generic.cc: New test.
    	* testsuite/29_atomics/atomic_ref/integral.cc: New test.
    	* testsuite/29_atomics/atomic_ref/pointer.cc: New test.
    	* testsuite/29_atomics/atomic_ref/requirements.cc: New test.

From-SVN: r273420
2019-07-11 20:43:25 +01:00
Jonathan Wakely a10b664eb7 Fix recent regression in __atomic_add_dispatch
* include/ext/atomicity.h (__exchange_and_add, __atomic_add): Replace
	throw() with _GLIBCXX_NOTHROW.
	(__atomic_add_dispatch): Return after performing atomic increment.

From-SVN: r273167
2019-07-06 22:16:38 +01:00
Jonathan Wakely 0dc7adb037 Fix ODR violations in code using <ext/atomicity.h>
Because the inline versions of __exchange_and_add and __atomic_add are
also marked static, they cannot be used from templates or other inline
functions without ODR violations. This change gives them external
linkage, but adds the always_inline attribute.

    	* include/ext/atomicity.h [_GLIBCXX_ATOMIC_BUILTINS] (__atomic_add)
    	(__exchange_and_add): Replace static specifier with always_inline
    	attribute.
    	(__exchange_and_add_single, __atomic_add_single): Likewise.
    	(__exchange_and_add_dispatch, __atomic_add_dispatch): Likewise. Also
    	combine !__gthread_active_p() and !__GTHREADS branches.

From-SVN: r273144
2019-07-05 17:10:47 +01:00
Jonathan Wakely 4887c9e808 Fix preprocessor checks for Clang builtins
Clang seems to define built-ins that start with "__builtin_" as
non-keywords, which means that we need to use __has_builtin to detect
them, not __is_identifier. The built-ins that don't start with
"__builtin_" are keywords, and can only be detected using
__is_identifier and not by __has_builtin.

	* include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_LAUNDER)
	(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Use __has_builtin
	instead of __is_identifier to detect Clang support.

From-SVN: r272931
2019-07-02 12:50:27 +01:00
Jonathan Wakely 22ff8929d7 Define std::chars_format enumeration type
This type isn't used anywhere yet, but will be needed for the
floating-point overloads of to_chars and from_chars.

	* include/std/charconv (chars_format): Define bitmask type.
	* testsuite/20_util/to_chars/chars_format.cc: New test.

From-SVN: r272718
2019-06-26 23:54:38 +01:00
Jonathan Wakely 47f7905440 Add new helper traits for signed/unsigned integer types
Reuse the __is_one_of alias in additional places, and define traits to
check for signed/unsigned integer types so we don't have to duplicate
those checks elsewhere.

The additional overloads for std::byte in <bit> were reviewed by LEWG
and considered undesirable, so this patch removes them.

	* include/bits/fs_path.h (path::__is_encoded_char): Use __is_one_of.
	* include/std/bit (_If_is_unsigned_integer_type): Remove.
	(_If_is_unsigned_integer): Use __is_unsigned_integer.
	(rotl(byte, unsigned), rotr(byte, unsigned), countl_zero(byte))
	(countl_one(byte), countr_zero(byte), countr_one(byte))
	(popcount(byte), ispow2(byte), ceil2(byte), floor2(byte))
	(log2p1(byte)): Remove.
	* include/std/charconv (__detail::__is_one_of): Move to <type_traits>.
	(__detail::__is_int_to_chars_type): Remove.
	(__detail::__integer_to_chars_result_type): Use __is_signed_integer
	and __is_unsigned_integer.
	* include/std/type_traits (__is_one_of): Move here from <charconv>.
	(__is_signed_integer, __is_unsigned_integer): New helpers.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Remove test for
	std::byte overload.
	* 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/bitops.count/countl_one.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countl_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countr_one.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/countr_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.count/popcount.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.rot/rotl.cc: Likewise.
	* testsuite/26_numerics/bit/bitops.rot/rotr.cc: Likewise.

From-SVN: r272695
2019-06-26 15:38:23 +01:00
Jonathan Wakely e88d863cbd Fix non-portable use of std::abs(double) in constexpr function
Although libstdc++ adds 'constexpr' to its std::abs(floating-point)
overloads (as a non-conforming extension), those overloads are not used
if the target libc provides them, which is the case on Solaris.

The fix is to avoid std::abs and simply apply the negation when needed.

	* include/std/numeric (midpoint(T, T)): Avoid std::abs in constexpr
	function.

From-SVN: r272653
2019-06-25 14:18:36 +01:00
Jakub Jelinek 32bab8b6ad pstl_config.h (_PSTL_PRAGMA_SIMD_SCAN, [...]): Define to OpenMP 5.0 pragmas even for GCC 10.0+.
* include/pstl/pstl_config.h (_PSTL_PRAGMA_SIMD_SCAN,
	_PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN, _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN):
	Define to OpenMP 5.0 pragmas even for GCC 10.0+.
	(_PSTL_UDS_PRESENT): Define to 1 for GCC 10.0+.

From-SVN: r272634
2019-06-25 08:59:12 +02:00
Jonathan Wakely a3c8d7fbe2 Fix std::midpoint for denormal values
* include/std/numeric (midpoint(T, T)): Change implementation for
	floating-point types to avoid incorrect rounding of denormals.
	* testsuite/26_numerics/midpoint/floating.cc: Add check for correct
	rounding with denormals.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Adjust dg-error line numbers.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.

From-SVN: r272616
2019-06-24 13:09:51 +01:00
Jonathan Wakely d306dee31d Qualify calls to __never_valueless in <variant>
* include/std/variant (_Variant_storage, _Extra_visit_slot_needed):
	Qualify calls to __never_valueless.

From-SVN: r272508
2019-06-20 15:17:51 +01:00
Jonathan Wakely 638ad333ec Fix non-standard behaviour of std::istream_iterator
The current implementation of istream_iterator allows the iterator to be
reused after reaching end-of-stream, so that subsequent reads from the
stream can succeed (e.g. if the stream state has been cleared and stream
position changed from EOF). The P0738R2 paper clarified that the
expected behaviour is to set the stream pointer to null after reaching
end-of-stream, preventing further reads.

This implements that requirement, and adds the new default constructor
to std::ostream_iterator.

	* include/bits/stream_iterator.h (istream_iterator::_M_equal()): Make
	private.
	(istream_iterator::_M_read()): Do not check stream state before
	attempting extraction. Set stream pointer to null when extraction
	fails (P0738R2).
	(operator==(const istream_iterator&, const istream_iterator&)): Change
	to be a hidden friend of istream_iterator.
	(operator!=(const istream_iterator&, const istream_iterator&)):
	Likewise.
	(ostream_iterator::ostream_iterator()): Add default constructor.
	(ostream_iterator::ostream_iterator(ostream_type*, const C*)): Use
	addressof.
	* testsuite/24_iterators/istream_iterator/1.cc: New test.
	* testsuite/24_iterators/ostream_iterator/1.cc: New test.
	* testsuite/24_iterators/ostream_iterator/70766.cc: Also check
	constructor taking a string.
	* testsuite/24_iterators/ostream_iterator/requirements/constexpr.cc:
	New test.

From-SVN: r272491
2019-06-19 23:57:10 +01:00
Jonathan Wakely 0fd9e8482e PR libstdc++/90920 restore previous checks for empty ranges
The change in r263433 broke the contract of the __rotate functions, by no
longer accepting empty ranges. That means that callers which inlined the
old version of std::rotate (without checks) that end up linking to a new
definition of std::__rotate (also without checks) could perform a divide
by zero and crash.

This restores the old contract of the __rotate overloads.

	PR libstdc++/90920 partially revert r263433
	* include/bits/stl_algo.h (__rotate): Restore checks for empty ranges.
	(rotate): Remove checks.
	* testsuite/25_algorithms/rotate/90920.cc: New test.

From-SVN: r272489
2019-06-19 23:57:02 +01:00
Jonathan Wakely 74fda2dc9f Fix value category bugs in std::reduce
* include/std/numeric (reduce(Iter, Iter, T, BinOp)): Fix value
	category used in invocable check.
	(reduce(Iter, Iter, T)): Pass initial value as rvalue.
	* testsuite/26_numerics/reduce/2.cc: New test.

From-SVN: r272477
2019-06-19 16:29:49 +01:00
Jonathan Wakely ed920373a5 Implement new serial algorithms from Parallelism TS (P0024R2)
These new (non-parallel) algorithms were added to C++17 along with the
parallel algorithms, but were missing from libstdc++.

	* include/bits/algorithmfwd.h: Change title of doc group.
	* include/bits/stl_algo.h (for_each_n): Add new C++17 algorithm from
	P0024R2.
	* include/bits/stl_numeric.h: Define doc group and add algos to it.
	* include/std/numeric (__is_random_access_iter): New internal trait.
	(reduce, transform_reduce, exclusive_scan, inclusive_scan)
	(transform_exclusive_scan, transform_inclusive_scan): Likewise.
	* testsuite/25_algorithms/for_each/for_each_n.cc: New test.
	* testsuite/26_numerics/exclusive_scan/1.cc: New test.
	* testsuite/26_numerics/inclusive_scan/1.cc: New test.
	* testsuite/26_numerics/reduce/1.cc: New test.
	* testsuite/26_numerics/transform_exclusive_scan/1.cc: New test.
	* testsuite/26_numerics/transform_inclusive_scan/1.cc: New test.
	* testsuite/26_numerics/transform_reduce/1.cc: New test.
	* testsuite/util/testsuite_iterators.h (test_container::size()): New
	member function.

From-SVN: r272459
2019-06-19 00:01:16 +01:00
Jonathan Wakely 0c65926ffa Avoid undefined behaviour in std::byte operators (LWG 2950)
* include/c_global/cstddef (std::byte): Perform arithmetic operations
	in unsigned int to avoid promotion (LWG 2950).

From-SVN: r272415
2019-06-18 12:39:43 +01:00
Jonathan Wakely 360a758ec8 Add 'noexcept' to std::lerp
* include/c_global/cmath (__lerp, lerp): Add noexcept (LWG 3201).

From-SVN: r272386
2019-06-17 15:32:44 +01:00
Jonathan Wakely 26b1320ee5 PR libstdc++/90281 Fix string conversions for filesystem::path
Fix several bugs in the encoding conversions for filesystem::path that
prevent conversion of Unicode characters outside the Basic Multilingual
Plane, and prevent returning basic_string specializations with
alternative allocator types.

The std::codecvt_utf8 class template is not suitable for UTF-16
conversions because it uses UCS-2 instead. For conversions between UTF-8
and UTF-16 either std::codecvt<C, char, mbstate> or
codecvt_utf8_utf16<C> must be used.

The __str_codecvt_in and __str_codecvt_out utilities do not
return false on a partial conversion (e.g. for invalid or incomplete
Unicode input). Add new helpers that treat partial conversions as
errors, and use them for all filesystem::path conversions.

	PR libstdc++/90281 Fix string conversions for filesystem::path
	* include/bits/fs_path.h (u8path) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]:
	Use codecvt_utf8_utf16 instead of codecvt_utf8. Use
	__str_codecvt_in_all to fail for partial conversions and throw on
	error.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS && _GLIBCXX_USE_CHAR8_T]
	(path::_Cvt<char8_t>): Add explicit specialization.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_wconvert): Remove
	overloads.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	if-constexpr instead of dispatching to _S_wconvert. Use codecvt
	instead of codecvt_utf8. Use __str_codecvt_in_all and
	__str_codecvt_out_all.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	codecvt instead of codecvt_utf8. Use __str_codecvt_out_all.
	(path::_S_str_convert) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Construct return values
	with allocator. Use __str_codecvt_out_all. Fallthrough to POSIX code
	after converting to UTF-8.
	(path::_S_str_convert): Use codecvt instead of codecvt_utf8. Use
	__str_codecvt_in_all.
	(path::string): Fix initialization of string types with different
	allocators.
	(path::u8string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Use __str_codecvt_out_all.
	* include/bits/locale_conv.h (__do_str_codecvt): Reorder static and
	runtime conditions.
	(__str_codecvt_out_all, __str_codecvt_in_all): New functions that
	return false for partial conversions.
	* include/experimental/bits/fs_path.h (u8path):
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Implement correctly for mingw.
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_wconvert): Add
	missing handling for char8_t. Use codecvt and codecvt_utf8_utf16
	instead of codecvt_utf8. Use __str_codecvt_in_all and
	__str_codecvt_out_all.
	[!_GLIBCXX_FILESYSTEM_IS_WINDOWS] (path::_Cvt::_S_convert): Use
	codecvt instead of codecvt_utf8. Use __str_codecvt_out_all.
	(path::string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Construct return values
	with allocator. Use __str_codecvt_out_all and __str_codecvt_in_all.
	(path::string) [!_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	__str_codecvt_in_all.
	(path::u8string) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Use
	codecvt_utf8_utf16 instead of codecvt_utf8. Use __str_codecvt_out_all.
	* src/c++17/fs_path.cc (path::_S_convert_loc): Use
	__str_codecvt_in_all.
	* src/filesystem/path.cc (path::_S_convert_loc): Likewise.
	* testsuite/27_io/filesystem/path/construct/90281.cc: New test.
	* testsuite/27_io/filesystem/path/factory/u8path.cc: New test.
	* testsuite/27_io/filesystem/path/native/string.cc: Test with empty
	strings and with Unicode characters outside the basic multilingual
	plane.
	* testsuite/27_io/filesystem/path/native/alloc.cc: New test.
	* testsuite/experimental/filesystem/path/construct/90281.cc: New test.
	* testsuite/experimental/filesystem/path/factory/u8path.cc: New test.
	* testsuite/experimental/filesystem/path/native/alloc.cc: New test.
	* testsuite/experimental/filesystem/path/native/string.cc: Test with
	empty strings and with Unicode characters outside the basic
	multilingual plane.

From-SVN: r272385
2019-06-17 15:19:04 +01:00
François Dumont b0c849fadb Simplify node ownership in _Hashtable members
Introduce an RAII type to manage nodes in unordered containers while
they are being inserted. If the caller always owns a node until it is
inserted, then the insertion functions don't need to deallocate on
failure. This allows a FIXME in the node re-insertion API to be removed.

Also change extract(const key_type&) to not call extract(const_iterator)
anymore.  This avoids looping through the bucket nodes again to find the
node before the one being extracted.

2019-06-17  François Dumont  <fdumont@gcc.gnu.org>
	    Jonathan Wakely  <jwakely@redhat.com>

	* include/bits/hashtable.h (struct _Hashtable::_Scoped_node): New type.
	(_Hashtable::_M_insert_unique_node): Add key_type parameter. Don't
	deallocate node if insertion fails.
	(_Hashtable::_M_insert_multi_node): Likewise.
	(_Hashtable::_M_reinsert_node): Pass additional key argument.
	(_Hashtable::_M_reinsert_node_multi): Likewise. Remove FIXME.
	(_Hashtable::_M_extract_node(size_t, __node_base*)): New function.
	(_Hashtable::extract(const_iterator)): Use _M_extract_node.
	(_Hashtable::extract(const _Key&)): Likewise.
	(_Hashtable::_M_merge_unique): Pass additional key argument.
	(_Hashtable::_M_emplace<Args>(true_type, Args&&...)): Likewise. Use
	_Scoped_node.
	(_Hashtable::_M_insert): Likewise.
	* include/bits/hashtable_policy.h (_Map_base::operator[]): Likewise.
	(_Hashtable_alloc): Add comments to functions with misleading names.

Co-Authored-By: Jonathan Wakely <jwakely@redhat.com>

From-SVN: r272381
2019-06-17 11:25:04 +01:00
Jonathan Wakely cc28d23496 Disable -Wctor-dtor-privacy warnings for some standard types
* include/experimental/type_traits (experimental::nonesuch): Use
	pragma to disable -Wctor-dtor-privacy warnings.
	* include/std/type_traits (__is_convertible_helper<From, To, false>)
	(__is_nt_convertible_helper<From, To, false>, __nonesuch): Likewise.

From-SVN: r272289
2019-06-14 15:03:20 +01:00
Jonathan Wakely c68c4c982d Add __cpp_lib_bind_front macro to <version> header
* include/std/version (__cpp_lib_bind_front): Add missing macro.

From-SVN: r272288
2019-06-14 15:03:16 +01:00
Jonathan Wakely 95b3d0fda3 Fix incorrect __cpp_lib_parallel_algorithm macro definitions
* include/std/algorithm (__cpp_lib_parallel_algorithm): Fix value.
	* include/std/memory (__cpp_lib_parallel_algorithm): Likewise.
	* include/std/numeric (__cpp_lib_parallel_algorithm): Likewise.
	* testsuite/25_algorithms/pstl/feature_test.cc: New test.

From-SVN: r272216
2019-06-12 21:16:03 +01:00
Jonathan Wakely 801b2266de Improve static_assert messages for std::variant
Also fix a warning with -Wunused-parameter -Wsystem-headers.

	* include/std/variant (get<T>, get<N>, get_if<N>, get_if<T>)
	(variant::emplace): Change static_assert messages from "should be"
	to "must be".
	(hash<monostate>::operator()): Remove name of unused parameter.

From-SVN: r272188
2019-06-12 15:52:09 +01:00
Jonathan Wakely ce657a7414 Simplify std::scoped_lock destructor
* include/std/mutex (scoped_lock::~scoped_lock()): Use fold
	expression.

From-SVN: r272187
2019-06-12 15:52:06 +01:00
Jonathan Wakely cd0b94e650 Replace std::to_string for integers with optimized version
The std::to_chars functions from C++17 can be used to implement
std::to_string with much better performance than calling snprintf. Only
the __detail::__to_chars_len and __detail::__to_chars_10 functions are
needed for to_string, because it always outputs base 10 representations.

The return type of __detail::__to_chars_10 should not be declared before
C++17, so the function body is extracted into a new function that can be
reused by to_string and __detail::__to_chars_10.

The existing tests for to_chars rely on to_string to check for correct
answers. Now that they use the same code that doesn't actually ensure
correctness, so add new tests for std::to_string that compare against
printf output.

	* include/Makefile.am: Add new <bits/charconv.h> header.
	* include/Makefile.in: Regenerate.
	* include/bits/basic_string.h (to_string(int), to_string(unsigned))
	(to_string(long), to_string(unsigned long), to_string(long long))
	(to_string(unsigned long long)): Rewrite to use __to_chars_10_impl.
	* include/bits/charconv.h: New header.
	(__detail::__to_chars_len): Move here from <charconv>.
	(__detail::__to_chars_10_impl): New function extracted from
	__detail::__to_chars_10.
	* include/std/charconv (__cpp_lib_to_chars): Add, but comment out.
	(__to_chars_unsigned_type): New class template that reuses
	__make_unsigned_selector_base::__select to pick a type.
	(__unsigned_least_t): Redefine as __to_chars_unsigned_type<T>::type.
	(__detail::__to_chars_len): Move to new header.
	(__detail::__to_chars_10): Add inline specifier. Move code doing the
	output to __detail::__to_chars_10_impl and call that.
	* include/std/version (__cpp_lib_to_chars): Add, but comment out.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string.cc: Fix reference in comment. Remove unused variable.
	* testsuite/21_strings/basic_string/numeric_conversions/char/
	to_string_int.cc: New test.

From-SVN: r272186
2019-06-12 15:52:02 +01:00
Thomas Rodgers f32ee8a25e Synchronize libstdc++ PSTL with upstream LLVM PSTL
Rename PSTL macro's consistent with libstdc++ (and llvm upstream
	project) standards.
	* include/bits/c++config: Rename all macros of the form __PSTL* to
	_PSTL*.
	* include/std/algorithm: Likewise.
	* include/std/execution: Likewise.
	* include/std/numeric: Likewise.
	* include/std/memory: Likewise.
	* include/pstl/glue_memory_impl.h: Likewise.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/glue_memory_defs.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* include/pstl/algorithm_fwd.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/glue_numeric_defs.h: Likewise.
	* include/pstl/parallel_backend_utils.h: Likewise.
	* include/pstl/glue_algorithm_defs.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* testsuite/util/pstl/pstl_test_config.h: Likewise.
	* testsuite/util/pstl/test_utils.h: Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc: Likewise.

	Rename header guards to be consistent with upstream project's
	conventions.
	* include/pstl/glue_memory_impl.h: Rename all macros of the form
	_PSTL_(.*)_H to _PSTL_\U\1_H.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/glue_memory_defs.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* include/pstl/algorithm_fwd.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/glue_numeric_defs.h: Likewise.
	* include/pstl/parallel_backend_utils.h: Likewise.
	* include/pstl/glue_algorithm_defs.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* testsuite/util/pstl/pstl_test_config.h: Likewise.

	Synchronize libstdc++ parallel algorithms with upstream
	project.
	* include/pstl/algorithm_fwd.h: Synchronize with
	upstream PSTL project.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/parallel_backend_serial.h: New file.
	* include/Makefile.am (pstl_headers): Add
	parallel_backend_serial.h.
	* include/Makefile.in: Regenerate.

	Clean up non-conforming names
	* include/pstl/algorithm_impl.h (__parallel_set_union_op):
	Uglfiy copy_range1 and copy_range2
	(__pattern_walk2_n): Rename local n to __n
	* include/pstl/parallel_backend_tbb.h (struct __binary_no_op):
	Rename parameter _T to _Tp.

	Integrate non-TBB serial backend support
	* include/bits/c++config: Adjust TBB detection logic to select serial
	PSTL backend if no TBB present.
	* testsuite/utils/pstl/test_utils.h: Remove check for
	_PSTL_USE_PAR_POLICIES

From-SVN: r272056
2019-06-07 22:01:16 +00:00
Jonathan Wakely beb0086f59 Avoid unnecessary inclusion of <stdexcept> header
This can greatly reduce the amount of preprocessed code that is included
by other headers, because <stdexcept> depends on <string> which is huge.

	* include/std/array: Do not include <stdexcept>.
	* include/std/optional: Include <exception> and
	<bits/exception_defines.h> instead of <stdexcept>.
	* testsuite/20_util/function_objects/searchers.cc: Include <cctype>
	for std::isalnum.
	* testsuite/20_util/tuple/cons/deduction.cc: Include <memory> for
	std::allocator.
	* testsuite/23_containers/map/erasure.cc: Include <string>.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.

From-SVN: r272011
2019-06-06 16:34:56 +01:00
Jonathan Wakely 209ee62421 Remove redundant static assertions in [meta.unary.prop] traits
The type property predicates that are implemented by a compiler builtin
already do the right checks in the compiler. The checks for complete
type or unbounded arrays were wrong for these types anyway.

	* include/std/type_traits (is_empty, is_polymorphic, is_final)
	(is_abstract, is_aggregate): Remove static_assert.
	* testsuite/20_util/is_abstract/incomplete_neg.cc: Check for error
	from builtin only.
	* testsuite/20_util/is_aggregate/incomplete_neg.cc: Likewise. Add
	missing -std=gnu++17 option.
	* testsuite/20_util/is_empty/incomplete_neg.cc: New test.
	* testsuite/20_util/is_final/incomplete_neg.cc: New test.
	* testsuite/20_util/is_polymorphic/incomplete_neg.cc: Check for error
	from builtin only.

From-SVN: r272000
2019-06-06 13:13:47 +01:00
Jonathan Wakely d355635e6b Refactor SFINAE constraints on std::tuple constructors
Replace the _TC class template with the better-named _TupleConstraints
one, which provides a different set of member functions. The new members
do not distinguish construction from lvalues and rvalues, but expects
the caller to do that by providing different template arguments. Within
the std::tuple primary template and std::tuple<T1, T2> partial
specialization the _TupleConstraints members are used via new alias
templates like _ImplicitCtor and _ExplicitCtor which makes the
constructor constraints less verbose and repetitive. For example, where
we previously had:

     template<typename... _UElements, typename
             enable_if<
                _TMC<_UElements...>::template
                   _MoveConstructibleTuple<_UElements...>()
                 && _TMC<_UElements...>::template
                   _ImplicitlyMoveConvertibleTuple<_UElements...>()
                 && (sizeof...(_Elements) >= 1),
       bool>::type=true>
       constexpr tuple(_UElements&&... __elements)

We now have:

     template<typename... _UElements,
             bool _Valid = __valid_args<_UElements...>(),
             _ImplicitCtor<_Valid, _UElements...> = true>
      constexpr
      tuple(_UElements&&... __elements)

There are two semantic changes as a result of the refactoring:

- The allocator-extended default constructor is now constrained.
- The rewritten constraints fix PR 90700.

	* include/std/tuple (_TC): Replace with _TupleConstraints.
	(_TupleConstraints): New helper for SFINAE constraints, with more
	expressive member functions to reduce duplication when used.
	(tuple::_TC2, tuple::_TMC, tuple::_TNTC): Remove.
	(tuple::_TCC): Replace dummy type parameter with bool non-type
	parameter that can be used to check the pack size.
	(tuple::_ImplicitDefaultCtor, tuple::_ExplicitDefaultCtor)
	(tuple::_ImplicitCtor, tuple::_ExplicitCtor): New alias templates for
	checking constraints in constructors.
	(tuple::__valid_args, tuple::_UseOtherCtor, tuple::__use_other_ctor):
	New SFINAE helpers.
	(tuple::tuple): Use new helpers to reduce repitition in constraints.
	(tuple::tuple(allocator_arg_t, const Alloc&)): Constrain.
	(tuple<T1, T2>::_TCC, tuple<T1, T2>::_ImplicitDefaultCtor)
	(tuple<T1, T2>::_ExplicitDefaultCtor, tuple<T1, T2>::_ImplicitCtor)
	(tuple<T1, T2>::_ExplicitCtor): New alias templates for checking
	constraints in constructors.
	(tuple::__is_alloc_arg()): New SFINAE helpers.
	(tuple<T1, T2>::tuple): Use new helpers to reduce repitition in
	constraints.
	(tuple<T1, T2>::tuple(allocator_arg_t, const Alloc&)): Constrain.
	* testsuite/20_util/tuple/cons/90700.cc: New test.
	* testsuite/20_util/tuple/cons/allocators.cc: Add default constructor
	to meet new constraint on allocator-extended default constructor.

From-SVN: r271998
2019-06-06 13:13:36 +01:00
Jonathan Wakely ffef1e30a7 Fix uses of static_assert not guarded by C++11 check
* include/bits/stl_map.h (map): Disable static assert for C++98 mode.
	* include/bits/stl_multimap.h (multimap): Likewise.

From-SVN: r271884
2019-06-03 23:18:31 +01:00
François Dumont 7cfe71d1d2 Rename variables and cleanup comments.
2019-06-03  François Dumont  <fdumont@gcc.gnu.org>

	Rename variables and cleanup comments.
	* include/bits/hashtable_policy.h
	* include/bits/hashtable.h

From-SVN: r271876
2019-06-03 17:08:34 +00:00
Jonathan Wakely ebaf365963 Enforce allocator::value_type consistency for containers in C++2a
In previous standards it is undefined for a container and its allocator
to have a different value_type. Libstdc++ has traditionally allowed it
as an extension, automatically rebinding the allocator to the
container's value_type. Since GCC 8.1 that extension has been disabled
for C++11 and later when __STRICT_ANSI__ is defined (i.e. for
-std=c++11, -std=c++14, -std=c++17 and -std=c++2a).

Since the acceptance of P1463R1 into the C++2a draft an incorrect
allocator::value_type now requires a diagnostic. This patch implements
that by enabling the static_assert for -std=gnu++2a as well.

	* doc/xml/manual/status_cxx2020.xml: Document P1463R1 status.
	* include/bits/forward_list.h [__cplusplus > 201703]: Enable
	allocator::value_type assertion for C++2a.
	* include/bits/hashtable.h: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_list.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_vector.h: Likewise.
	* testsuite/23_containers/deque/48101-3_neg.cc: New test.
	* testsuite/23_containers/forward_list/48101-3_neg.cc: New test.
	* testsuite/23_containers/list/48101-3_neg.cc: New test.
	* testsuite/23_containers/map/48101-3_neg.cc: New test.
	* testsuite/23_containers/multimap/48101-3_neg.cc: New test.
	* testsuite/23_containers/multiset/48101-3_neg.cc: New test.
	* testsuite/23_containers/set/48101-3_neg.cc: New test.
	* testsuite/23_containers/unordered_map/48101-3_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/48101-3_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/48101-3_neg.cc: New test.
	* testsuite/23_containers/unordered_set/48101-3_neg.cc: New test.
	* testsuite/23_containers/vector/48101-3_neg.cc: New test.

From-SVN: r271866
2019-06-03 14:22:59 +01:00
Jonathan Wakely b1bb4869e2 Add noexcept to tuple<> and simplify tuple<T1,T2> noexcept-specifiers
* include/std/tuple (tuple<>): Add noexcept to allocator-extended
	constructors.
	(tuple<T1, T2>::__nothrow_default_constructible()): New helper
	function.
	(tuple<T1, T2>::tuple(), explicit tuple<T1, T2>::tuple()): Use helper.

From-SVN: r271814
2019-05-31 15:58:05 +01:00