Commit Graph

267 Commits

Author SHA1 Message Date
Patrick Palka
cc9c94d43d libstdc++: Reduce ranges::minmax/minmax_element comparison complexity
This rewrites ranges::minmax and ranges::minmax_element so that it
performs at most 3*N/2 many comparisons, as required by the standard.
In passing, this also fixes PR100387 by avoiding a premature std::move
in ranges::minmax and in std::shift_right.

	PR libstdc++/100387

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__minmax_fn::operator()): Rewrite
	to limit comparison complexity to 3*N/2.
	(__minmax_element_fn::operator()): Likewise.
	(shift_right): Avoid premature std::move of __result.
	* testsuite/25_algorithms/minmax/constrained.cc (test04, test05):
	New tests.
	* testsuite/25_algorithms/minmax_element/constrained.cc (test02):
	Likewise.
2021-06-18 19:33:39 -04:00
Jonathan Wakely
6fdc59f196 libstdc++: Qualify functions used in tests
These tests rely on ADL for some functions, probably unintentionally.
The calls only work because the iterator wrappers derive from
std::iterator and so namespace std is an associated namespace.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/inplace_merge/constrained.cc: Qualify
	call to ranges::next.
	* testsuite/25_algorithms/is_sorted/constrained.cc: Likewise.
	* testsuite/25_algorithms/is_sorted_until/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/swap_ranges/1.cc: Qualify call to
	swap_ranges.
2021-05-24 18:42:09 +01:00
Jonathan Wakely
d1adbe5c1b libstdc++: Fix some problems in PSTL tests
libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc:
	Increase dg-timeout-factor to 4. Fix -Wunused-parameter
	warnings. Replace bitwise AND with logical AND in loop
	condition.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc:
	Replace bitwise AND with logical AND in loop condition.
	* testsuite/util/pstl/test_utils.h: Remove unused parameter
	names.
2021-05-12 14:51:15 +01:00
Jonathan Wakely
37407a2ae7 libstdc++: Fix tests that fail in C++98 mode
The header synopsis test fails to define NOTHROW for C++98.

The shared_ptr test should be skipped for C++98.

The debug mode one should work for C++98 too, it just needs to avoid
C++11 syntax that isn't valid in C++98.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/headers/memory/synopsis.cc: Define C++98
	alternative for macro.
	* testsuite/20_util/shared_ptr/creation/99006.cc: Add effective
	target keyword.
	* testsuite/25_algorithms/copy/debug/99402.cc: Avoid C++11
	syntax.
2021-05-11 17:21:08 +01:00
Jonathan Wakely
d7b2d92747 libstdc++: Remove redundant -std=gnu++17 option from algorithm tests
GCC defaults to -std=gnu++17 now anyway, and using it explicitly in the
dg-options directive prevents running these tests with different modes
such as -std=c++17 or -std=gnu++20.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/function_objects/searchers.cc: Remove
	-std=gnu++17 from dg-options directive.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/1.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/memory_management_tools/destroy_neg.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94540.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct/94831.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/94540.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/specialized_algorithms/swap_cxx17.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/25_algorithms/for_each/for_each_n.cc: Likewise.
	* testsuite/25_algorithms/for_each/for_each_n_debug.cc:
	Likewise.
	* testsuite/25_algorithms/sample/1.cc: Likewise.
	* testsuite/25_algorithms/sample/2.cc: Likewise.
	* testsuite/25_algorithms/sample/3.cc: Likewise.
	* testsuite/25_algorithms/sample/81221.cc: Likewise.
	* testsuite/25_algorithms/search/searcher.cc: Likewise.
	* testsuite/26_numerics/exclusive_scan/1.cc: Likewise.
	* testsuite/26_numerics/inclusive_scan/1.cc: Likewise.
	* testsuite/26_numerics/reduce/1.cc: Likewise.
	* testsuite/26_numerics/reduce/2.cc: Likewise.
	* testsuite/26_numerics/transform_exclusive_scan/1.cc: Likewise.
	* testsuite/26_numerics/transform_inclusive_scan/1.cc: Likewise.
	* testsuite/26_numerics/transform_reduce/1.cc: Likewise.
2021-05-10 16:22:54 +01:00
Jonathan Wakely
646e6c6524 libstdc++: Remove redundant -std=gnu++17 options from PSTL tests
GCC defaults to -std=gnu++17 now anyway, and using it explicitly in the
dg-options directive prevents running these tests with different modes
such as -std=c++17 or -std=gnu++20.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc:
	Remove -std=gnu++17 from dg-options.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_fill_destroy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/fill.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/generate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/swap_ranges.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/transform_binary.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/transform_unary.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/adjacent_find.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/for_each.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/mismatch.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/includes.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_sorted.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/minmax_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/set.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/sort.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-2.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-3.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-4.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-5.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc:
	Likewise.
2021-05-10 16:22:53 +01:00
Jonathan Wakely
07dd185755 libstdc++: Improve static assert messages
The message used for static assertions should be phrased so that it's
unambiguous whether the condition should be true or false. The message
should definitely not state the negative condition.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algobase.h (__copy_move, __copy_move_backward):
	Improve static_assert messages.
	* testsuite/25_algorithms/copy/58982.cc: Adjust expected output.
	* testsuite/25_algorithms/copy_n/58982.cc: Likewise.
2021-05-06 16:07:10 +01:00
Jonathan Wakely
6fb8b67089 libstdc++ Fix undefined behaviour in testsuite
Fix some test bugs found by ubsan.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/from_chars/3.cc: Use unsigned type to avoid
	overflow.
	* testsuite/24_iterators/reverse_iterator/2.cc: Do not add
	non-zero value to null pointer.
	* testsuite/25_algorithms/copy_backward/move_iterators/69478.cc:
	Use past-the-end iterator for result.
	* testsuite/25_algorithms/move_backward/69478.cc: Likewise.
	* testsuite/25_algorithms/move_backward/93872.cc: Likewise.
2021-05-04 22:34:20 +01:00
François Dumont
cc79682046 libstdc++: [_GLIBCXX_DEBUG] Fix management of __dp_sign_max_size [PR 99402]
__dp_sign precision indicates that we found out what iterator comes first or
last in the range. __dp_sign_max_size is the same plus it gives the information
of the max size of the range that is to say the max_size value such that
distance(lhs, rhs) < max_size.
Thanks to this additional information we are able to tell when a copy of n elements
to that range will fail even if we do not know exactly how large it is.

This patch makes sure that we are properly using this information.

libstdc++-v3/ChangeLog:

	PR libstdc++/99402
	* include/debug/helper_functions.h (__can_advance(_InputIterator,
	const std::pair<_Diff, _Distance_precision>&, int)): New.
	(__can_advance(const _Safe_iterator<>&,
	const std::pair<_Diff, _Distance_precision>&, int)): New.
	* include/debug/macros.h (__glibcxx_check_can_increment_dist): New,
	use latter.
	(__glibcxx_check_can_increment_range): Adapt to use latter.
	(__glibcxx_check_can_decrement_range): Likewise.
	* include/debug/safe_iterator.h
	(_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, _Distance_precision>&,
	int)): New.
	(__can_advance(const _Safe_iterator<>&,
	const std::pair<_Diff, _Distance_precision>&, int)): New.
	* include/debug/safe_iterator.tcc
	(_Safe_iterator<>::_M_can_advance(const std::pair<_Diff, _Distance_precision>&,
	int)): New.
	(_Safe_iterator<>::_M_valid_range(const _Safe_iterator<>&,
	std::pair<difference_type, _Distance_precision>&, bool)): Adapt for
	__dp_sign_max_size.
	(__copy_move_a): Adapt to use __glibcxx_check_can_increment_dist.
	(__copy_move_backward_a): Likewise.
	(__equal_aux): Likewise.
	* include/debug/stl_iterator.h (__can_advance(const std::reverse_iterator<>&,
	const std::pair<_Diff, _Distance_precision>&, int)): New.
	(__can_advance(const std::move_iterator<>&,
	const std::pair<_Diff, _Distance_precision>&, int)): New.
	* testsuite/25_algorithms/copy/debug/99402.cc: New test.
2021-04-09 21:46:35 +02:00
Jakub Jelinek
99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
Jonathan Wakely
e831ad4dab libstdc++: Increase timeout for tests in debug mode
These tests FAIL when testing debug mode with a small tool_timeout
value. Give them a longer relative timeout.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/lexicographical_compare/deque_iterators/1.cc:
	Add dg-timeout-factor directive.
	* testsuite/ext/pb_ds/regression/tree_map_rand_debug.cc:
	Increase timeout factor from 2.0 to 3.0.
	* testsuite/ext/pb_ds/regression/tree_set_rand_debug.cc:
	Likewise.
	* testsuite/lib/libstdc++.exp (check_effective_target_debug-mode):
	Define "debug-mode" as an effective-target keyword.
2020-12-15 15:39:58 +00:00
François Dumont
815eb852a2 libstdc++: Fix _GLIBCXX_DEBUG mode constexpr compatibility
The __glibcxx_check_can_[increment|decrement]_range macros are using the
_GLIBCXX_DEBUG_VERIFY_COND_AT macro which is not constexpr compliant and will produce nasty
diagnostics rather than the std::__failed_assertion dedicated to constexpr. Replace it with
correct _GLIBCXX_DEBUG_VERIFY_AT_F.

libstdc++-v3/ChangeLog:

	* include/debug/macros.h (__glibcxx_check_can_increment_range): Replace
	_GLIBCXX_DEBUG_VERIFY_COND_AT usage with _GLIBCXX_DEBUG_VERIFY_AT_F.
	(__glibcxx_check_can_decrement_range): Likewise.
	* testsuite/25_algorithms/copy_backward/constexpr.cc (test03): New.
	* testsuite/25_algorithms/copy/debug/constexpr_neg.cc: New test.
	* testsuite/25_algorithms/copy_backward/debug/constexpr_neg.cc: New test.
	* testsuite/25_algorithms/equal/constexpr_neg.cc: New test.
	* testsuite/25_algorithms/equal/debug/constexpr_neg.cc: New test.
2020-12-12 18:07:45 +01:00
Jonathan Wakely
b6a8e3479e libstdc++: Set dg-timeout-factor for more slow tests
As in r11-5449, this adds a muliplier to the timeout for slow tests.
This covers the majority of the <regex> and PSTL tests.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/specialized_algorithms/pstl/*: Add
	dg-timeout-factor.
	* testsuite/25_algorithms/pstl/*: Likewise.
	* testsuite/26_numerics/pstl/*: Likewise.
	* testsuite/28_regex/*: Likewise.
2020-11-30 14:39:54 +00:00
François Dumont
ba23e045fc libstdc++: Limit memory allocation in stable_sort/inplace_merge (PR 83938)
Reduce memory allocation in stable_sort/inplace_merge algorithms to what is needed
by the implementation.

Co-authored-by: John Chang  <john.chang@samba.tv>

libstdc++-v3/ChangeLog:

	PR libstdc++/83938
	* include/bits/stl_tempbuf.h (get_temporary_buffer): Change __len
	computation in the loop to avoid truncation.
	* include/bits/stl_algo.h:
	(__inplace_merge): Take temporary buffer length from smallest range.
	(__stable_sort): Limit temporary buffer length.
	* testsuite/25_algorithms/inplace_merge/1.cc (test4): New.
	* testsuite/performance/25_algorithms/stable_sort.cc: Test stable_sort
	under different heap memory conditions.
	* testsuite/performance/25_algorithms/inplace_merge.cc: New test.
2020-11-20 22:25:04 +01:00
Patrick Palka
8661f4faa8 libstdc++: Fix ranges::search_n for random access iterators [PR97828]
My ranges transcription of the std::search_n implementation for random
access iterators missed a crucial part of the algorithm which the
existing tests didn't exercise.  When __remainder is less than __count
at the start of an iteration of the outer while loop, it means we're
continuing a partial match of __count - __remainder elements from the
previous iteration.  If at the end of the iteration we don't complete
this partial match, we need to reset __remainder so that it's only
offset by the size of the most recent partial match before starting the
next iteration.

This patch fixes this appropriately, mirroring how it's done in the
corresponding std::search_n implementation.

libstdc++-v3/ChangeLog:

	PR libstdc++/97828
	* include/bits/ranges_algo.h (__search_n_fn::operator()): Check
	random_access_iterator before using the backtracking
	implementation.  When the backwards scan fails prematurely,
	reset __remainder appropriately.
	* testsuite/25_algorithms/search_n/97828.cc: New test.
2020-11-17 10:28:20 -05:00
François Dumont
38b17c27ce libstdc++: Make _GLIBCXX_DEBUG checks constexpr compatible
libstdc++-v3/ChangeLog:

	* include/debug/assertions.h (__glibcxx_requires_non_empty_range):
	Remove __builtin_expect.
	(__glibcxx_requires_subscript): Likewise.
	(__glibcxx_requires_nonempty): Likewise.
	* include/debug/formatter.h (__check_singular): Add C++11 constexpr
	qualification.
	* include/debug/helper_functions.h (__check_singular): Likewise. Skip
	check if constant evaluated.
	(__valid_range): Do not skip check if constant evaluated.
	* include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Add
	__builtin_expect.
	(_GLIBCXX_DEBUG_VERIFY_AT_F): Use __glibcxx_assert_1.
	* testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
	New test.
	* testsuite/21_strings/basic_string_view/element_access/char/constexpr.cc: New test.
	* testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc: New test.
	* testsuite/21_strings/basic_string_view/element_access/char/front_back_constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
	New test.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc:
	New test.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr.cc: New test.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc: New test.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc:
	New test.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc: New test.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc: New test.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc: New test.
	* testsuite/25_algorithms/lower_bound/debug/partitioned_neg.cc: New test.
	* testsuite/25_algorithms/lower_bound/debug/partitioned_pred_neg.cc: New test.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc: New test.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc: New test.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc: New test.
	* testsuite/25_algorithms/upper_bound/debug/partitioned_neg.cc: New test.
	* testsuite/25_algorithms/upper_bound/debug/partitioned_pred_neg.cc: New test.
2020-11-09 21:11:13 +01:00
Marek Polacek
5b2003105b c++: Implement -Wvexing-parse [PR25814]
This patch implements the -Wvexing-parse warning to warn about the
sneaky most vexing parse rule in C++: the cases when a declaration
looks like a variable definition, but the C++ language requires it
to be interpreted as a function declaration.  This warning is on by
default (like clang++).  From the docs:

  void f(double a) {
    int i();        // extern int i (void);
    int n(int(a));  // extern int n (int);
  }

  Another example:

  struct S { S(int); };
  void f(double a) {
    S x(int(a));   // extern struct S x (int);
    S y(int());    // extern struct S y (int (*) (void));
    S z();         // extern struct S z (void);
  }

You can find more on this in [dcl.ambig.res].

I spent a fair amount of time on fix-it hints so that GCC can recommend
various ways to resolve such an ambiguity.  Sometimes that's tricky.
E.g., suggesting default-initialization when the class doesn't have
a default constructor would not be optimal.  Suggesting {}-init is also
not trivial because it can use an initializer-list constructor if no
default constructor is available (which ()-init wouldn't do).  And of
course, pre-C++11, we shouldn't be recommending {}-init at all.

I also uncovered a bug in cp_parser_declarator, where we were setting
*parenthesized_p to true despite the comment saying the exact opposite.

gcc/c-family/ChangeLog:

	PR c++/25814
	* c.opt (Wvexing-parse): New option.

gcc/cp/ChangeLog:

	PR c++/25814
	* cp-tree.h (enum cp_tree_index): Add CPTI_EXPLICIT_VOID_LIST.
	(explicit_void_list_node): Define.
	(PARENTHESIZED_LIST_P): New macro.
	(struct cp_declarator): Add function::parens_loc.
	* decl.c (cxx_init_decl_processing): Initialize explicit_void_list_node.
	(grokparms): Also break when explicit_void_list_node.
	* parser.c (make_call_declarator): New location_t parameter.  Use it
	to set declarator->u.function.parens_loc.
	(cp_parser_lambda_declarator_opt): Pass UNKNOWN_LOCATION to
	make_call_declarator.
	(warn_about_ambiguous_parse): New function.
	(cp_parser_init_declarator): Call warn_about_ambiguous_parse.
	(cp_parser_declarator): Set *parenthesized_p to false rather than to
	true.
	(cp_parser_direct_declarator): Create a location for the function's
	parentheses and pass it to make_call_declarator.
	(cp_parser_parameter_declaration_clause): Return explicit_void_list_node
	for (void).
	(cp_parser_parameter_declaration_list): Set PARENTHESIZED_LIST_P
	in the parameters tree.

gcc/ChangeLog:

	PR c++/25814
	* doc/invoke.texi: Document -Wvexing-parse.

gcc/testsuite/ChangeLog:

	PR c++/25814
	* g++.dg/cpp2a/fn-template16.C: Add a dg-warning.
	* g++.dg/cpp2a/fn-template7.C: Likewise.
	* g++.dg/lookup/pr80891-5.C: Likewise.
	* g++.dg/lto/pr79050_0.C: Add extern.
	* g++.dg/lto/pr84805_0.C: Likewise.
	* g++.dg/parse/pr58898.C: Add a dg-warning.
	* g++.dg/template/scope5.C: Likewise.
	* g++.old-deja/g++.brendan/recurse.C: Likewise.
	* g++.old-deja/g++.jason/template4.C: Likewise.
	* g++.old-deja/g++.law/arm4.C: Likewise.
	* g++.old-deja/g++.mike/for2.C: Likewise.
	* g++.old-deja/g++.other/local4.C: Likewise.
	* g++.old-deja/g++.pt/crash3.C: Likewise.
	* g++.dg/warn/Wvexing-parse.C: New test.
	* g++.dg/warn/Wvexing-parse2.C: New test.
	* g++.dg/warn/Wvexing-parse3.C: New test.
	* g++.dg/warn/Wvexing-parse4.C: New test.
	* g++.dg/warn/Wvexing-parse5.C: New test.
	* g++.dg/warn/Wvexing-parse6.C: New test.
	* g++.dg/warn/Wvexing-parse7.C: New test.

libstdc++-v3/ChangeLog:

	PR c++/25814
	* testsuite/20_util/reference_wrapper/lwg2993.cc: Add a dg-warning.
	* testsuite/25_algorithms/generate_n/87982_neg.cc: Likewise.
2020-11-05 15:55:14 -05: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
8c84486bba libstdc++: Improve tests for constexpr algorithms
These tests just return true without checking that the results of the
algorithms. Although it should be safe to assume that the algorithms
behave the same at compile-time as at run-time, we can use these tests
to verify it.

This replaces each 'return true' statement with a condition that depends
on the basic functionality of the algorithm, such as returning an
iterator to the right position.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/all_of/constexpr.cc: Check result of
	the algorithm.
	* testsuite/25_algorithms/any_of/constexpr.cc: Likewise.
	* testsuite/25_algorithms/binary_search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: Likewise.
	* testsuite/25_algorithms/count/constexpr.cc: Likewise.
	* testsuite/25_algorithms/equal/constexpr.cc: Likewise.
	* testsuite/25_algorithms/equal_range/constexpr.cc: Likewise.
	* testsuite/25_algorithms/fill/constexpr.cc: Likewise.
	* testsuite/25_algorithms/find_end/constexpr.cc: Likewise.
	* testsuite/25_algorithms/find_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_partitioned/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_permutation/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: Likewise.
	* testsuite/25_algorithms/merge/constexpr.cc: Likewise.
	* testsuite/25_algorithms/mismatch/constexpr.cc: Likewise.
	* testsuite/25_algorithms/none_of/constexpr.cc: Likewise.
	* testsuite/25_algorithms/partition_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_copy_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/remove_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/replace_if/constexpr.cc: Likewise.
	* testsuite/25_algorithms/reverse/constexpr.cc: Likewise.
	* testsuite/25_algorithms/reverse_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/rotate_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_difference/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_intersection/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_union/constexpr.cc: Likewise.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: Likewise.
2020-10-29 14:47:18 +00:00
Patrick Palka
2e0216f9c4 libstdc++: Fix memory issue in ranges::lexicographical_compare testcase
libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/lexicographical_compare/constrained.cc:
	(test03): Fix initializing the vector vy with the array y of size 4.
2020-10-29 10:11:12 -04:00
Patrick Palka
813ad9c4dd libstdc++: Fix division by zero in std::sample
This fixes a division by zero in the selection-sampling std::__sample
overload when the input range is empty (and hence __unsampled_sz is 0).

libstdc++-v3/ChangeLog:

	* include/bits/stl_algo.h (__sample): Exit early when the
	input range is empty.
	* testsuite/25_algorithms/sample/3.cc: New test.
2020-09-21 20:48:23 -04:00
Patrick Palka
f017952d31 libstdc++: Mark some more algorithms constexpr for C++20
As per P0202.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algo.h (for_each_n): Mark constexpr for C++20.
	(search): Likewise for the overload that takes a searcher.
	* testsuite/25_algorithms/for_each/constexpr.cc: Test constexpr
	std::for_each_n.
	* testsuite/25_algorithms/search/constexpr.cc: Test constexpr
	std::search overload that takes a searcher.
2020-09-21 20:48:17 -04:00
Jonathan Wakely
988fb2f597 libstdc++: Skip PSTL tests when installed TBB is too old [PR 96718]
These tests do not actually require TBB, because they only inspect the
feature test macros present in the headers. However, if TBB is installed
then its headers will be included, and the version will be checked. If
the version is too old, compilation fails due to a #error directive.

This change disables the tests if TBB is not present, so that we skip
them instead of failing.

libstdc++-v3/ChangeLog:

	PR libstdc++/96718
	* testsuite/25_algorithms/pstl/feature_test-2.cc: Require
	tbb-backend effective target.
	* testsuite/25_algorithms/pstl/feature_test-3.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-5.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test.cc: Likewise.
2020-08-21 12:01:05 +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
Patrick Palka
a73051a0ea libstdc++: Fix some ranges algos optimizations [PR95578]
ranges::copy and a number of other ranges algorithms have unwrapping
optimizations for iterators of type __normal_iterator, move_iterator and
reverse_iterator.  But in the checks that guard these optimizations we
currently only test that the iterator of the iterator/sentinel pair has
the appropriate type before proceeding with the corresponding
optimization, and do not also test the sentinel type.

This breaks the testcase in this PR because this testcase constructs via
range adaptors a range whose begin() is a __normal_iterator and whose
end() is a custom sentinel type, and then performs ranges::copy on it.
From there we bogusly perform the __normal_iterator unwrapping
optimization on this iterator/sentinel pair, which immediately leads to
a constraint failure since the custom sentinel type does not model
sentinel_for<int*>.

This patch fixes this issue by refining each of the problematic checks
to also test that the iterator and sentinel types are the same before
applying the corresponding unwrapping optimization.  Along the way, some
code simplifications are made.

libstdc++-v3/ChangeLog:

	PR libstdc++/95578
	* include/bits/ranges_algo.h (__lexicographical_compare_fn):
	Also check that the iterator and sentinel have the same type before
	applying the unwrapping optimization for __normal_iterator.
	Split the check into two, one for the first iterator/sentinel
	pair and another for second iterator/sentinel pair.  Remove uses
	of __niter_base, and remove uses of std::move on a
	__normal_iterator.
	* include/bits/ranges_algobase.h (__equal_fn): Likewise.
	(__copy_or_move): Likewise.  Perform similar adjustments for
	the reverse_iterator and move_iterator optimizations.  Inline
	the checks into the if-constexprs, and use using-declarations to
	make them less visually noisy.  Remove uses of __niter_wrap.
	(__copy_or_move_backward): Likewise.
	* testsuite/25_algorithms/copy/95578.cc: New test.
	* testsuite/25_algorithms/copy_backward/95578.cc: New test.
	* testsuite/25_algorithms/equal/95578.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/95578.cc: New test.
	* testsuite/25_algorithms/move/95578.cc: New test.
	* testsuite/25_algorithms/move_backward/95578.cc: New test.
2020-06-10 17:37:53 -04:00
François Dumont
3a391adf7a libstdc++: Extend memcmp optimization in std::lexicographical_compare
Make the memcmp optimization work for std::deque iterators and safe
iterators.

Co-authored-by: Jonathan Wakely  <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

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

	* include/bits/deque.tcc (__lex_cmp_dit): New.
	(__lexicographical_compare_aux1): Define overloads for deque
	iterators.
	* include/bits/stl_algobase.h (__lexicographical_compare::__3way):
	New static member function.
	(__lexicographical_compare<true>::__3way): Likewise.
	(__lexicographical_compare<true>::__lc): Use __3way.
	(__lexicographical_compare_aux): Rename to
	__lexicographical_compare_aux1 and declare overloads for deque
	iterators.
	(__lexicographical_compare_aux): Define new forwarding function
	that calls __lexicographical_compare_aux1 and declare new overloads
	for safe iterators.
	(lexicographical_compare): Do not use __niter_base on
	parameters.
	* include/debug/safe_iterator.tcc
	(__lexicographical_compare_aux): Define overloads for safe
	iterators.
	* testsuite/25_algorithms/lexicographical_compare/1.cc: Add
	checks with random access iterators.
	* testsuite/25_algorithms/lexicographical_compare/deque_iterators/1.cc:
	New test.
2020-06-10 17:48:56 +01:00
François Dumont
4e05c918d2 libstdc++: Specialize copy/copy_n for istreambuf_iterator and deque iterators
Add __copy_n_a overloads for std::deque iterators to replace with C memmove
when possible. Expose std::copy_n implementation details in pre-C++11 modes
and use it for std::copy overloads.

libstdc++-v3/ChangeLog

	* include/bits/stl_algo.h (__copy_n_a): Move to ...
	* include/bits/stl_algobase.h (__copy_n_a): ...here. Add __strict
	parameter.
	(__copy_n_a(istreambuf_iterator<>, _Size, _Deque_iterator<>, bool)):
	Declare.
	(__niter_base(const _Safe_iterator<_Ite, _Seq,
	random_access_iterator_tag>&)): Declare.
	(__copy_move_a2(istreambuf_iterator<>, istreambuf_iterator<>,
	_Deque_iterator<>)): Declare.
	* include/bits/deque.tcc
	(__copy_move_a2(istreambuf_iterator<>, istreambuf_iterator<>,
	_Deque_iterator<>)): New.
	(__copy_n_a(istreambuf_iterator<>, _Size, _Deque_iterator<>, bool)):
	New.
	* include/bits/streambuf_iterator.h
	(__copy_n_a(istreambuf_iterator<>, _Size, _CharT*, bool)): Adapt.
	* include/debug/safe_iterator.tcc (__niter_base): New.
	* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc
	(test03): New.
	* testsuite/25_algorithms/copy/streambuf_iterators/char/debug/deque_neg.cc:
	New test.
	* testsuite/25_algorithms/copy_n/debug/istreambuf_ite_deque_neg.cc:
	New test.
	* testsuite/25_algorithms/copy_n/istreambuf_iterator/2.cc: New test.
	* testsuite/25_algorithms/copy_n/istreambuf_iterator/deque.cc:
	New test.
2020-06-04 22:27:47 +02:00
Jonathan Wakely
e1008cd1d8 libstdc++: Make std::copy_n work with negative and non-integral sizes
Since it was added in C++11, std::copy_n and std::ranges::copy_n should
do nothing given a negative size, but for random access iterators we add
the size to the iterator, possibly resulting in undefined behaviour.

Also, C++20 clarified that std::copy_n requires the Size type to be
convertible to an integral type. We previously assumed that it could be
directly used in arithmetic expressions, without conversion to an
integral type.

This also fixes a bug in the random_access_iterator_wrapper helper adds
some convenience aliases for using the iterator wrappers.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algobase.h (__copy_n_fn): Only call
	ranges::copy for positive values.
	* include/bits/stl_algo.h (copy_n): Convert Size argument to an
	integral type and only call __copy_n for positive values.
	* testsuite/util/testsuite_iterators.h
	(random_access_iterator_wrapper::operator+=): Fix range check for
	negative values.
	(output_container, input_container, forward_container)
	(bidirectional_container, random_access_container): New alias
	templates.
	* testsuite/25_algorithms/copy_n/5.cc: New test.
2020-06-04 14:21:34 +01:00
Jonathan Wakely
3cb0c7cc16 libstdc++: Fix function that can't be constexpr in C++11 (PR 95289)
The body of this function isn't just a return statement, so it can't be
constexpr until C++14.

	PR libstdc++/95289
	* include/debug/helper_functions.h (__get_distance): Only declare
	as a constexpr function for C++14 and up.
	* testsuite/25_algorithms/copy/debug/95289.cc: New test.
2020-05-23 18:27:35 +01:00
François Dumont
72a54e5e81 libstdc++ std::fill overload for std::vector<bool>::iterator
Extend the overload so that it is used even when _GLIBCXX_DEBUG mode
is activated.

	* include/bits/stl_algobase.h (struct _Bit_iterator): New declaration.
	(std::__fill_a1(_Bit_iterator, _Bit_iterator, const bool&)): Likewise.
	* include/bits/stl_bvector.h (__fill_bvector): Move outside
	_GLIBCXX_STD_C namespace.
	(fill(_Bit_iterator, _Bit_iterator, const bool&)): Likewise and rename
	into...
	(__fill_a1): ...this.
	* testsuite/25_algorithms/fill/bvector/1.cc: New.
2020-05-06 23:28:22 +02:00
Jonathan Wakely
22b6b5d6cf libstdc++: Make byte-sized std::fill_n a constant expression (PR 94933)
The overload for byte types uses memset and isn't constexpr. This adds
the specifier and uses std::is_constant_evaluated() to provide a
compile-time alternative.

	PR libstdc++/94933
	* include/bits/stl_algobase.h (__fill_a1): Make overload for byte types
	usable in constant expressions.
	* testsuite/25_algorithms/fill_n/constexpr.cc: Test with bytes and
	non-scalars.
2020-05-03 13:33:15 +01:00
Jonathan Wakely
aac39307e8 libstdc++: Define __cpp_lib_execution feature test macro
This macro has never been defined by libstdc++, despite supporting the
parallel algorithms. It should have a different value for C++17 and
C++20, because P1001R2 should not be supported in C++17, but
unsequenced_policy is defined for C++17 (see PR p4702).

	* include/std/execution (__cpp_lib_execution): Define to indicate
	support for P0024R2 and P1001R2.
	* include/std/version (__cpp_lib_execution): Define.
	* testsuite/25_algorithms/pstl/feature_test.cc: Only test macro
	defined by <algorithm>, move other tests to new tests ...
	* testsuite/25_algorithms/pstl/feature_test-2.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-3.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-4.cc: New test.
	* testsuite/25_algorithms/pstl/feature_test-5.cc: New test.
2020-04-22 22:54:35 +01:00
Patrick Palka
712b182a8b libstdc++: Fix incorrect use of memset in ranges::fill_n (PR 94017)
When deciding whether to perform the memset optimization in ranges::fill_n, we
were crucially neglecting to check that the output pointer's value type is a
byte type.  This patch adds such a check to the problematic condition in
ranges::fill_n.

At the same time, this patch relaxes the overly conservative
__is_byte<_Tp>::__value check that requires the fill type be a byte type.  It's
overly conservative because it means we won't enable the memset optimization in
the following example

  char c[100];
  ranges::fill(c, 37);

because the fill type is deduced to be int here.  Rather than requiring that the
fill type be a byte type, it seems safe to just require the fill type be an
integral type, which is what this patch does.

libstdc++-v3/ChangeLog:

	PR libstdc++/94017
	* include/bits/ranges_algobase.h (__fill_n_fn::operator()): Refine
	condition for when to use memset, making sure to additionally check that
	the output pointer's value type is a non-volatile byte type.  Instead of
	requiring that the fill type is a byte type, just require that it's an
	integral type.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill/94017.cc:
	New test.
	* testsuite/20_util/specialized_algorithms/uninitialized_fill_n/94017.cc:
	New test.
	* testsuite/25_algorithms/fill/94013.cc: Uncomment part that was blocked
	by PR 94017.
	* testsuite/25_algorithms/fill/94017.cc: New test.
	* testsuite/25_algorithms/fill_n/94017.cc: New test.
2020-03-03 22:46:39 -05:00
Jonathan Wakely
462f6c2041 libstdc++: Workaround is_trivially_copyable<volatile T> (PR 94013)
Several algorithms check the is_trivially_copyable trait to decide
whether to dispatch to memmove or memcmp as an optimization. Since
r271435 (CWG DR 2094) the trait is true for volatile-qualified scalars,
but we can't use memmove or memcmp when the type is volatile. We need to
also check for volatile types.

This is complicated by the fact that in C++20 (but not earlier standards)
iterator_traits<volatile T*>::value_type is T, so we can't just check
whether the value_type is volatile.

The solution in this patch is to introduce new traits __memcpyable and
__memcmpable which combine into a single trait the checks for pointers,
the value types being the same, and the type being trivially copyable
but not volatile-qualified.

	PR libstdc++/94013
	* include/bits/cpp_type_traits.h (__memcpyable, __memcmpable): New
	traits to control when to use memmove and memcmp optimizations.
	(__is_nonvolatile_trivially_copyable): New helper trait.
	* include/bits/ranges_algo.h (__lexicographical_compare_fn): Do not
	use memcmp optimization with volatile data.
	* include/bits/ranges_algobase.h (__equal_fn): Use __memcmpable.
	(__copy_or_move, __copy_or_move_backward): Use __memcpyable.
	* include/bits/stl_algobase.h (__copy_move_a2): Use __memcpyable.
	(__copy_move_backward_a2): Likewise.
	(__equal_aux1): Use __memcmpable.
	(__lexicographical_compare_aux): Do not use memcmp optimization with
	volatile data.
	* testsuite/25_algorithms/copy/94013.cc: New test.
	* testsuite/25_algorithms/copy_backward/94013.cc: New test.
	* testsuite/25_algorithms/equal/94013.cc: New test.
	* testsuite/25_algorithms/fill/94013.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/94013.cc: New test.
	* testsuite/25_algorithms/move/94013.cc: New test.
	* testsuite/25_algorithms/move_backward/94013.cc: New test.
2020-03-03 21:39:19 +00:00
Jonathan Wakely
d112e173ea libstdc++: Fix std::lexicographic_compare for unsigned char (PR 93972)
The new 25_algorithms/lexicographical_compare/93972.cc test fails on
targets where char is unsigned, revealing an existing regression with
the std::__memcmp helper that had gone unnoticed in
std::lexicographical_compare. When comparing char and unsigned char, the
memcmp optimisation is enabled, but the new std::__memcmp function fails
to compile for mismatched types.

	PR libstdc++/93972
	* include/bits/stl_algobase.h (__memcmp): Allow pointer types to
	differ.
	* testsuite/25_algorithms/lexicographical_compare/uchar.cc: New test.
2020-03-02 17:03:28 +00:00
Patrick Palka
ce33801fe4 libstdc++: Fix bogus use of memcmp in ranges::lexicographical_compare (PR 93972)
We were enabling the memcmp optimization in ranges::lexicographical_compare for
signed integral types and for integral types wider than a byte.  But memcmp
gives the wrong answer for arrays of such types.  This patch fixes this issue by
refining the condition that enables the memcmp optimization.  It's now
consistent with the corresponding condition used in
std::lexicographical_compare.

libstdc++-v3/ChangeLog:

	PR libstdc++/93972
	* include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
	Fix condition for when to use memcmp, making it consistent with the
	corresponding condition used in std::lexicographical_compare.
	* testsuite/25_algorithms/lexicographical_compare/93972.cc: New test.
2020-02-28 17:55:44 -05:00
Patrick Palka
10a32d4798 libstdc++: -D_GLIBCXX_DEBUG fixes in the constrained algos tests
This fixes the failures in the constrained algos tests when they are run in
debug mode.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/copy/constrained.cc: Don't assume that the
	base() of a vector<>::iterator is a pointer.
	* testsuite/25_algorithms/copy_backward/constrained.cc: Likewise.
	* testsuite/25_algorithms/move/constrained.cc: Likewise.
	* testsuite/25_algorithms/move_backward/constrained.cc: Likewise.
	* testsuite/25_algorithms/inplace_merge/constrained.cc: Use foo.data()
	instead of &foo[0].
	* testsuite/25_algorithms/partial_sort/constrained.cc: Likewise.
	* testsuite/25_algorithms/partial_sort_copy/constrained.cc: Likewise.
	* testsuite/25_algorithms/shuffle/constrained.cc: Likewise.
	* testsuite/25_algorithms/sort/constrained.cc: Likewise.
	* testsuite/25_algorithms/stable_sort/constrained.cc: Likewise.
2020-02-27 12:47:17 -05:00
Jonathan Wakely
eb8e6a30a4 libstdc++: Make _GLIBCXX_CONCEPT_CHECKS more constexpr-friendly
Although most of the old-style "concept checks" are only really usable
with C++98 because they enforce the wrong things, this is a simple
change that makes them a bit more useful for C++14 and up.

	* include/bits/boost_concept_check.h (__function_requires): Add
	_GLIBCXX14_CONSTEXPR.
	* testsuite/25_algorithms/min/concept_checks.cc: New test.
2020-02-27 10:52:28 +00:00
Jonathan Wakely
490350a11f libstdc++: Remove __memmove wrapper for constexpr algorithms
The mutating sequence algorithms std::copy, std::copy_backward,
std::move and std::move_backward conditionally use __builtin_memmove
for trivially copyable types. However, because memmove isn't usable in
constant expressions the use of __builtin_memmove is wrapped in a
__memmove function which replaces __builtin_memmove with a handwritten
loop when std::is_constant_evaluated() is true.

This means we have a manual loop for non-trivially copyable cases, and a
different manual loop for trivially copyable but constexpr cases. The
latter loop has incorrect semantics for the {copy,move}_backward cases
and so isn't used for them. Until earlier today the latter loop also had
incorrect semantics for the std::move cases, trying to move from const
rvalues.

The approach taken by this patch is to remove the __memmove function
entirely and use the original (and correct) manual loops for the
constexpr cases as well as the non-trivially copyable cases. This was
already done for move_backward and copy_backward, but was incorrectly
turning copy_backward into move_backward, by failing to use the _IsMove
constant to select the right specialization. This patch also fixes that.

	* include/bits/ranges_algobase.h (__copy_or_move): Do not use memmove
	during constant evaluation. Call __builtin_memmove directly instead of
	__memmove.
	(__copy_or_move_backward): Likewise.
	* include/bits/stl_algobase.h (__memmove): Remove.
	(__copy_move<M, true, random_access_iterator_tag>::__copy_m)
	(__copy_move_backward<M, true, random_access_iterator_tag>::__copy_m):
	Use __builtin_memmove directly instead of __memmove.
	(__copy_move_a2): Do not use memmove during constant evaluation.
	(__copy_move_backward_a2): Use _IsMove constant to select correct
	__copy_move_backward specialization.
	* testsuite/25_algorithms/copy_backward/constexpr.cc: Check for copies
	begin turned into moves during constant evaluation.
2020-02-25 17:01:50 +00:00
Jonathan Wakely
6de946e65c libstdc++: Add test accidentally left out of previous commit
* testsuite/25_algorithms/move_backward/93872.cc: Add test left out of
	previous commit.
2020-02-25 12:42:03 +00:00
Jonathan Wakely
5b904f175f libstdc++: Fix regression in std::move algorithm (PR 93872)
The std::move and std::move_backward algorithms dispatch to the
std::__memmove helper when appropriate. That function uses a
pointer-to-const for the source values, preventing them from being
moved. The two callers of that function have the same problem.

Rather than altering __memmove and its callers to work with const or
non-const source pointers, this takes a more conservative approach of
casting away the const at the point where we want to do a move
assignment. This relies on the fact that we only use __memmove when the
type is trivially copyable, so we know the move assignment doesn't alter
the source anyway.

	PR libstdc++/93872
	* include/bits/stl_algobase.h (__memmove): Cast away const before
	doing move assignment.
	* testsuite/25_algorithms/move/93872.cc: New test.
	* testsuite/25_algorithms/move_backward/93872.cc: New test.
2020-02-25 12:21:44 +00:00
Patrick Palka
c5eab4ed45 libstdc++: P0769R2 Add shift to <algorithm>
This patch adds std::shift_left and std::shift_right as per P0769R2.  Alhough
these are STL-style algos, this patch places them in <bits/ranges_algo.h>
because they make use of some functions in the ranges namespace that are more
easily reachable from <bits/ranges_algo.h> than from <bits/stl_algo.h>, namely
ranges::next.  In order to place these algos in <bits/stl_algo.h>, we would need
to include <bits/range_access.h> from <bits/stl_algo.h> which would undesirably
increase the size of <bits/stl_algo.h>.

libstdc++-v3/ChangeLog:

	P0769R2 Add shift to <algorithm>
	* include/bits/ranges_algo.h (shift_left, shift_right): New.
	* testsuite/25_algorithms/shift_left/1.cc: New test.
	* testsuite/25_algorithms/shift_right/1.cc: New test.
2020-02-24 10:08:57 -05:00
Patrick Palka
aa667c3f36 libstdc++: P2106R0 Alternative wording for GB315 and GB316
libstdc++-v3/ChangeLog:

	P2106R0 Alternative wording for GB315 and GB316
	* include/bits/ranges_algo.h (in_fun_result): New.
	(for_each_result, for_each_n_result): Change into an alias of
	in_fun_result.
	(in_in_result): New.
	(mismatch_result): Change into an alias of in_in_result.
	(copy_if_result): Change into an alias of in_out_result.
	(swap_ranges_result): Change into an alias of in_in_result.
	(unary_transform_result): Change into an alias of in_out_result.
	(in_in_out_result): New.
	(binary_transform_result): Change into an alias of in_in_out_result.
	(replace_copy_result, replace_copy_if_result, remove_copy_if_result,
	remove_copy_result, unique_copy_result, reverse_copy_result,
	rotate_copy_result, partial_sort_copy_result): Change into an alias of
	in_out_result.
	(in_out_out_result): New.
	(partition_copy_result, merge_result): Change into an alias of
	in_out_out_result.
	(set_union_result, set_intersection_result): Change into an alias of
	in_in_out_result.
	(set_difference_result): Change into an alias of in_out_result.
	(set_symmetric_difference): Change into an alias of in_in_out_result.
	(min_max_result): New.
	(minmax_result, minmax_element_result): Change into an alias of
	min_max_result.
	(in_found_result): New.
	(next_permutation_result, prev_permutation_result): Change into an alias
	of in_found_result.
	(__next_permutation_fn::operator(), __prev_permutation_fn::operator()):
	Adjust following changes to next_permutation_result and
	prev_permutation_result.
	* include/bits/ranges_algobase.h (in_out_result): New.
	(copy_result, move_result, move_backward_result, copy_backward_result,
	copy_n_result): Change into an alias of in_out_result.
	* include/bits/ranges_uninitialized.h (uninitialized_copy_result,
	uninitialized_copy_n_result, uninitialized_move_result,
	uninitialized_move_n_result): Likewise.
	* testsuite/25_algorithms/next_permutation/constrained.cc: Adjust uses of
	structured bindings.
	* testsuite/25_algorithms/prev_permutation/constrained.cc: Likewise.
2020-02-18 11:06:50 -05:00
Patrick Palka
f316994199 libstdc++: P1243R4 Rangify new algorithms
This adds rangified overloads for for_each_n, sample and clamp as per P1243R4.

libstdc++-v3/ChangeLog:

	P1243R4 Rangify new algorithms
	* include/bits/ranges_algo.h (for_each_n_result, __for_each_n_fn,
	for_each_n, __sample_fn, sample, __clamp_fn, clamp): New.
	* testsuite/25_algorithms/clamp/constrained.cc: New test.
	* testsuite/25_algorithms/for_each/constrained.cc: Augment test.
	* testsuite/25_algorithms/sample/constrained.cc: New test.
2020-02-18 11:06:49 -05:00
Patrick Palka
bc4646410a libstdc++: Implement C++20 constrained algorithms
This patch implements the C++20 ranges overloads for the algorithms in
[algorithms].  Most of the algorithms were reimplemented, with each of their
implementations very closely following the existing implementation in
bits/stl_algo.h and bits/stl_algobase.h.  The reason for reimplementing most of
the algorithms instead of forwarding to their STL-style overload is because
forwarding cannot be conformantly and efficiently performed for algorithms that
operate on non-random-access iterators.  But algorithms that operate on random
access iterators can safely and efficiently be forwarded to the STL-style
implementation, and this patch does so for push_heap, pop_heap, make_heap,
sort_heap, sort, stable_sort, nth_element, inplace_merge and stable_partition.

What's missing from this patch is debug-iterator and container specializations
that are present for some of the STL-style algorithms that need to be ported
over to the ranges algos.  I marked them missing at TODO comments.  There are
also some other minor outstanding TODOs.

The code that could use the most thorough review is ranges::__copy_or_move,
ranges::__copy_or_move_backward, ranges::__equal and
ranges::__lexicographical_compare.  In the tests, I tried to test the interface
of each new overload, as well as the correctness of the new implementation.

libstdc++-v3/ChangeLog:

	Implement C++20 constrained algorithms
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/std/algorithm: Include <bits/ranges_algo.h>.
	* include/bits/ranges_algo.h: New file.
	* testsuite/25_algorithms/adjacent_find/constrained.cc: New test.
	* testsuite/25_algorithms/all_of/constrained.cc: New test.
	* testsuite/25_algorithms/any_of/constrained.cc: New test.
	* testsuite/25_algorithms/binary_search/constrained.cc: New test.
	* testsuite/25_algorithms/copy/constrained.cc: New test.
	* testsuite/25_algorithms/copy_backward/constrained.cc: New test.
	* testsuite/25_algorithms/copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/copy_n/constrained.cc: New test.
	* testsuite/25_algorithms/count/constrained.cc: New test.
	* testsuite/25_algorithms/count_if/constrained.cc: New test.
	* testsuite/25_algorithms/equal/constrained.cc: New test.
	* testsuite/25_algorithms/equal_range/constrained.cc: New test.
	* testsuite/25_algorithms/fill/constrained.cc: New test.
	* testsuite/25_algorithms/fill_n/constrained.cc: New test.
	* testsuite/25_algorithms/find/constrained.cc: New test.
	* testsuite/25_algorithms/find_end/constrained.cc: New test.
	* testsuite/25_algorithms/find_first_of/constrained.cc: New test.
	* testsuite/25_algorithms/find_if/constrained.cc: New test.
	* testsuite/25_algorithms/find_if_not/constrained.cc: New test.
	* testsuite/25_algorithms/for_each/constrained.cc: New test.
	* testsuite/25_algorithms/generate/constrained.cc: New test.
	* testsuite/25_algorithms/generate_n/constrained.cc: New test.
	* testsuite/25_algorithms/heap/constrained.cc: New test.
	* testsuite/25_algorithms/includes/constrained.cc: New test.
	* testsuite/25_algorithms/inplace_merge/constrained.cc: New test.
	* testsuite/25_algorithms/is_partitioned/constrained.cc: New test.
	* testsuite/25_algorithms/is_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/is_sorted/constrained.cc: New test.
	* testsuite/25_algorithms/is_sorted_until/constrained.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/constrained.cc: New
	test.
	* testsuite/25_algorithms/lower_bound/constrained.cc: New test.
	* testsuite/25_algorithms/max/constrained.cc: New test.
	* testsuite/25_algorithms/max_element/constrained.cc: New test.
	* testsuite/25_algorithms/merge/constrained.cc: New test.
	* testsuite/25_algorithms/min/constrained.cc: New test.
	* testsuite/25_algorithms/min_element/constrained.cc: New test.
	* testsuite/25_algorithms/minmax/constrained.cc: New test.
	* testsuite/25_algorithms/minmax_element/constrained.cc: New test.
	* testsuite/25_algorithms/mismatch/constrained.cc: New test.
	* testsuite/25_algorithms/move/constrained.cc: New test.
	* testsuite/25_algorithms/move_backward/constrained.cc: New test.
	* testsuite/25_algorithms/next_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/none_of/constrained.cc: New test.
	* testsuite/25_algorithms/nth_element/constrained.cc: New test.
	* testsuite/25_algorithms/partial_sort/constrained.cc: New test.
	* testsuite/25_algorithms/partial_sort_copy/constrained.cc: New test.
	* testsuite/25_algorithms/partition/constrained.cc: New test.
	* testsuite/25_algorithms/partition_copy/constrained.cc: New test.
	* testsuite/25_algorithms/partition_point/constrained.cc: New test.
	* testsuite/25_algorithms/prev_permutation/constrained.cc: New test.
	* testsuite/25_algorithms/remove/constrained.cc: New test.
	* testsuite/25_algorithms/remove_copy/constrained.cc: New test.
	* testsuite/25_algorithms/remove_copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/remove_if/constrained.cc: New test.
	* testsuite/25_algorithms/replace/constrained.cc: New test.
	* testsuite/25_algorithms/replace_copy/constrained.cc: New test.
	* testsuite/25_algorithms/replace_copy_if/constrained.cc: New test.
	* testsuite/25_algorithms/replace_if/constrained.cc: New test.
	* testsuite/25_algorithms/reverse/constrained.cc: New test.
	* testsuite/25_algorithms/reverse_copy/constrained.cc: New test.
	* testsuite/25_algorithms/rotate/constrained.cc: New test.
	* testsuite/25_algorithms/rotate_copy/constrained.cc: New test.
	* testsuite/25_algorithms/search/constrained.cc: New test.
	* testsuite/25_algorithms/search_n/constrained.cc: New test.
	* testsuite/25_algorithms/set_difference/constrained.cc: New test.
	* testsuite/25_algorithms/set_intersection/constrained.cc: New test.
	* testsuite/25_algorithms/set_symmetric_difference/constrained.cc: New
	test.
	* testsuite/25_algorithms/set_union/constrained.cc: New test.
	* testsuite/25_algorithms/shuffle/constrained.cc: New test.
	* testsuite/25_algorithms/sort/constrained.cc: New test.
	* testsuite/25_algorithms/stable_partition/constrained.cc: New test.
	* testsuite/25_algorithms/stable_sort/constrained.cc: New test.
	* testsuite/25_algorithms/swap_ranges/constrained.cc: New test.
	* testsuite/25_algorithms/transform/constrained.cc: New test.
	* testsuite/25_algorithms/unique/constrained.cc: New test.
	* testsuite/25_algorithms/unique_copy/constrained.cc: New test.
	* testsuite/25_algorithms/upper_bound/constrained.cc: New test.
2020-02-06 20:08:34 -05:00
Jonathan Wakely
78f02e8003 libstdc++: Fix testcase for C++98 compatibility
* testsuite/25_algorithms/equal/deque_iterators/1.cc: Don't use C++11
	initialization syntax.

From-SVN: r280117
2020-01-10 15:27:50 +00:00
Jakub Jelinek
8d9254fc8a Update copyright years.
From-SVN: r279813
2020-01-01 12:51:42 +01:00
François Dumont
6004c17b4d libstdc++: Rework std::copy/copy_backward/move/move_backward/fill/fill_n algos
Enhance those algos overloads to generalize existing optimization for
__gnu_debug::_Safe_iterator w/o _GLIBCXX_DEBUG mode and for std::deque
 iterators.

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

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

From-SVN: r279201
2019-12-10 21:49:55 +00:00
Jonathan Wakely
f1355c8dda libstdc++: Define std::lexicographical_compare_three_way for C++20
* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Define for C++20.
	* testsuite/25_algorithms/lexicographical_compare_three_way/1.cc: New
	test.
	* testsuite/25_algorithms/lexicographical_compare_three_way/
	constexpr.cc: New test.

From-SVN: r278996
2019-12-05 12:46:50 +00:00
François Dumont
af4e8d4d5a libstdc++: Improve _GLIBCXX_DEBUG __valid_range check
Adds iterator singular check within the valid range check.

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

From-SVN: r278658
2019-11-24 17:09:44 +00:00