Commit Graph

205 Commits

Author SHA1 Message Date
Jakub Jelinek
254a858ae7 Update copyright years. 2026-01-02 09:56:11 +01:00
Patrick Palka
2d3142c009 libstdc++: Correctly implement LWG 3946 changes to const_iterator_t [PR122842]
LWG 3946 made const_iterator_t/sentinel_t agree with ranges::cbegin/cend
by defining the aliases in terms of the CPOs, but I defined it the other
way around in an incorrect way that made the aliases not consider
range-ness of const T via __possibly_const_range.  This patch
reimplements the proposed resolution in a more obviously correct way,
mirroring the wording.

	PR libstdc++/122842

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__access:_CBegin): Define in
	terms of const_iterator directly, not const_iterator_t.
	(__access::_CEnd): Likewise in terms of const_sentinel vs
	const_sentinel_t.
	(const_iterator_t): Move down definition and define in terms
	of ranges::cbegin as per LWG 3946.
	(const_sentinel_t): Likewise in terms of ranges::cend.
	* testsuite/24_iterators/const_iterator/1.cc (test02): Correct
	test for int[], std::array and std::vector.  Also test
	std::string.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-11-28 15:38:04 -05:00
Jonathan Wakely
02797a4eeb libstdc++: Avoid incrementing input iterators with std::prev [PR122224]
As explained in PR libstdc++/122224 we do not make it ill-formed to call
std::prev with a non-Cpp17BidirectionalIterator. Instead we just use a
runtime assertion to check the std::advance precondition that the
distance is not negative.

This allows us to support std::prev on types which model the C++20
std::bidirectional_iterator concept but do not meet the
Cpp17BidirectionalIterator requirements, e.g. iota_view's iterators.

It also allows us to support std::prev(iter, -1) which is admittedly
weird, but there's no reason it shouldn't be equivalent to
std::next(iter), which is perfectly fine to use on non-bidirectional
iterators. In other words, "reverse decrementing" is valid for
non-bidirectional iterators.

However, the current implementation of std::advance for
non-bidirectional iterators uses a loop that does `while (n--) ++i;`
which assumes that n is not negative and so will eventually reach zero.
When the assertion for the precondition is not enabled, incrementing the
iterator while n is non-zero means that using std::prev(iter) or
std::next(iter, -1) on a non-bidirectional iterator will keep
incrementing the iterator until n reaches INT_MIN, overflows, and then
keeps decrementing until it eventually reaches zero. Incrementing most
iterators that many times will cause memory safety errors long before
the integer reaches zero and terminates the loop.

This commit changes the loop to use `while (n-- > 0)` which means that
the loop doesn't execute at all if a negative n is used. We still
consider such calls to be erroneous, but when the precondition isn't
checked by an assertion, the function now has no effects. The undefined
behaviour resulting from incrementing the iterator is prevented.

libstdc++-v3/ChangeLog:

	PR libstdc++/122224
	* include/bits/stl_iterator_base_funcs.h (prev): Compare
	distance as n > 0 instead of n != 0.
	* testsuite/24_iterators/range_operations/122224.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-10-22 14:48:04 +01:00
Jonathan Wakely
7b99d184bc libstdc++: Fix algorithms to use iterators' difference_type for arithmetic [PR121890]
Whenever we use operator+ or similar operators on random access
iterators we need to be careful to use the iterator's difference_type
rather than some other integer type. It's not guaranteed that an
expression with an arbitrary integer type, such as `it + 1u`, has the
same effects as `it + iter_difference_t<It>(1)`.

Some of our algorithms need changes to cast values to the correct type,
or to use std::next or ranges::next instead of `it + n`. Several tests
also need fixes where the arithmetic occurs directly in the test.

The __gnu_test::random_access_iterator_wrapper class template is
adjusted to have deleted operators that make programs ill-formed if the
argument to relevant operators is not the difference_type. This will
make it easier to avoid regressing in future.

libstdc++-v3/ChangeLog:

	PR libstdc++/121890
	* include/bits/ranges_algo.h (ranges::rotate, ranges::shuffle)
	(__insertion_sort, __unguarded_partition_pivot, __introselect):
	Use ranges::next to advance iterators. Use local variables in
	rotate to avoid duplicate expressions.
	(ranges::push_heap, ranges::pop_heap, ranges::partial_sort)
	(ranges::partial_sort_copy): Use ranges::prev.
	(__final_insertion_sort): Use iter_difference_t<Iter>
	for operand of operator+ on iterator.
	* include/bits/ranges_base.h (ranges::advance): Use iterator's
	difference_type for all iterator arithmetic.
	* include/bits/stl_algo.h (__search_n_aux, __rotate)
	(__insertion_sort, __unguarded_partition_pivot, __introselect)
	(__final_insertion_sort, for_each_n, random_shuffle): Likewise.
	Use local variables in __rotate to avoid duplicate expressions.
	* include/bits/stl_algobase.h (__fill_n_a, __lc_rai::__newlast1):
	Likewise.
	* include/bits/stl_heap.h (push_heap): Likewise.
	(__is_heap_until): Add static_assert.
	(__is_heap): Convert distance to difference_type.
	* include/std/functional (boyer_moore_searcher::operator()): Use
	iterator's difference_type for iterator arithmetic.
	* testsuite/util/testsuite_iterators.h
	(random_access_iterator_wrapper): Add deleted overloads of
	operators that should be called with difference_type.
	* testsuite/24_iterators/range_operations/advance.cc: Use
	ranges::next.
	* testsuite/25_algorithms/heap/constrained.cc: Use ranges::next
	and ranges::prev.
	* testsuite/25_algorithms/nth_element/58800.cc: Use std::next.
	* testsuite/25_algorithms/nth_element/constrained.cc: Use
	ptrdiff_t for loop variable.
	* testsuite/25_algorithms/nth_element/random_test.cc: Use
	iterator's difference_type instead of int.
	* testsuite/25_algorithms/partial_sort/check_compare_by_value.cc:
	Use std::next.
	* testsuite/25_algorithms/partial_sort/constrained.cc: Use
	ptrdiff_t for loop variable.
	* testsuite/25_algorithms/partial_sort/random_test.cc: Use
	iterator's difference_type instead of int.
	* testsuite/25_algorithms/partial_sort_copy/constrained.cc:
	Use ptrdiff_t for loop variable.
	* testsuite/25_algorithms/partial_sort_copy/random_test.cc:
	Use iterator's difference_type instead of int.
	* testsuite/std/ranges/adaptors/drop.cc: Use ranges::next.
	* testsuite/25_algorithms/fill_n/diff_type.cc: New test.
	* testsuite/25_algorithms/lexicographical_compare/diff_type.cc:
	New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-12 21:46:48 +01:00
Tomasz Kamiński
8c2b3377a2 libstdc++: Restore call to test6642 in string_vector_iterators.cc test [PR104874]
The test call was accidentally omitted in r16-2484-gdc49c0a46ec96e,
a commit that refactored this test file. This patch adds it back.

	PR libstdc++/104874

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/random_access/string_vector_iterators.cc:
	Call test6642.
2025-08-19 11:03:15 +02:00
Jonathan Wakely
86dc3b61c3 libstdc++: Teach std::distance and std::advance about C++20 iterators [PR102181]
When the C++98 std::distance and std::advance functions (and C++11
std::next and std::prev) are used with C++20 iterators there can be
unexpected results, ranging from compilation failure to decreased
performance to undefined behaviour.

An iterator which satisfies std::input_iterator but does not meet the
Cpp17InputIterator requirements might have std::output_iterator_tag for
its std::iterator_traits<I>::iterator_category, which means it currently
cannot be used with std::advance at all. However, the implementation of
std::advance for a Cpp17InputIterator doesn't do anything that isn't
valid for iterator types satsifying C++20 std::input_iterator.

Similarly, a type satisfying C++20 std::bidirectional_iterator might be
usable with std::prev, if it weren't for the fact that its C++17
iterator_category is std::input_iterator_tag.

Finally, a type satisfying C++20 std::random_access_iterator might use a
slower implementation for std::distance or std::advance if its C++17
iterator_category is not std::random_access_iterator_tag.

This commit adds a __promotable_iterator concept to detect C++20
iterators which explicitly define an iterator_concept member, and which
either have no iterator_category, or their iterator_category is weaker
than their iterator_concept. This is used by std::distance and
std::advance to detect iterators which should dispatch based on their
iterator_concept instead of their iterator_category. This means that
those functions just work and do the right thing for C++20 iterators
which would otherwise fail to compile or have suboptimal performance.

This is related to LWG 3197, which considers making it undefined to use
std::prev with types which do not meet the Cpp17BidirectionalIterator
requirements.  I think making it work, as in this commit, is a better
solution than banning it (or rejecting it at compile-time as libc++
does).

	PR libstdc++/102181

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator_base_funcs.h (distance, advance):
	Check C++20 iterator concepts and handle appropriately.
	(__detail::__iter_category_converts_to_concept): New concept.
	(__detail::__promotable_iterator): New concept.
	* testsuite/24_iterators/operations/cxx20_iterators.cc: New
	test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-28 17:04:04 +02:00
Nathaniel Shead
f1872cc05b c++: Unwrap type traits defined in terms of builtins within diagnostics [PR117294]
Currently, concept failures of standard type traits just report
'expression X<T> evaluates to false'.  However, many type traits are
actually defined in terms of compiler builtins; we can do better here.
For instance, 'is_constructible_v' could go on to explain why the type
is not constructible, or 'is_invocable_v' could list potential
candidates.

Apart from concept diagnostics, this is also useful when using such
traits in a 'static_assert' directly, so this patch also adjusts the
diagnostics in that context.

As a first step to supporting that we need to be able to map the
standard type traits to the builtins that they use.  Rather than adding
another list that would need to be kept up-to-date whenever a builtin is
added, this patch instead tries to detect any variable template defined
directly in terms of a TRAIT_EXPR.

This patch also adjusts 'diagnose_trait_expr' to provide more helpful
diagnostics for these cases.  Not all type traits have yet been updated,
this patch just updates those that seem particularly valuable or
straight-forward.  The function also gets moved to cp/semantics.cc to be
closer to 'trait_expr_value'.

Various other parts of the compiler are also adjusted here to assist in
making clear diagnostics, such as making more use of 'is_stub_object' to
refer to a type directly rather than in terms of 'std::declval<T>()'.
Additionally, since there are now more cases of nesting within a
'static_assert'ion I felt it was helpful for the experimental-nesting
mode to nest here as well.

	PR c++/117294
	PR c++/113854

gcc/cp/ChangeLog:

	* call.cc (implicit_conversion_error): Hide label when printing
	a stub object.
	(convert_like_internal): Likewise, and nest candidate
	diagnostics.
	* constexpr.cc (diagnose_failing_condition): Nest diagnostics,
	attempt to provide more helpful diagnostics for traits.
	* constraint.cc (satisfy_atom): Pass result before constant
	evaluation to diagnose_atomic_constraint.
	(diagnose_trait_expr): Adjust diagnostics for clarity and
	detail.
	(maybe_diagnose_standard_trait): New function.
	(diagnose_atomic_constraint): Attempt to provide more helpful
	diagnostics for more traits.
	* cp-tree.h (explain_not_noexcept): Declare new function.
	(is_trivially_xible): Add parameter.
	(is_nothrow_xible): Likewise.
	(is_xible): Likewise.
	(is_convertible): Likewise.
	(is_nothrow_convertible): Likewise.
	(diagnose_trait_expr): Declare new function.
	(maybe_diagnose_standard_trait): Declare new function.
	* error.cc (dump_type) <case TREE_VEC>: Handle trait types.
	* except.cc (explain_not_noexcept): New function.
	* method.cc (build_trait_object): Add complain parameter.
	(build_invoke): Propagate complain parameter.
	(assignable_expr): Add explain parameter to show diagnostics.
	(constructible_expr): Likewise.
	(destructible_expr): Likewise.
	(is_xible_helper): Replace trivial flag with explain flag,
	add diagnostics.
	(is_trivially_xible): New explain flag.
	(is_nothrow_xible): Likewise.
	(is_xible): Likewise.
	(is_convertible_helper): Add complain flag.
	(is_convertible): New explain flag.
	(is_nothrow_convertible): Likewise.
	* typeck.cc (cp_build_function_call_vec): Add handling for stub
	objects.
	(convert_arguments): Always return -1 on error.
	* typeck2.cc (cxx_readonly_error): Add handling for stub
	objects.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/any/misc/any_cast_neg.cc: Adjust
	diagnostics.
	* testsuite/20_util/expected/illformed_neg.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else_neg.cc: Likewise.
	* testsuite/23_containers/array/creation/3_neg.cc: Likewise.
	* testsuite/24_iterators/range_generators/lwg3900.cc: Likewise.
	* testsuite/29_atomics/atomic/requirements/types_neg.cc:
	Likewise.
	* testsuite/30_threads/stop_token/stop_callback/invocable_neg.cc:
	Likewise.
	* testsuite/30_threads/stop_token/stop_callback/destructible_neg.cc:
	Likewise.
	* testsuite/std/format/arguments/args_neg.cc: Likewise.
	* testsuite/std/format/string_neg.cc: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-traits3.C: Adjust diagnostics.
	* g++.dg/cpp2a/concepts-traits4.C: New test.
	* g++.dg/diagnostic/static_assert5.C: New test.
	* g++.dg/ext/has_virtual_destructor2.C: New test.
	* g++.dg/ext/is_assignable2.C: New test.
	* g++.dg/ext/is_constructible9.C: New test.
	* g++.dg/ext/is_convertible7.C: New test.
	* g++.dg/ext/is_destructible3.C: New test.
	* g++.dg/ext/is_invocable6.C: New test.
	* g++.dg/ext/is_virtual_base_of_diagnostic2.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-07-25 08:18:45 +10:00
Tomasz Kamiński
dc49c0a46e libstdc++: Cleaned up string_vector_iterators.cc test [PR104874]
Removed the wrong_stuff() function, which was effectively empty for
actual test runs. Replaced the manual failure counter with the VERIFY
macro to simplify identifying failures.

	PR libstdc++/104874

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/random_access/string_vector_iterators.cc:
	Reworked.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-24 16:38:36 +02:00
Jonathan Wakely
6df6978477 libstdc++: Disable -Wlong-long warnings in boost_concept_check.h
The _IntegerConcept, _SignedIntegerConcept and _UnsignedIntegerConcept
class template are specialized for long long, which gives warnings with
-Wsystem-headers in C++98 mode.

libstdc++-v3/ChangeLog:

	* include/bits/boost_concept_check.h: Disable -Wlong-long
	warnings.
	* testsuite/24_iterators/operations/prev_neg.cc: Adjust dg-error
	line number.
2025-05-29 11:49:03 +01:00
Jonathan Wakely
a4e8d1884e libstdc++: Add lvalue overload for generator::yield_value
This was approved in Wrocław as LWG 3899.

This avoids creating a new coroutine frame to co_yield the elements of
an lvalue generator.

libstdc++-v3/ChangeLog:

	* include/std/generator (generator::yield_value): Add overload
	taking lvalue element_of view, as per LWG 3899.
	* testsuite/24_iterators/range_generators/lwg3899.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Arsen Arsenović <arsen@aarsen.me>
2025-04-24 22:22:33 +01:00
Patrick Palka
49e79b8693 Revert "libstdc++: Optimize std::projected<I, std::identity>" [PR119888]
This non-standard optimization breaks real-world code that expects the
result of std::projected to always (be a class type and) have a value_type
member, which isn't true for e.g. I=int*, so revert it for now.

	PR libstdc++/119888

This reverts commit 51761c50f8.
2025-04-22 12:52:34 -04:00
Jonathan Wakely
3e52eb28c5 libstdc++: Fix std::ranges::iter_move for function references [PR119469]
The result of std::move (or a cast to an rvalue reference) on a function
reference is always an lvalue. Because std::ranges::iter_move was using
the type std::remove_reference_t<X>&& as the result of std::move, it was
giving the wrong type for function references. Use a decltype-specifier
with declval<remove_reference_t<X>>() instead of just using the
remove_reference_t<X>&& type directly. This gives the right result,
while still avoiding the cost of doing overload resolution for
std::move.

libstdc++-v3/ChangeLog:

	PR libstdc++/119469
	* include/bits/iterator_concepts.h (_IterMove::__result): Use
	decltype-specifier instead of an explicit type.
	* testsuite/24_iterators/customization_points/iter_move.cc:
	Check results for function references.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-27 11:14:52 +00:00
Jonathan Wakely
f7c0b0fc4f libstdc++: Add testcases for resolved bug [PR101527]
These tests were fixed by a front-end change r13-465-g4df735e01e3199 so
this just adds them to the testsuite to be sure we don't regress.

libstdc++-v3/ChangeLog:

	PR libstdc++/101527
	* testsuite/24_iterators/common_iterator/101527.cc: New test.
	* testsuite/24_iterators/counted_iterator/101527.cc: New test.
2025-03-24 21:38:07 +00:00
Jonathan Wakely
a8ee522c59 libstdc++: Fix ranges::iter_move handling of rvalues [PR106612]
The specification for std::ranges::iter_move apparently requires us to
handle types which do not satisfy std::indirectly_readable, for example
with overloaded operator* which behaves differently for different value
categories.

libstdc++-v3/ChangeLog:

	PR libstdc++/106612
	* include/bits/iterator_concepts.h (_IterMove::__iter_ref_t):
	New alias template.
	(_IterMove::__result): Use __iter_ref_t instead of
	std::iter_reference_t.
	(_IterMove::__type): Remove incorrect __dereferenceable
	constraint.
	(_IterMove::operator()): Likewise. Add correct constraints. Use
	__iter_ref_t instead of std::iter_reference_t. Forward parameter
	as correct value category.
	(iter_swap): Add comments.
	* testsuite/24_iterators/customization_points/iter_move.cc: Test
	that iter_move is found by ADL and that rvalue arguments are
	handled correctly.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-02-28 21:48:01 +00:00
Patrick Palka
4342c50ca8 libstdc++: Fix constraint recursion in basic_const_iterator relops [PR112490]
Here for

  using RCI = reverse_iterator<basic_const_iterator<vector<int>::iterator>>
  static_assert(std::totally_ordered<RCI>);

we effectively need to check the requirement

  requires (RCI x) { x RELOP x; }  for each RELOP in {<, >, <=, >=}

which we expect to be straightforwardly satisfied by reverse_iterator's
namespace-scope relops.  But due to ADL we find ourselves also
considering the basic_const_iterator relop friends, which before CWG
2369 would be quickly discarded since RCI clearly isn't convertible to
basic_const_iterator.  After CWG 2369 though we must first check these
relops' constraints (with _It = vector<int>::iterator and _It2 = RCI),
which entails checking totally_ordered<RCI> recursively.

This patch fixes this by turning the problematic non-dependent function
parameters of type basic_const_iterator<_It> into dependent ones of
type basic_const_iterator<_It3> where _It3 is constrained to match _It.
Thus the basic_const_iterator relop friends now get quickly discarded
during deduction and before the constraint check if the second operand
isn't a specialization of basic_const_iterator (or derived from one)
like before CWG 2369.

	PR libstdc++/112490

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (basic_const_iterator::operator<):
	Replace non-dependent basic_const_iterator function parameter with
	a dependent one of type basic_const_iterator<_It3> where _It3
	matches _It.
	(basic_const_iterator::operator>): Likewise.
	(basic_const_iterator::operator<=): Likewise.
	(basic_const_iterator::operator>=): Likewise.
	* testsuite/24_iterators/const_iterator/112490.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-02-28 09:39:57 -05:00
Jonathan Wakely
7bc72a3d20 libstdc++: Add conditional noexcept to remaining range access functions
Add conditional noexcept to the remaining range access functions that
were not changed in r15-5669-g8692cb10e82e72. This is now being proposed
for C++26 by P3623R0 (not published yet).

libstdc++-v3/ChangeLog:

	* include/bits/range_access.h (rbegin, rend, crbegin, crend):
	Add conditional noexcept, as per P3623R0.
	* testsuite/24_iterators/headers/iterator/range_access.cc: Add
	noexcept-specifier to rbegin, rend, crbegin and crend
	declarations.
2025-02-15 10:58:56 +00:00
Jonathan Wakely
08f70200ce libstdc++: Combine three tests into one
Instead of a test with { target c++11_only } and another with
c++14_only and another with c++17 we can have a single test that uses
{ target c++11 }. This avoids needing to make edits to three very
similar tests.

Also fix the signatures for std::cbegin and std::cend which had the
wrong expression in the trailing-return-type and were missing their
constexpr and conditional noexcept (which were always present even in
C++14). That was wrong in two files, but now only needs to be fixed in
one place!

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
	Removed.
	* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
	Removed.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
	Removed.
	* testsuite/24_iterators/headers/iterator/range_access.cc:
	New test.
2025-02-15 10:58:55 +00:00
Jakub Jelinek
6441eb6dc0 Update copyright years. 2025-01-02 11:59:57 +01:00
Jakub Jelinek
a326ecf541 libstdc++: Fix up pr118196.cc test [PR118196]
The test used #include "<generator>", so FAILed everywhere with
fatal error: <generator>: No such file or directory

2024-12-28  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/118196
	* testsuite/24_iterators/range_generators/pr118196.cc: Include
	<generator> rather than "<generator>".
2024-12-28 08:50:28 +01:00
Arsen Arsenović
9a1cb52cae libstdc++: add missing return in generator assignment operator [PR118196]
libstdc++-v3/ChangeLog:

	PR libstdc++/118196
	* include/std/generator (generator::operator=(generator)): Add
	missing 'return *this;'.
	* testsuite/24_iterators/range_generators/pr118196.cc: New test.
2024-12-27 12:29:42 +01:00
Arsen Arsenović
5a41ab8da0 libstdc++: don't implicit-construct _Yielded_decvref [PR118022]
This overload requires

  constructible_from<remove_cvref_t<yielded>,
                     const remove_reference_t<yielded>&>

... but then tries to construct remove_cvref_t<yielded> implicitly,
which means it imposes an additional constraint not in the standard.

libstdc++-v3/ChangeLog:

	PR libstdc++/118022
	* include/std/generator
	(_Promise_erased::yield_value(const _Yielded_deref&)): Don't
	implicit-constuct _Yielded_decvref.
	* testsuite/24_iterators/range_generators/pr118022.cc: New test.
2024-12-27 12:29:42 +01:00
Jonathan Wakely
2835bd76c1 libstdc++: Remove constraints on std::generator::promise_type::operator new
This was approved in Wrocław as LWG 3900, so that passing an incorrect
argument intended as an allocator will be ill-formed, instead of
silently ignored.

This also renames the template parameters and function parameters for
the allocators, to align with the names in the standard. I found it too
confusing to have a parameter _Alloc which doesn't correspond to Alloc
in the standard. Rename _Alloc to _Allocator (which the standard calls
Allocator) and rename _Na to _Alloc (which the standard calls Alloc).

libstdc++-v3/ChangeLog:

	* include/std/generator (_Promise_alloc): Rename template
	parameter. Use __alloc_rebind to rebind allocator.
	(_Promise_alloc::operator new): Replace constraints with a
	static_assert in the body. Rename allocator parameter.
	(_Promise_alloc<void>::_M_allocate): Rename allocator parameter.
	Use __alloc_rebind to rebind allocator.
	(_Promise_alloc<void>::operator new): Rename allocator
	parameter.
	* testsuite/24_iterators/range_generators/alloc.cc: New test.
	* testsuite/24_iterators/range_generators/lwg3900.cc: New test.

Reviewed-by: Arsen Arsenović <arsen@aarsen.me>
2024-12-11 21:46:20 +00:00
Jonathan Wakely
8692cb10e8 libstdc++: Add conditional noexcept to range access functions
As an extension, this adds conditional noexcept to std::begin, std::end,
and std::ssize.

libstdc++-v3/ChangeLog:

	* include/bits/range_access.h (begin, end, ssize): Add
	conditional noexcept.
	* testsuite/18_support/initializer_list/range_access.cc: Check
	results and noexcept-specifier for std::begin and std::end.
	* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
	Check for conditional noexcept on std::begin and std::end.
	* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
	Likewise.
	* testsuite/24_iterators/range_access/range_access.cc: Check
	conditional noexcept is correct.
	* testsuite/24_iterators/range_access/range_access_cpp17.cc:
	Check std::size, std::empty and std::data.
	* testsuite/24_iterators/range_access/range_access_cpp20.cc:
	Check conditional noexcept on std::ssize.
2024-11-26 08:31:27 +00:00
Jonathan Wakely
f91e34644e libstdc++: Add missing constraint to operator+ for std::move_iterator
This constraint was added by the One Ranges proposal (P0896R4) and
then fixed by LWG 3293, but it was missing from libstdc++.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (operator+): Add constraint to
	move_iterator operator.
	* testsuite/24_iterators/move_iterator/rel_ops_c++20.cc:
2024-11-14 15:39:03 +00:00
Jonathan Wakely
85e5b80ee2 libstdc++: Avoid using std::__to_address with iterators
In r12-3935-g82626be2d633a9 I added the partial specialization
std::pointer_traits<__normal_iterator<It, Cont>> so that __to_address
would work with __normal_iterator objects. Soon after that, François
replaced it in r12-6004-g807ad4bc854cae with an overload of __to_address
that served the same purpose, but was less complicated and less wrong.

I now think that both commits were mistakes, and that instead of adding
hacks to make __normal_iterator work with __to_address, we should not be
using __to_address with iterators at all before C++20.

The pre-C++20 std::__to_address function should only be used with
pointer-like types, specifically allocator_traits<A>::pointer types.
Those pointer-like types are guaranteed to be contiguous iterators, so
that getting a raw memory address from them is OK.

For arbitrary iterators, even random access iterators, we don't know
that it's safe to lower the iterator to a pointer e.g. for std::deque
iterators it's not, because (it + n) == (std::to_address(it) + n) only
holds within the same block of the deque's storage.

For C++20, std::to_address does work correctly for contiguous iterators,
including __normal_iterator, and __to_address just calls std::to_address
so also works. But we have to be sure we have an iterator that satisfies
the std::contiguous_iterator concept for it to be safe, and we can't
check that before C++20.

So for pre-C++20 code the correct way to handle iterators that might be
pointers or might be __normal_iterator is to call __niter_base, and if
necessary use is_pointer to check whether __niter_base returned a real
pointer.

We currently have some uses of std::__to_address with iterators where
we've checked that they're either pointers, or __normal_iterator
wrappers around pointers, or satisfy std::contiguous_iterator. But this
seems a little fragile, and it would be better to just use
std::__niter_base for the pointers and __normal_iterator cases, and use
C++20 std::to_address when the C++20 std::contiguous_iterator concept is
satisfied. This patch does that.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string::assign): Replace
	use of __to_address with __niter_base or std::to_address as
	appropriate.
	* include/bits/ptr_traits.h (__to_address): Add comment.
	* include/bits/shared_ptr_base.h (__shared_ptr): Qualify calls
	to __to_address.
	* include/bits/stl_algo.h (find): Replace use of __to_address
	with __niter_base or std::to_address as appropriate. Only use
	either of them when the range is not empty.
	* include/bits/stl_iterator.h (__to_address): Remove overload
	for __normal_iterator.
	* include/debug/safe_iterator.h (__to_address): Remove overload
	for _Safe_iterator.
	* include/std/ranges (views::counted): Replace use of
	__to_address with std::to_address.
	* testsuite/24_iterators/normal_iterator/to_address.cc: Removed.
2024-10-22 17:08:32 +01:00
Jonathan Wakely
2608fcfe5f libstdc++: Move std::__niter_base and std::__niter_wrap to stl_iterator.h
Move the functions for unwrapping and rewrapping __normal_iterator
objects to the same file as the definition of __normal_iterator itself.

This will allow a later commit to make use of std::__niter_base in other
headers without having to include all of <bits/stl_algobase.h>.

libstdc++-v3/ChangeLog:

	* include/bits/stl_algobase.h (__niter_base, __niter_wrap): Move
	to ...
	* include/bits/stl_iterator.h: ... here.
	(__niter_base, __miter_base): Move all overloads to the end of
	the header.
	* testsuite/24_iterators/normal_iterator/wrapping.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18 14:49:34 +01:00
Patrick Palka
7c0d1e9f2a libstdc++: Implement LWG 3664 changes to ranges::distance
libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__distance_fn::operator()):
	Adjust iterator/sentinel overloads as per LWG 3664.
	* testsuite/24_iterators/range_operations/distance.cc:
	Test LWG 3664 example.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-05 13:48:06 -04:00
Jason Merrill
63a598deb0 libstdc++: #ifdef out #pragma GCC system_header
In r15-3714-gd3a7302ec5985a I added -Wsystem-headers to the libstdc++ build
flags to help catch problems in the library.  This patch takes a different
approach, of disabling the #pragma system_header unless _GLIBCXX_SYSHDR is
defined.  As a result, the testsuites will treat them as non-system-headers
to get better warning coverage during regression testing of both gcc and
libstdc++, not just when building the library.

My rationale for the #ifdef instead of just removing the #pragma is the
three G++ tests that want to test libstdc++ system header behavior, so we
need a way to select it.

This doesn't affect installed libraries, as they get their
system-header status from the lookup path.  But testsuite_flags
--build-includes gives -I directives rather than -isystem.

This patch doesn't change the headers in config/ because I'm not compiling
with most of them, so won't see any warnings that need fixing.  Adjusting
them could happen later, or we can not bother.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (WARN_FLAGS): Remove -Wsystem-headers.
	* configure: Regenerate.
	* include/bits/algorithmfwd.h: #ifdef out #pragma GCC system_header.
	* include/bits/atomic_base.h
	* include/bits/atomic_futex.h
	* include/bits/atomic_timed_wait.h
	* include/bits/atomic_wait.h
	* include/bits/basic_ios.h
	* include/bits/basic_string.h
	* include/bits/boost_concept_check.h
	* include/bits/char_traits.h
	* include/bits/charconv.h
	* include/bits/chrono.h
	* include/bits/chrono_io.h
	* include/bits/codecvt.h
	* include/bits/concept_check.h
	* include/bits/cpp_type_traits.h
	* include/bits/elements_of.h
	* include/bits/enable_special_members.h
	* include/bits/erase_if.h
	* include/bits/forward_list.h
	* include/bits/functional_hash.h
	* include/bits/gslice.h
	* include/bits/gslice_array.h
	* include/bits/hashtable.h
	* include/bits/indirect_array.h
	* include/bits/invoke.h
	* include/bits/ios_base.h
	* include/bits/iterator_concepts.h
	* include/bits/locale_classes.h
	* include/bits/locale_facets.h
	* include/bits/locale_facets_nonio.h
	* include/bits/localefwd.h
	* include/bits/mask_array.h
	* include/bits/max_size_type.h
	* include/bits/memory_resource.h
	* include/bits/memoryfwd.h
	* include/bits/move_only_function.h
	* include/bits/node_handle.h
	* include/bits/ostream_insert.h
	* include/bits/out_ptr.h
	* include/bits/parse_numbers.h
	* include/bits/postypes.h
	* include/bits/quoted_string.h
	* include/bits/range_access.h
	* include/bits/ranges_base.h
	* include/bits/refwrap.h
	* include/bits/sat_arith.h
	* include/bits/semaphore_base.h
	* include/bits/slice_array.h
	* include/bits/std_abs.h
	* include/bits/std_function.h
	* include/bits/std_mutex.h
	* include/bits/std_thread.h
	* include/bits/stl_iterator_base_funcs.h
	* include/bits/stl_iterator_base_types.h
	* include/bits/stl_tree.h
	* include/bits/stream_iterator.h
	* include/bits/streambuf_iterator.h
	* include/bits/stringfwd.h
	* include/bits/this_thread_sleep.h
	* include/bits/unique_lock.h
	* include/bits/uses_allocator_args.h
	* include/bits/utility.h
	* include/bits/valarray_after.h
	* include/bits/valarray_array.h
	* include/bits/valarray_before.h
	* include/bits/version.h
	* include/c_compatibility/fenv.h
	* include/c_compatibility/inttypes.h
	* include/c_compatibility/stdint.h
	* include/decimal/decimal.h
	* include/experimental/bits/net.h
	* include/experimental/bits/shared_ptr.h
	* include/ext/aligned_buffer.h
	* include/ext/alloc_traits.h
	* include/ext/atomicity.h
	* include/ext/concurrence.h
	* include/ext/numeric_traits.h
	* include/ext/pod_char_traits.h
	* include/ext/pointer.h
	* include/ext/stdio_filebuf.h
	* include/ext/stdio_sync_filebuf.h
	* include/ext/string_conversions.h
	* include/ext/type_traits.h
	* include/ext/vstring.h
	* include/ext/vstring_fwd.h
	* include/ext/vstring_util.h
	* include/parallel/algorithmfwd.h
	* include/parallel/numericfwd.h
	* include/tr1/functional_hash.h
	* include/tr1/hashtable.h
	* include/tr1/random.h
	* libsupc++/exception.h
	* libsupc++/hash_bytes.h
	* include/bits/basic_ios.tcc
	* include/bits/basic_string.tcc
	* include/bits/fstream.tcc
	* include/bits/istream.tcc
	* include/bits/locale_classes.tcc
	* include/bits/locale_facets.tcc
	* include/bits/locale_facets_nonio.tcc
	* include/bits/ostream.tcc
	* include/bits/sstream.tcc
	* include/bits/streambuf.tcc
	* include/bits/string_view.tcc
	* include/bits/version.tpl
	* include/experimental/bits/string_view.tcc
	* include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp
	* include/ext/random.tcc
	* include/ext/vstring.tcc
	* include/tr2/bool_set.tcc
	* include/tr2/dynamic_bitset.tcc
	* include/bits/c++config
	* include/c/cassert
	* include/c/cctype
	* include/c/cerrno
	* include/c/cfloat
	* include/c/ciso646
	* include/c/climits
	* include/c/clocale
	* include/c/cmath
	* include/c/csetjmp
	* include/c/csignal
	* include/c/cstdarg
	* include/c/cstddef
	* include/c/cstdio
	* include/c/cstdlib
	* include/c/cstring
	* include/c/ctime
	* include/c/cuchar
	* include/c/cwchar
	* include/c/cwctype
	* include/c_global/cassert
	* include/c_global/ccomplex
	* include/c_global/cctype
	* include/c_global/cerrno
	* include/c_global/cfenv
	* include/c_global/cfloat
	* include/c_global/cinttypes
	* include/c_global/ciso646
	* include/c_global/climits
	* include/c_global/clocale
	* include/c_global/cmath
	* include/c_global/csetjmp
	* include/c_global/csignal
	* include/c_global/cstdalign
	* include/c_global/cstdarg
	* include/c_global/cstdbool
	* include/c_global/cstddef
	* include/c_global/cstdint
	* include/c_global/cstdio
	* include/c_global/cstdlib
	* include/c_global/cstring
	* include/c_global/ctgmath
	* include/c_global/ctime
	* include/c_global/cuchar
	* include/c_global/cwchar
	* include/c_global/cwctype
	* include/c_std/cassert
	* include/c_std/cctype
	* include/c_std/cerrno
	* include/c_std/cfloat
	* include/c_std/ciso646
	* include/c_std/climits
	* include/c_std/clocale
	* include/c_std/cmath
	* include/c_std/csetjmp
	* include/c_std/csignal
	* include/c_std/cstdarg
	* include/c_std/cstddef
	* include/c_std/cstdio
	* include/c_std/cstdlib
	* include/c_std/cstring
	* include/c_std/ctime
	* include/c_std/cuchar
	* include/c_std/cwchar
	* include/c_std/cwctype
	* include/debug/array
	* include/debug/bitset
	* include/debug/deque
	* include/debug/forward_list
	* include/debug/list
	* include/debug/map
	* include/debug/set
	* include/debug/string
	* include/debug/unordered_map
	* include/debug/unordered_set
	* include/debug/vector
	* include/decimal/decimal
	* include/experimental/algorithm
	* include/experimental/any
	* include/experimental/array
	* include/experimental/buffer
	* include/experimental/chrono
	* include/experimental/contract
	* include/experimental/deque
	* include/experimental/executor
	* include/experimental/filesystem
	* include/experimental/forward_list
	* include/experimental/functional
	* include/experimental/internet
	* include/experimental/io_context
	* include/experimental/iterator
	* include/experimental/list
	* include/experimental/map
	* include/experimental/memory
	* include/experimental/memory_resource
	* include/experimental/net
	* include/experimental/netfwd
	* include/experimental/numeric
	* include/experimental/propagate_const
	* include/experimental/ratio
	* include/experimental/regex
	* include/experimental/scope
	* include/experimental/set
	* include/experimental/socket
	* include/experimental/string
	* include/experimental/string_view
	* include/experimental/synchronized_value
	* include/experimental/system_error
	* include/experimental/timer
	* include/experimental/tuple
	* include/experimental/type_traits
	* include/experimental/unordered_map
	* include/experimental/unordered_set
	* include/experimental/vector
	* include/ext/algorithm
	* include/ext/cmath
	* include/ext/functional
	* include/ext/iterator
	* include/ext/memory
	* include/ext/numeric
	* include/ext/random
	* include/ext/rb_tree
	* include/ext/rope
	* include/parallel/algorithm
	* include/std/algorithm
	* include/std/any
	* include/std/array
	* include/std/atomic
	* include/std/barrier
	* include/std/bit
	* include/std/bitset
	* include/std/charconv
	* include/std/chrono
	* include/std/codecvt
	* include/std/complex
	* include/std/concepts
	* include/std/condition_variable
	* include/std/coroutine
	* include/std/deque
	* include/std/execution
	* include/std/expected
	* include/std/filesystem
	* include/std/format
	* include/std/forward_list
	* include/std/fstream
	* include/std/functional
	* include/std/future
	* include/std/generator
	* include/std/iomanip
	* include/std/ios
	* include/std/iosfwd
	* include/std/iostream
	* include/std/istream
	* include/std/iterator
	* include/std/latch
	* include/std/limits
	* include/std/list
	* include/std/locale
	* include/std/map
	* include/std/memory
	* include/std/memory_resource
	* include/std/mutex
	* include/std/numbers
	* include/std/numeric
	* include/std/optional
	* include/std/ostream
	* include/std/print
	* include/std/queue
	* include/std/random
	* include/std/ranges
	* include/std/ratio
	* include/std/regex
	* include/std/scoped_allocator
	* include/std/semaphore
	* include/std/set
	* include/std/shared_mutex
	* include/std/span
	* include/std/spanstream
	* include/std/sstream
	* include/std/stack
	* include/std/stacktrace
	* include/std/stdexcept
	* include/std/streambuf
	* include/std/string
	* include/std/string_view
	* include/std/syncstream
	* include/std/system_error
	* include/std/text_encoding
	* include/std/thread
	* include/std/tuple
	* include/std/type_traits
	* include/std/typeindex
	* include/std/unordered_map
	* include/std/unordered_set
	* include/std/utility
	* include/std/valarray
	* include/std/variant
	* include/std/vector
	* include/std/version
	* include/tr1/array
	* include/tr1/cfenv
	* include/tr1/cinttypes
	* include/tr1/cmath
	* include/tr1/complex
	* include/tr1/cstdbool
	* include/tr1/cstdint
	* include/tr1/cstdio
	* include/tr1/cstdlib
	* include/tr1/cwchar
	* include/tr1/cwctype
	* include/tr1/functional
	* include/tr1/memory
	* include/tr1/random
	* include/tr1/regex
	* include/tr1/tuple
	* include/tr1/type_traits
	* include/tr1/unordered_map
	* include/tr1/unordered_set
	* include/tr1/utility
	* include/tr2/bool_set
	* include/tr2/dynamic_bitset
	* include/tr2/type_traits
	* libsupc++/atomic_lockfree_defines.h
	* libsupc++/compare
	* libsupc++/cxxabi.h
	* libsupc++/cxxabi_forced.h
	* libsupc++/cxxabi_init_exception.h
	* libsupc++/exception
	* libsupc++/initializer_list
	* libsupc++/new
	* libsupc++/typeinfo: Likewise.
	* testsuite/20_util/ratio/operations/ops_overflow_neg.cc
	* testsuite/23_containers/array/tuple_interface/get_neg.cc
	* testsuite/23_containers/vector/cons/destructible_debug_neg.cc
	* testsuite/24_iterators/operations/prev_neg.cc
	* testsuite/ext/type_traits/add_unsigned_floating_neg.cc
	* testsuite/ext/type_traits/add_unsigned_integer_neg.cc
	* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc
	* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Adjust
	line numbers.

gcc/testsuite/ChangeLog

	* g++.dg/analyzer/fanalyzer-show-events-in-system-headers-default.C
	* g++.dg/analyzer/fanalyzer-show-events-in-system-headers-no.C
	* g++.dg/diagnostic/disable.C: #define _GLIBCXX_SYSHDR.
2024-09-25 08:20:45 -04:00
Jonathan Wakely
819deae0a5 libstdc++: Specialize std::disable_sized_sentinel_for for std::move_iterator [PR116549]
LWG 3736 added a partial specialization of this variable template for
two std::move_iterator types. This is needed for the case where the
types satisfy std::sentinel_for and are subtractable, but do not model
the semantics requirements of std::sized_sentinel_for.

libstdc++-v3/ChangeLog:

	PR libstdc++/116549
	* include/bits/stl_iterator.h (disable_sized_sentinel_for):
	Define specialization for two move_iterator types, as per LWG
	3736.
	* testsuite/24_iterators/move_iterator/lwg3736.cc: New test.
2024-09-03 16:18:21 +01:00
Patrick Palka
51761c50f8 libstdc++: Optimize std::projected<I, std::identity>
Algorithms that are generalized to take projections typically default the
projection to std::identity, which is equivalent to no projection at all.
In that case, I believe we could shortcut the projection logic to return
the iterator unchanged rather than wrapping it.  This should reduce compile
times especially after P2609R3 which made the indirect invocability
concepts more expensive to check when actual projections are involved.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (__detail::__projected): Define
	an optimized partial specialization for when the projection is
	std::identity.
	* testsuite/24_iterators/indirect_callable/projected.cc: Verify the
	optimization.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-22 09:24:39 -04:00
Patrick Palka
620232426b libstdc++: Implement P2997R1 changes to the indirect invocability concepts
This implements the changes of this C++26 paper as a DR against C++20.

In passing this patch removes the std/ranges/version_c++23.cc test which
is now mostly obsolete after the version.def FTM refactoring, and instead
expands the __cpp_lib_ranges checks in another test so that it verifies
the exact value of the FTM on a per language version basis.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (indirectly_unary_invocable):
	Relax as per P2997R1.
	(indirectly_regular_unary_invocable): Likewise.
	(indirect_unary_predicate): Likewise.
	(indirect_binary_predicate): Likewise.
	(indirect_equivalence_relation): Likewise.
	(indirect_strict_weak_order): Likewise.
	* include/bits/version.def (ranges): Update value for C++26.
	* include/bits/version.h: Regenerate.
	* testsuite/24_iterators/indirect_callable/p2997r1.cc: New test.
	* testsuite/std/ranges/version_c++23.cc: Remove.
	* testsuite/std/ranges/headers/ranges/synopsis.cc: Refine the
	__cpp_lib_ranges checks.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-22 09:24:20 -04:00
Patrick Palka
b552730faf libstdc++: Implement P2609R3 changes to the indirect invocability concepts
This implements the changes of this C++23 paper as a DR against C++20.

Note that after the later P2538R1 "ADL-proof std::projected" (which we
already implement), we can't use a simple partial specialization to match
specializations of the 'projected' alias template.  So instead we identify
such specializations using a pair of distinguishing member aliases.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (__detail::__indirect_value):
	Define.
	(__indirect_value_t): Define as per P2609R3.
	(iter_common_reference_t): Adjust as per P2609R3.
	(indirectly_unary_invocable): Likewise.
	(indirectly_regular_unary_invocable): Likewise.
	(indirect_unary_predicate): Likewise.
	(indirect_binary_predicate): Likewise.
	(indirect_equivalence_relation): Likewise.
	(indirect_strict_weak_order): Likewise.
	(__detail::__projected::__type): Define member aliases
	__projected_Iter and __projected_Proj providing the
	template arguments of the current specialization.
	* include/bits/version.def (ranges): Update value.
	* include/bits/version.h: Regenerate.
	* testsuite/24_iterators/indirect_callable/p2609r3.cc: New test.
	* testsuite/std/ranges/version_c++23.cc: Update expected value
	of __cpp_lib_ranges macro.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-08-22 09:24:11 -04:00
Arsen Arsenović
f15cea16cc libstdc++-v3: drop GCC Runtime Library Exception from gen tests
It was mistakenly added to these files.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/range_generators/01.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/02.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/copy.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/except.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/subrange.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/synopsis.cc: Drop GCC
	Runtime Library Exception.
	* testsuite/24_iterators/range_generators/iter_deref_return.cc:
	Drop GCC Runtime Library Exception from the "You should have
	received a copy" paragraph.
2024-03-29 12:50:06 +01:00
Arsen Arsenović
fb1d50e1f6 libstdc++: fix generator iterator operator* return type
Per the standard, the return type of a generators ranges iterator op*
should be the reference type rather than the yielded type.

The yielded type was used here by mistake.

libstdc++-v3/ChangeLog:

	* include/std/generator (generator::_Iterator::operator*): Fix
	return type.
	* testsuite/24_iterators/range_generators/iter_deref_return.cc:
	New test.
2024-03-26 22:33:48 +01:00
Patrick Palka
731444b3c3 libstdc++: Implement P2836R1 changes to const_iterator
libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (const_iterator): Define conversion
	operators as per P2836R1.
	* include/bits/version.def (ranges_as_const): Update value.
	* include/bits/version.h: Regenerate.
	* testsuite/24_iterators/const_iterator/1.cc (test04): New test.
	* testsuite/std/ranges/adaptors/as_const/1.cc: Adjust expected
	value of __cpp_lib_ranges_as_const.
	* testsuite/std/ranges/version_c++23.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-01-15 15:13:53 -05:00
Jakub Jelinek
a945c346f5 Update copyright years. 2024-01-03 12:19:35 +01:00
Arsen Arsenović
ec2ec24a4d libstdc++: implement std::generator
libstdc++-v3/ChangeLog:

	* include/Makefile.am: Install std/generator, bits/elements_of.h
	as freestanding.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def: Add __cpp_lib_generator.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Include <generator>.
	* include/std/ranges: Include bits/elements_of.h
	* include/bits/elements_of.h: New file.
	* include/std/generator: New file.
	* testsuite/24_iterators/range_generators/01.cc: New test.
	* testsuite/24_iterators/range_generators/02.cc: New test.
	* testsuite/24_iterators/range_generators/copy.cc: New test.
	* testsuite/24_iterators/range_generators/except.cc: New test.
	* testsuite/24_iterators/range_generators/synopsis.cc: New test.
	* testsuite/24_iterators/range_generators/subrange.cc: New test.
2023-12-21 22:59:22 +01:00
Jonathan Wakely
f4ab68469c libstdc++: Test for feature test macros more accurately
Tests which check for feature test macros should use the no_pch option,
so that we're really testing for the definition being in the intended
header, and not just testing that it's present in <bits/stdc++.h> (which
includes all the standard headers and so defines all the macros).

libstdc++-v3/ChangeLog:

	* testsuite/18_support/byte/requirements.cc: Disable PCH.
	* testsuite/18_support/destroying_delete.cc: Likewise.
	* testsuite/18_support/source_location/1.cc: Likewise.
	* testsuite/18_support/source_location/version.cc: Likewise.
	* testsuite/18_support/type_info/constexpr.cc: Likewise.
	* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc:
	Likewise.
	* testsuite/19_diagnostics/stacktrace/output.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
	* testsuite/20_util/addressof/requirements/constexpr.cc:
	Likewise.
	* testsuite/20_util/allocator_traits/header-2.cc: Likewise.
	* testsuite/20_util/allocator_traits/header.cc: Likewise.
	* testsuite/20_util/as_const/1.cc: Likewise. Likewise.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise.
	* testsuite/20_util/bitset/version.cc: Likewise.
	* testsuite/20_util/duration/arithmetic/constexpr_c++17.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/exchange/constexpr.cc: Likewise.
	* testsuite/20_util/expected/synopsis.cc: Likewise.
	* testsuite/20_util/expected/version.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/1.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/2.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/3.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/4.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/constexpr.cc:
	Likewise.
	* testsuite/20_util/function_objects/invoke/version.cc:
	Likewise.
	* testsuite/20_util/function_objects/searchers.cc: Likewise.
	* testsuite/20_util/integer_comparisons/1.cc: Likewise.
	* testsuite/20_util/integer_comparisons/2.cc: Likewise.
	* testsuite/20_util/is_bounded_array/value.cc: Likewise.
	* testsuite/20_util/is_layout_compatible/value.cc: Likewise.
	* testsuite/20_util/is_layout_compatible/version.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/value.h: Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/value.cc: Disable
	PCH.
	* testsuite/20_util/is_pointer_interconvertible/value.cc:
	Likewise.
	* testsuite/20_util/is_pointer_interconvertible/version.cc:
	Likewise.
	* testsuite/20_util/is_scoped_enum/value.cc: Likewise.
	* testsuite/20_util/is_scoped_enum/version.cc: Likewise.
	* testsuite/20_util/is_swappable/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable/requirements/typedefs.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable/value.cc: Disable PCH.
	* testsuite/20_util/is_swappable/value.h: Reorder headers.
	* testsuite/20_util/is_swappable_with/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable_with/requirements/typedefs.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable_with/value.cc: Disable PCH.
	* testsuite/20_util/is_unbounded_array/value.cc: Likewise.
	* testsuite/20_util/move_only_function/cons.cc: Likewise.
	* testsuite/20_util/move_only_function/version.cc: Likewise.
	* testsuite/20_util/optional/monadic/and_then.cc: Likewise.
	* testsuite/20_util/optional/requirements.cc: Likewise.
	* testsuite/20_util/optional/version.cc: Likewise.
	* testsuite/20_util/owner_less/void.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/version.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/array.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/overwrite.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/version.cc: Likewise.
	* testsuite/20_util/time_point_cast/rounding.cc: Likewise.
	* testsuite/20_util/to_chars/constexpr.cc: Likewise.
	* testsuite/20_util/to_chars/result.cc: Likewise.
	* testsuite/20_util/to_chars/version.cc: Likewise.
	* testsuite/20_util/to_underlying/1.cc: Likewise.
	* testsuite/20_util/to_underlying/version.cc: Likewise.
	* testsuite/20_util/tuple/apply/1.cc: Likewise.
	* testsuite/20_util/tuple/cons/constexpr_allocator_arg_t.cc:
	Likewise.
	* testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise.
	* testsuite/20_util/tuple/p2321r2.cc: Likewise.
	* testsuite/20_util/tuple/tuple_element_t.cc: Likewise.
	* testsuite/20_util/unique_ptr/cons/constexpr_c++20.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc:
	Likewise.
	* testsuite/20_util/unreachable/1.cc: Likewise.
	* testsuite/20_util/unreachable/version.cc: Likewise.
	* testsuite/20_util/unwrap_reference/1.cc: Likewise.
	* testsuite/20_util/unwrap_reference/3.cc: Likewise.
	* testsuite/20_util/variant/constexpr.cc: Likewise.
	* testsuite/20_util/variant/version.cc: Likewise.
	* testsuite/20_util/variant/visit_inherited.cc: Likewise.
	* testsuite/20_util/void_t/1.cc: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
	Likewise.
	* testsuite/21_strings/basic_string/erasure.cc: Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/to_string_float.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/version.cc:
	Likewise.
	* testsuite/21_strings/basic_string/version.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/constexpr.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/version.cc:
	Likewise.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc:
	Likewise.
	* testsuite/23_containers/array/creation/1.cc: Likewise.
	* testsuite/23_containers/array/creation/2.cc: Likewise.
	* testsuite/23_containers/array/element_access/constexpr_c++17.cc:
	Likewise.
	* testsuite/23_containers/array/requirements/constexpr_fill.cc:
	Likewise.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc:
	Likewise.
	* 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/queue/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/span/1.cc: Likewise.
	* testsuite/23_containers/span/2.cc: Likewise.
	* testsuite/23_containers/stack/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/operations/1.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/operations/1.cc:
	Likewise.
	* testsuite/23_containers/vector/cons/constexpr.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.
	* testsuite/23_containers/vector/requirements/version.cc:
	Likewise.
	* testsuite/24_iterators/insert_iterator/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/1.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/25_algorithms/constexpr_macro.cc: Likewise.
	* testsuite/25_algorithms/cpp_lib_constexpr.cc: Likewise.
	* testsuite/25_algorithms/fold_left/1.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/bit/bit.byteswap/byteswap.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/bit_cast.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/version.cc: Likewise.
	* testsuite/26_numerics/bit/header-2.cc: Likewise.
	* testsuite/26_numerics/bit/header.cc: Likewise.
	* testsuite/26_numerics/complex/1.cc: Likewise.
	* testsuite/26_numerics/complex/2.cc: Likewise.
	* testsuite/26_numerics/endian/2.cc: Likewise.
	* testsuite/26_numerics/endian/3.cc: Likewise.
	* testsuite/26_numerics/gcd/1.cc: Likewise.
	* testsuite/26_numerics/lcm/1.cc: Likewise.
	* testsuite/26_numerics/lerp/1.cc: Likewise.
	* testsuite/26_numerics/lerp/version.cc: Likewise.
	* testsuite/26_numerics/midpoint/integral.cc: Likewise.
	* testsuite/26_numerics/midpoint/version.cc: Likewise.
	* testsuite/26_numerics/numbers/1.cc: Likewise.
	* testsuite/26_numerics/numbers/2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/native_handle/char/1.cc:
	Likewise.
	* testsuite/27_io/basic_filebuf/native_handle/version.cc:
	Likewise.
	* testsuite/27_io/basic_ofstream/open/char/noreplace.cc:
	Likewise.
	* testsuite/27_io/basic_ofstream/open/wchar_t/noreplace.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/1.cc: Likewise.
	* testsuite/27_io/basic_syncbuf/2.cc: Likewise.
	* testsuite/27_io/basic_syncstream/1.cc: Likewise.
	* testsuite/27_io/basic_syncstream/2.cc: Likewise.
	* testsuite/27_io/spanstream/1.cc: Likewise.
	* testsuite/27_io/spanstream/version.cc: Likewise.
	* testsuite/29_atomics/atomic/cons/value_init.cc: Likewise.
	* testsuite/29_atomics/atomic/lock_free_aliases.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/1.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: Likewise.
	* testsuite/30_threads/barrier/1.cc: Likewise.
	* testsuite/30_threads/barrier/2.cc: Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/1.cc:
	Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/2.cc:
	Likewise.
	* testsuite/30_threads/jthread/1.cc: Likewise.
	* testsuite/30_threads/jthread/version.cc: Likewise.
	* testsuite/30_threads/latch/1.cc: Likewise.
	* testsuite/30_threads/latch/2.cc: Likewise.
	* testsuite/30_threads/scoped_lock/requirements/typedefs.cc:
	Likewise.
	* testsuite/30_threads/semaphore/1.cc: Likewise.
	* testsuite/30_threads/semaphore/2.cc: Likewise.
	* testsuite/30_threads/stop_token/1.cc: Likewise.
	* testsuite/30_threads/stop_token/2.cc: Likewise.
	* testsuite/experimental/feat-char8_t.cc: Likewise.
	* testsuite/experimental/iterator/ostream_joiner.cc: Likewise.
	* testsuite/experimental/numeric/gcd.cc: Likewise.
	* testsuite/experimental/scopeguard/uniqueres.cc: Likewise.
	* testsuite/std/concepts/1.cc: Likewise.
	* testsuite/std/concepts/2.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_const/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk_by/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/enumerate/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/join_with/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/slide/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/stride/1.cc: Likewise.
	* testsuite/std/ranges/cartesian_product/1.cc: Likewise.
	* testsuite/std/ranges/headers/ranges/synopsis.cc: Likewise.
	* testsuite/std/ranges/repeat/1.cc: Likewise.
	* testsuite/std/ranges/version_c++23.cc: Likewise.
	* testsuite/std/ranges/zip/1.cc: Likewise.
	* testsuite/std/time/syn_c++20.cc: Likewise.
	* testsuite/experimental/feat-cxx14.cc: Likewise. Include
	<algorithm> and <iterator>.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
2023-11-16 08:06:59 +00:00
Jonathan Wakely
762baaf026 libstdc++: Remove dg-options "-std=gnu++20" from 24_iterators tests
The testsuite will automatically select C++20 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++23
and C++26 as well.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/aliases.cc: Remove dg-options
	-std=gnu++2a.
	* testsuite/24_iterators/associated_types/incrementable.traits.cc:
	Likewise.
	* testsuite/24_iterators/associated_types/iterator.traits.cc:
	Likewise.
	* testsuite/24_iterators/associated_types/readable.traits.cc:
	Likewise.
	* testsuite/24_iterators/back_insert_iterator/constexpr.cc:
	Likewise.
	* testsuite/24_iterators/back_insert_iterator/pr93884.cc:
	Likewise.
	* testsuite/24_iterators/bidirectional/concept.cc: Likewise.
	* testsuite/24_iterators/common_iterator/1.cc: Likewise.
	* testsuite/24_iterators/common_iterator/100823.cc: Likewise.
	* testsuite/24_iterators/common_iterator/2.cc: Likewise.
	* testsuite/24_iterators/contiguous/concept.cc: Likewise.
	* testsuite/24_iterators/contiguous/tag.cc: Likewise.
	* testsuite/24_iterators/counted_iterator/1.cc: Likewise.
	* testsuite/24_iterators/counted_iterator/lwg3389.cc: Likewise.
	* testsuite/24_iterators/counted_iterator/lwg3643.cc: Likewise.
	* testsuite/24_iterators/customization_points/92894.cc:
	Likewise.
	* testsuite/24_iterators/customization_points/iter_move.cc:
	Likewise.
	* testsuite/24_iterators/customization_points/iter_swap.cc:
	Likewise.
	* testsuite/24_iterators/customization_points/lwg3420.cc:
	Likewise.
	* testsuite/24_iterators/forward/concept.cc: Likewise.
	* testsuite/24_iterators/front_insert_iterator/constexpr.cc:
	Likewise.
	* testsuite/24_iterators/front_insert_iterator/pr93884.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/synopsis_c++20.cc:
	Likewise.
	* testsuite/24_iterators/indirect_callable/92894.cc: Likewise.
	* testsuite/24_iterators/indirect_callable/projected-adl.cc:
	Likewise.
	* testsuite/24_iterators/indirect_callable/projected.cc:
	Likewise.
	* testsuite/24_iterators/input/concept.cc: Likewise.
	* testsuite/24_iterators/insert_iterator/constexpr.cc: Likewise.
	* testsuite/24_iterators/istream_iterator/cons/sentinel.cc:
	Likewise.
	* testsuite/24_iterators/istream_iterator/sentinel.cc: Likewise.
	* testsuite/24_iterators/istreambuf_iterator/cons/sentinel.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/sentinel.cc:
	Likewise.
	* testsuite/24_iterators/move_iterator/cust.cc: Likewise.
	* testsuite/24_iterators/move_iterator/dr3435.cc: Likewise.
	* testsuite/24_iterators/move_iterator/input_iterator.cc:
	Likewise.
	* testsuite/24_iterators/move_iterator/lwg3390.cc: Likewise.
	* testsuite/24_iterators/move_iterator/lwg3391.cc: Likewise.
	* testsuite/24_iterators/move_iterator/move_only.cc: Likewise.
	* testsuite/24_iterators/move_iterator/p2520r0.cc: Likewise.
	* testsuite/24_iterators/move_iterator/rel_ops_c++20.cc:
	Likewise.
	* testsuite/24_iterators/move_iterator/sentinel.cc: Likewise.
	* testsuite/24_iterators/normal_iterator/cmp_c++20.cc: Likewise.
	* testsuite/24_iterators/output/concept.cc: Likewise.
	* testsuite/24_iterators/random_access/concept.cc: Likewise.
	* testsuite/24_iterators/range_access/range_access_cpp20.cc:
	Likewise.
	* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
	Likewise.
	* testsuite/24_iterators/range_operations/100768.cc: Likewise.
	* testsuite/24_iterators/range_operations/advance.cc: Likewise.
	* testsuite/24_iterators/range_operations/advance_overflow.cc:
	Likewise.
	* testsuite/24_iterators/range_operations/distance.cc: Likewise.
	* testsuite/24_iterators/range_operations/lwg3392.cc: Likewise.
	* testsuite/24_iterators/range_operations/next.cc: Likewise.
	* testsuite/24_iterators/range_operations/prev.cc: Likewise.
	* testsuite/24_iterators/reverse_iterator/cust.cc: Likewise.
	* testsuite/24_iterators/reverse_iterator/dr3435.cc: Likewise.
	* testsuite/24_iterators/reverse_iterator/rel_ops_c++20.cc:
	Likewise.
2023-09-16 00:10:45 +01:00
Jonathan Wakely
ed8fcd0df5 libstdc++: Remove dg-options "-std=gnu++2a" from XFAIL std::span tests
The testsuite will automatically select C++20 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++23
and C++26 as well.

We can also combine the { dg-require-effective-target c++2a } directive
with the dg-do selector.

We need to add the no_pch options for tests that define
_GLIBCXX_ASSERTIONS in the test, otherwise the PCH is included without
that defined.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/span/back_assert_neg.cc: Remove
	dg-options and add effective target selector to dg-do. Add
	no_pch.
	* testsuite/23_containers/span/back_neg.cc: Likewise.
	* testsuite/23_containers/span/cons_1_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/cons_2_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/first_2_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/first_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/first_neg.cc: Likewise.
	* testsuite/23_containers/span/front_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/front_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_assert_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_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/last_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.
	* testsuite/23_containers/span/subspan_neg.cc: Likewise.
	* testsuite/24_iterators/range_operations/advance_debug_neg.cc:
	Likewise.
2023-09-15 21:57:40 +01:00
Jonathan Wakely
7810fb3a14 libstdc++: Remove dg-options "-std=gnu++23" from remaining tests
The testsuite will automatically select C++23 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++26
as well.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/headers/limits/synopsis_cxx23.cc: Remove
	dg-options.
	* testsuite/18_support/headers/stdfloat/types_std.cc: Likewise.
	* testsuite/18_support/type_info/constexpr.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/current.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
	* testsuite/20_util/aligned_storage/deprecated-2b.cc: Likewise.
	* testsuite/20_util/aligned_union/deprecated-2b.cc: Likewise.
	* testsuite/20_util/bitset/access/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise.
	* testsuite/20_util/bitset/count/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/ext/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/operations/constexpr_c++23.cc:
	Likewise.
	* testsuite/20_util/bitset/version.cc: Likewise.
	* testsuite/20_util/from_chars/8.cc: Likewise.
	* testsuite/20_util/from_chars/constexpr.cc: Likewise.
	* testsuite/20_util/function/cons/deduction_c++23.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/4.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/dangling_ref.cc:
	Likewise.
	* testsuite/20_util/is_scoped_enum/value.cc: Likewise.
	* testsuite/20_util/is_scoped_enum/version.cc: Likewise.
	* testsuite/20_util/move_only_function/call.cc: Likewise.
	* testsuite/20_util/move_only_function/cons.cc: Likewise.
	* testsuite/20_util/move_only_function/move.cc: Likewise.
	* testsuite/20_util/move_only_function/version.cc: Likewise.
	* testsuite/20_util/optional/monadic/and_then.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else_neg.cc: Likewise.
	* testsuite/20_util/optional/monadic/pr109242.cc: Likewise.
	* testsuite/20_util/optional/monadic/transform.cc: Likewise.
	* testsuite/20_util/pair/p2321r2.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value2.cc:
	Likewise.
	* testsuite/20_util/reference_from_temporary/version.cc:
	Likewise.
	* testsuite/20_util/to_chars/constexpr.cc: Likewise.
	* testsuite/20_util/to_chars/float128_c++23.cc: Likewise.
	* testsuite/20_util/to_chars/float16_c++23.cc: Likewise.
	* testsuite/20_util/to_chars/version.cc: Likewise.
	* testsuite/20_util/to_underlying/1.cc: Likewise.
	* testsuite/20_util/to_underlying/version.cc: Likewise.
	* testsuite/20_util/tuple/p2321r2.cc: Likewise.
	* testsuite/20_util/unique_ptr/assign/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/comparison/constexpr.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/cons/constexpr_c++20.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/modifiers/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/specialized_algorithms/constexpr.cc: Likewise.
	* testsuite/20_util/unreachable/1.cc: Likewise.
	* testsuite/20_util/unreachable/version.cc: Likewise.
	* testsuite/20_util/uses_allocator/lwg3677.cc: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc: Likewise.
	* testsuite/21_strings/basic_string/operations/contains/char.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/contains/nonnull.cc: Likewise.
	* testsuite/21_strings/basic_string/operations/contains/wchar_t.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/wchar_t.cc: Likewise.
	* testsuite/23_containers/queue/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/stack/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/vector/bool/element_access/1.cc:
	Likewise.
	* testsuite/24_iterators/const_iterator/1.cc: Likewise.
	* testsuite/25_algorithms/contains/1.cc: Likewise.
	* testsuite/25_algorithms/contains_subrange/1.cc: Likewise.
	* testsuite/25_algorithms/find_last/1.cc: Likewise.
	* testsuite/25_algorithms/find_last_if/1.cc: Likewise.
	* testsuite/25_algorithms/find_last_if_not/1.cc: Likewise.
	* testsuite/25_algorithms/fold_left/1.cc: Likewise.
	* testsuite/25_algorithms/fold_right/1.cc: Likewise.
	* testsuite/25_algorithms/iota/1.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: Likewise.
	* testsuite/26_numerics/complex/ext_c++23.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc:
	Likewise.
	* testsuite/26_numerics/numbers/4.cc: Likewise.
	* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc: Likewise.
	* testsuite/27_io/filesystem/path/native/conv_c++23.cc:
	Likewise.
	* testsuite/27_io/spanstream/1.cc: Likewise.
	* testsuite/27_io/spanstream/2.cc: Likewise.
	* testsuite/27_io/spanstream/version.cc: Likewise.
	* testsuite/29_atomics/atomic_float/requirements_cxx23.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: Likewise.
	* testsuite/30_threads/packaged_task/cons/deduction_c++23.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/native/conv_c++23.cc:
	Likewise.
	* testsuite/std/ranges/adaptors/adjacent/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/adjacent_transform/1.cc:
	Likewise.
	* testsuite/std/ranges/adaptors/as_const/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk_by/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/enumerate/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/join_with/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/lwg3715.cc: Likewise.
	* testsuite/std/ranges/adaptors/slide/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/stride/1.cc: Likewise.
	* testsuite/std/ranges/cartesian_product/1.cc: Likewise.
	* testsuite/std/ranges/range_adaptor_closure.cc: Likewise.
	* testsuite/std/ranges/repeat/1.cc: Likewise.
	* testsuite/std/ranges/version_c++23.cc: Likewise.
	* testsuite/std/ranges/zip/1.cc: Likewise.
	* testsuite/std/ranges/zip_transform/1.cc: Likewise.
2023-09-15 21:57:40 +01:00
Jonathan Wakely
07c602bbbd libstdc++: Replace dg-options "-std=c++20" with dg-add-options strict_std
The testsuite will automatically select C++20 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++23
and C++26 as well. Because they test a problem seen with -std=c++20 add
the new { dg-add-options strict_std } directive so that the test runner
uses -std=c++NN not -std=gnu++NN.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/reverse_iterator/100639.cc: Remove
	dg-options and add dg-add-options strict_std.
	* testsuite/std/ranges/iota/93267.cc: Likewise.
	* testsuite/std/ranges/iota/96042.cc: Likewise.
	* testsuite/std/ranges/iota/size.cc: Likewise.
	* testsuite/std/ranges/subrange/96042.cc: Likewise.
2023-09-15 21:57:38 +01:00
Jonathan Wakely
51d702f3ba libstdc++: Disable PCH for tests that rely on include order
These tests expect to be able to #undef a feature test macro and then
include <version> to get it redefined. But if <version> has already been
included by the <bits/stdc++.h> PCH then including it again does nothing
and the macro remains undefined.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/move_iterator/p2520r0.cc: Add no_pch.
	* testsuite/std/format/functions/format.cc: Likewise.
	* testsuite/std/format/functions/format_c++23.cc: Likewise.
2023-08-17 08:42:45 +01:00
Jonathan Wakely
6eafdfc73c libstdc++: Implement P2538R1 ADL-proof std::projected
This was recently approved for C++26, but there's no harm in
implementing it unconditionally for C++20 and C++23. As it says in the
paper, it doesn't change the meaning of any valid code. It only enables
things that were previously ill-formed for questionable reasons.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (projected): Replace class
	template with alias template denoting an ADL-proofed helper.
	(incremental_traits<projected<Iter, Proj>>): Remove.
	* testsuite/24_iterators/indirect_callable/projected-adl.cc:
	New test.
2023-06-26 17:43:22 +01:00
Patrick Palka
0d94c6df18 libstdc++: Implement P2278R4 "cbegin should always return a constant iterator"
This also implements the approved follow-up LWG issues 3765, 3766, 3769,
3770, 3811, 3850, 3853, 3862 and 3872.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (const_iterator_t): Define for C++23.
	(const_sentinel_t): Likewise.
	(range_const_reference_t): Likewise.
	(constant_range): Likewise.
	(__cust_access::__possibly_const_range): Likewise, replacing ...
	(__cust_access::__as_const): ... this.
	(__cust_access::_CBegin::operator()): Redefine for C++23 as per P2278R4.
	(__cust_access::_CEnd::operator()): Likewise.
	(__cust_access::_CRBegin::operator()): Likewise.
	(__cust_access::_CREnd::operator()): Likewise.
	(__cust_access::_CData::operator()): Likewise.
	* include/bits/ranges_util.h (ranges::__detail::__different_from):
	Make it an alias of std::__detail::__different_from.
	(view_interface::cbegin): Define for C++23.
	(view_interface::cend): Likewise.
	* include/bits/stl_iterator.h (__detail::__different_from): Define.
	(iter_const_reference_t): Define for C++23.
	(__detail::__constant_iterator): Likewise.
	(__detail::__is_const_iterator): Likewise.
	(__detail::__not_a_const_iterator): Likewise.
	(__detail::__iter_const_rvalue_reference_t): Likewise.
	(__detail::__basic_const_iter_cat):: Likewise.
	(const_iterator): Likewise.
	(__detail::__const_sentinel): Likewise.
	(const_sentinel): Likewise.
	(basic_const_iterator): Likewise.
	(common_type<basic_const_iterator<_Tp>, _Up>): Likewise.
	(common_type<_Up, basic_const_iterator<_Tp>>): Likewise.
	(common_type<basic_const_iterator<_Tp>, basic_const_iterator<Up>>):
	Likewise.
	(make_const_iterator): Define for C++23.
	(make_const_sentinel): Likewise.
	* include/std/ranges (__cpp_lib_ranges_as_const): Likewise.
	(as_const_view): Likewise.
	(enable_borrowed_range<as_const_view>): Likewise.
	(views::__detail::__is_ref_view): Likewise.
	(views::__detail::__can_is_const_view): Likewise.
	(views::_AsConst, views::as_const): Likewise.
	* include/std/span (span::const_iterator): Likewise.
	(span::const_reverse_iterator): Likewise.
	(span::cbegin): Likewise.
	(span::cend): Likewise.
	(span::crbegin): Likewise.
	(span::crend): Likewise.
	* include/std/version (__cpp_lib_ranges_as_const): Likewise.
	* testsuite/std/ranges/adaptors/join.cc (test06): Adjust to
	behave independently of C++20 vs C++23.
	* testsuite/std/ranges/version_c++23.cc: Verify value of
	__cpp_lib_ranges_as_const macro.
	* testsuite/24_iterators/const_iterator/1.cc: New test.
	* testsuite/std/ranges/adaptors/as_const/1.cc: New test.
2023-04-14 10:32:12 -04:00
Jonathan Wakely
ad0b9cf1a0 libstdc++: Make std::istream_iterator copy ctor constexpr (LWG 3600)
As explained in LWG 3600, we never implemented a C++0x change that made
the copy constructor of std::istream_iterator defined as defaulted. That
would be an ABI break, so the resolution of LWG 3600 is to not require
it to be trivial, but just constexpr and conditionally noexcept. This
applies that resolution.

libstdc++-v3/ChangeLog:

	* include/bits/stream_iterator.h (istream_iterator): Add
	constexpr to copy constructor, as per LWG 3600.
	* testsuite/24_iterators/istream_iterator/cons/constexpr.cc:
	Check copy construction.
2023-03-22 17:48:19 +00:00
Patrick Palka
2b204accd0 libstdc++: Implement P2520R0 changes to move_iterator's iterator_concept
libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (move_iterator::_S_iter_concept):
	Define.
	(__cpp_lib_move_iterator_concept): Define for C++20.
	(move_iterator::iterator_concept): Strengthen as per P2520R0.
	* include/std/version (__cpp_lib_move_iterator_concept): Define
	for C++20.
	* testsuite/24_iterators/move_iterator/p2520r0.cc: New test.
2023-03-14 16:44:32 -04:00
Jakub Jelinek
83ffe9cde7 Update copyright years. 2023-01-16 11:52:17 +01:00
Jonathan Wakely
bbcb84bba0 libstdc++: Fix -Wsystem-headers warnings in tests
libstdc++-v3/ChangeLog:

	* testsuite/18_support/new_nothrow.cc: Add missing noexcept
	to operator delete replacements.
	* testsuite/20_util/any/cons/92156.cc: Disable
	-Winit-list-lifetime warnings from instantiating invalid
	specialization of manager function.
	* testsuite/20_util/any/modifiers/92156.cc: Likewise.
	* testsuite/20_util/default_delete/void_neg.cc: Prune additional
	diagnostics.
	* testsuite/20_util/headers/memory/synopsis.cc: Add missing
	noexcept.
	* testsuite/20_util/shared_ptr/cons/void_neg.cc: Prune
	additional diagnostic.
	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Add
	missing noexcept to operator delete replacements.
	* testsuite/21_strings/basic_string/cons/char/103919.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/emplace/92300.cc:
	Likewise.
	* testsuite/23_containers/map/modifiers/insert/92300.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/range_access_c++11.cc:
	Add missing noexcept to synopsis declarations.
	* testsuite/24_iterators/headers/iterator/range_access_c++14.cc:
	Likewise.
	* testsuite/24_iterators/headers/iterator/range_access_c++17.cc:
	Likewise.
2022-11-08 17:35:15 +00:00
Jonathan Wakely
1d2f07ed4c libstdc++: Revert addition of constraints to make_signed/make_unsigned
Constraining the primary template makes it unusable in uninstantiated
contexts.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (make_signed, make_unsigned): Remove
	constraints on primary template.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
	Undo changes to expected error in C++20 mode.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.
	* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/uninstantiated.cc:
	New test.
	* testsuite/20_util/make_unsigned/requirements/uninstantiated.cc:
	New test.
2022-10-10 21:37:03 +01:00