Commit Graph

4690 Commits

Author SHA1 Message Date
Jonathan Wakely
bbaec68c86 libstdc++: Fix atomic<FP>::load (PR 95282)
PR libstdc++/95282
	* include/bits/atomic_base.h (__atomic_impl::load): Add
	cv-qualifiers to parameter so that _Tp is deduced as the
	unqualified type.
	* testsuite/29_atomics/atomic_float/95282.cc: New test.
2020-05-27 22:55:21 +01:00
Jonathan Wakely
6c2582c040 libstdc++: Fix view adaptors for mixed-const sentinels and iterators (PR 95322)
The bug report is that transform_view's sentinel<false> cannot be
compared to its iterator<true>.  The comparison is supposed to use
operator==(iterator<Const>, sentinel<Const>) after converting
sentinel<false> to sentinel<true>. However, the operator== is a hidden
friend so is not a candidate when comparing iterator<true> with
sentinel<false>. The required conversion would only happen if we'd found
the operator, but we can't find the operator until after the conversion
happens.

A new LWG issue has been reported, but not yet assigned a number.  The
solution suggested by Casey Carter is to make the hidden friends of the
sentinel types work with iterators of any const-ness, so that no
conversions are required.

Patrick Palka observed that join_view has a similar problem and a
similar fix is used for its sentinel.

	PR libstdc++/95322
	* include/std/ranges (transform_view::_Sentinel): Allow hidden
	friends to work with _Iterator<true> and _Iterator<false>.
	(join_view::_Sentinel): Likewise.
	* testsuite/std/ranges/adaptors/95322.cc: New test.
2020-05-27 22:08:15 +01:00
Jonathan Wakely
979e89a9a9 libstdc++: Fix std::reverse_iterator comparisons (PR 94354)
The std::reverse_iterator comparisons have always been implemented only
in terms of equality and less than. In C++98 that made no difference for
reasonable code, because when the underlying operators are the same type
they are required to support all comparisons anyway.

But since LWG 280 it's possible to compare reverse_iterator<X> and
reverse_iterator<Y>, and comparisons between X and Y might not support
the full set of equality and relational operators. This means that it
matters whether we implement operator!= as x.base() != y.base() or
!(x.base() == y.base()), and the current implementation is
non-conforming.

This was already fixed in GCC 10.1 for C++20, this change also fixes it
for all other -std modes.

	PR libstdc++/94354
	* include/bits/stl_iterator.h (reverse_iterator): Fix comparison
	operators to use the correct operations on the underlying
	iterators.
	* testsuite/24_iterators/reverse_iterator/rel_ops.cc: New test.
2020-05-27 21:58:56 +01:00
Jonathan Wakely
116e3cfc7b libstdc++: Add new testcase for comparison category types
Comparing a comparison category type to anything except a literal 0 is
undefined. This verifies that at least some misuses are diagnosed at
compile time.

	* testsuite/18_support/comparisons/categories/zero_neg.cc: New test.
2020-05-27 13:14:17 +01:00
Patrick Palka
3bf5e7657b libstdc++: Fix common_iterator::operator-> [PR95322]
This patch fixes the definition of common_iterator::operator-> when the
underlying iterator's operator* returns a non-reference.

The first problem is that the class __detail::_Common_iter_proxy is used
unqualified.  Fixing that revealed another problem: the class's template
friend declaration of common_iterator doesn't match up with the
definition of common_iterator, because the friend declaration isn't
constrained.

If we try to make the friend declaration match up by adding constraints,
we run into frontend bug PR93467.  So we currently can't correctly
express this friend relation between __detail::_Common_iter_proxy and
common_iterator.

As a workaround to this frontend bug, this patch moves the definition of
_Common_iter_proxy into the class template of common_iterator so that we
could instead express the friend relation via the injected-class-name.

(This bug was found when attempting to use views::common to work around
the compile failure with the testcase in PR95322.)

libstdc++-v3/ChangeLog:

	PR libstdc++/95322
	* include/bits/stl_iterator.h (__detail::_Common_iter_proxy):
	Remove and instead define it ...
	(common_iterator::_Proxy): ... here.
	(common_iterator::operator->): Use it.
	* testsuite/24_iterators/common_iterator/2.cc: New test.
	* testsuite/std/ranges/adaptors/95322.cc: New test.
2020-05-26 16:17:34 -04:00
Patrick Palka
a57aa11191 libstdc++: Compile PR93978 testcase with -Wall
Now that the frontend issue PR c++/94038 is thoroughly fixed, the
testcase for PR93978 no longer fails to compile with -O -Wall, so add
-Wall to the testcase's compile flags to help ensure we don't regress
here.

libstdc++-v3/ChangeLog:

	PR libstdc++/93978
	* testsuite/std/ranges/adaptors/93978.cc: Add -Wall to
	dg-additional-options.  Avoid unused-but-set-variable warning.
2020-05-23 15:25:40 -04:00
Jonathan Wakely
3cb0c7cc16 libstdc++: Fix function that can't be constexpr in C++11 (PR 95289)
The body of this function isn't just a return statement, so it can't be
constexpr until C++14.

	PR libstdc++/95289
	* include/debug/helper_functions.h (__get_distance): Only declare
	as a constexpr function for C++14 and up.
	* testsuite/25_algorithms/copy/debug/95289.cc: New test.
2020-05-23 18:27:35 +01:00
Jonathan Wakely
988b853f9c libstdc++: Simplify filesystem::path SFINAE constraints
This replaces the filesystem::__detail::_Path SFINAE helper with two
separate helpers, _Path and _Path2. This avoids having one helper which
tries to check two different sets of requirements.

The _Path helper now uses variable templates instead of a set of
overloaded functions to detect specializations of basic_string or
basic_string_view.

The __not_<is_void<remove_pointer_t<_Tp1>> check is not necessary in
C++20 because iterator_traits<void*> is now empty. For C++17 replace
that check with a __safe_iterator_traits helper with partial
specializations for void pointers.

Finally, the __is_encoded_char check no longer uses remove_const_t,
which means that iterators with a const value_type will no longer be
accepted as arguments for path creation. Such iterators resulted in
undefined behaviour anyway, so it's still conforming to reject them in
the constraint checks.

	* include/bits/fs_path.h (filesystem::__detail::__is_encoded_char):
	Replace alias template with variable template. Don't remove const.
	(filesystem::__detail::__is_path_src): Replace overloaded function
	template with variable template and specializations.
	(filesystem::__detail::__is_path_iter_src): Replace alias template
	with class template.
	(filesystem::__detail::_Path): Use __is_path_src. Remove support for
	iterator pairs.
	(filesystem::__detail::_Path2): New alias template for checking
	InputIterator requirements.
	(filesystem::__detail::__constructible_from): Remove.
	(filesystem::path): Replace _Path<Iter, Iter> with _Path2<Iter>.
	* testsuite/27_io/filesystem/path/construct/80762.cc: Check with two
	constructor arguments of void and void* types.
2020-05-23 09:40:16 +01:00
Matthias Kretz
bc7a4f2f9e libstdc++: Enable simple invocation of runtest in testsuite
2020-05-21  Matthias Kretz  <kretz@kde.org>

	* testsuite/Makefile.am: Remove dup target_triplet and set tool,
	allowing runtest to work without arguments.
	* testsuite/Makefile.in: Regenerate.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
2020-05-21 14:16:19 +01:00
Jonathan Wakely
f094665d46 libstdc++: Avoid constraint recursion with iterator_traits (PR 93983)
Checking whether a filesystem::path constructor argument is an iterator
requires instantiating std::iterator_traits. In C++20 that checks for
satisfaction of std::iterator_traits constraints, which checks if the
type is copyable, which can end up recursing back to the path
constructor. The fix in LWG 3420 is to reorder the cpp17-iterator
concept's constraints to check if the type looks vaguely like an
iterator before checking copyable. That avoids the recursion for types
which definitely aren't iterators, but isn't foolproof.

	PR libstdc++/93983
	* include/bits/iterator_concepts.h (__detail::__cpp17_iterator):
	Reorder constraints to avoid recursion when constructors use
	iterator_traits (LWG 3420).
	* testsuite/24_iterators/customization_points/lwg3420.cc: New test.
2020-05-21 07:32:15 +01:00
Jonathan Wakely
d9d34449bb libstdc++: Fix net::basic_socket::close(error_code&)
Also add some missing member functions, nodiscard attributes, and
noexcept-specifiers.

	* include/experimental/executor (use_future_t::use_future_t()): Fix
	incorrect noexcept-specifier.
	* include/experimental/internet (basic_resolver_results): Adjust
	whitespace.
	* include/experimental/socket (__basic_socket_impl::release): Add
	member function.
	(basic_socket(io_context&, const endpoint_type&)): Fix argument to
	target constructor.
	(basic_socket::release(), basic_socket::release(error_code&)): Add
	missing member functions.
	(basic_socket::is_open()): Add nodiscard attribute.
	(basic_socket::close(error_code&)): Pass argument to base function.
	(basic_socket_acceptor::release())
	(basic_socket_acceptor::release(error_code&)): Add missing member
	functions.
	(basic_socket_acceptor::is_open()): Add nodiscard attribute.
	(basic_socket_streambuf::error()): Add noexcept.
	(basic_socket_iostream::error()): Likewise.
	* testsuite/experimental/net/socket/basic_socket.cc: New test.
2020-05-21 00:59:55 +01:00
Jonathan Wakely
a2d196e75c libstdc++: Use RDRAND as fallback if RDSEED keeps failing (PR 94087)
It's not difficult for multiple threads to drain the entropy available
to the RDSEED instruction, at which point we throw an exception. This
change will try to use RDRAND after RDSEED fails repeatedly, and only
throw if RDRAND also fails repeatedly. This doesn't guarantee a random
value can always be read, but reduces the likelihood of failure when
using the RDSEED instruction.

	PR libstdc++/94087
	* src/c++11/random.cc (__x86_rdseed): Allow fallback function to be
	passed in.
	(__x86_rdseed_rdrand): New function that uses rdseed with rdrand
	fallback.
	(random_device::_M_init): Use __x86_rdseed_rdrand when both
	instructions are available.
	* testsuite/26_numerics/random/random_device/94087.cc: New test.
2020-05-19 23:04:45 +01:00
Patrick Palka
864fed4a49 c++: Explain fn template argument type/value mismatches [PR66439]
In fn_type_unifcation, we are passing NULL_TREE as the 'in_decl'
parameter to coerce_template_parms, and this is causing template
type/value mismatch error messages to get suppressed regardless of the
value of 'complain'.

This means that when substitution into a function template fails due to
a type/value mismatch between a template parameter and the provided
template argument, we just say "template argument deduction/substitution
failed:" without a followup explanation of the failure.

Fix this by passing 'fn' instead of NULL_TREE to coerce_template_parms.

gcc/cp/ChangeLog:

	PR c++/66439
	* pt.c (fn_type_unification): Pass 'fn' instead of NULL_TREE as
	the 'in_decl' parameter to coerce_template_parms.

gcc/testsuite/ChangeLog:

	PR c++/66439
	* g++.dg/cpp2a/concepts-ts4.C: Expect a "type/value mismatch"
	diagnostic.
	* g++.dg/cpp2a/concepts-ts6.C: Likewise.
	* g++.dg/template/error56.C: Likewise.
	* g++.dg/template/error59.C: New test.

libstdc++-v3/ChangeLog:

	PR c++/66439
	* testsuite/20_util/pair/astuple/get_neg.cc: Prune "type/value
	mismatch" messages.
	* testsuite/20_util/tuple/element_access/get_neg.cc: Likewise.
2020-05-18 23:50:14 -04:00
Alexandre Oliva
883246530f x86-vxworks malloc aligns to 8 bytes like solaris
Vxworks 7's malloc, like Solaris', only ensures 8-byte alignment of
returned pointers on 32-bit x86, though GCC's stddef.h defines
max_align_t with 16-byte alignment for __float128.  This patch enables
on x86-vxworks the same memory_resource workaround used for x86-solaris.

The testsuite also had a workaround, defining BAD_MAX_ALIGN_T and
xfailing the test; extend those to x86-vxworks as well, and remove the
check for char-aligned requested allocation to be aligned like
max_align_t.  With that change, the test passes on x86-vxworks; I'm
guessing that's the same reason for the test not to pass on
x86-solaris (and on x86_64-solaris -m32), so with the fix, I'm
tentatively removing the xfail.


for libstdc++-v3/ChangeLog

	PR libstdc++/77691
	* include/experimental/memory_resource
	(__resource_adaptor_imp::do_allocate): Handle max_align_t on
	x86-vxworks as on x86-solaris.
	(__resource_adaptor_imp::do_deallocate): Likewise.
	* testsuite/experimental/memory_resource/new_delete_resource.cc:
	Drop xfail.
	(BAD_MAX_ALIGN_T): Define on x86-vxworks as on x86-solaris.
	(test03): Drop max-align test for char-aligned alloc.
2020-05-13 04:49:00 -03:00
Ulrich Drepper
7a2e715c9a Actually comment the new tests 2020-05-12 07:38:28 +02:00
François Dumont
72a54e5e81 libstdc++ std::fill overload for std::vector<bool>::iterator
Extend the overload so that it is used even when _GLIBCXX_DEBUG mode
is activated.

	* include/bits/stl_algobase.h (struct _Bit_iterator): New declaration.
	(std::__fill_a1(_Bit_iterator, _Bit_iterator, const bool&)): Likewise.
	* include/bits/stl_bvector.h (__fill_bvector): Move outside
	_GLIBCXX_STD_C namespace.
	(fill(_Bit_iterator, _Bit_iterator, const bool&)): Likewise and rename
	into...
	(__fill_a1): ...this.
	* testsuite/25_algorithms/fill/bvector/1.cc: New.
2020-05-06 23:28:22 +02:00
Jonathan Wakely
ec40967f13 libstdc++: Make pmr::synchronized_pool_resource work without libpthread (PR 94936)
I implicitly assumed that programs using pmr::synchronized_pool_resource
would also be using multiple threads, and so the weak symbols in
gthr-posix.h would be resolved by linking to libpthread. If that isn't
true then it crashes when trying to use pthread_key_create.

This commit makes the pool resource check __gthread_active_p() before
using thread-specific data, and just use a single set of memory pools
when there's only a single thread.

	PR libstdc++/94936
	* src/c++17/memory_resource.cc (synchronized_pool_resource::_TPools):
	Add comment about single-threaded behaviour.
	(synchronized_pool_resource::_TPools::move_nonempty_chunks()): Hoist
	class member access out of loop.
	(synchronized_pool_resource::synchronized_pool_resource())
	(synchronized_pool_resource::~synchronized_pool_resource())
	(synchronized_pool_resource::release()): Check __gthread_active_p
	before creating and/or deleting the thread-specific data key.
	(synchronized_pool_resource::_M_thread_specific_pools()): Adjust
	assertions.
	(synchronized_pool_resource::do_allocate(size_t, size_t)): Add fast
	path for single-threaded case.
	(synchronized_pool_resource::do_deallocate(void*, size_t, size_t)):
	Likewise. Return if unable to find a pool that owns the allocation.
	* testsuite/20_util/synchronized_pool_resource/allocate_single.cc:
	New test.
	* testsuite/20_util/synchronized_pool_resource/cons_single.cc: New
	test.
	* testsuite/20_util/synchronized_pool_resource/release_single.cc: New
	test.
2020-05-04 13:37:31 +01:00
Jonathan Wakely
22b6b5d6cf libstdc++: Make byte-sized std::fill_n a constant expression (PR 94933)
The overload for byte types uses memset and isn't constexpr. This adds
the specifier and uses std::is_constant_evaluated() to provide a
compile-time alternative.

	PR libstdc++/94933
	* include/bits/stl_algobase.h (__fill_a1): Make overload for byte types
	usable in constant expressions.
	* testsuite/25_algorithms/fill_n/constexpr.cc: Test with bytes and
	non-scalars.
2020-05-03 13:33:15 +01:00
Jonathan Wakely
187c854cc6 libstdc++: Add more tests for _E10, _E11 etc. (PR 94901)
PR libstdc++/94901
	* testsuite/17_intro/badnames.cc: Test values between _E9 and _E24 too.
2020-05-01 14:49:48 +01:00
Jonathan Wakely
a5f2fb1ff1 libstdc++: Replace deduced return type in ranges::iter_move (PR 92894)
The deduced return type causes the instantiation of the function body,
which can then require the instantiation of std::projected::operator*
which is intentionally not defined.

This patch uses a helper trait to define the return type, so that the
function body doesn't need to be instantiated. That helper trait can
then also be used in other places that currently check the return type
of ranges::iter_move (iter_rvalue_reference_t and indirectly_readable).

2020-05-01  Jonathan Wakely  <jwakely@redhat.com>
	    Patrick Palka  <ppalka@redhat.com>

	PR libstdc++/92894
	* include/bits/iterator_concepts.h (ranges::__cust_imove::_IMove):
	Add trait to determine return type and an alias for it.
	(ranges::__cust_imove::_IMove::operator()): Use __result instead of
	deduced return type.
	(iter_rvalue_reference_t): Use _IMove::__type instead of checking
	the result of ranges::iter_move.
	(__detail::__indirectly_readable_impl): Use iter_rvalue_reference_t
	instead of checking the result of ranges::iter_move.
	* testsuite/24_iterators/customization_points/92894.cc: New test.
	* testsuite/24_iterators/indirect_callable/92894.cc: New test.
2020-05-01 14:27:25 +01:00
Jonathan Wakely
070b4df8a0 libstdc++: Replace reserved identifier _T with _Tp (PR 94901)
The libstdc++ manual documents that _T can not be used, because it's a
macro in system headers on some targets.

	PR libstdc++/94901
	* include/std/type_traits (__is_complete_or_unbounded): Replace
	BADNAME _T with _Tp.
	* testsuite/17_intro/badnames.cc: New test.
2020-05-01 13:41:02 +01:00
Jonathan Wakely
b1983f4582 libstdc++: Avoid errors in allocator's noexcept-specifier (PR 89510)
This fixes a regression due to the conditional noexcept-specifier on
std::allocator::construct and std::allocator::destroy, as well as the
corresponding members of new_allocator, malloc_allocator, and
allocator_traits. Those noexcept-specifiers were using expressions which
might be ill-formed, which caused errors outside the immediate context
when checking for the presence of construct and destroy in SFINAE
contexts.

The fix is to use the is_nothrow_constructible and
is_nothrow_destructible type traits instead, because those traits are
safe to use even when the construction/destruction itself is not valid.

The is_nothrow_constructible trait will be false for a type that is not
also nothrow-destructible, even if the new-expression used in the
construct function body is actually noexcept. That's not the correct
answer, but isn't a problem because providing a noexcept-specifier on
these functions is not required by the standard anyway. If the answer is
false when it should be true, that's suboptimal but OK (unlike giving
errors for valid code, or giving a true answer when it should be false).

	PR libstdc++/89510
	* include/bits/alloc_traits.h (allocator_traits::_S_construct)
	(allocator_traits::_S_destroy)
	(allocator_traits<allocator<T>>::construct): Use traits in
	noexcept-specifiers.
	* include/bits/allocator.h (allocator<void>::construct)
	(allocator<void>::destroy): Likewise.
	* include/ext/malloc_allocator.h (malloc_allocator::construct)
	(malloc_allocator::destroy): Likewise.
	* include/ext/new_allocator.h (new_allocator::construct)
	(new_allocator::destroy): Likewise.
	* testsuite/20_util/allocator/89510.cc: New test.
	* testsuite/ext/malloc_allocator/89510.cc: New test.
	* testsuite/ext/new_allocator/89510.cc: New test.
2020-04-30 16:01:43 +01:00
Jonathan Wakely
d0330a0360 libstdc++: Fixes for feature test macros (PR 91480)
Remove the non-standard __cpp_lib_allocator_is_always_equal macro and
add the missing macros for P1032R1.

	PR libstdc++/91480
	* include/bits/allocator.h (__cpp_lib_allocator_is_always_equal):
	Remove non-standard macro.
	* include/bits/stl_iterator.h (__cpp_lib_constexpr_iterator): Define
	to indicate P1032R1 support.
	* include/bits/stl_pair.h (__cpp_lib_constexpr_utility): Likewise.
	* include/std/string_view (__cpp_lib_constexpr_string_view): Likewise.
	* include/std/tuple (__cpp_lib_constexpr_tuple): Likewise.
	* include/std/version (__cpp_lib_allocator_is_always_equal): Remove.
	(__cpp_lib_constexpr_iterator, __cpp_lib_constexpr_string_view)
	(__cpp_lib_constexpr_tuple, __cpp_lib_constexpr_utility): Define.
	* testsuite/20_util/function_objects/constexpr_searcher.cc: Check
	feature test macro.
	* testsuite/20_util/tuple/cons/constexpr_allocator_arg_t.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/
	constexpr.cc: Likewise.
	* testsuite/24_iterators/insert_iterator/constexpr.cc: Likewise.
2020-04-28 23:40:18 +01:00
Jonathan Wakely
162c40a4c1 libstdc++: Fix regression in std::_Construct (PR 94831)
By trying to reuse the existing std::_Construct function as a wrapper
for std::construct_at I introduced regressions, because changing
std::_Construct to return non-void made it ill-formed for array types.

The solution is to revert _Construct to its former state, and change
allocator_traits::construct to explicitly call construct_at instead.
This decouples all the existing callers of _Construct from the new
construct_at requirements.

	PR libstdc++/94831
	* include/bits/alloc_traits.h (_S_construct): Restore placement
	new-expression for C++11/14/17 and call std::construct_at directly
	for C++20.
	* include/bits/stl_construct.h (_Construct): Revert to non-constexpr
	function returning void.
	* testsuite/20_util/specialized_algorithms/
	uninitialized_value_construct/94831.cc: New test.
	* testsuite/23_containers/vector/cons/94831.cc: New test.
2020-04-28 23:39:38 +01:00
Patrick Palka
19667c82e4 libstdc++: Fix subrange::advance and subrange::prev (LWG 3433)
This implements the proposed resolution of LWG 3433, which fixes
subrange::advance when called with a negative argument.

libstdc++-v3/ChangeLog:

	LWG 3433 subrange::advance(n) has UB when n < 0
	* include/std/ranges (subrange::prev): Fix typo.
	(subrange::advance): Handle a negative argument as per the proposed
	resolution of LWG 3433.
	* testsuite/std/ranges/subrange/lwg3433.cc: New test.
2020-04-28 16:43:23 -04:00
Jonathan Wakely
00082ff88c libstdc++: Make net::service_already_exists default constructible
The LWG issue I created is Tentatively Ready and proposes to declare a
public default constructor, rather than the private one I added
recently.

	* include/experimental/executor (service_already_exists): Make default
	constructor public (LWG 3414).
	* testsuite/experimental/net/execution_context/make_service.cc: Check
	the service_already_exists can be default constructed.
2020-04-24 14:15:51 +01:00
Jonathan Wakely
d1462b0782 libstdc++: Fix constructor constraints for std::any (PR 90415)
This removes a non-standard extension to std::any which causes errors
for valid code, due to recursive instantiation of a trait that isn't
supposed to be in the constraints.

It also removes some incorrect constraints on the in_place_type<T>
constructors and emplace members, which were preventing creating a
std::any object with another std::any as the contained value.

2020-04-24  Kamlesh Kumar  <kamleshbhalui@gmail.com>
	    Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/90415
	PR libstdc++/92156
	* include/std/any (any): Rename template parameters for consistency
	with the standard.
	(any::_Decay): Rename to _Decay_if_not_any.
	(any::any(T&&):: Remove is_constructible from constraints. Remove
	non-standard overload.
	(any::any(in_place_type_t<T>, Args&&...))
	(any::any(in_place_type_t<T>, initializer_list<U>, Args&&...))
	(any::emplace(Args&&...))
	(any::emplace(initializer_list<U>, Args&&...)):
	Use decay_t instead of _Decay.
	* testsuite/20_util/any/cons/90415.cc: New test.
	* testsuite/20_util/any/cons/92156.cc: New Test.
	* testsuite/20_util/any/misc/any_cast_neg.cc: Make dg-error directives
	more robust.
	* testsuite/20_util/any/modifiers/92156.cc: New test.
2020-04-24 00:54:20 +01:00
Thomas Rodgers
8c9d69bafc libstdc++: Mark experimental::net::system_context ctor deleted
* include/experimental/net/executor (system_context): Mark
           system_context::system_context() = delete.
           * testsuite/experimental/net/executor/1.cc: Add new
           test to check system_context is not default constructible.
2020-04-23 13:44:23 -07:00
Jonathan Wakely
40541efe1c libstdc++: Change __cpp_lib_array_constexpr for C++17 again
This partially reverts my previous change related to this macro. The
C++20 constexpr iterator requirements are always met by array:iterator,
because it's just a pointer. So the macro can be set to 201803 even in
C++17 mode.

	* include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Revert
	value for C++17 to 201803L because P0858R0 is supported for C++17.
	* include/std/version (__cpp_lib_array_constexpr): Likewise.
	* testsuite/23_containers/array/element_access/constexpr_c++17.cc:
	Check for value corresponding to P0031R0 features being tested.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc:
	Check for value corresponding to P0858R0 features being tested.
2020-04-23 21:39:33 +01:00
Jonathan Wakely
aac39307e8 libstdc++: Define __cpp_lib_execution feature test macro
This macro has never been defined by libstdc++, despite supporting the
parallel algorithms. It should have a different value for C++17 and
C++20, because P1001R2 should not be supported in C++17, but
unsequenced_policy is defined for C++17 (see PR p4702).

	* include/std/execution (__cpp_lib_execution): Define to indicate
	support for P0024R2 and P1001R2.
	* include/std/version (__cpp_lib_execution): Define.
	* testsuite/25_algorithms/pstl/feature_test.cc: Only test macro
	defined by <algorithm>, move other tests to new tests ...
	* testsuite/25_algorithms/pstl/feature_test-2.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-3.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-4.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-5.cc: New test.
2020-04-22 22:54:35 +01:00
Jonathan Wakely
e851aa1703 libstdc++: Update (and revert) value of __cpp_lib_array_constexpr
This macro should have been updated to 201811 when the last C++20
changes were implemented. However those changes are not enabled for
C++17 mode, so the macro should only have the new value in C++20 mode.

This change ensures that the macro is defined to 201603 for C++17 and
201811 for C++20.

	* include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Define
	different values for C++17 and C++20, to indicate different feature
	sets. Update value for C++20 to indicate P1032R1 support.
	* include/std/version (__cpp_lib_array_constexpr): Likewise.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc:
	Check feature test macro.
	* testsuite/23_containers/array/element_access/constexpr_c++17.cc:
	New test.
	* testsuite/23_containers/array/requirements/constexpr_fill.cc: Check
	feature test macro.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc: Test
	in C++17 mode and check feature test macro.
2020-04-22 22:54:35 +01:00
Jonathan Wakely
2025db692e libstdc++: Do not define __cpp_lib_constexpr_algorithms in <utility>
The C++20 draft and SD-6 both say this should only be in <version> and
<algorithm>, not in <utility>.

	* include/std/utility (__cpp_lib_constexpr_algorithms): Do not define
	here.
	* testsuite/20_util/exchange/constexpr.cc: Do not expect macro to be
	defined by <utility>.
2020-04-22 22:54:35 +01:00
Jonathan Wakely
c9313582d8 libstdc++: Update __cpp_lib_concepts value
* include/std/functional (__cpp_lib_concepts): Update macro value to
	indicate P1964R2 support.
	* include/std/version (__cpp_lib_concepts): Likewise.
	* testsuite/std/concepts/1.cc: Adjust expected value.
	* testsuite/std/concepts/2.cc: Likewise.
2020-04-22 22:54:34 +01:00
Jonathan Wakely
eca477d16c libstdc++: Rename __cpp_lib_constexpr_invoke macro
This macro was renamed after it was added to the working draft, but we
never renamed it  in libstdc++. We haven't made a release with the old
macro name, so I see no need to keep it around.

	* include/std/functional (__cpp_lib_constexpr_invoke): Rename to
	__cpp_lib_constexpr_functional.
	* include/std/version (__cpp_lib_constexpr_invoke): Likewise.
	* testsuite/20_util/function_objects/invoke/constexpr.cc: Adjust.
2020-04-22 22:54:34 +01:00
Jonathan Wakely
56772f623e libstdc++: Add missing feature test macros
These macros all correspond to features that are already supported, but
the macro was not defined when the feature was implemented.

	* include/bits/ptr_traits.h (__cpp_lib_constexpr_memory): Define to
	indicate P1006R1 support.
	(__cpp_lib_to_address): Define to indicate P0653R2 support.
	* include/bits/range_access.h (__cpp_lib_ssize): Define to indicate
	P1227R2 support.
	* include/bits/ranges_algo.h (__cpp_lib_shift): Define to indicate
	P0769R2 support.
	* include/std/atomic (__cpp_lib_atomic_float): Define to indicate
	P0020R6 support.
	* include/std/memory (__cpp_lib_assume_aligned): Define to indicate
	P1007R3 support.
	* include/std/memory_resource (__cpp_lib_polymorphic_allocator):
	Define to indicate P0339R6 support.
	* include/std/string_view (__cpp_lib_starts_ends_with): Define to
	indicate P0457R2 support.
	* include/std/type_traits (__cpp_lib_is_nothrow_convertible): Define
	to indicate P0758R1 support.
	(__cpp_lib_remove_cvref): Define to indicate P0550R2 support.
	(__cpp_lib_type_identity): Define to indicate P0887R1 support.
	* include/std/version (__cpp_lib_atomic_float)
	(__cpp_lib_is_nothrow_convertible, __cpp_lib_remove_cvref)
	(__cpp_lib_type_identity, __cpp_lib_assume_aligned)
	(__cpp_lib_constexpr_memory, __cpp_lib_polymorphic_allocator)
	(__cpp_lib_shift, __cpp_lib_ssize, __cpp_lib_starts_ends_with)
	(__cpp_lib_to_address): Define.
	* testsuite/20_util/to_address/1_neg.cc: Adjust dg-error line number.
2020-04-22 22:54:34 +01:00
Jonathan Wakely
aa12ab2e93 libstdc++: Update value of __cpp_lib_jthread macro
* include/std/condition_variable (__cpp_lib_jthread): Remove
	redundant definition.
	* include/std/stop_token (__cpp_lib_jthread): Update macro value to
	indicate P1869R1 support.
	* include/std/version (__cpp_lib_jthread): Update value.
	* testsuite/30_threads/condition_variable_any/stop_token/1.cc: Check
	for updated macro value.
	* testsuite/30_threads/condition_variable_any/stop_token/2.cc:
	Likewise.
	* testsuite/30_threads/jthread/1.cc: Likewise.
	* testsuite/30_threads/jthread/2.cc: Likewise.
	* testsuite/30_threads/stop_token/1.cc: Likewise.
	* testsuite/30_threads/stop_token/2.cc: Likewise.
2020-04-22 22:54:34 +01:00
Jonathan Wakely
0fe9eaaa08 libstdc++: Improve tests for __cpp_lib_erase_if macro
* testsuite/21_strings/basic_string/erasure.cc: Check for updated
	value of __cpp_lib_erase_if.
	* testsuite/23_containers/deque/erasure.cc: Likewise.
	* 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-04-22 07:25:02 +01:00
Jonathan Wakely
87841658d4 libstdc++: Fix __normal_iterator comparisons for C++20
This fixes a regression introduced when I replaced __normal_iterator's
relational operators with operator<=>. If the wrapped iterator type
doesn't define operator<=> then __normal_iterator doesdn't either, which
breaks any use of fancy pointers that don't define <=>. The regression
was found when trying to build cmcstl2.

The solution is to use synth-three-way to define __normal_iterator's
spaceship operator, so that it is still defined even if the wrapped type
only supports operator<.

	* include/bits/stl_iterator.h (__normal_iterator): Use synth-three-way
	to define operator<=>.
	* testsuite/24_iterators/normal_iterator/cmp_c++20.cc: New test.
2020-04-21 23:46:54 +01:00
Jonathan Wakely
d76925e46f libstdc++: Support arrays in std::is_nothrow_constructible (PR 94149)
The front end now supports parenthesized initialization for arrays in
C++20, so extend std::is_nothrow_constructible to support them too.

gcc/testsuite:

	PR c++/94149
	* g++.dg/cpp2a/paren-init24.C: Fix FIXMEs.

libstdc++-v3:

	PR c++/94149
	* include/std/type_traits (__is_nt_constructible_impl): Add partial
	specializations for bounded arrays with non-empty initializers.
	* testsuite/20_util/is_nothrow_constructible/value_c++20.cc: New test.
2020-04-21 22:18:51 +01:00
Thomas Rodgers
b90ff7a20b libstdc++: Fix PSTL tests to run correctly with newer Thread Building Blocks
* testsuite/lib/libstdc++.exp: Add additional_flags=
	-DTBB_SUPRESS_DEPRECATED_MESSAGES=1 to suppress warnings when
	compiling with a newer Thread Building Blocks.
2020-04-21 01:05:13 -07:00
Jonathan Wakely
86119f1417 libstdc++: Add test for using istreambuf_iterator with sentinel
This test was supposed to be added two months ago as part of commit
120e873484 but was omitted by mistake.

	* testsuite/24_iterators/istreambuf_iterator/sentinel.cc: New test.
2020-04-20 22:06:32 +01:00
Jonathan Wakely
0ea89b1578 libstdc++: Fix tests that fail in C++20 mode
* testsuite/20_util/is_constructible/51185.cc: Make test class a
	non-aggregate so that the test verifies the same thing in all -std
	modes.
	* testsuite/20_util/is_constructible/value-2.cc: Adjust expected
	results for some types when paren-init for aggregates is supported.
2020-04-20 22:06:32 +01:00
Jonathan Wakely
93843da697 libstdc++: Add comparison operators to associative containers
The last C++20 changes from P1614R2, "The Mothership has Landed"

	* include/bits/stl_map.h (map): Define operator<=> and remove
	operator< for C++20.
	* include/bits/stl_multimap.h (multimap): Likewise.
	* include/bits/stl_multiset.h (multiset): Likewise.
	* include/bits/stl_set.h (set): Likewise.
	* include/bits/stl_tree.h (_Rb_tree): Likewise.
	(_Rb_tree_iterator, _Rb_tree_const_iterator): Remove redundant
	operator!= for C++20.
	* include/debug/map.h (__gnu_debug::map): Define operator<=> for C++20.
	* include/debug/multimap.h (__gnu_debug::multimap): Likewise.
	* include/debug/multiset.h (__gnu_debug::multiset): Likewise.
	* include/debug/set.h (__gnu_debug::set): Likewise.
	* testsuite/23_containers/map/operators/cmp_c++20.cc: New test.
	* testsuite/23_containers/multimap/operators/cmp_c++20.cc: New test.
	* testsuite/23_containers/multiset/operators/cmp_c++20.cc: New test.
	* testsuite/23_containers/set/operators/cmp_c++20.cc: New test.
2020-04-20 17:50:10 +01:00
Matthias Kretz
697b94cfae libstdc++: Avoid illegal argument to verbose in dg-test callback
If extra_tool_flags starts with a dash, an error like 'ERROR: verbose:
illegal argument: -march=native -O2 -std=c++17' is printed. This is
easily fixed by inserting a double dash before the variable.

2020-04-20  Matthias Kretz  <kretz@kde.org>

	* testsuite/lib/libstdc++.exp: Avoid illegal argument to verbose.
2020-04-20 15:29:44 +01:00
Jonathan Wakely
717e91dbc4 libstdc++: Define operator<=> for std::stack and std::queue
Some more C++20 changes from P1614R2, "The Mothership has Landed".

	* include/bits/stl_queue.h (queue): Define operator<=> for C++20.
	* include/bits/stl_stack.h (stack): Likewise.
	* testsuite/23_containers/queue/cmp_c++20.cc: New test.
	* testsuite/23_containers/stack/cmp_c++20.cc: New test.
2020-04-19 21:30:15 +01:00
Jonathan Wakely
27c171775a libstdc++: Add comparison operators to <chrono> types
Some more C++20 changes from P1614R2, "The Mothership has Landed".

	* include/std/chrono (duration, time_point): Define operator<=> and
	remove redundant operator!= for C++20.
	* testsuite/20_util/duration/comparison_operators/three_way.cc: New
	test.
	* testsuite/20_util/time_point/comparison_operators/three_way.cc: New
	test.
2020-04-18 00:47:45 +01:00
Jonathan Wakely
c996029406 libstdc++: Fix testsuite utility's use of allocators
In C++20 the rebind and const_reference members of std::allocator are
gone, so this testsuite utility stopped working, causing
ext/pb_ds/regression/priority_queue_rand_debug.cc to FAIL.

	* testsuite/util/native_type/native_priority_queue.hpp: Use
	allocator_traits to rebind allocator.
2020-04-18 00:12:26 +01:00
Jonathan Wakely
bd2420f8fa libstdc++: Add comparison operators to sequence containers
Some more C++20 changes from P1614R2, "The Mothership has Landed".

This implements <=> for sequence containers (and the __normal_iterator
and _Pointer_adapter class templates).

	* include/bits/forward_list.h (forward_list): Define operator<=> and
	remove redundant comparison operators for C++20.
	* include/bits/stl_bvector.h (vector<bool, Alloc>): Likewise.
	* include/bits/stl_deque.h (deque): Likewise.
	* include/bits/stl_iterator.h (__normal_iterator): Likewise.
	* include/bits/stl_list.h (list): Likewise.
	* include/bits/stl_vector.h (vector): Likewise.
	* include/debug/deque (__gnu_debug::deque): Likewise.
	* include/debug/forward_list (__gnu_debug::forward_list): Likewise.
	* include/debug/list (__gnu_debug::list): Likewise.
	* include/debug/safe_iterator.h (__gnu_debug::_Safe_iterator):
	Likewise.
	* include/debug/vector (__gnu_debug::vector): Likewise.
	* include/ext/pointer.h (__gnu_cxx::_Pointer_adapter): Define
	operator<=> for C++20.
	* testsuite/23_containers/deque/operators/cmp_c++20.cc: New test.
	* testsuite/23_containers/forward_list/cmp_c++20.cc: New test.
	* testsuite/23_containers/list/cmp_c++20.cc: New test.
	* testsuite/23_containers/vector/bool/cmp_c++20.cc: New test.
	* testsuite/23_containers/vector/cmp_c++20.cc: New test.
2020-04-17 23:41:04 +01:00
Jonathan Wakely
875d6cb3b4 libstdc++: Add comparison operators for string and regex types
Some more C++20 changes from P1614R2, "The Mothership has Landed".

This adds three-way comparison support to std::char_traits,
std::basic_string, std::basic_string_view, and std::sub_match.

	* include/bits/basic_string.h (basic_string): Define operator<=> and
	remove redundant comparison operators for C++20.
	* include/bits/char_traits.h (__gnu_cxx::char_traits, char_traits):
	Add comparison_category members.
	(__detail::__char_traits_cmp_cat): New helper to get comparison
	category from char traits class.
	* include/bits/regex.h (regex_traits::_RegexMask::operator!=): Do not
	define for C++20.
	(sub_match): Define operator<=> and remove redundant comparison
	operators for C++20.
	(match_results): Remove redundant operator!= for C++20.
	* include/std/string_view (basic_string_view): Define operator<=> and
	remove redundant comparison operators for C++20.
	* testsuite/21_strings/basic_string/operators/char/cmp_c++20.cc: New
	test.
	* testsuite/21_strings/basic_string/operators/wchar_t/cmp_c++20.cc:
	New test.
	* testsuite/21_strings/basic_string_view/operations/copy/char/
	constexpr.cc: Initialize variable.
	* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/
	constexpr.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operators/char/2.cc: Add
	dg-do directive and remove comments showing incorrect signatures.
	* testsuite/21_strings/basic_string_view/operators/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operators/char/cmp_c++20.cc:
	New test.
	* testsuite/21_strings/basic_string_view/operators/wchar_t/cmp_c++20.cc:
	New test.
	* testsuite/28_regex/sub_match/compare_c++20.cc: New test.
2020-04-17 16:40:11 +01:00
Jonathan Wakely
c8d88bf26e libstdc++: Fix -Wunused-parameter warning in test
* testsuite/20_util/unsynchronized_pool_resource/allocate.cc: Remove
	name of unused parameter.
2020-04-16 08:44:10 +01:00