Commit Graph

733 Commits

Author SHA1 Message Date
Jonathan Wakely
40ccb47b50 libstdc++: Fix invalid constexpr function in C++11 mode [PR 99985]
I keep forgetting that a constexpr function in C++11 has to be a single
return statement.

libstdc++-v3/ChangeLog:

	PR libstdc++/99985
	* include/bits/hashtable.h (_Hashtable::_S_nothrow_move()): Fix
	to be a valid constexpr function in C++11.
	* testsuite/23_containers/unordered_set/cons/99985.cc: New test.
2021-04-09 13:09:24 +01:00
Jonathan Wakely
1cbba49e34 libstdc++: Simplify noexcept-specifiers for move constructors
This puts the logic for the noexcept-specifier in one place, and then
reuses it elsewhere. This means checking whether the move constructor
can throw doesn't need to do overload resolution and then check whether
some other constructor can throw, we just get the answer directly.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h (_Hashtable::_S_nothrow_move()):
	New function to determine noexcept-specifier for move
	constructors.
	(_Hashtable): Use _S_nothrow_move() on move constructors.
	* testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc:
	Correct static assertion message.
	* testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc:
	Likewise.
2021-04-08 17:49:59 +01:00
François Dumont
d04c246cae libstdc++: _GLIBCXX_DEBUG Fix allocator-extended move constructor
libstdc++-v3/ChangeLog:

	* include/debug/forward_list
	(forward_list(forward_list&&, const allocator_type&)): Add noexcept qualification.
	* include/debug/list (list(list&&, const allocator_type&)): Likewise and add
	call to safe container allocator aware move constructor.
	* include/debug/vector (vector(vector&&, const allocator_type&)):
	Fix noexcept qualification.
	* testsuite/23_containers/forward_list/cons/noexcept_move_construct.cc:
	Add allocator-extended move constructor noexceot qualification check.
	* testsuite/23_containers/list/cons/noexcept_move_construct.cc: Likewise.
2021-03-28 22:06:33 +02:00
François Dumont
d2b1a6842c libstdc++: Add unordered containers heterogeneous lookup
Add unordered containers heterogeneous lookup member functions find, count, contains and
equal_range in C++20. Those members are considered for overload resolution only if hash and
equal functors used to instantiate the container have a nested is_transparent type.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tree.h
	(__has_is_transparent, __has_is_transparent_t): Move...
	* include/bits/stl_function.h: ...here.
	* include/bits/hashtable_policy.h (_Hash_code_base<>::_M_hash_code_tr): New..
	(_Hashtable_base<>::_M_equals_tr): New.
	* include/bits/hashtable.h (_Hashtable<>::_M_find_tr, _Hashtable<>::_M_count_tr,
	_Hashtable<>::_M_equal_range_tr): New member function templates to perform
	heterogeneous lookup.
	(_Hashtable<>::_M_find_before_node_tr): New.
	(_Hashtable<>::_M_find_node_tr): New.
	* include/bits/unordered_map.h (unordered_map::find<>, unordered_map::count<>,
	unordered_map::contains<>, unordered_map::equal_range<>): New member function
	templates to perform heterogeneous lookup.
	(unordered_multimap::find<>, unordered_multimap::count<>,
	unordered_multimap::contains<>, unordered_multimap::equal_range<>): Likewise.
	* include/bits/unordered_set.h  (unordered_set::find<>, unordered_set::count<>,
	unordered_set::contains<>, unordered_set::equal_range<>): Likewise.
	(unordered_multiset::find<>, unordered_multiset::count<>,
	unordered_multiset::contains<>, unordered_multiset::equal_range<>): Likewise.
	* include/debug/unordered_map
	(unordered_map::find<>, unordered_map::equal_range<>): Likewise.
	(unordered_multimap::find<>, unordered_multimap::equal_range<>): Likewise.
	* include/debug/unordered_set
	(unordered_set::find<>, unordered_set::equal_range<>): Likewise.
	(unordered_multiset::find<>, unordered_multiset::equal_range<>): Likewise.
	* testsuite/23_containers/unordered_map/operations/1.cc: New test.
	* testsuite/23_containers/unordered_multimap/operations/1.cc: New test.
	* testsuite/23_containers/unordered_multiset/operations/1.cc: New test.
	* testsuite/23_containers/unordered_set/operations/1.cc: New test.
2021-02-09 21:56:27 +01:00
François Dumont
33a1e511b5 libstdc++: Make deque iterator operator- usable with value-init iterators
N3644 implies that operator- can be used on value-init iterators. We now return
0 if both iterators are value initialized. If only one is value initialized we
keep the UB by returning the result of a normal computation which is a meaningless
value.

libstdc++-v3/ChangeLog:

	PR libstdc++/70303
	* include/bits/stl_deque.h (std::deque<>::operator-(iterator, iterator)):
	Return 0 if both iterators are value-initialized.
	* testsuite/23_containers/deque/70303.cc: New test.
	* testsuite/23_containers/vector/70303.cc: New test.
2021-02-01 19:19:53 +01:00
François Dumont
02e7af1122 libstdc++: Implement N3644 for _GLIBCXX_DEBUG iterators
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/deque/debug/98466.cc: Make it pre-C++11
	compliant.
2021-01-14 22:43:26 +01:00
François Dumont
05a30af3f2 libstdc++: Implement N3644 for _GLIBCXX_DEBUG iterators
libstdc++-v3/ChangeLog:

	PR libstdc++/98466
	* include/bits/hashtable_policy.h (_Node_iterator_base()): Set _M_cur to nullptr.
	(_Node_iterator()): Make default.
	(_Node_const_iterator()): Make default.
	* include/debug/macros.h (__glibcxx_check_erae_range_after): Add _M_singular
	iterator checks.
	* include/debug/safe_iterator.h
	(_GLIBCXX_DEBUG_VERIFY_OPERANDS): Accept if both iterator are value initialized.
	* include/debug/safe_local_iterator.h (_GLIBCXX_DEBUG_VERIFY_OPERANDS):
	Likewise.
	* include/debug/safe_iterator.tcc (_Safe_iterator<>::_M_valid_range): Add
	_M_singular checks on input iterators.
	* src/c++11/debug.cc (_Safe_iterator_base::_M_can_compare): Remove _M_singular
	checks.
	* testsuite/23_containers/deque/debug/98466.cc: New test.
	* testsuite/23_containers/unordered_map/debug/98466.cc: New test.
2021-01-14 19:23:54 +01:00
Jakub Jelinek
99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
François Dumont
4c275e83dd libstdc++: Make tests with Undefined Behavior in C++11 UNSUPPORTED
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/array/debug/back1_neg.cc: Target c++14 because assertion
	is disabled in C++11.
	* testsuite/23_containers/array/debug/front1_neg.cc: Likewise.
	* testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc: Likewise.
2020-12-14 22:28:38 +01:00
François Dumont
8e56e4d956 libstdc++: Fix several _GLIBCXX_DEBUG tests
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/array/debug/back2_neg.cc: target c++14 because assertion
	for constexpr is disabled in C++11.
	* testsuite/23_containers/array/debug/front2_neg.cc: Likewise.
	* testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc: Likewise.
	* testsuite/23_containers/vector/debug/multithreaded_swap.cc: Include <memory>
	for shared_ptr.
2020-12-14 07:46:25 +01:00
Jonathan Wakely
91cfacc4b5 libstdc++: Disable std::array assertions for C++11 constexpr
The recent changes to add assertions to std::array broke the functions
that need to be constexpr in C++11, because of the restrictive rules for
constexpr functions in C++11.

This simply disables the assertions for C++11 mode, so the functions can
be constexpr again.

libstdc++-v3/ChangeLog:

	* include/std/array (array::operator[](size_t) const, array::front() const)
	(array::back() const) [__cplusplus == 201103]: Disable
	assertions.
	* testsuite/23_containers/array/element_access/constexpr_element_access.cc:
	Check for correct values.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
	* testsuite/23_containers/array/debug/constexpr_c++11.cc: New test.
2020-12-03 17:08:01 +00:00
François Dumont
90bf60c3c2 libstdc++: _Rb_tree code cleanup, remove lambdas
Use new template parameters to replace usage of lambdas to move or not
tree values on copy.

libstdc++-v3/ChangeLog:

	* include/bits/move.h (_GLIBCXX_FWDREF): New.
	* include/bits/stl_tree.h: Adapt to use latter.
	(_Rb_tree<>::_M_clone_node): Add _MoveValue template parameter.
	(_Rb_tree<>::_M_mbegin): New.
	(_Rb_tree<>::_M_begin): Use latter.
	(_Rb_tree<>::_M_copy): Add _MoveValues template parameter.
	* testsuite/23_containers/map/allocator/move_cons.cc: New test.
	* testsuite/23_containers/multimap/allocator/move_cons.cc: New test.
	* testsuite/23_containers/multiset/allocator/move_cons.cc: New test.
	* testsuite/23_containers/set/allocator/move_cons.cc: New test.
2020-11-20 20:56:10 +01:00
François Dumont
6db082477a libstdc++: Remove <debug/array>
Add _GLIBCXX_ASSERTIONS assert in normal std::array and remove __gnu_debug::array
implementation.

libstdc++-v3/ChangeLog:

	* include/debug/array: Remove.
	* include/Makefile.am: Remove <debug/array>.
	* include/Makefile.in: Regenerate.
	* include/experimental/functional: Adapt.
	* include/std/array: Move to _GLIBCXX_INLINE_VERSION namespace.
	* include/std/functional: Adapt.
	* include/std/span: Adapt.
	* testsuite/23_containers/array/debug/back1_neg.cc:
	Remove dg-require-debug-mode. Add -D_GLIBCXX_ASSERTIONS option.
	* testsuite/23_containers/array/debug/back2_neg.cc: Likewise.
	* testsuite/23_containers/array/debug/front1_neg.cc: Likewise.
	* testsuite/23_containers/array/debug/front2_neg.cc: Likewise.
	* testsuite/23_containers/array/debug/square_brackets_operator1_neg.cc:
	Likewise.
	* testsuite/23_containers/array/debug/square_brackets_operator2_neg.cc:
	Likewise.
	* testsuite/23_containers/array/element_access/60497.cc
	* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
	Remove.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc
	* testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc
	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc
2020-11-09 21:20:01 +01:00
Jonathan Wakely
d1e5d82af8 libstdc++: Fix some more warnings in test
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc:
	Avoid -Wcatch-value warnings.
2020-10-30 20:58:08 +00:00
Jonathan Wakely
13feb0234b libstdc++: Avoid warnings in tests
This fixes some warnings emitted when testing with warning flags added.
Some of these are only necessary when testing with -Wsystem-headers, but
either way it cleans up the tests to be less noisy under non-default
flags.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/96817.cc: Avoid -Wunused warnings.
	* testsuite/20_util/any/assign/2.cc: Likewise.
	* testsuite/20_util/any/cons/2.cc: Likewise.
	* testsuite/20_util/align/1.cc: Avoid -Wsign-compare warning.
	* testsuite/20_util/function/65760.cc: Avoid -Wunused warning.
	* testsuite/20_util/function/1.cc: Avoid -Wcatch-value warning.
	* testsuite/20_util/function/cons/move_target.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/headers/memory/synopsis.cc: Add exception
	specification.
	* testsuite/20_util/monotonic_buffer_resource/allocate.cc: Avoid
	-Wsign-compare warning.
	* testsuite/20_util/tuple/cons/deduction.cc: Avoid -Wunused
	warning.
	* testsuite/20_util/specialized_algorithms/uninitialized_copy/808590-cxx11.cc:
	Avoid -Wdeprecated-copy warning.
	* testsuite/21_strings/basic_string/56166.cc: Avoid
	-Wcatch-value warning.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stod.cc:
	Avoid -Wcatch-value warnings.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stod.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stof.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoi.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stol.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stold.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoll.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoul.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/wchar_t/stoull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/nonnull.cc:
	Prune additional diagnostics.
	* testsuite/21_strings/basic_string_view/operations/find/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/nonnull.cc:
	Likewise.
	* testsuite/21_strings/headers/string/synopsis.cc: Add exception
	specifications.
	* testsuite/22_locale/locale/cons/12352.cc: Define sized
	delete operators to avoid warnings.
	* testsuite/23_containers/deque/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/23_containers/forward_list/cons/11.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/headers/bitset/synopsis.cc: Add
	exception specification.
	* testsuite/23_containers/headers/deque/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/forward_list/synopsis.cc:
	Likewise.
	* testsuite/23_containers/headers/list/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/map/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/queue/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/set/synopsis.cc: Likewise.
	* testsuite/23_containers/headers/vector/synopsis.cc: Likewise.
	* testsuite/23_containers/list/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/map/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/multiset/modifiers/swap/1.cc:
	Likewise.
	* testsuite/23_containers/set/modifiers/swap/1.cc: Likewise.
	* testsuite/23_containers/unordered_set/56267-2.cc: Avoid
	-Wdeprecated-copy warning.
	* testsuite/23_containers/vector/bool/23632.cc: Avoid
	-Wempty-body warning.
	* testsuite/23_containers/vector/modifiers/swap/1.cc: Add
	exception specification.
	* testsuite/25_algorithms/heap/moveable2.cc: Fix misplaced
	parentheses around arguments.
	* testsuite/25_algorithms/sample/1.cc: Use return value.
	* testsuite/25_algorithms/search/searcher.cc: Avoid -Wunused
	warnings.
	* testsuite/27_io/basic_ostream/exceptions/char/9561.cc:
	Likewise.
	* testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc:
	Likewise.
	* testsuite/27_io/filesystem/operations/remove_all.cc: Avoid
	-Wsign-compare warning.
	* testsuite/experimental/any/assign/2.cc: Avoid -Wunused warnings.
	* testsuite/experimental/any/cons/2.cc: Likewise.
	* testsuite/experimental/filesystem/operations/remove_all.cc:
	Avoid -Wign-compare warning.
	* testsuite/experimental/memory/observer_ptr/cons/cons.cc:
	Likewise.
	* testsuite/experimental/memory_resource/null_memory_resource.cc:
	Likewise.
	* testsuite/experimental/source_location/1.cc: Avoid -Waddress
	warning.
	* testsuite/ext/pod_char_traits.cc: Avoid -Wunused warning.
	* testsuite/ext/vstring/modifiers/clear/56166.cc: Avoid
	-Wcatch-value.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swap.cc:
	Avoid -Wunused warning.
	* testsuite/std/concepts/concepts.lang/concept.swappable/swappable.cc:
	Likewise.
	* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc:
	Prune additional warnings.
	* testsuite/tr1/3_function_objects/function/1.cc: Avoid
	-Wcatch-value warning.
	* testsuite/util/replacement_memory_operators.h: Define sized
	delete to avoid warnings.
	* testsuite/util/testsuite_api.h (_NonDefaultConstructible): Add
	user-declared assignment operator to stop -Wdeprecated-copy
	warnings.
	* testsuite/util/testsuite_containers.h: Avoid -Wunused warning.
	* testsuite/util/testsuite_iterators.h: Avoid -Wsign-compare
	warnings.
	* testsuite/util/testsuite_new_operators.h: Define sized deleted.
2020-10-29 22:47:21 +00:00
Jonathan Wakely
0f7cd5e573 libstdc++: Make std::span layout-compatible with struct iovec [PR 95609]
This change reorders the data members of std::span so that span<byte> is
layout-compatible with common implementations of struct iovec. This will
allow span<byte> to be used directly in places that use a struct iovec
to do scatter-gather I/O.

It's important to note that POSIX doesn't specify the order of members
in iovec. Also the equivalent type on Windows has members in the other
order, and uses type ULONG (which is always 32-bit whereas size_t is
64-bit for Win64). So this change will only help for certain targets and
an indirection between std::span and I/O system calls will still be
needed for the general case.

libstdc++-v3/ChangeLog:

	PR libstdc++/95609
	* include/std/span (span): Reorder data members to match common
	implementations of struct iovec.
	* testsuite/23_containers/span/layout_compat.cc: New test.
2020-10-28 12:07:40 +00:00
Patrick Palka
37edf28c24 libstdc++: Remove overzealous static_asserts from std::span
For a span with statically empty extent, we currently model the
preconditions of front(), back(), and operator[] as if they are
mandates, by using a static_assert to verify that extent != 0.  This
causes us to reject valid programs that would instantiate these member
functions and at runtime never call them.

Since they are already followed by more general runtime asserts, this
patch just removes these static_asserts altogether,

libstdc++-v3/ChangeLog:

	* include/std/span (span::front): Remove static_assert.
	(span::back): Likewise.
	(span::operator[]): Likewise.
	* testsuite/23_containers/span/back_neg.cc: Rewrite to verify
	that we check the preconditions of back() only when it's called.
	* testsuite/23_containers/span/front_neg.cc: Likewise for
	front().
	* testsuite/23_containers/span/index_op_neg.cc: Likewise for
	operator[].
2020-09-21 23:21:34 -04:00
Jonathan Wakely
2f983fa690 libstdc++: Fix three-way comparison for std::array [PR 96851]
The spaceship operator for std::array uses memcmp when the
__is_byte<value_type> trait is true, but memcmp isn't usable in
constexpr contexts. Also, memcmp should only be used for unsigned byte
types, because it gives the wrong answer for signed chars with negative
values.

We can simply check std::is_constant_evaluated() so that we don't use
memcmp during constant evaluation.

To fix the problem of using memcmp for inappropriate types, this patch
adds new __is_memcmp_ordered and __is_memcmp_ordered_with traits. These
say whether using memcmp will give the right answer for ordering
operations such as lexicographical_compare and three-way comparisons.
The new traits can be used in several places, and can also be used to
implement my suggestion in PR 93059 comment 37 to use memcmp for
unsigned integers larger than one byte on big endian targets.

libstdc++-v3/ChangeLog:

	PR libstdc++/96851
	* include/bits/cpp_type_traits.h (__is_memcmp_ordered):
	New trait that says if memcmp can be used for ordering.
	(__is_memcmp_ordered_with): Likewise, for two types.
	* include/bits/deque.tcc (__lex_cmp_dit): Use new traits
	instead of __is_byte and __numeric_traits.
	(__lexicographical_compare_aux1): Likewise.
	* include/bits/ranges_algo.h (__lexicographical_compare_fn):
	Likewise.
	* include/bits/stl_algobase.h (__lexicographical_compare_aux1)
	(__is_byte_iter): Likewise.
	* include/std/array (operator<=>): Likewise. Only use memcmp
	when std::is_constant_evaluated() is false.
	* testsuite/23_containers/array/comparison_operators/96851.cc:
	New test.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
2020-09-02 15:32:11 +01:00
Jonathan Wakely
9f9c0549dd libstdc++: Fix regression in hash containers
A recent change altered the layout of EBO-helper base classes, resulting
in an ambiguity when the hash function and equality predicate are the
same type.

This modifies the type of one of the base classes, so that we don't get
two base classes of the same type.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (_Hash_code_base): Change
	index of _Hashtable_ebo_helper base class.
	* testsuite/23_containers/unordered_map/dup_types.cc: New test.
2020-08-26 17:44:23 +01:00
Jonathan Wakely
24f2764521 libstdc++: Remove tests for self-move debug assertions
I recently removed the debug mode checks for self-move assignment, which
means these tests now fail when _GLIBCXX_DEBUG is added to the options
or when the check-debug target is used. Remove all the tests.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/21_strings/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/deque/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/deque/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/forward_list/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/forward_list/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/list/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/list/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/map/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/map/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/multimap/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/multimap/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/multiset/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/multiset/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/set/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/set/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_map/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_map/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_multimap/debug/iterator_self_move_assign_neg.cc:
	Removed.
	* testsuite/23_containers/unordered_multimap/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_multiset/debug/iterator_self_move_assign_neg.cc:
	Removed.
	* testsuite/23_containers/unordered_multiset/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_set/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/unordered_set/debug/self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/vector/debug/iterator_self_move_assign_neg.cc: Removed.
	* testsuite/23_containers/vector/debug/self_move_assign_neg.cc: Removed.
2020-08-25 16:36:01 +01:00
Jonathan Wakely
c2fb0a1a2e libstdc++: Make self-move well-defined for containers [PR 85828]
The C++ LWG recently confirmed that self-move assignment should not have
undefined behaviour for standard containers (see the proposed resolution
of LWG 2839). The result should be a valid but unspecified value, just
like other times when a container is moved from.

Our std::list, std::__cxx11::basic_string and unordered containers all
have bugs which result in undefined behaviour.

For std::list the problem is that we clear the previous contents using
_M_clear() instead of clear(). This means the _M_next, _M_prev and
_M_size members are not zeroed, and so after we "update" them (with
their existing values), we are left with dangling pointers and a
non-zero size, but no elements.

For the unordered containers the problem is similar. _Hashtable first
deallocates the existing contents, then takes ownership of the pointers
from the RHS object (which has just had its contents deallocated so the
pointers are dangling).

For std::basic_string it's a little more subtle. When the string is
local (i.e. fits in the SSO buffer) we use char_traits::copy to copy the
contents from this->data() to __rhs.data(). When &__rhs == this that
copy violates the precondition that the ranges don't overlap. We only
need to check for self-move for this case where it's local, because the
only other case that can be true for self-move is that it's non-local
but the allocators compare equal. In that case the data pointer is
neither deallocated nor leaked, so the result is well-defined.

This patch also makes a small optimization for std::deque move
assignment, to use the efficient move when is_always_equal is false, but
the allocators compare equal at runtime.

Finally, we need to remove all the Debug Mode checks which abort the
program when a self-move is detected, because it's not undefined to do
that.

Before PR 85828 can be closed we should also look into fixing
std::shuffle so it doesn't do any redundant self-swaps.

libstdc++-v3/ChangeLog:

	PR libstdc++/85828
	* include/bits/basic_string.h (operator=(basic_string&&)): Check
	for self-move before copying with char_traits::copy.
	* include/bits/hashtable.h (operator=(_Hashtable&&)): Check for
	self-move.
	* include/bits/stl_deque.h (_M_move_assign1(deque&&, false_type)):
	Check for equal allocators.
	* include/bits/stl_list.h (_M_move_assign(list&&, true_type)):
	Call clear() instead of _M_clear().
	* include/debug/formatter.h (__msg_self_move_assign): Change
	comment.
	* include/debug/macros.h (__glibcxx_check_self_move_assign):
	(_GLIBCXX_DEBUG_VERIFY): Remove.
	* include/debug/safe_container.h (operator=(_Safe_container&&)):
	Remove assertion check for safe move and make it well-defined.
	* include/debug/safe_iterator.h (operator=(_Safe_iterator&&)):
	Remove assertion check for self-move.
	* include/debug/safe_local_iterator.h
	(operator=(_Safe_local_iterator&&)): Likewise.
	* testsuite/21_strings/basic_string/cons/char/self_move.cc: New test.
	* testsuite/23_containers/deque/cons/self_move.cc: New test.
	* testsuite/23_containers/forward_list/cons/self_move.cc: New test.
	* testsuite/23_containers/list/cons/self_move.cc: New test.
	* testsuite/23_containers/set/cons/self_move.cc: New test.
	* testsuite/23_containers/unordered_set/cons/self_move.cc: New test.
	* testsuite/23_containers/vector/cons/self_move.cc: New test.
2020-08-12 20:36:00 +01:00
François Dumont
8b7af071b0 libstdc++: Implement DR 526 on [forward_]list remove_if/unique [PR 91620]
Respect DR 526 in implementation of std::[forward_]list remove/remove_if/unique.
[forward_]list::remove was already implementing it but the implementation has
been modified to generalize the following pattern. All nodes to remove are
collected in an intermediate [forward_]list which purpose is just to be
detroyed once out of scope.

libstdc++-v3/ChangeLog:

	PR libstdc++/91620
	* include/bits/forward_list.tcc (forward_list<>::remove): Collect nodes
	to destroy in an intermediate forward_list.
	(forward_list<>::remove_if, forward_list<>::unique): Likewise.
	* include/bits/list.tcc (list<>::remove, list<>::unique): Likewise.
	(list<>::remove_if): Likewise.
	* include/debug/forward_list (forward_list<>::_M_erase_after): Remove.
	(forward_list<>::erase_after): Adapt.
	(forward_list<>::remove, forward_list<>::remove_if): Collect nodes to
	destroy in an intermediate forward_list.
	(forward_list<>::unique): Likewise.
	* include/debug/list (list<>::remove, list<>::unique): Likewise.
	(list<>::remove_if): Likewise.
	* testsuite/23_containers/forward_list/operations/91620.cc: New test.
	* testsuite/23_containers/list/operations/91620.cc: New test.
2020-08-11 21:30:05 +02:00
Jonathan Wakely
de1e3b8795 libstdc++: Fix ambiguous comparisons in __gnu_debug::bitset [PR 96303]
With -pedantic the debug mode bitset has an ambiguous equality
comparison operator, because it tries to compare the non-debug base to
the debug object. The base object can be converted to another debug
bitset, making the same operator== a candidate again.

The fix is to do the comparison on both base objects, so the operator
for the derived type isn't a candidate.

For the inequality operator the same change should be done, but that
operator can be removed entirely for C++20 because it can be synthesized
by the compiler.

I don't think either equality or inequality operators are really needed,
because the public _GLIBCXX_STD_C::bitset base class cam always be
compared using its own comparison operators. I'm not changing that here
though.

libstdc++-v3/ChangeLog:

	PR libstdc++/96303
	* include/debug/bitset (bitset::operator==): Call _M_base() on
	right operand.
	(bitset::operator!=): Likewise, but don't define it at all when
	default comparisons are supported by the compiler.
	* testsuite/23_containers/bitset/operations/96303.cc: New test.
2020-08-07 20:29:11 +01:00
François Dumont
6f00ccbad3 libstdc++: Fix and improve std::vector<bool> implementation.
Do not consider allocator noexcept qualification for vector<bool> move
constructor.
Improve swap performance using TBAA like in main vector implementation. Bypass
_M_initialize_dispatch/_M_assign_dispatch in post-c++11 modes.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h
	[_GLIBCXX_INLINE_VERSION](_Bvector_impl_data::_M_start): Define as
	_Bit_type*.
	(_Bvector_impl_data(const _Bvector_impl_data&)): Default.
	(_Bvector_impl_data(_Bvector_impl_data&&)): Delegate to latter.
	(_Bvector_impl_data::operator=(const _Bvector_impl_data&)): Default.
	(_Bvector_impl_data::_M_move_data(_Bvector_impl_data&&)): Use latter.
	(_Bvector_impl_data::_M_reset()): Likewise.
	(_Bvector_impl_data::_M_swap_data): New.
	(_Bvector_impl::_Bvector_impl(_Bvector_impl&&)): Implement explicitely.
	(_Bvector_impl::_Bvector_impl(_Bit_alloc_type&&, _Bvector_impl&&)): New.
	(_Bvector_base::_Bvector_base(_Bvector_base&&, const allocator_type&)):
	New, use latter.
	(vector::vector(vector&&, const allocator_type&, true_type)): New, use
	latter.
	(vector::vector(vector&&, const allocator_type&, false_type)): New.
	(vector::vector(vector&&, const allocator_type&)): Use latters.
	(vector::vector(const vector&, const allocator_type&)): Adapt.
	[__cplusplus >= 201103](vector::vector(_InputIt, _InputIt,
	const allocator_type&)): Use _M_initialize_range.
	(vector::operator[](size_type)): Use iterator operator[].
	(vector::operator[](size_type) const): Use const_iterator operator[].
	(vector::swap(vector&)): Add assertions on allocators. Use _M_swap_data.
	[__cplusplus >= 201103](vector::insert(const_iterator, _InputIt,
	_InputIt)): Use _M_insert_range.
	(vector::_M_initialize(size_type)): Adapt.
	[__cplusplus >= 201103](vector::_M_initialize_dispatch): Remove.
	[__cplusplus >= 201103](vector::_M_insert_dispatch): Remove.
	* python/libstdcxx/v6/printers.py (StdVectorPrinter._iterator): Stop
	using start _M_offset.
	(StdVectorPrinter.to_string): Likewise.
	* testsuite/23_containers/vector/bool/allocator/swap.cc: Adapt.
	* testsuite/23_containers/vector/bool/cons/noexcept_move_construct.cc:
	Add check.
2020-07-31 23:18:51 +02:00
Jonathan Wakely
a92e0f58d8 libstdc++: Add dg-require-effective-target to std::span assert tests
The current dg directives say that the tests can run for any standard
mode, but should fail for C++20. What we want is that they only run for
C++20, and are always expected to fail.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/span/back_assert_neg.cc: Split c++2a
	effective-target from xfail selector.
	* 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-07-31 19:58:02 +01:00
Jonathan Wakely
6458742a15 libstdc++: Ensure c++NN effective target present in all C++17 tests
Also reorder some directives so that the dg-options setting -std=gnu++17
comes before the dg-do that requires c++17.

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/headers/c++2017/all_attributes.cc: Add
	c++17 effective-target.
	* testsuite/17_intro/headers/c++2017/all_no_exceptions.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/all_no_rtti.cc: Likewise.
	* testsuite/17_intro/headers/c++2017/all_pedantic_errors.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/operator_names.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/stdc++.cc: Likewise.
	* testsuite/17_intro/headers/c++2017/stdc++_multiple_inclusion.cc:
	Likewise.
	* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc:
	Likewise.
	* testsuite/19_diagnostics/error_code/is_error_code_v.cc:
	Likewise.
	* testsuite/20_util/any/assign/1.cc: Likewise.
	* testsuite/20_util/any/assign/2.cc: Likewise.
	* testsuite/20_util/any/assign/emplace.cc: Likewise.
	* testsuite/20_util/any/assign/exception.cc: Likewise.
	* testsuite/20_util/any/assign/self.cc: Likewise.
	* testsuite/20_util/any/cons/1.cc: Likewise.
	* testsuite/20_util/any/cons/2.cc: Likewise.
	* testsuite/20_util/any/cons/aligned.cc: Likewise.
	* testsuite/20_util/any/cons/explicit.cc: Likewise.
	* testsuite/20_util/any/cons/in_place.cc: Likewise.
	* testsuite/20_util/any/cons/nontrivial.cc: Likewise.
	* testsuite/20_util/any/make_any.cc: Likewise.
	* testsuite/20_util/any/misc/any_cast.cc: Likewise.
	* testsuite/20_util/any/misc/any_cast_no_rtti.cc: Likewise.
	* testsuite/20_util/any/misc/swap.cc: Likewise.
	* testsuite/20_util/any/modifiers/1.cc: Likewise.
	* testsuite/20_util/any/observers/type.cc: Likewise.
	* testsuite/20_util/any/requirements.cc: Likewise.
	* testsuite/20_util/any/typedefs.cc: Likewise.
	* testsuite/20_util/as_const/1.cc: Likewise.
	* testsuite/20_util/as_const/rvalue_neg.cc: Likewise.
	* testsuite/20_util/bind/is_placeholder_v.cc: Likewise.
	* testsuite/20_util/bool_constant/requirements.cc: Likewise.
	* testsuite/20_util/duration/requirements/treat_as_floating_point_v.cc:
	Likewise.
	* testsuite/20_util/duration_cast/rounding.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	Likewise.
	* testsuite/20_util/function_objects/invoke/59768.cc: Likewise.
	* testsuite/20_util/function_objects/not_fn/1.cc: Likewise.
	* testsuite/20_util/function_objects/searchers.cc: Likewise.
	* testsuite/20_util/in_place/requirements.cc: Likewise.
	* testsuite/20_util/is_invocable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_invocable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_invocable/value.cc: Likewise.
	* testsuite/20_util/is_nothrow_invocable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_invocable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/value.cc: Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/value.cc:
	Likewise.
	* testsuite/20_util/is_swappable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_swappable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_swappable/value.cc: Likewise.
	* testsuite/20_util/is_swappable_with/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_swappable_with/value.cc: Likewise.
	* testsuite/20_util/logical_traits/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/logical_traits/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/logical_traits/value.cc: Likewise.
	* testsuite/20_util/optional/constexpr/make_optional.cc: Likewise.
	* testsuite/20_util/optional/constexpr/observers/2.cc: Likewise.
	* testsuite/20_util/optional/constexpr/observers/3.cc: Likewise.
	* testsuite/20_util/optional/hash.cc: Likewise.
	* testsuite/20_util/pair/swap_cxx17.cc: Likewise.
	* testsuite/20_util/ratio/requirements/ratio_equal_v.cc: Likewise.
	* testsuite/20_util/shared_ptr/requirements/weak_type.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc:
	Likewise.
	* testsuite/20_util/tuple/apply/1.cc: Likewise.
	* testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise.
	* testsuite/20_util/tuple/swap_cxx17.cc: Likewise.
	* testsuite/20_util/tuple/tuple_size_v.cc: Likewise.
	* testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.cc:
	Likewise.
	* testsuite/20_util/uses_allocator/requirements/uses_allocator_v.cc:
	Likewise.
	* testsuite/20_util/variant/any.cc: Likewise.
	* testsuite/20_util/variant/compile.cc: Likewise.
	* testsuite/20_util/variant/hash.cc: Likewise.
	* testsuite/20_util/variant/index_type.cc: Likewise.
	* testsuite/20_util/variant/run.cc: Likewise.
	* testsuite/20_util/void_t/1.cc: Likewise.
	* testsuite/21_strings/basic_string/79162.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/char/7.cc: Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/7.cc: Likewise.
	* testsuite/21_strings/basic_string/lwg2758.cc: Likewise.
	* testsuite/21_strings/basic_string/lwg2946.cc: Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/insert/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/char/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/replace/wchar_t/7.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/data/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/data/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/char/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operators/char/5.cc: Likewise.
	* testsuite/21_strings/basic_string/operators/wchar_t/5.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/capacity/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/1.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/3.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/empty.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_back.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/include.cc: Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/pod/10081-out.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/inserters/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/char/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/compare/wchar_t/13650.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/data/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/char/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/find/wchar_t/4.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/char/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/rfind/wchar_t/3.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/string_conversion/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/substr/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/range_access/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/range_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/char8_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/typedefs.cc: Likewise.
	* testsuite/21_strings/basic_string_view/types/1.cc: Likewise.
	* testsuite/23_containers/array/specialized_algorithms/swap_cxx17.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/map/modifiers/insert_or_assign/1.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/map/modifiers/try_emplace/1.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/multimap/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/multiset/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/multiset/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/set/modifiers/extract.cc: Likewise.
	* testsuite/23_containers/set/modifiers/merge.cc: Likewise.
	* testsuite/23_containers/unordered_map/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/insert_or_assign.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/modifiers/try_emplace.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/merge.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/modifiers/extract.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/modifiers/merge.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/synopsis_c++17.cc:
	Likewise.
	* testsuite/25_algorithms/clamp/1.cc: Likewise.
	* testsuite/25_algorithms/clamp/2.cc: Likewise.
	* testsuite/25_algorithms/clamp/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/functions_std_c++17.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/special_functions_global.cc:
	Likewise.
	* testsuite/27_io/basic_ostream/inserters_other/char/lwg2221.cc:
	Likewise.
	* testsuite/29_atomics/atomic/is_always_lock_free.cc: Likewise.
	* testsuite/29_atomics/atomic_integral/is_always_lock_free.cc:
	Likewise.
	* testsuite/30_threads/shared_lock/70766.cc: Likewise.
	* testsuite/30_threads/shared_mutex/cons/1.cc: Likewise.
	* testsuite/30_threads/shared_mutex/cons/assign_neg.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/cons/copy_neg.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/requirements/standard_layout.cc:
	Likewise.
	* testsuite/30_threads/shared_mutex/try_lock/1.cc: Likewise.
	* testsuite/30_threads/shared_mutex/try_lock/2.cc: Likewise.
	* testsuite/30_threads/shared_mutex/unlock/1.cc: Likewise.
2020-07-31 19:58:02 +01:00
Jonathan Wakely
357beca8bc libstdc++: Fix tests using wrong allocator type
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/unordered_multiset/cons/noexcept_default_construct.cc:
	Use allocator with the correct value type.
	* testsuite/23_containers/unordered_set/cons/noexcept_default_construct.cc:
	Likewise.
2020-07-30 18:41:59 +01:00
Jonathan Wakely
4c27c6584d libstdc++: Make testsuite usable with -fno-exceptions
Previously it was not possible to add -fno-exceptions to the testsuite
flags, because some files that are compiled by the v3-build_support
procedure failed with exceptions disabled.

This adjusts those files to still compile without exceptions (with
degraded functionality in some cases).

The sole testcase that explicitly checks for -fno-exceptions has also
been adjusted to use the more robust exceptions_enabled effective-target
keyword from gcc/testsuite/lib/target-supports.exp.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/vector/bool/72847.cc: Use the
	exceptions_enabled effective-target keyword instead of
	checking for an explicit -fno-exceptions option.
	* testsuite/util/testsuite_abi.cc (examine_symbol): Remove
	redundant try-catch.
	* testsuite/util/testsuite_allocator.h [!__cpp_exceptions]:
	Do not define check_allocate_max_size and memory_resource.
	* testsuite/util/testsuite_containers.h: Replace comment with
	#error if wrong standard dialect used.
	* testsuite/util/testsuite_shared.cc: Likewise.
2020-07-30 12:50:02 +01:00
François Dumont
12324b9a93 libstdc++: Fix unordered containers move constructors noexcept qualification
_Hashtable move constructor is wrongly qualified as noexcept(true) regardless of
_Equal and _H1 copy constructor qualifications.
_Hashtable allocator-aware move constructor is missing its noexcept
qualification like the depending unordered containers ones.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h
	(_Hashtable(_Hashtable&& __ht, __node_alloc_type&& __a, true_type)):
	Add noexcept qualification.
	(_Hashtable(_Hashtable&&)): Fix noexcept qualification.
	(_Hashtable(_Hashtable&&, const allocator_type&)): Add noexcept
	qualification.
	* include/bits/unordered_map.h
	(unordered_map(unordered_map&&, const allocator_type&)): Add noexcept
	qualification.
	(unordered_multimap(unordered_multimap&&, const allocator_type&)):
	Likewise.
	* include/bits/unordered_set.h
	(unordered_set(unordered_set&&, const allocator_type&)): Likewise.
	(unordered_multiset(unordered_multiset&&, const allocator_type&)):
	Likewise.
	* include/debug/unordered_map
	(unordered_map(unordered_map&&, const allocator_type&)): Likewise.
	(unordered_multimap(unordered_multimap&&, const allocator_type&)):
	Likewise.
	* include/debug/unordered_set
	(unordered_set(unordered_set&&, const allocator_type&)): Likewise.
	(unordered_multiset(unordered_multiset&&, const allocator_type&)):
	Likewise.
	* testsuite/23_containers/unordered_map/allocator/default_init.cc:
	New test.
	* testsuite/23_containers/unordered_map/cons/noexcept_default_construct.cc:
	New test.
	* testsuite/23_containers/unordered_map/cons/noexcept_move_construct.cc:
	New test.
	* testsuite/23_containers/unordered_map/modifiers/move_assign.cc:
	New test.
	* testsuite/23_containers/unordered_multimap/cons/noexcept_default_construct.cc:
	New test.
	* testsuite/23_containers/unordered_multimap/cons/noexcept_move_construct.cc:
	New test.
	* testsuite/23_containers/unordered_multiset/cons/noexcept_default_construct.cc:
	New test.
	* testsuite/23_containers/unordered_multiset/cons/noexcept_move_construct.cc:
	New test.
	* testsuite/23_containers/unordered_set/allocator/default_init.cc:
	New test.
	* testsuite/23_containers/unordered_set/cons/noexcept_default_construct.cc:
	New test.
	* testsuite/23_containers/unordered_set/cons/noexcept_move_construct.cc:
	New test.
2020-07-29 11:26:42 +02:00
François Dumont
6dcf042368 libstdc++: Do not over-size hashtable buckets on range insertion
We used to consider range size on insertion but on unique keys container
not all range values might be inserted resulting in over-sizing. In this
case we just consider user reservation and if none then the container will
adapt to actually inserted elements.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h
	(_Hashtable<>(_InputIterator, _InputIterator, size_t, const _H1&,
	const _H2&, const _Hash&, const _Equal&, const _ExtractKey&,
	const allocator_type&, true_type)): New.
	(_Hashtable<>(_InputIterator, _InputIterator, size_t, const _H1&,
	const _H2&, const _Hash&, const _Equal&, const _ExtractKey&,
	const allocator_type&, false_type)): New.
	(_Hashtable<>(_InputIterator, _InputIterator, size_t, const _H1&,
	const _H2&, const _Hash&, const _Equal&, const _ExtractKey&,
	const allocator_type&)): Delegate to latters.
	(operator=(initializer_list<value_type>)): Rehash if too small.
	(_M_insert(_Arg&&, const _NodeGenerator&, true_type)): Remove
	size_t len parameter.
	* include/bits/hashtable_policy.h (_Insert_base<>::_M_insert_range):
	Do not try to get input range distance.
	* testsuite/23_containers/unordered_set/cons/bucket_hint.cc: New test.
	* testsuite/23_containers/unordered_set/modifiers/insert.cc: New test.
2020-07-28 14:37:16 +02:00
François Dumont
c832cf1c1d libstdc++: Fix [multi]map/[multi]set move constructors noexcept qualification
Container move constructors shall not consider their allocator move
constructor qualification.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tree.h (_Rb_tree_impl(_Rb_tree_impl&&)): Add noexcept
	qualification based only on _Compare one.
	* testsuite/23_containers/map/cons/noexcept_move_construct.cc: Add
	static asserts.
	* testsuite/23_containers/multimap/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/23_containers/multiset/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/23_containers/set/cons/noexcept_move_construct.cc: Likewise.
2020-07-08 08:02:16 +02:00
Jonathan Wakely
b857b17977 libstdc++: Require c++98_only effective target for some tests
These tests verify that including C++11 headers fails to compile in
C++98 mode. They use { dg-options "-std=gnu++98" } so that they are
explicitly run in C++98 mode. This change also adds a target selector so
that the tests will be skipped even if the dg-options directive is
filtered out or overridden. This is in preparation for a desired future
change where tests do not use -std options, so that they can be tested
with e.g. --target_board=unix\"{-std=gnu++17,-std=gnu++20}\"

In some cases the dg-options and dg-do directives need to be reordered,
so that the -std=gnu++98 option is already added to the options before
the target selector is checked.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/headers/cstdalign/std_c++0x_neg.cc: Add
	c++98_only target selector.
	* testsuite/18_support/headers/cstdbool/std_c++0x_neg.cc:
	Likewise.
	* testsuite/18_support/headers/cstdint/std_c++0x_neg.cc:
	Likewise.
	* testsuite/18_support/headers/new/synopsis_cxx98.cc: Likewise.
	* testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc:
	Likewise.
	* testsuite/20_util/headers/type_traits/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/array/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/tuple/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc:
	Likewise.
	* testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/ccomplex/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/cfenv/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++98.cc:
	Likewise.
	* testsuite/26_numerics/headers/ctgmath/std_c++0x_neg.cc:
	Likewise.
	* testsuite/26_numerics/headers/random/std_c++0x_neg.cc:
	Likewise.
	* testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc: Likewise.
	* testsuite/28_regex/headers/regex/std_c++0x_neg.cc: Likewise.
	* testsuite/29_atomics/headers/atomic/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/future/std_c++0x_neg.cc:
	Likewise.
	* testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: Likewise.
	* testsuite/30_threads/headers/thread/std_c++0x_neg.cc:
	Likewise.
2020-07-02 21:27:12 +01:00
Jonathan Wakely
632183ddcc libstdc++: Avoid stack overflow in std::vector (PR 94540)
The std::__uninitialized_default_n algorithm used by std::vector creates
an initial object as a local variable then copies that into the
destination range. If the object is too large for the stack this
crashes. We should create the first object directly into the
destination and then copy it from there.

This doesn't fix the bug for C++98, because in that case the initial
value is created as a default argument of the vector constructor i.e. in
the user's code, not inside libstdc++. We can't prevent that.

	PR libstdc++/94540
	* include/bits/stl_uninitialized.h (__uninitialized_default_1<true>):
	Construct the first value at *__first instead of on the stack.
	(__uninitialized_default_n_1<true>): Likewise.
	Improve comments on several of the non-standard algorithms.
	* testsuite/20_util/specialized_algorithms/uninitialized_default/94540.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_default_n/94540.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94540.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/94540.cc:
	New test.
	* testsuite/23_containers/vector/cons/94540.cc: New test.
2020-06-17 22:49:06 +01:00
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