Commit Graph

700 Commits

Author SHA1 Message Date
Jonathan Wakely eca833b812 libstdc++: Make debug containers prefer copy ctor to base ctor (PR 90102)
When given a type which can convert to any container-like type, the
C(const C&) copy constructor and C(const C::_Base&) converting
constructor are ambiguous. This change replaces the converting
constructor's parameter with a reference_wrapper-like type so that
calling that constructor requires an additional user-defined conversion.
This gives it a lower rank than the copy constructor, avoiding the
ambiguity.

While testing this change I discovered that __gnu_debug::forward_list
doesn't have a convering constructor from the std::forward_list base, so
this adds it.

We should probably consider whether the converting constructors should
be 'explicit' but I'm not changing that now.

libstdc++-v3/ChangeLog:

	PR libstdc++/90102
	* include/debug/deque (deque(const _Base&)): Replace parameter
	with a struct that wraps a const _Base&.
	* include/debug/forward_list (forward_list(_Base_ref)): New
	constructor.
	* include/debug/list (list(const _Base&)): Replace parameter
	with a struct that wraps a const _Base&.
	* include/debug/map.h (map(const _Base&)): Likewise.
	* include/debug/multimap.h (multimap(const _Base&)): Likewise.
	* include/debug/multiset.h (multiset(const _Base&)): Likewise.
	* include/debug/set.h (set(const _Base&)): Likewise.
	* include/debug/unordered_map (unordered_map(const _Base&))
	(unordered_multimap(const _Base&)): Likewise.
	* include/debug/unordered_set (unordered_set(const _Base&))
	(unordered_multiset(const _Base&)): Likewise.
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
	Adjust dg-error line number.
	* include/debug/vector (vector(const _Base&)): Likewise.
	* testsuite/23_containers/deque/debug/90102.cc: New test.
	* testsuite/23_containers/forward_list/debug/90102.cc: New test.
	* testsuite/23_containers/list/debug/90102.cc: New test.
	* testsuite/23_containers/map/debug/90102.cc: New test.
	* testsuite/23_containers/multimap/debug/90102.cc: New test.
	* testsuite/23_containers/multiset/debug/90102.cc: New test.
	* testsuite/23_containers/set/debug/90102.cc: New test.
	* testsuite/23_containers/unordered_map/debug/90102.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/90102.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/90102.cc: New test.
	* testsuite/23_containers/unordered_set/debug/90102.cc: New test.
	* testsuite/23_containers/vector/debug/90102.cc: New test.
2020-06-02 18:13:33 +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
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 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 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 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
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 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
Ville Voutilainen e06cde870e Library-side tests for parenthesized aggregate init
PR c++/92878
PR c++/92947

* testsuite/20_util/allocator_traits/members/92878_92947.cc: New.
* testsuite/20_util/any/assign/92878_92947.cc: Likewise.
* testsuite/20_util/any/cons/92878_92947.cc: Likewise.
* testsuite/20_util/is_constructible/92878_92947.cc: Likewise.
* testsuite/20_util/optional/assignment/92878_92947.cc: Likewise.
* testsuite/20_util/optional/cons/92878_92947.cc: Likewise.
* testsuite/20_util/pair/cons/92878_92947.cc: Likewise.
* testsuite/20_util/shared_ptr/creation/92878_92947.cc: Likewise.
* testsuite/20_util/specialized_algorithms/construct_at/92878_92947.cc:
Likewise.
* testsuite/20_util/unique_ptr/creation/92878_92947.cc: Likewise.
* testsuite/20_util/uses_allocator/92878_92947.cc: Likewise.
* testsuite/20_util/variant/92878_92947.cc: Likewise.
* testsuite/23_containers/deque/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/forward_list/modifiers/92878_92947.cc:
Likewise.
* testsuite/23_containers/list/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/map/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/multimap/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/multiset/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/priority_queue/92878_92947.cc: Likewise.
* testsuite/23_containers/queue/92878_92947.cc: Likewise.
* testsuite/23_containers/set/modifiers/emplace/92878_92947.cc:
Likewise.
* testsuite/23_containers/stack/92878_92947.cc: Likewise.
* testsuite/23_containers/unordered_map/modifiers/92878_92947.cc:
Likewise.
* testsuite/23_containers/unordered_multimap/modifiers/92878_92947.cc:
Likewise.
* testsuite/23_containers/unordered_multiset/modifiers/92878_92947.cc:
Likewise.
* testsuite/23_containers/unordered_set/modifiers/92878_92947.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/emplace/92878_92947.cc:
Likewise.
2020-03-31 17:07:52 +03:00
Jonathan Wakely 3654d49d0f libstdc++: Change compile-only test to run
The 24_iterators/ostream_iterator/1.cc test uses VERIFY and so is
obviously meant to have been run, not just compiled.

	* testsuite/23_containers/unordered_set/allocator/ext_ptr.cc: Add
	comment explaining multiple dg-do directives.
	* testsuite/24_iterators/ostream_iterator/1.cc: Fix do-do directive
	so test is run as well as compiled.
2020-03-10 09:47:15 +00:00
Jonathan Wakely ae7051590d libstdc++: Define <=> for Debug Mode array
This fixes a test failure with -D_GLIBCXX_DEBUG:

FAIL: 23_containers/array/comparison_operators/constexpr.cc (test for excess errors)

	* include/debug/array (operator<=>): Define for C++20.
	* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
	Adjust dg-error line numbers.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_debug_neg.cc: Likewise.
2020-02-27 15:13:16 +00:00
Jonathan Wakely b112e3cb60 libstdc++: Fix std::span test failures with _GLIBCXX_ASSERTIONS
This fixes several failures with -D_GLIBCXX_ASSERTIONS added to the
testsuite flags, such as:

FAIL: 23_containers/span/back_assert_neg.cc (test for excess errors)

	* testsuite/23_containers/span/back_assert_neg.cc: Add #undef before
	defining _GLIBCXX_ASSERTIONS.
	* testsuite/23_containers/span/first_2_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/first_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/front_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/last_2_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/last_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_2_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_3_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_4_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_5_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_6_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/subspan_assert_neg.cc: Likewise.
2020-02-27 15:13:16 +00:00
Jonathan Wakely 66ae31eb30 libstdc++: span's deduction-guide for built-in arrays doesn't work (LWG 3369)
The 23_containers/span/deduction.cc test was already passing, but only
because I had previously implemented the original proposed resolution of
3255. As pointed out in 3255 that original P/R was incorrect because it
broke construction from array xvalues. This reverts the incorrect part
of 3255 (and adds tests for the case it broke), and implements the
resolution of 3369 instead.

	* include/std/span (span(T (&)[N])): Use non-deduced context to
	prevent first parameter from interfering with class template argument
	deduction (LWG 3369).
	* testsuite/23_containers/span/deduction.cc: Add missing 'const'.
	* testsuite/23_containers/span/lwg3255.cc: Check for construction from
	rvalues.
2020-02-19 15:28:33 +00:00
Jonathan Wakely 247f410b83 libstdc++: Remove std::span::cbegin and std::span::cend (LWG 3320)
* include/std/span (span::const_iterator, span::const_reverse_iterator)
	(span::cbegin(), span::cend(), span::crbegin(), span::crend()):
	Remove (LWG 3320).
	* testsuite/23_containers/span/everything.cc: Replace uses of cbegin
	and cend.
	* testsuite/20_util/specialized_algorithms/destroy/constrained.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/
	constrained.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/
	uninitialized_default_construct/constrained.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill/
	constrained.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_move/
	constrained.cc: Likewise.
	* testsuite/20_util/specialized_algorithms/
	uninitialized_value_construct/constrained.cc: Likewise.
2020-02-19 15:27:49 +00:00
Jonathan Wakely 9b8e2dea78 libstdc++: P1976R2 Fixed-size span construction from dynamic range
This includes fixes for first, last, as_bytes and as_writable_bytes
which were missing from the paper.

	* include/std/span (__cpp_lib_span): Update value.
	(span(It, size_type), span(It, End)): Make conditionally explicit. Add
	assertion.
	(span(R&&), span(const span<OType, OExtent>&)): Likewise and relax
	constraints.
	(span::first<Count>(), span::last<Count>()): Use explicit type in
	return statement.
	(as_bytes, as_writable_bytes): Likewise.
	* include/std/version (__cpp_lib_span): Update value.
	* testsuite/23_containers/span/1.cc: Check new value.
	* testsuite/23_containers/span/2.cc: Check new value.
	* testsuite/23_containers/span/explicit.cc: New test.
2020-02-18 17:43:36 +00:00
Jonathan Wakely f5b4dc3885 libstdc++: P2116R0 Remove tuple-like protocol support from fixed-extent span
Following this change it's no longer possible to use std::span with
structured bindings or with the tuple-like API. It will probably come
back for C++23 though.

	P2116R0 Remove tuple-like protocol support from fixed-extent span
	* include/std/span (get, tuple_size, tuple_element): Remove.
	* testsuite/23_containers/span/everything.cc: Remove checks for
	tuple-like API.
	* testsuite/23_containers/span/get_neg.cc: Remove.
	* testsuite/23_containers/span/tuple_element_dynamic_neg.cc: Remove.
	* testsuite/23_containers/span/tuple_element_oob_neg.cc: Remove.
	* testsuite/23_containers/span/tuple_size_neg.cc: Remove.
2020-02-18 17:41:57 +00:00
Jonathan Wakely 55b00d14f4 libstdc++: Update __cpp_lib_erase_if macro (P1115R3)
Now that this feature has been approved for C++20 we can define the
macro to the official value.

	* include/bits/erase_if.h (__cpp_lib_erase_if): Define to 202002L.
	* include/std/deque: Likewise.
	* include/std/forward_list: Likewise.
	* include/std/list: Likewise.
	* include/std/string: Likewise.
	* include/std/vector: Likewise.
	* include/std/version: Likewise.
	* testsuite/23_containers/deque/erasure.cc: Test for new value.
	* testsuite/23_containers/forward_list/erasure.cc: Likewise.
	* testsuite/23_containers/list/erasure.cc: Likewise.
	* testsuite/23_containers/map/erasure.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.
2020-02-15 10:25:23 +00:00
Jonathan Wakely 389cd88ce7 libstdc++: Fix deduction guide for std::span (PR93426)
The deduction guide from an iterator and sentinel used the wrong alias
template and so didn't work.

	PR libstdc++/93426
	* include/std/span (span): Fix deduction guide.
	* testsuite/23_containers/span/deduction.cc: New test.
2020-01-27 10:55:19 +00:00
François Dumont d916538965 libstdc++: Improve unordered containers == operator (PR 91263)
Avoid comparing elements with operator== multiple times by replacing
uses of find and equal_range with equivalent inlined code that uses
operator== instead of the container's equality comparison predicate.
This is valid because the standard requires that operator== is a
refinement of the equality predicate.

Also replace the _S_is_permutation function with std::is_permutation,
which wasn't yet implemented when this code was first written.

	PR libstdc++/91263
	* include/bits/hashtable.h (_Hashtable<>): Make _Equality<> friend.
	* include/bits/hashtable_policy.h: Include <bits/stl_algo.h>.
	(_Equality_base): Remove.
	(_Equality<>::_M_equal): Review implementation. Use
	std::is_permutation.
	* testsuite/23_containers/unordered_multiset/operators/1.cc
	(Hash, Equal, test02, test03): New.
	* testsuite/23_containers/unordered_set/operators/1.cc
	(Hash, Equal, test02, test03): New.
2020-01-16 14:39:05 +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
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
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
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 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 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
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
Jonathan Wakely 9aeb3bef2c Apply C++20 changes to various iterator types
This ensures that __normal_iterator<T*, C> satisfies the
contiguous_iterator concept, by defining the iterator_concept member
type.

Also update vector<bool>'s iterators, reverse_iterator,
istreambuf_iterator and ostreambuf_iterator to meet the C++20
requirements.

	PR libstdc++/92272
	* include/bits/stl_bvector.h (_Bit_iterator::pointer)
	(_Bit_const_iterator::pointer): Define as void for C++20.
	* include/bits/stl_iterator.h (reverse_iterator::operator->()): Add
	constraints for C++20.
	(__normal_iterator::iterator_concept): Define for C++20.
	* include/bits/streambuf_iterator.h (istreambuf_iterator::pointer):
	Define as void for C++20.
	(ostreambuf_iterator::difference_type): Define as ptrdiff_t for C++20.
	(ostreambuf_iterator::ostreambuf_iterator()): Add default constructor
	for C++20.
	* testsuite/23_containers/vector/bool/iterator_c++20.cc: New test.
	* testsuite/24_iterators/bidirectional/concept.cc: New test.
	* testsuite/24_iterators/bidirectional/tag.cc: New test.
	* testsuite/24_iterators/contiguous/concept.cc: New test.
	* testsuite/24_iterators/contiguous/tag.cc: New test.
	* testsuite/24_iterators/forward/concept.cc: New test.
	* testsuite/24_iterators/forward/tag.cc: New test.
	* testsuite/24_iterators/input/concept.cc: New test.
	* testsuite/24_iterators/input/tag.cc: New test.
	* testsuite/24_iterators/istreambuf_iterator/requirements/typedefs.cc:
	New test.
	* testsuite/24_iterators/ostreambuf_iterator/requirements/typedefs.cc:
	New test.
	* testsuite/24_iterators/output/concept.cc: New test.
	* testsuite/24_iterators/output/tag.cc: New test.
	* testsuite/24_iterators/random_access/concept.cc: New test.
	* testsuite/24_iterators/random_access/tag.cc: New test.
	* testsuite/24_iterators/range_operations/advance_debug_neg.cc: New
	test.
	* testsuite/24_iterators/random_access_iterator/26020.cc: Move to ...
	* testsuite/24_iterators/operations/26020.cc: ... here.
	* testsuite/24_iterators/random_access_iterator/
	string_vector_iterators.cc: Move to ...
	* testsuite/24_iterators/random_access/string_vector_iterators.cc: ...
	here.

From-SVN: r277629
2019-10-30 15:48:11 +00:00
Jonathan Wakely 0ed4d40833 PR libstdc++/92267 fix ABI change in deque iterators
Defaulting the copy constructor on its first declaration made it change
from user-provided (and non-trivial) to implicitly-defined (and
trivial). This caused an ABI incompatibility between GCC 8 and GCC 9,
where functions taking a deque iterator disagree on the argument passing
convention.

	PR libstdc++/92267
	* include/bits/stl_deque.h (_Deque_iterator(const _Deque_iterator&)):
	Do not define as defaulted.
	* testsuite/23_containers/deque/types/92267.cc: New test.

From-SVN: r277577
2019-10-29 17:14:55 +00:00
Jonathan Wakely 85f2411493 PR c++/91369 Implement P0784R7 changes to allocation and construction
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.

std::allocator::allocate and std::allocator::deallocate need to be
added so that they can be intercepted by the compiler during constant
evaluation. Outside of constant evaluation those new member functions
just forward to the existing implementation in the base class.

	PR c++/91369 Implement P0784R7 changes to allocation and construction
	* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
	(allocator_traits::_S_allocate, allocator_traits::_S_construct)
	(allocator_traits::_S_destroy, allocator_traits::_S_max_size)
	(allocator_traits::_S_select, allocator_traits::allocate)
	(allocator_traits::deallocate, allocator_traits::construct)
	(allocator_traits::destroy, allocator_traits::max_size)
	(allocator_traits::select_on_container_copy_construction)
	(allocator_traits<allocator<T>>): Add constexpr specifier for C++20.
	(allocator_traits<allocator<T>>::construct): Use construct_at.
	(allocator_traits<allocator<T>>::destroy): Use destroy_at.
	(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Add constexpr
	specifier.
	(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
	(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move here
	from <bits/stl_construct.h>.
	* include/bits/allocator.h (allocator::~allocator): Remove for C++20.
	(allocator::allocate, allocate::deallocate): Define for C++20 and up.
	(operator==, operator!=): Add constexpr specifier for C++20.
	* include/bits/stl_construct.h: Don't include <ext/alloc_traits.h>.
	(destroy_at): For C++20 add constexpr specifier and support for
	destroying arrays.
	(construct_at): Define new function for C++20.
	(_Construct): Return result of placement new-expression. For C++11 and
	up add constexpr. For C++20 dispatch to std::construct_at during
	constant evaluation.
	(_Destroy(pointer)): Add constexpr specifier. For C++20 dispatch to
	std::destroy_at during constant evaluation.
	(_Destroy_aux::__destroy, _Destroy_n_aux::__destroy_n): Add constexpr
	specifier for C++20.
	(_Destroy(ForwardIterator, ForwardIterator))
	(_Destroy(ForwardIterator, Size)): Likewise. Do not elide trivial
	destructors during constant evaluation.
	(destroy, destroy_n): Add constexpr specifier for C++20.
	(_Destroy(ForwardIterator, ForwardIterator, Alloc&))
	(_Destroy(ForwardIterator, ForwardIterator, allocator<T>&)): Move to
	<bits/alloc_traits.h>, to remove dependency on allocators.
	* include/bits/stl_uninitialized.h: Include <ext/alloc_traits.h>.
	Include <bits/stl_pair.h> instead of <utility>.
	* include/ext/alloc_traits.h: Always include <bits/alloc_traits.h>.
	(__alloc_traits::construct, __alloc_traits::destroy)
	(__alloc_traits::_S_select_on_copy, __alloc_traits::_S_on_swap): Add
	constexpr specifier.
	* include/ext/malloc_allocator.h  (operator==, operator!=): Add
	constexpr specifier for C++20.
	* include/ext/new_allocator.h (operator==, operator!=): Likewise.
	* testsuite/20_util/headers/memory/synopsis.cc: Add constexpr.
	* testsuite/20_util/scoped_allocator/69293_neg.cc: Ignore additional
	errors due to constexpr function called after failed static_assert.
	* testsuite/20_util/specialized_algorithms/construct_at/1.cc: New test.
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
	Ignore additional errors due to constexpr function called after failed
	static_assert.
	* testsuite/23_containers/vector/cons/destructible_neg.cc: Likewise.

From-SVN: r277342
2019-10-23 18:42:11 +01:00
Jonathan Wakely 2cae56bd61 Remove redundant std::allocator members for C++20
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.

Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.

	* include/bits/alloc_traits.h
	(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
	(allocator_traits<allocator<T>>::construct): Perform placement new
	directly for C++20, instead of calling allocator<T>::construct.
	(allocator_traits<allocator<T>>::destroy): Call destructor directly
	for C++20, instead of calling allocator<T>::destroy.
	(allocator_traits<allocator<T>>::max_size): Return value directly
	for C++20, instead of calling std::allocator<T>::max_size().
	(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
	define for C++17 and up.
	(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
	for C++17 and up, instead of tag dispatching.
	* include/bits/allocator.h (allocator<void>): Remove for C++20.
	(allocator::pointer, allocator::const_pointer, allocator::reference)
	(allocator::const_reference, allocator::rebind): Remove for C++20.
	* include/bits/basic_string.h (basic_string): Use __alloc_traits to
	rebind allocator.
	* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
	* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
	* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
	(malloc_allocator::pointer, malloc_allocator::const_pointer)
	(malloc_allocator::reference, malloc_allocator::const_reference)
	(malloc_allocator::rebind, malloc_allocator::max_size)
	(malloc_allocator::construct, malloc_allocator::destroy): Do not
	define for C++20.
	(malloc_allocator::_M_max_size): Define new function.
	* include/ext/new_allocator.h (new_allocator::~new_allocator)
	(new_allocator::pointer, new_allocator::const_pointer)
	(new_allocator::reference, new_allocator::const_reference)
	(new_allocator::rebind, new_allocator::max_size)
	(new_allocator::construct, new_allocator::destroy): Do not
	define for C++20.
	(new_allocator::_M_max_size): Define new function.
	* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
	__alloc_traits to rebind allocator.
	* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
	(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
	to construct character.
	* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
	allocator.
	* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
	Use __alloc_traits.
	* include/ext/throw_allocator.h (throw_allocator): Do not use optional
	members of std::allocator, use __alloc_traits members instead.
	* include/ext/vstring.h (__versa_string): Use __alloc_traits.
	* include/ext/vstring_util.h (__vstring_utility): Likewise.
	* include/std/memory: Include <bits/alloc_traits.h>.
	* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
	* testsuite/20_util/allocator/rebind_c++20.cc: New test.
	* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
	for pointer, const_pointer, reference, const_reference or rebind in
	C++20.
	* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
	* testsuite/23_containers/deque/capacity/29134.cc: Use
	__gnu_test::max_size.
	* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
	* testsuite/23_containers/list/capacity/29134.cc: Likewise.
	* testsuite/23_containers/map/capacity/29134.cc: Likewise.
	* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
	* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
	* testsuite/23_containers/set/capacity/29134.cc: Likewise.
	* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
	* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
	test for C++20.
	* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
	* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
	* testsuite/util/replacement_memory_operators.h: Do not assume
	Alloc::pointer exists.
	* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
	helper to call max_size for any allocator.

From-SVN: r277300
2019-10-22 22:48:39 +01:00
Jonathan Wakely 47519a5687 PR libstdc++/92124 fix incorrect container move assignment
The container requirements say that for move assignment "All existing
elements of [the target] are either move assigned or destroyed". Some of
our containers currently use __make_move_if_noexcept which makes the
move depend on whether the element type is nothrow move constructible.
This is incorrect, because the standard says we must move assign, not
move or copy depending on the move constructor.

Use make_move_iterator instead so that we move unconditionally. This
ensures existing elements won't be copy assigned.

	PR libstdc++/92124
	* include/bits/forward_list.h
	(_M_move_assign(forward_list&&, false_type)): Do not use
	__make_move_if_noexcept, instead move unconditionally.
	* include/bits/stl_deque.h (_M_move_assign2(deque&&, false_type)):
	Likewise.
	* include/bits/stl_list.h (_M_move_assign(list&&, false_type)):
	Likewise.
	* include/bits/stl_vector.h (_M_move_assign(vector&&, false_type)):
	Likewise.
	* testsuite/23_containers/vector/92124.cc: New test.

From-SVN: r277113
2019-10-17 15:21:27 +01:00
Marek Polacek 89e0a492af Implement C++20 P0388R4, DR 1307, and DR 330.
This patch implements P0388R4, Permit conversions to arrays of unknown bound,
<http://wg21.link/p0388r4>.  CWG 393 allowed references to arrays of unknown
bound and this C++20 feature allows conversions like

  void f(int(&)[]);
  int arr[1];

  void g() { f(arr); }
  int(&r)[] = arr;

The proposal seemed fairly straightforward but it turned out to be quite
shifty.  I found out that I needed to implement DR 2352 (done), and also
DR 1307 (done in this patch).  The latter DR added wording for
list-initialization ranking of references to arrays which this proposal
extends.  DR 330 was also implemented in this patch.

	PR c++/91364 - P0388R4: Permit conversions to arrays of	unknown bound.
	PR c++/69531 - DR 1307: Differently bounded array parameters.
	PR c++/88128 - DR 330: Qual convs and pointers to arrays of pointers.
	* call.c (build_array_conv): Build ck_identity at the beginning
	of the conversion.
	(standard_conversion): Pass bounds_none to comp_ptr_ttypes_const.
	(maybe_warn_array_conv): New.
	(convert_like_real): Call it.  Add an error message about converting
	from arrays of unknown bounds.
	(conv_get_original_expr): New.
	(nelts_initialized_by_list_init): New.
	(conv_binds_to_array_of_unknown_bound): New.
	(compare_ics): Implement list-initialization ranking based on
	array sizes, as specified in DR 1307 and P0388R.
	* cp-tree.h (comp_ptr_ttypes_const): Adjust declaration.
	(compare_bounds_t): New enum.
	* typeck.c (comp_array_types): New bool and compare_bounds_t
	parameters.  Use them.
	(structural_comptypes): Adjust the call to comp_array_types.
	(similar_type_p): Handle ARRAY_TYPE.
	(build_const_cast_1): Pass bounds_none to comp_ptr_ttypes_const.
	(comp_ptr_ttypes_real): Don't check cv-quals of ARRAY_TYPEs.  Use
	comp_array_types to compare array types.  Look through arrays as per
	DR 330.
	(comp_ptr_ttypes_const): Use comp_array_types to compare array types.
	Look through arrays as per DR 330.

	* g++.dg/conversion/qual1.C: New test.
	* g++.dg/conversion/qual2.C: New test.
	* g++.dg/conversion/qual3.C: New test.
	* g++.dg/conversion/ref2.C: New test.
	* g++.dg/conversion/ref3.C: New test.
	* g++.dg/cpp0x/initlist-array3.C: Remove dg-error.
	* g++.dg/cpp0x/initlist-array7.C: New test.
	* g++.dg/cpp0x/initlist-array8.C: New test.
	* g++.dg/cpp2a/array-conv1.C: New test.
	* g++.dg/cpp2a/array-conv10.C: New test.
	* g++.dg/cpp2a/array-conv11.C: New test.
	* g++.dg/cpp2a/array-conv12.C: New test.
	* g++.dg/cpp2a/array-conv13.C: New test.
	* g++.dg/cpp2a/array-conv14.C: New test.
	* g++.dg/cpp2a/array-conv15.C: New test.
	* g++.dg/cpp2a/array-conv16.C: New test.
	* g++.dg/cpp2a/array-conv17.C: New test.
	* g++.dg/cpp2a/array-conv2.C: New test.
	* g++.dg/cpp2a/array-conv3.C: New test.
	* g++.dg/cpp2a/array-conv4.C: New test.
	* g++.dg/cpp2a/array-conv5.C: New test.
	* g++.dg/cpp2a/array-conv6.C: New test.
	* g++.dg/cpp2a/array-conv7.C: New test.
	* g++.dg/cpp2a/array-conv8.C: New test.
	* g++.dg/cpp2a/array-conv9.C: New test.
	* g++.old-deja/g++.bugs/900321_01.C: Adjust dg-error.

	* testsuite/23_containers/span/lwg3255.cc: Adjust test to match the
	post-P0388R4 behavior.

From-SVN: r276771
2019-10-09 20:58:00 +00:00
Jonathan Wakely 61e619b4fd Disable tests that aren't valid in parallel mode
Tests that depend on debug mode can't be tested in parallel mode.

	* testsuite/17_intro/using_namespace_std_tr1_neg.cc: Skip test for
	parallel mode.
	* testsuite/20_util/hash/84998.cc: Likewise.
	* testsuite/23_containers/deque/types/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/forward_list/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/list/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/map/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/multimap/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/multiset/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/set/pmr_typedefs_debug.cc: Likewise.
	* testsuite/23_containers/unordered_map/pmr_typedefs_debug.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/pmr_typedefs_debug.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/pmr_typedefs_debug.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/pmr_typedefs_debug.cc:
	Likewise.
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
	Likewise.
	* testsuite/23_containers/vector/types/pmr_typedefs_debug.cc: Likewise.
	* testsuite/25_algorithms/binary_search/partitioned.cc: Likewise.
	* testsuite/25_algorithms/copy/86658.cc: Likewise.
	* testsuite/25_algorithms/equal_range/partitioned.cc: Likewise.
	* testsuite/25_algorithms/lexicographical_compare/71545.cc: Likewise.
	* testsuite/25_algorithms/lower_bound/partitioned.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/partitioned.cc: Likewise.

From-SVN: r276430
2019-10-01 22:02:17 +01:00
François Dumont 2d2ad752c0 Implement C++20 constexpr comparison operators for __debug::array (P1023).
* include/debug/array: Add C++20 constexpr to comparison operators.
	* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc: Adapt
	dg-error line numbers.
	* testsuite/23_containers/array/tuple_interface/
	tuple_element_debug_neg.cc: Likewise.

From-SVN: r276375
2019-09-30 20:33:51 +00:00
Jonathan Wakely 582c57a17e Implement LWG 3255 for std::span constructors
Also fix the constraints on span(Container&) and span(const Container&)
constructors so that they aren't used for const spans or const arrays.

	* include/std/span (span(element_type(&)[N]))
	(span(array<value_type, N>&), span(const array<value_type, N>&)):
	Deduce array element type to allow safe const conversions (LWG 3255).
	[!_GLIBCXX_P1394] (span(Container&), span(const Container&)): Use
	remove_cv_t on arguments to __is_std_span and __is_std_array.
	* testsuite/23_containers/span/lwg3255.cc: New test.

From-SVN: r276298
2019-09-30 12:52:08 +01:00
Jonathan Wakely e2c11cd16b PR libstdc++/91711 fix failing test
PR libstdc++/91711
	* testsuite/23_containers/span/get_neg.cc: Avoid ambiguity due to
	0ul being a valid null pointer constant.

From-SVN: r275563
2019-09-10 08:35:40 +01:00
Jonathan Wakely b5c433ce11 Improve precondition checks for std::span
* doc/xml/manual/status_cxx2020.xml: Update status for P0122R7 and
	P1024R3. Remove entry for P0920R2.
	* include/std/span  (__cpp_lib_span): Change value.
	(__extent_storage, __extent_storage<dynamic_extent>): Remove default
	constructor.
	(span): Replace __extent_storage base class with data member.
	(span::_S_subspan_extent): New function.
	(span::empty()): Add nodiscard attribute.
	(span::front, span::back, span::operator[]): Check preconditions.
	(span::first, span::last, span::subspan): Add noexcept. Improve
	precondition checks (LWG 3103).
	(get): Remove redundant condition from static_assert.
	(tuple_element<I, span<T, E>>): Fix static_assert message and simplify.
	(as_writable_bytes): Add inline specifier.
	* include/std/version (__cpp_lib_span): Change value.
	* testsuite/23_containers/span/back_neg.cc: Remove stray semi-colon.
	* testsuite/23_containers/span/front_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_neg.cc: Likewise.
	* testsuite/23_containers/span/last_neg.cc: Improve test.
	* testsuite/23_containers/span/subspan_neg.cc: Likewise.
	* testsuite/23_containers/span/1.cc: New test.
	* testsuite/23_containers/span/2.cc: New test.
	* testsuite/23_containers/span/back_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_assert_neg.cc: New test.
	* testsuite/23_containers/span/first_neg.cc: New test.
	* testsuite/23_containers/span/front_assert_neg.cc: New test.
	* testsuite/23_containers/span/index_op_assert_neg.cc: New test.
	* testsuite/23_containers/span/last_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/last_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_2_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_3_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_4_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_5_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_6_assert_neg.cc: New test.
	* testsuite/23_containers/span/subspan_assert_neg.cc: New test.

From-SVN: r275411
2019-09-05 14:48:33 +01:00
JeanHeyd Meneide 95e9a7616d Implement std::span for C++20
2019-09-05  JeanHeyd Meneide  <phdofthehouse@gmail.com>

	* include/Makefile.am: Add <span> header.
	* include/Makefile.in: Regenerate.
	* include/bits/range_access.h (__adl_begin, __adl_end, __adl_cbegin)
	(__adl_cend, __adl_rbegin, __adl_rend, __adl_crbegin, __adl_crend)
	(__adl_data, __adl_cdata, __adl_size, __adl_empty, __adl_to_address):
	New functions for performing argument-dependent lookup of range
	customization points.
	* include/bits/stl_iterator.h (__normal_iterator): Add
	_GLIBCXX20_CONSTEXPR to all functions.
	* include/std/span: New header.
	* include/std/version (__cpp_lib_span): Define feature test macro.
	* testsuite/23_containers/span/contiguous_range_neg.cc: New test.
	* testsuite/23_containers/span/everything.cc: New test.
	* testsuite/23_containers/span/get_neg.cc: New test.
	* testsuite/23_containers/span/last_neg.cc: New test.
	* testsuite/23_containers/span/subspan_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_dynamic_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_oob_neg.cc: New test.
	* testsuite/23_containers/span/tuple_size_neg.cc: New test.

From-SVN: r275403
2019-09-05 12:27:45 +01:00
Jonathan Wakely 1ecaf589db Fix errors in new test
* testsuite/23_containers/vector/cons/89164_c++17.cc: Fix errors.

From-SVN: r275204
2019-08-30 17:25:20 +01:00
Jonathan Wakely 61f5cb2313 PR libstdc++/89164 enforce constraints for uninitialized algos
The memmove optimizations for std::uninitialized_copy/fill/_n will
compile even if the type is not copy constructible, because std::copy
doesn't require copy construction to work. But the uninitialized
algorithms do require it.

This adds explicit static assertions to ensure we don't allow ill-formed
initializations.

	PR libstdc++/89164
	* include/bits/stl_algobase.h (__copy_move): Give descriptive names
	to template parameters.
	* include/bits/stl_uninitialized.h (uninitialized_copy)
	(uninitialized_fill, uninitialized_fill_n): Add static assertions to
	diagnose invalid uses.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc:
	Adjust expected error.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/89164.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy_n/
	89164.cc: New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill/89164.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill_n/
	89164.cc: New test.
	* testsuite/23_containers/vector/cons/89164.cc: New test.
	* testsuite/23_containers/vector/cons/89164_c++17.cc: New test.

From-SVN: r275177
2019-08-30 14:54:49 +01: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
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 9a9c7a625d Fix tests that fail without PCH
The recent change to stop transitively including <string> broke some
tests, but only when the library is configured without PCH, because
otherwise the <string> header still gets included via the precompiled
<bits/stdc++.h> header.

	* testsuite/20_util/bad_function_call/what.cc: Include <string> header
	for std::string.
	* testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc: Likewise.
	* testsuite/20_util/tuple/cons/allocator_with_any.cc: Include <memory>
	header for std::allocator.
	* testsuite/23_containers/array/tuple_interface/tuple_element.cc: Add
	using-declaration for std::size_t.
	* testsuite/23_containers/array/tuple_interface/tuple_size.cc:
	Likewise.
	* testsuite/23_containers/deque/cons/55977.cc: Include <istream> for
	std::istream.
	* testsuite/23_containers/vector/cons/55977.cc: Likewise.
	* testsuite/experimental/map/erasure.cc: Include <string> for
	std::string.
	* testsuite/experimental/unordered_map/erasure.cc: Likewise.

From-SVN: r272376
2019-06-17 09:18:17 +01:00
Edward Smith-Rowland d37c29f942 Fix ConstexprIterator requirements tests - No constexpr algorithms!
2019-06-09  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Fix ConstexprIterator requirements tests - No constexpr algorithms!
	* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
	Replace copy with hand-rolled loop.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc:
	Ditto.

From-SVN: r272159
2019-06-11 16:29:35 +00:00
Edward Smith-Rowland 79f31e3d18 Test for C++20 p0858 - ConstexprIterator requirements.
2019-06-08  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Test for C++20 p0858 - ConstexprIterator requirements.
	* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
	New test.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc:
	New test.

From-SVN: r272085
2019-06-08 22:18:36 +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 ad60f42883 Fix more failing tests for C++98 mode
* testsuite/23_containers/deque/requirements/dr438/assign_neg.cc: Add
	dg-prune-output for different C++98 diagnostic.
	* testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc:
	Likewise.
	* testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc:
	Likewise.
	* testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
	Likewise.
	* testsuite/23_containers/list/requirements/dr438/assign_neg.cc:
	Likewise.
	* testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc:
	Likewise.
	* testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc:
	Likewise.
	* testsuite/23_containers/list/requirements/dr438/insert_neg.cc:
	Likewise.
	* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
	Likewise.
	* testsuite/23_containers/vector/requirements/dr438/
	constructor_1_neg.cc: Likewise.
	* testsuite/23_containers/vector/requirements/dr438/
	constructor_2_neg.cc: Likewise.
	* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
	Likewise.
	* testsuite/libstdc++-prettyprinters/compat.cc: Do not run for C++98.

From-SVN: r272010
2019-06-06 16:34:51 +01:00
Jonathan Wakely d561a18ee6 Fix more tests that fail in C++2a mode
* testsuite/23_containers/unordered_map/requirements/debug_container.cc:
	Do not test allocator rebinding extension for C++2a.
	* testsuite/23_containers/unordered_set/allocator/ext_ptr.cc: Change
	dg-do directive for C++17 and C++2a.

From-SVN: r272009
2019-06-06 16:34:45 +01:00