Commit Graph

4511 Commits

Author SHA1 Message Date
Jonathan Wakely
fe7cc34fd5 libstdc++: Ensure root-dir converted to forward slash (PR93244)
PR libstdc++/93244
	* include/bits/fs_path.h (path::generic_string<C,A>)
	[_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Convert root-dir to forward-slash.
	* testsuite/27_io/filesystem/path/generic/generic_string.cc: Check
	root-dir is converted to forward slash in generic pathname.
	* testsuite/27_io/filesystem/path/generic/utf.cc: New test.
	* testsuite/27_io/filesystem/path/generic/wchar_t.cc: New test.
2020-01-13 13:22:48 +00:00
Jonathan Wakely
e4379a931d libstdc++: Value-initialize std::atomic for C++20 (P0883R2)
This implements the new requirements for C++20 that std::atomic should
initialize the atomic variable in its default constructor.

This patch does not add the deprecated attribute to atomic_init, but
that should be done at some point as it's deprecated in C++20.

The paper also deprecates the ATOMIC_FLAG_INIT macro, although we can't
apply the deprecated attribute to a macro.

	PR libstdc++/58605
	* include/bits/atomic_base.h (__cpp_lib_atomic_value_initialization):
	Define.
	(__atomic_flag_base, __atomic_base, __atomic_base<_PTp*>)
	(__atomic_float): Add default member initializer for C++20.
	* include/std/atomic (atomic): Likewise.
	(atomic::atomic()): Remove noexcept-specifier on default constructor.
	* include/std/version (__cpp_lib_atomic_value_initialization): Define.
	* testsuite/29_atomics/atomic/cons/assign_neg.cc: Adjust dg-error line
	number.
	* testsuite/29_atomics/atomic/cons/copy_neg.cc: Likewise.
	* testsuite/29_atomics/atomic/cons/value_init.cc: New test.
	* testsuite/29_atomics/atomic_flag/cons/value_init.cc: New test.
	* testsuite/29_atomics/atomic_flag/requirements/trivial.cc: Adjust
	expected result for is_trivially_default_constructible.
	* testsuite/29_atomics/atomic_float/requirements.cc: Likewise.
	* testsuite/29_atomics/atomic_float/value_init.cc: New test.
	* testsuite/29_atomics/atomic_integral/cons/assign_neg.cc: Likewise.
	* testsuite/29_atomics/atomic_integral/cons/copy_neg.cc: Likewise.
	* testsuite/29_atomics/atomic_integral/cons/value_init.cc
	* testsuite/29_atomics/atomic_integral/requirements/trivial.cc: Adjust
	expected results for is_trivially_default_constructible.
	* testsuite/util/testsuite_common_types.h (has_trivial_dtor): Add
	new test generator.
2020-01-13 13:22:28 +00:00
Jonathan Wakely
68be73fc42 libstdc++: Improve comment about testsuite utilities
This fixes a typo and also explains why test_container is not a range
when used with output_iterator_wrapper or input_iterator_wrapper.

	* testsuite/util/testsuite_iterators.h: Improve comment.

From-SVN: r280146
2020-01-10 22:10:48 +00:00
Jonathan Wakely
78f02e8003 libstdc++: Fix testcase for C++98 compatibility
* testsuite/25_algorithms/equal/deque_iterators/1.cc: Don't use C++11
	initialization syntax.

From-SVN: r280117
2020-01-10 15:27:50 +00:00
Jonathan Wakely
7918cb93f6 libstdc++: Make istreambuf_iterator base class consistent (PR92285)
Since LWG 445 was implemented for GCC 4.7, the std::iterator base class
of std::istreambuf_iterator changes type depending on the -std mode
used. This creates an ABI incompatibility between different -std modes.

This change ensures the base class always has the same type. This makes
layout for C++98 compatible with the current -std=gnu++14 default, but
no longer compatible with C++98 code from previous releases. In practice
this is unlikely to cause real problems, because it only affects the
layout of types with two std::iterator base classes, one of which comes
from std::istreambuf_iterator. Such types are expected to be vanishingly
rare.

	PR libstdc++/92285
	* include/bits/streambuf_iterator.h (istreambuf_iterator): Make type
	of base class independent of __cplusplus value.
	[__cplusplus < 201103L] (istreambuf_iterator::reference): Override the
	type defined in the base class
	* testsuite/24_iterators/istreambuf_iterator/92285.cc: New test.
	* testsuite/24_iterators/istreambuf_iterator/requirements/
	base_classes.cc: Adjust expected base class for C++98.

From-SVN: r280116
2020-01-10 15:27:39 +00:00
Jonathan Wakely
caa39b2e84 libstdc++: Fix testsuite failures and warnings due to is_pod deprecation
With -std=gnu++2a and -Wsystem-headers the std::is_pod deprecation
causes some new diagnostics. This suppresses them.

	* include/experimental/type_traits (experimental::is_pod_v): Disable
	-Wdeprecated-declarations warnings around reference to std::is_pod.
	* include/std/type_traits (is_pod_v): Likewise.
	* testsuite/18_support/max_align_t/requirements/2.cc: Also check
	is_standard_layout and is_trivial. Do not check is_pod for C++20.
	* testsuite/20_util/is_pod/requirements/explicit_instantiation.cc:
	Add -Wno-deprecated for C++20.
	* testsuite/20_util/is_pod/requirements/typedefs.cc: Likewise.
	* testsuite/20_util/is_pod/value.cc: Likewise.
	* testsuite/experimental/type_traits/value.cc: Likewise.

From-SVN: r280066
2020-01-09 21:31:50 +00:00
JeanHeyd "ThePhD" Meneide
1a6c5064f9 libstdc++: Implementing P0767 - deprecate POD
This adds the deprecated attribute to std::is_pod and std::is_pod_v for
C++20.

2019-12-05  JeanHeyd "ThePhD" Meneide  <phdofthehouse@gmail.com>

	* include/bits/c++config (_GLIBCXX20_DEPRECATED): Add new macro.
	* include/std/type_traits (is_pod, is_pod_v): Deprecate for C++20.
	* testuite/20_util/is_pod/deprecated-2a.cc: New test.

From-SVN: r280065
2020-01-09 21:31:43 +00:00
Jonathan Wakely
160e95dc3d libstdc++: Fix undefined behaviour in random dist serialization (PR93205)
The deserialization functions for random number distributions fail to
check the stream state before using the extracted values. In some cases
this leads to using indeterminate values to resize a vector, and then
filling that vector with indeterminate values.

No values that affect control flow should be used without checking that a
good value was read from the stream.

Additionally, where reasonable to do so, defer modifying any state in
the distribution until all values have been successfully read, to avoid
modifying some of the distribution's parameters and leaving others
unchanged.

	PR libstdc++/93205
	* include/bits/random.h (operator>>): Check stream operation succeeds.
	* include/bits/random.tcc (operator<<): Remove redundant __ostream_type
	typedefs.
	(operator>>): Remove redundant __istream_type typedefs. Check stream
	operations succeed.
	(__extract_params): New function to fill a vector from a stream.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line.

From-SVN: r280061
2020-01-09 16:50:51 +00:00
Jonathan Wakely
d574c8aafe libstdc++: Define memory resource key functions non-inline (PR93208)
This prevents the vtables and RTTI from being emitted in every object
file that uses memory_resource and monotonic_buffer_resource.

Objects compiled by GCC 9.1 or 9.2 will contain inline definitions of
the destructors, vtable and RTTI, but this is harmless. The inline
definitions have identical effects to the ones that are now defined in
libstdc++.so so it doesn't matter if the inline ones are used instead of
calling the symbols exported from the runtime library.

	PR libstdc++/93208
	* config/abi/pre/gnu.ver: Add new exports.
	* include/std/memory_resource (memory_resource::~memory_resource()):
	Do not define inline.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Likewise.
	* src/c++17/memory_resource.cc (memory_resource::~memory_resource()):
	Define.
	(monotonic_buffer_resource::~monotonic_buffer_resource()): Define.
	* testsuite/20_util/monotonic_buffer_resource/93208.cc: New test.

From-SVN: r280044
2020-01-09 13:18:20 +00:00
François Dumont
b9c84e9503 PR libstdc++/92124 fix incorrect unordered container move assignment
* include/bits/hashtable.h (_Hashtable<>::__alloc_node_gen_t): New
	template alias.
	(_Hashtable<>::__fwd_value_for): New.
	(_Hashtable<>::_M_assign_elements<>): Remove _NodeGenerator template
	parameter.
	(_Hashtable<>::_M_assign<>): Add _Ht template parameter.
	(_Hashtable<>::operator=(const _Hashtable<>&)): Adapt.
	(_Hashtable<>::_M_move_assign): Adapt. Replace std::move_if_noexcept
	with std::move.
	(_Hashtable<>::_Hashtable(const _Hashtable&)): Adapt.
	(_Hashtable<>::_Hashtable(const _Hashtable&, const allocator_type&)):
	Adapt.
	(_Hashtable<>::_Hashtable(_Hashtable&&, const allocator_type&)):
	Adapt.
	* testsuite/23_containers/unordered_set/92124.cc: New.

From-SVN: r280028
2020-01-09 05:40:08 +00:00
Jonathan Wakely
fff148b787 libstdc++: Fix error handling in filesystem::remove_all (PR93201)
When recursing into a directory, any errors that occur while removing a
directory entry are ignored, because the subsequent increment of the
directory iterator clears the error_code object.

This fixes that bug by checking the result of each recursive operation
before incrementing. This is a change in observable behaviour, because
previously other directory entries would still be removed even if one
(or more) couldn't be removed due to errors. Now the operation stops on
the first error, which is what the code intended to do all along. The
standard doesn't specify what happens in this case (because the order
that the entries are processed is unspecified anyway).

It also improves the error reporting so that the name of the file that
could not be removed is included in the filesystem_error exception. This
is done by introducing a new helper type for reporting errors with
additional context and a new function that uses that type. Then the
overload of std::filesystem::remove_all that throws an exception can use
the new function to ensure any exception contains the additional
information.

For std::experimental::filesystem::remove_all just fix the bug where
errors are ignored.

	PR libstdc++/93201
	* src/c++17/fs_ops.cc (do_remove_all): New function implementing more
	detailed error reporting for remove_all. Check result of recursive
	call before incrementing iterator.
	(remove_all(const path&), remove_all(const path&, error_code&)): Use
	do_remove_all.
	* src/filesystem/ops.cc (remove_all(const path&, error_code&)): Check
	result of recursive call before incrementing iterator.
	* testsuite/27_io/filesystem/operations/remove_all.cc: Check errors
	are reported correctly.
	* testsuite/experimental/filesystem/operations/remove_all.cc: Likewise.

From-SVN: r280014
2020-01-08 16:44:45 +00:00
Thomas Rodgers
9e3c1eb773 Rename condition_variable_any wait* methods to match current draft standard
2020-01-07  Thomas Rodgers  <trodgers@redhat.com>

	* include/std/condition_variable
	(condition_variable_any::wait_on): Rename to match current draft
	standard.
	(condition_variable_any::wait_on_until): Likewise.
	(condition_variable_any::wait_on_for): Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc:
	Adjust tests to account for renamed methods.

From-SVN: r279988
2020-01-08 03:00:40 +00:00
François Dumont
6af8819be1 PR libstdc++/92124 fix incorrect container move assignment
* include/bits/stl_tree.h
	(_Rb_tree<>::_M_move_assign(_Rb_tree&, false_type)): Replace
	std::move_if_noexcept by std::move.
	* testsuite/23_containers/map/92124.cc: New.
	* testsuite/23_containers/set/92124.cc: New.

From-SVN: r279967
2020-01-07 21:01:37 +00:00
Jonathan Wakely
a4a1f96551 libstdc++: Remove redundant inequality operators in <stop_token>
* include/std/stop_token (stop_token): Remove operator!= (LWG 3254).
	(stop_source): Likewise (LWG 3362).
	* testsuite/30_threads/stop_token/stop_source.cc: Test equality
	comparisons.

From-SVN: r279897
2020-01-06 12:06:47 +00:00
Jakub Jelinek
8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
François Dumont
33bd8e5e22 libstdc++: Fix versioned namespace tests
* testsuite/23_containers/map/48101_neg.cc: Add versioned namespace
	pattern to tested error message.
	* testsuite/23_containers/multimap/48101_neg.cc: Likewise.
	* testsuite/30_threads/headers/stop_token/synopsis.cc: Add
	dg-require-normal-namepace.

From-SVN: r279641
2019-12-20 13:24:52 +00:00
François Dumont
e278e62f91 libstdc++: Fix pretty printers script and tests
* python/libstdcxx/v6/printers.py (lookup_node_type): Remove redundant
	call to lookup_node_type.
	* testsuite/libstdc++-prettyprinters/80276.cc: Define
	_GLIBCXX_USE_CXX11_ABI to 0.
	* testsuite/libstdc++-prettyprinters/91997.cc: Use regexp-test to check
	'a' content.

From-SVN: r279640
2019-12-20 12:42:50 +00:00
Jonathan Wakely
cff87282f4 libstdc++: Correct noexcept-specifiers on span constructors
As discussed at https://github.com/cplusplus/draft/issues/3534 two
std::span constructors specify incorrect conditions for throwing
exceptions. This patch makes those constructors have correct
noexcept-specifiers that accurately reflect what can actually throw.

	(span(ContiguousIterator, Sentinel)): Add conditional noexcept.
	* include/std/span (span(ContiguousIterator, size_type)): Change
	noexcept to be unconditionally true.
	* testsuite/23_containers/span/nothrow_cons.cc: New test.

From-SVN: r279206
2019-12-10 23:50:26 +00:00
François Dumont
6004c17b4d libstdc++: Rework std::copy/copy_backward/move/move_backward/fill/fill_n algos
Enhance those algos overloads to generalize existing optimization for
__gnu_debug::_Safe_iterator w/o _GLIBCXX_DEBUG mode and for std::deque
 iterators.

Also extend __copy_move_a2 ostreambuf_iterator overloads to std::vector and
std::deque iterators.

	* include/bits/stl_algobase.h
	(__copy_move_a1<>(_II, _II, _OI)): New.
	(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__copy_move_a1<>(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_a<>(_II, _II, _OI)): Adapt, call __copy_move_a1<>.
	(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__copy_move_a<>(_II, _II, const _Safe_iterator<>&)): New.
	(copy, move): Adapt, call __copy_move_a.
	(__copy_move_backward_a1<>(_II, _II, _OI)): New,
	call __copy_move_backward_a2.
	(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__copy_move_backward_a1<>(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_backward_a<>(_II, _II, _OI)): Adapt, call
	__copy_move_backward_a1<>.
	(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__copy_move_backward_a<>(_II, _II, const _Safe_iterator<>&)): New.
	(copy_backward, move_backward): Adapt, call __copy_move_backward_a<>.
	(__fill_a): Rename into...
	(__fill_a1): ... this.
	(__fill_a1(__normal_iterator<>, __normal_iterator<>, const _Tp&)): New.
	(__fill_a1(const _Deque_iterator<>&, const _Deque_iterator<>&, _VTp)):
	New.
	(__fill_a(_FIte, _FIte, const _Tp&)): New, call __fill_a1.
	(__fill_a(const _Safe_iterator<>&, const _Safe_iterator<>&,
	const _Tp&)): New.
	(fill): Adapt, remove __niter_base usage.
	(__fill_n_a): Rename into...
	(__fill_n_a1): ...this.
	(__fill_n_a(const _Safe_iterator<>&, _Size, const _Tp&,
	input_iterator_tag)): New.
	(__fill_n_a(_OI, _Size, const _Tp&, output_iterator_tag)): New, call
	__fill_n_a1.
	(__fill_n_a(_OI, _Size, const _Tp&, random_access_iterator_tag)): New,
	call __fill_a.
	(__equal_aux): Rename into...
	(__equal_aux1): ...this.
	(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
	(__equal_aux(_II1, _II1, _II2)): New, call __equal_aux1.
	(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__equal_aux(_II, _II, const _Safe_iterator<>&)): New.
	(equal(_II1, _II1, _II2)): Adapt.
	* include/bits/stl_deque.h
	(fill, copy, copy_backward, move, move_backward): Remove.
	* include/bits/deque.tcc: Include <bits/stl_algobase.h>.
	(__fill_a1): New.
	(__copy_move_dit): New.
	(__copy_move_a1): New, use latter.
	(__copy_move_a1(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_backward_dit): New.
	(__copy_move_backward_a1): New, use latter.
	(__copy_move_backward_a1(_II, _II, _Deque_iterator<>)): New.
	(__equal_dit): New.
	(__equal_aux1): New, use latter.
	(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
	* include/std/numeric (__is_random_access_iter): Move...
	* include/bits/stl_iterator_base_types.h (__is_random_access_iter): ...
	here. Provide pre-C++11 definition.
	* include/debug/debug.h (_Safe_iterator<>): New declaration.
	* include/debug/safe_iterator.h (_Safe_iterator<>::_M_can_advance): Add
	__strict parameter.
	* include/debug/safe_iterator.tcc: Include <bits/stl_algobase.h>.
	(_Safe_iterator<>::_M_can_advance): Adapt.
	(std::__copy_move_a, std::__copy_move_backward_a, __fill_a): New.
	(__fill_n_a, __equal_aux): New.
	* include/debug/stl_iterator.h (__niter_base): Remove.
	* include/debug/vector (__niter_base): Remove.
	* testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc:
	Include <vector> and <list>. Add benches.
	* testsuite/performance/25_algorithms/copy_deque_iterators.cc: Likewise.
	* testsuite/performance/25_algorithms/equal_deque_iterators.cc: Likewise.
	* testsuite/25_algorithms/copy/debug/1_neg.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/31.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/32.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/33.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/41.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/42.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/43.cc: New.
	* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc (test02):
	New.
	* testsuite/25_algorithms/copy_backward/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/equal/deque_iterators/1.cc: New.
	* testsuite/25_algorithms/fill/deque_iterators/1.cc: New.
	* testsuite/25_algorithms/move/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/move_backward/deque_iterators/2.cc: New.

From-SVN: r279201
2019-12-10 21:49:55 +00:00
Jonathan Wakely
393283b8ef libstdc++: Define __cpp_lib_constexpr_complex macro
This is LWG issue 3349.

	* include/std/complex (__cpp_lib_constexpr_complex): Define.
	* include/std/version (__cpp_lib_constexpr_complex): Likewise.
	* testsuite/26_numerics/complex/1.cc: New test.
	* testsuite/26_numerics/complex/2.cc: New test.

From-SVN: r279172
2019-12-10 16:15:59 +00:00
Jonathan Wakely
990a09e486 libstdc++: Fix bug in std::indirect_result_t
The alias template wasn't working because it applied iter_reference_t to
the pack of iterators before and after passing the pack to the
__indeirect_result helper.

	* include/bits/iterator_concepts.h (indirect_result_t): Do not apply
	iter_reference_t to parameter pack.
	* testsuite/24_iterators/indirect_callable/projected.cc: New test.

From-SVN: r279170
2019-12-10 16:15:49 +00:00
Jonathan Wakely
b5b2e3879d libstdc++: Implement ranges::safe_range for C++20 (P1870R1)
This change replaces the __forwarding_range implementation detail with
the ranges::safe_range concept and adds the ranges::enable_safe_range
variable template for opt-in in to the concept.

It also adjusts the begin/end/rbegin/rend customization point objects to
match the new rules for accessing rvalue ranges only when safe to do so.

	* include/bits/range_access.h (ranges::enable_safe_range): Define.
	(ranges::begin, ranges::end, ranges::rbegin, ranges::rend): Constrain
	to only accept types satisfying safe_range and treat argument as an
	lvalue when calling a member of performing ADL.
	(ranges::__detail::__range_impl, ranges::__detail::__forwarding_range):
	Remove.
	(ranges::range): Adjust definition.
	(ranges::safe_range): Define.
	(ranges::iterator_t, ranges::range_difference_t): Reorder definitions
	to match the synopsis in the working draft.
	(ranges::disable_sized_range): Remove duplicate definition.
	* include/experimental/string_view (ranges::enable_safe_range): Add
	partial specialization for std::experimental::basic_string_view.
	* include/std/ranges (ranges::viewable_range, ranges::subrange)
	(ranges::empty_view, ranges::iota_view): Use safe_range. Specialize
	enable_safe_range.
	(ranges::safe_iterator_t, ranges::safe_subrange_t): Define.
	* include/std/span (ranges::enable_safe_range): Add partial
	specialization for std::span.
	* include/std/string_view (ranges::enable_safe_range): Likewise for
	std::basic_string_view.
	* testsuite/std/ranges/access/begin.cc: Adjust expected results.
	* testsuite/std/ranges/access/cbegin.cc: Likewise.
	* testsuite/std/ranges/access/cdata.cc: Likewise.
	* testsuite/std/ranges/access/cend.cc: Likewise.
	* testsuite/std/ranges/access/crbegin.cc: Likewise.
	* testsuite/std/ranges/access/crend.cc: Likewise.
	* testsuite/std/ranges/access/data.cc: Likewise.
	* testsuite/std/ranges/access/end.cc: Likewise.
	* testsuite/std/ranges/access/rbegin.cc: Likewise.
	* testsuite/std/ranges/access/rend.cc: Likewise.
	* testsuite/std/ranges/empty_view.cc: Test ranges::begin and
	ranges::end instead of unqualified calls to begin and end.
	* testsuite/std/ranges/safe_range.cc: New test.
	* testsuite/std/ranges/safe_range_types.cc: New test.
	* testsuite/util/testsuite_iterators.h: Add comment about safe_range.

From-SVN: r279135
2019-12-09 17:35:24 +00:00
Jonathan Wakely
1d214c3f83 libstdc++: Improve testing for path::operator+=(const string&)
* testsuite/27_io/filesystem/path/concat/strings.cc: Test more cases.

From-SVN: r279111
2019-12-09 09:59:00 +00:00
Jonathan Wakely
023a3fb491 libstdc++: fix buffer overflow in path::operator+= (PR92853)
When concatenating a path ending in a root-directory onto another path,
we added an empty filename to the end of the path twice, but only
reserved space for one. That meant the second write went past the end of
the allocated buffer.

	PR libstdc++/92853
	* src/c++17/fs_path.cc (filesystem::path::operator+=(const path&)):
	Do not process a trailing directory separator twice.
	* testsuite/27_io/filesystem/path/concat/92853.cc: New test.
	* testsuite/27_io/filesystem/path/concat/path.cc: Test more cases.

From-SVN: r279110
2019-12-09 09:58:56 +00:00
François Dumont
4383959047 libstdc++: Add C++20 P1032 constexpr to _GLIBCXX_DEBUG array
* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
	Fix static_assert line number.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_debug_neg.cc: Likewise.

From-SVN: r279108
2019-12-09 08:44:15 +00:00
Jonathan Wakely
5a784d350c libstdc++: Fix bug in std::span test
The previous commit fixed the std::span constructors from const arrays,
revealing a bug in this test.

	* testsuite/23_containers/span/lwg3255.cc: Fix test. Constructing a
	span of non-const elements should not be possible from a const array
	or an array of const elements.

From-SVN: r279001
2019-12-05 13:50:08 +00:00
Jonathan Wakely
f1355c8dda libstdc++: Define std::lexicographical_compare_three_way for C++20
* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Define for C++20.
	* testsuite/25_algorithms/lexicographical_compare_three_way/1.cc: New
	test.
	* testsuite/25_algorithms/lexicographical_compare_three_way/
	constexpr.cc: New test.

From-SVN: r278996
2019-12-05 12:46:50 +00:00
Jonathan Wakely
a59c50bd14 libstdc++: Define pretty printer for comparison categories
* python/libstdcxx/v6/printers.py (StdCmpCatPrinter): New printer.
	* testsuite/libstdc++-prettyprinters/cxx20.cc: New test.

From-SVN: r278982
2019-12-05 00:42:11 +00:00
Jonathan Wakely
3a4cc6281b libstdc++: Implement spaceship for std::array (P1614R2)
As done for std::pair, this defines operator<=> as a non-member function
template and does not alter operator==, as expected to be proposed as
the resolution to an unpublished LWG issue.

Instead of calling std::lexicographical_compare_three_way the <=>
overload is implemented by hand to take advantage of the fact the
element types and array sizes are known to be the same.

	* include/bits/cpp_type_traits.h (__is_byte<char8_t>): Add
	specialization.
	* include/std/array (operator<=>): Likewise.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc:
	Test three-way comparisons and arrays of unsigned char.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust
	dg-error line numbers.

From-SVN: r278981
2019-12-05 00:42:06 +00:00
Jonathan Wakely
7f397e4519 libstdc++: Implement spaceship for std::pair (P1614R2)
This defines operator<=> as a non-member function template and does not
alter operator==. This contradicts the changes made by P1614R2, which
specify both as hidden friends, but that specification of operator<=> is
broken and the subject of a soon-to-be-published LWG issue.

	* include/bits/stl_pair.h [__cpp_lib_three_way_comparison]
	(operator<=>): Define for C++20.
	* libsupc++/compare (__cmp2way_res_t): Rename to __cmp3way_res_t,
	move into __detail namespace. Do not turn argument types into lvalues.
	(__cmp3way_helper): Rename to __cmp3way_res_impl, move into __detail
	namespace. Constrain with concepts instead of using void_t.
	(compare_three_way_result): Adjust name of base class.
	(compare_three_way_result_t): Use __cmp3way_res_impl directly.
	(__detail::__3way_cmp_with): Add workaround for PR 91073.
	(compare_three_way): Use workaround.
	(__detail::__synth3way, __detail::__synth3way_t): Define new helpers
	implementing synth-three-way and synth-three-way-result semantics.
	* testsuite/20_util/pair/comparison_operators/constexpr_c++20.cc: New
	test.

From-SVN: r278951
2019-12-03 23:57:46 +00:00
Jonathan Wakely
819fb01933 libstdc++: Fix copyright date on new test header
The slow_clock type was introduced to the testsuite in 2018 in the
testsuite/30_threads/condition_variable/members/2.cc test, so the new
header should have that date.

	* testsuite/util/slow_clock.h: Fix copyright date.

From-SVN: r278926
2019-12-03 09:51:49 +00:00
Mike Crowe
a7334019b1 libstdc++: Fix timed_mutex::try_lock_until on arbitrary clock (PR 91906)
A non-standard clock may tick more slowly than
std::chrono::steady_clock.  This means that we risk returning false
early when the specified timeout may not have expired. This can be
avoided by looping until the timeout time as reported by the
non-standard clock has been reached.

Unfortunately, we have no way to tell whether the non-standard clock
ticks more quickly that std::chrono::steady_clock. If it does then we
risk returning later than would be expected, but that is unavoidable and
permitted by the standard.

2019-12-02  Mike Crowe  <mac@mcrowe.com>

	PR libstdc++/91906 Fix timed_mutex::try_lock_until on arbitrary clock
	* include/std/mutex (__timed_mutex_impl::_M_try_lock_until): Loop
	until the absolute timeout time is reached as measured against the
	appropriate clock.
	* testsuite/util/slow_clock.h: New file. Move implementation of
	slow_clock test class.
	* testsuite/30_threads/condition_variable/members/2.cc: Include
	slow_clock from header.
	* testsuite/30_threads/shared_timed_mutex/try_lock/3.cc: Convert
	existing test to templated function so that it can be called with
	both system_clock and steady_clock.
	* testsuite/30_threads/timed_mutex/try_lock_until/3.cc: Also run test
	using slow_clock to test above fix.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
	Likewise.
	* testsuite/30_threads/recursive_timed_mutex/try_lock_until/4.cc: Add
	new test that try_lock_until behaves as try_lock if the timeout has
	already expired or exactly matches the current time.

From-SVN: r278902
2019-12-02 16:23:06 +00:00
Mike Crowe
49638674a4 libstdc++: Improve tests for try_lock_until members of mutex types
2019-12-02  Mike Crowe  <mac@mcrowe.com>

	* testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
	New test. Ensure that timed_mutex::try_lock_until actually times out
	after the specified time when using both system_clock and
	steady_clock.
	* testsuite/30_threads/timed_mutex/try_lock_until/3.cc: New test.
	Likewise but for recursive_timed_mutex.
	* testsuite/30_threads/timed_mutex/try_lock_until/57641.cc: Template
	test functions and use them to test both steady_clock and system_clock.
	* testsuite/30_threads/unique_lock/locking/4.cc: Likewise. Wrap call
	to timed_mutex::try_lock_until in VERIFY macro to check its return
	value.

From-SVN: r278900
2019-12-02 16:22:53 +00:00
Tom Honermann
cd502796cf libstdc++: P1423R3 char8_t remediation (4/4)
New tests

This patch adds new tests to validate new deleted overloads of wchar_t,
char8_t, char16_t, and char32_t for ordinary and wide formatted character and
string ostream inserters.

Additionally, new tests are added to validate invocations of u8path with
sequences of char8_t for both the C++17 and filesystem TS implementations.

2019-11-29  Tom Honermann  <tom@honermann.net>

	New tests
	* testsuite/27_io/basic_ostream/inserters_character/char/deleted.cc:
	New test to validate deleted overloads of character and string
	inserters for narrow ostreams.
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/deleted.cc:
	New test to validate deleted overloads of character and string
	inserters for wide ostreams.
	* testsuite/27_io/filesystem/path/factory/u8path-char8_t.cc: New test
	to validate u8path invocations with sequences of char8_t.
	* testsuite/experimental/filesystem/path/factory/u8path-char8_t.cc:
	New test to validate u8path invocations with sequences of char8_t.

From-SVN: r278858
2019-11-29 17:43:51 +00:00
Tom Honermann
2b68cdc7e5 libstdc++: P1423R3 char8_t remediation (3/4)
Updates to existing tests

This patch updates existing tests to validate the new value for the
__cpp_lib_char8_t feature test macros and to exercise u8path factory
function invocations with std::string, std::string_view, and interator
pair arguments.

2019-11-29  Tom Honermann  <tom@honermann.net>

	Updates to existing tests
	* testsuite/experimental/feat-char8_t.cc: Updated the expected
	__cpp_lib_char8_t feature test macro value.
	* testsuite/27_io/filesystem/path/factory/u8path.cc: Added testing of
	u8path invocation with std::string, std::string_view, and iterators
	thereof.
	* testsuite/experimental/filesystem/path/factory/u8path.cc: Added
	testing of u8path invocation with std::string, std::string_view, and
	iterators thereof.

From-SVN: r278857
2019-11-29 17:43:46 +00:00
Jonathan Wakely
9d50a6a785 libstdc++:: improve how pretty printers find node types (PR 91997)
This fixes two related problems.

The iterators for node-based containers use nested typedefs such as
std::list<T>::iterator::_Node to denote their node types. As reported in
https://bugzilla.redhat.com/show_bug.cgi?id=1053438 those typedefs are
not always present in the debug info. That means the pretty printers
cannot find them using gdb.lookup_type (via the find_type helper).
Instead of looking up the nested typedefs this patch makes the printers
look up the actual class templates directly.

A related problem (and the original topic of PR 91997) is that GDB fails
to find types via gdb.lookup_type when printing a backtrace from a
non-C++ functiion: https://sourceware.org/bugzilla/show_bug.cgi?id=25234
That is also solved by not looking up the nested typedef.

	PR libstdc++/91997
	* python/libstdcxx/v6/printers.py (find_type): Fail more gracefully
	if we run out of base classes to look at.
	(llokup_templ_spec, lookup_node_type): New utilities to find node
	types for node-based containers.
	(StdListPrinter.children, NodeIteratorPrinter.__init__)
	(NodeIteratorPrinter.to_string, StdSlistPrinter.children)
	(StdSlistIteratorPrinter.to_string, StdRbtreeIteratorPrinter.__init__)
	(StdMapPrinter.children, StdSetPrinter.children)
	(StdForwardListPrinter.children): Use lookup_node_type instead of
	find_type.
	(StdListIteratorPrinter.__init__, StdFwdListIteratorPrinter.__init__):
	Pass name of node type to NodeIteratorPrinter constructor.
	(Tr1HashtableIterator.__init__): Rename argument.
	(StdHashtableIterator.__init__): Likewise. Use lookup_templ_spec
	instead of find_type.
	* testsuite/libstdc++-prettyprinters/59161.cc: Remove workaround for
	_Node typedef not being present in debuginfo.
	* testsuite/libstdc++-prettyprinters/91997.cc: New test.

From-SVN: r278846
2019-11-29 14:47:03 +00:00
Jonathan Wakely
7def9bd7cd libstdc++: Add move_sentinel, common_iterator and counted_iterator
This implements most of the remaining C++20 additions to the <iterator>
header.

	* include/bits/iterator_concepts.h (ranges::iter_swap): Fix parameter
	types of poison pill overload. Use remove_reference_t when checking
	constraints.
	* include/bits/stl_iterator.h (move_sentinel): Define for C++20.
	(move_iterator): Adjust definitions of nested types for C++20. Add
	hidden friends for move_sentinel operations, iter_move and iter_swap.
	(common_iterator, counted_iterator): Define for C++20.
	* testsuite/24_iterators/move_iterator/cust.cc: New test.
	* testsuite/24_iterators/move_iterator/sentinel.cc: New test.
	* testsuite/24_iterators/common_iterator/1.cc: New test.
	* testsuite/24_iterators/counted_iterator/1.cc: New test.

From-SVN: r278698
2019-11-25 19:02:03 +00:00
François Dumont
af4e8d4d5a libstdc++: Improve _GLIBCXX_DEBUG __valid_range check
Adds iterator singular check within the valid range check.

	* include/debug/functions.h: Remove <bits/move.h> include.
	(__check_singular_aux, __check_singular): Move...
	* include/debug/helper_functions.h:
	(__check_singular_aux, __check_singular): ...here.
	(__valid_range_aux): Adapt to use latter.
	Add <bits/move.h> include.
	* testsuite/25_algorithms/copy/debug/2_neg.cc: New.

From-SVN: r278658
2019-11-24 17:09:44 +00:00
Jonathan Wakely
ebc464940d libstdc++: Fix std::jthread bugs
The std::jthread::get_id() function was missing a return statement.

The is_invocable check needs to be done using decayed types, as they'll
be forwarded to std::invoke as rvalues.

Also reduce header dependencies for the <thread> header. We don't need
to include <functional> for std::jthread because <bits/invoke.h> is
already included, which defines std::__invoke. We can also remove
<bits/functexcept.h> which isn't used at all. Finally, when
_GLIBCXX_HAS_GTHREADS is not defined there's no point including any
other headers, since we're not going to define anything in <thread>
anyway.

	* include/std/thread: Reduce header dependencies.
	(jthread::get_id()): Add missing return.
	(jthread::get_stop_token()): Avoid unnecessary stop_source temporary.
	(jthread::_S_create): Check is_invocable using decayed types. Add
	static assertion.
	* testsuite/30_threads/jthread/1.cc: Add dg-require-gthreads.
	* testsuite/30_threads/jthread/2.cc: Likewise.
	* testsuite/30_threads/jthread/3.cc: New test.
	* testsuite/30_threads/jthread/jthread.cc: Add missing directives for
	pthread and gthread support. Use VERIFY instead of assert.

From-SVN: r278402
2019-11-18 12:46:08 +00:00
Jonathan Wakely
8857080c81 libstdc++: add range constructor for std::string_view (P1391R4)
* include/std/string_view (basic_string_view(It, End)): Add range
	constructor and deduction guide from P1391R4.
	* testsuite/21_strings/basic_string_view/cons/char/range.cc: New test.

From-SVN: r278371
2019-11-17 01:32:55 +00:00
Jonathan Wakely
37f33df706 libstdc++: Define C++20 range utilities and range factories
This adds another chunk of the <ranges> header.

The changes from P1456R1 (Move-only views) and P1862R1 (Range adaptors
for non-copyable iterators) are included, but not the changes from
P1870R1 (forwarding-range<T> is too subtle).

The tests for subrange and iota_view are poor and should be improved.

	* include/bits/regex.h (match_results): Specialize __enable_view_impl.
	* include/bits/stl_set.h (set): Likewise.
	* include/bits/unordered_set.h (unordered_set, unordered_multiset):
	Likewise.
	* include/debug/multiset.h (__debug::multiset): Likewise.
	* include/debug/set.h (__debug::set): Likewise.
	* include/debug/unordered_set (__debug::unordered_set)
	(__debug::unordered_multiset): Likewise.
	* include/std/ranges (ranges::view, ranges::enable_view)
	(ranges::view_interface, ranges::subrange, ranges::empty_view)
	(ranges::single_view, ranges::views::single, ranges::iota_view)
	(ranges::views::iota): Define for C++20.
	* testsuite/std/ranges/empty_view.cc: New test.
	* testsuite/std/ranges/iota_view.cc: New test.
	* testsuite/std/ranges/single_view.cc: New test.
	* testsuite/std/ranges/view.cc: New test.

From-SVN: r278370
2019-11-17 01:07:54 +00:00
Edward Smith-Rowland
6d1402f0ed Implement the <tuple> part of C++20 p1032 Misc constexpr bits.
2019-11-15  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement the <tuple> part of C++20 p1032 Misc constexpr bits.
	* include/std/tuple (_Head_base, _Tuple_impl(allocator_arg_t,...)
	(_M_assign, tuple(allocator_arg_t,...), _Inherited, operator=, _M_swap)
	(swap, pair(piecewise_construct_t,): Constexpr.
	* (__uses_alloc0::_Sink::operator=, __uses_alloc_t): Constexpr.
	* testsuite/20_util/tuple/cons/constexpr_allocator_arg_t.cc: New test.
	* testsuite/20_util/tuple/constexpr_swap.cc : New test.
	* testsuite/20_util/uses_allocator/69293_neg.cc: Extra error for C++20.
	* testsuite/20_util/uses_allocator/cons_neg.cc: : Extra error for C++20.

From-SVN: r278331
2019-11-16 03:16:35 +00:00
Jonathan Wakely
e73ca078b8 libstdc++: Fix <stop_token> and improve tests
* include/std/stop_token: Reduce header dependencies by including
	internal headers.
	(stop_token::swap(stop_token&), swap(stop_token&, stop_token&)):
	Define.
	(operator!=(const stop_token&, const stop_token&)): Fix return value.
	(stop_token::_Stop_cb::_Stop_cb(Cb&&)): Use std::forward instead of
	(stop_token::_Stop_state_t) [_GLIBCXX_HAS_GTHREADS]: Use lock_guard
	instead of unique_lock.
	[!_GLIBCXX_HAS_GTHREADS]: Do not use mutex.
	(stop_token::stop_token(_Stop_state)): Change parameter to lvalue
	reference.
	(stop_source): Remove unnecessary using-declarations for names only
	used once.
	(swap(stop_source&, stop_source&)): Define.
	(stop_callback(const stop_token&, _Cb&&))
	(stop_callback(stop_token&&, _Cb&&)): Replace lambdas with a named
	function. Use std::forward instead of std::move. Run callbacks if a
	stop request has already been made.
	(stop_source::_M_execute()): Remove.
	(stop_source::_S_execute(_Stop_cb*)): Define.
	* include/std/version (__cpp_lib_jthread): Define conditionally.
	* testsuite/30_threads/stop_token/stop_callback.cc: New test.
	* testsuite/30_threads/stop_token/stop_source.cc: New test.
	* testsuite/30_threads/stop_token/stop_token.cc: Enable test for
	immediate execution of callback.

From-SVN: r278325
2019-11-15 23:44:47 +00:00
Edward Smith-Rowland
f982d12a51 Forgot to change teh date range.
From-SVN: r278318
2019-11-15 21:27:49 +00:00
Edward Smith-Rowland
12536431ad Implement the default_searcher part of C++20 p1032 Misc constexpr bits.
2019-11-15  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement the default_searcher part of C++20 p1032 Misc constexpr bits.
	* include/std/functional
	(default_searcher, default_searcher::operator()): Constexpr.
	* testsuite/20_util/function_objects/constexpr_searcher.cc: New.

From-SVN: r278317
2019-11-15 21:26:25 +00:00
Jonathan Wakely
a31517cb9a libstdc++: Implement LWG 3149 for std::default_constructible
The change approved in Belfast did not actually rename the concept from
std::default_constructible to std::default_initializable, even though
that was intended. That is expected to be done soon as a separate issue,
so I'm implementing that now too.

	* include/bits/iterator_concepts.h (weakly_incrementable): Adjust.
	* include/std/concepts (default_constructible): Rename to
	default_initializable and require default-list-initialization and
	default-initialization to be valid (LWG 3149).
	(semiregular): Adjust to new name.
	* testsuite/std/concepts/concepts.lang/concept.defaultconstructible/
	1.cc: Rename directory to concept.defaultinitializable and adjust to
	new name.
	* testsuite/std/concepts/concepts.lang/concept.defaultinitializable/
	lwg3149.cc: New test.
	* testsuite/util/testsuite_iterators.h (test_range): Adjust.

From-SVN: r278314
2019-11-15 19:58:27 +00:00
Jonathan Wakely
01eb211bad libstdc++: Implement LWG 3070 in path::lexically_relative
* src/c++17/fs_path.cc [_GLIBCXX_FILESYSTEM_IS_WINDOWS]
	(is_disk_designator): New helper function.
	(path::_Parser::root_path()): Use is_disk_designator.
	(path::lexically_relative(const path&)): Implement resolution of
	LWG 3070.
	* testsuite/27_io/filesystem/path/generation/relative.cc: Check with
	path components that look like a root-name.

From-SVN: r278313
2019-11-15 19:58:15 +00:00
Jonathan Wakely
a0e1dcd44f libstdc++: Fix definition of std::nostopstate object
Also add <stop_token> header to PCH and Doxygen config.

	* doc/doxygen/user.cfg.in: Add <stop_token>.
	* include/precompiled/stdc++.h: Likewise.
	* include/std/stop_token: Fix definition of std::nostopstate.
	* testsuite/30_threads/headers/stop_token/synopsis.cc: New test.
	* testsuite/30_threads/headers/thread/types_std_c++20.cc: New test.
	* testsuite/30_threads/stop_token/stop_source.cc: New test.
	* testsuite/30_threads/stop_token/stop_token.cc: Remove unnecessary
	dg-require directives. Remove I/O and inclusion of <iostream>.

From-SVN: r278296
2019-11-15 14:38:59 +00:00
Thomas Rodgers
942c4b32b0 Support for jthread and stop_token
* include/Makefile.am: Add <stop_token> header.
        * include/Makefile.in: Regenerate.
        * include/std/condition_variable: Add overloads for stop_token support
        to condition_variable_any.
        * include/std/stop_token: New file.
        * include/std/thread: Add jthread type.
        * include/std/version (__cpp_lib_jthread): New value.
        * testsuite/30_threads/condition_variable_any/stop_token/1.cc: New test.
        * testsuite/30_threads/condition_variable_any/stop_token/2.cc: New test.
        * testsuite/30_threads/condition_variable_any/stop_token/wait_on.cc: New test.
        * testsuite/30_threads/jthread/1.cc: New test.
        * testsuite/30_threads/jthread/2.cc: New test.
        * testsuite/30_threads/jthread/jthread.cc: New test.
        * testsuite/30_threads/stop_token/1.cc: New test.
        * testsuite/30_threads/stop_token/2.cc: New test.
        * testsuite/30_threads/stop_token/stop_token.cc: New test.

From-SVN: r278274
2019-11-15 03:09:19 +00:00
Edward Smith-Rowland
1c09b66494 Implement the <array> part of C++20 p1032 Misc constexpr bits.
2019-11-14  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement the <array> part of C++20 p1032 Misc constexpr bits.
	* include/std/array (fill, swap): Make constexpr.
	* testsuite/23_containers/array/requirements/constexpr_fill.cc: New.
	* testsuite/23_containers/array/requirements/constexpr_swap.cc: New.

From-SVN: r278269
2019-11-15 00:09:49 +00:00