aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
AgeCommit message (Collapse)AuthorFilesLines
14 hoursChange bellow in comments to belowJakub Jelinek1-2/+2
While I'm not a native English speaker, I believe all the uses of bellow (roar/bark/...) in comments in gcc are meant to be below (beneath/under/...). 2025-07-10 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-vect-loop.cc (scale_profile_for_vect_loop): Comment spelling fix: bellow -> below. * ipa-polymorphic-call.cc (record_known_type): Likewise. * config/i386/x86-tune.def: Likewise. * config/riscv/vector.md (*vsetvldi_no_side_effects_si_extend): Likewise. * tree-scalar-evolution.cc (iv_can_overflow_p): Likewise. * ipa-devirt.cc (add_type_duplicate): Likewise. * tree-ssa-loop-niter.cc (maybe_lower_iteration_bound): Likewise. * gimple-ssa-sccopy.cc: Likewise. * cgraphunit.cc: Likewise. * graphite.h (struct poly_dr): Likewise. * ipa-reference.cc (ignore_edge_p): Likewise. * tree-ssa-alias.cc (ao_compare::compare_ao_refs): Likewise. * profile-count.h (profile_probability::probably_reliable_p): Likewise. * ipa-inline-transform.cc (inline_call): Likewise. gcc/ada/ * par-load.adb: Comment spelling fix: bellow -> below. * libgnarl/s-taskin.ads: Likewise. gcc/testsuite/ * gfortran.dg/g77/980310-3.f: Comment spelling fix: bellow -> below. * jit.dg/test-debuginfo.c: Likewise. libstdc++-v3/ * testsuite/22_locale/codecvt/codecvt_unicode.h (ucs2_to_utf8_out_error): Comment spelling fix: bellow -> below. (utf16_to_ucs2_in_error): Likewise.
29 hourslibstdc++: Do not use list-initialization in std::span members [PR120997]Jonathan Wakely1-0/+46
As the bug report shows, for span<const bool> the return statements of the form `return {data(), count};` will use the new C++26 constructor, span(initializer_list<element_type>). Although the conversions from data() to bool and count to bool are narrowing and should be ill-formed, in system headers the narrowing diagnostics are suppressed. In any case, even if the compiler diagnosed them as ill-formed, we still don't want the initializer_list constructor to be used. We want to use the span(element_type*, size_t) constructor instead. Replace the braced-init-list uses with S(data(), count) where S is the correct return type. We need to make similar changes in the C++26 working draft, which will be taken care of via an LWG issue. libstdc++-v3/ChangeLog: PR libstdc++/120997 * include/std/span (span::first, span::last, span::subspan): Do not use braced-init-list for return statements. * testsuite/23_containers/span/120997.cc: New test.
35 hourslibstdc++: Add smart ptr owner_equals and owner_hash [PR117403]Paul Keir9-0/+498
New structs and member functions added to C++26 by P1901R2. libstdc++-v3/ChangeLog: PR libstdc++/117403 * include/bits/shared_ptr.h (shared_ptr::owner_equal) (shared_ptr::owner_hash, weak_ptr::owner_equal) (weak_ptr::owner_hash): Define new member functions. * include/bits/shared_ptr_base.h (owner_equal, owner_hash): Define new structs. * include/bits/version.def (smart_ptr_owner_equality): Define. * include/bits/version.h: Regenerate. * include/std/memory: Added define for __glibcxx_want_smart_ptr_owner_equality. * testsuite/20_util/owner_equal/version.cc: New test. * testsuite/20_util/owner_equal/cmp.cc: New test. * testsuite/20_util/owner_equal/noexcept.cc: New test. * testsuite/20_util/owner_hash/cmp.cc: New test. * testsuite/20_util/owner_hash/noexcept.cc: New test. * testsuite/20_util/shared_ptr/observers/owner_equal.cc: New test. * testsuite/20_util/shared_ptr/observers/owner_hash.cc: New test. * testsuite/20_util/weak_ptr/observers/owner_equal.cc: New test. * testsuite/20_util/weak_ptr/observers/owner_hash.cc: New test. Signed-off-by: Paul Keir <paul.keir@uws.ac.uk>
35 hourslibstdc++: Added missing members to numeric_limits specializations for ↵Mateusz Zych1-0/+31
integer-class types [iterator.concept.winc]/11 says that std::numeric_limits should be specialized for integer-class types, with each member defined appropriately. libstdc++-v3/ChangeLog: * include/bits/max_size_type.h (numeric_limits<__max_size_type>): New members. (numeric_limits<__max_diff_type>): Likewise. * testsuite/std/ranges/iota/max_size_type.cc: New test cases. Signed-off-by: Mateusz Zych <mte.zych@gmail.com>
36 hourslibstdc++: Fix memory_resource.cc bootstrap failure for non-gthreads targetsJonathan Wakely1-0/+1
The new choose_block_size function added in r16-2112-gac2fb60a67d6d1 was defined inside an #ifdef _GLIBCXX_HAS_GTHREADS group, which means that it's not available for single-threaded targets, and so can't be used by unsynchronized_pool_resource. Move it before that preprocessor group so it's always defined. libstdc++-v3/ChangeLog: * src/c++17/memory_resource.cc: Adjust indentation of unnamed namespaces. (pool_sizes): Add comment. (choose_block_size): Move outside preprocessor group for gthreads targets. * testsuite/20_util/synchronized_pool_resource/118681.cc: Require gthreads.
46 hourslibstdc++: Fix double free in new pool resource test [PR118681]Jonathan Wakely1-1/+1
This was supposed to free p1 and p2, not free p2 twice. libstdc++-v3/ChangeLog: PR libstdc++/118681 * testsuite/20_util/unsynchronized_pool_resource/118681.cc: Fix deallocate argument.
2 dayslibstdc++: Ensure pool resources meet alignment requirements [PR118681]Jonathan Wakely2-0/+63
For allocations with size > alignment and size % alignment != 0 we were sometimes returning pointers that did not meet the requested aligment. For example, allocate(24, 16) would select the pool for 24-byte objects and the second allocation from that pool (at offset 24 bytes into the pool) is only 8-byte aligned not 16-byte aligned. The pool resources need to round up the requested allocation size to a multiple of the alignment, so that the selected pool will always return allocations that meet the alignment requirement. libstdc++-v3/ChangeLog: PR libstdc++/118681 * src/c++17/memory_resource.cc (choose_block_size): New function. (synchronized_pool_resource::do_allocate): Use choose_block_size to determine appropriate block size. (synchronized_pool_resource::do_deallocate): Likewise (unsynchronized_pool_resource::do_allocate): Likewise. (unsynchronized_pool_resource::do_deallocate): Likewise * testsuite/20_util/synchronized_pool_resource/118681.cc: New test. * testsuite/20_util/unsynchronized_pool_resource/118681.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2 dayslibstdc++: Do not expose set_brackets/set_separator for formatter with ↵Tomasz Kamiński1-0/+52
format_kind other than sequence [PR119861] The standard defines separate specializations of range-default-formatter, out of which only one for range_format::sequence provide the set_brackets and set_separator methods. We implemented it as one specialization and exposed this method for range_format other than string or debug_string, i.e. when range_formatter was used as underlying formatter. PR libstdc++/119861 libstdc++-v3/ChangeLog: * include/std/format (formatter<_Rg, _CharT>::set_separator) (formatter<_Rg, _CharT>::set_brackets): Constrain with (format_kind<_Rg> == range_format::sequence). * testsuite/std/format/ranges/pr119861_neg.cc: New test.
2 dayslibstdc++: Better CTAD for span and mdspan [PR120914].Luc Grosheintz3-0/+48
This implements P3029R1. In P3029R1, the CTAD for span is refined to permit deducing the extent of the span from an integral constant, e.g. span((T*) ptr, integral_constant<size_t, 5>{}); is deduced as span<T, 5>. Similarly, in auto exts = extents(integral_constant<int, 2>); auto md = mdspan((T*) ptr, integral_constant<int, 2>); exts and md have types extents<size_t, 2> and mdspan<double, extents<size_t, 2>>, respectively. PR libstdc++/120914 libstdc++-v3/ChangeLog: * include/std/span (span): Update CTAD to enable integral constants [P3029R1]. * include/std/mdspan (extents): ditto. (mdspan): ditto. * testsuite/23_containers/span/deduction.cc: Test deduction guide. * testsuite/23_containers/mdspan/extents/misc.cc: ditto. * testsuite/23_containers/mdspan/mdspan.cc: ditto. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Silence a warning in a test for span.Luc Grosheintz1-0/+1
In a test of span, there's an unused variable myspan. This commit silences the warning. libstdc++-v3/ChangeLog: * testsuite/23_containers/span/contiguous_range_neg.cc: Silence warning about unused variable myspan. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Set feature test macro for complete C++23 mdspan [PR107761].Luc Grosheintz1-0/+9
PR libstdc++/107761 libstdc++-v3/ChangeLog: * include/bits/version.def (mdspan): Set to 202207 and remove no_stdname. * include/bits/version.h: Regenerate. * testsuite/23_containers/mdspan/version.cc: Test presence of feature test macro. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Implement mdspan and tests [PR107761].Luc Grosheintz4-0/+791
Implements the class mdspan as described in N4950, i.e. without P3029. It also adds tests for mdspan. This commit completes the implementation of P0009, i.e. the C++23 part <mdspan>. PR libstdc++/107761 libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan): New class. * src/c++23/std.cc.in (mdspan): Add. * testsuite/23_containers/mdspan/class_mandate_neg.cc: New test. * testsuite/23_containers/mdspan/mdspan.cc: New test. * testsuite/23_containers/mdspan/layout_like.h: Add class LayoutLike which models a user-defined layout. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Restructure mdspan tests to reuse IntLike.Luc Grosheintz2-26/+31
The class IntLike is used for testing extents with user-defined classes that convert to int. This commit places the class into a separate header file. This allows it to be reused across different parts of the mdspan related testsuite. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/extents/custom_integer.cc: Delete IntLike and include "int_like.h". * testsuite/23_containers/mdspan/extents/int_like.h: Add IntLike. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Check prerequisite of extents::extents.Luc Grosheintz2-0/+37
Previously the prerequisite of the extents ctors that static_extent(i) == dynamic_extent || extent(i) == other.extent(i). was not checked. This commit adds the __glibcxx_assert and test them. libstdc++-v3/ChangeLog: * include/std/mdspan (extents): Check prerequisite of the ctor that static_extent(i) == dynamic_extent || extent(i) == other.extent(i). * testsuite/23_containers/mdspan/extents/class_mandates_neg.cc: Test the implemented prerequisite. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 dayslibstdc++: Check prerequisites of layout_*::operator().Luc Grosheintz1-0/+30
Previously, the prerequisite that the arguments passed to operator() are a multi-dimensional index (of extents()) was not checked. Both mapping::operator() and mdspan::operator[] have the same prerequisite. Since, mdspan must check the prerequisite for user-defined layout mappings, the preference is to check in mdspan. Because out-of-bounds accesses are very common it's nevertheless useful to check the prerequisite in mapping::operator(). This is relevant for cases where the layout mappings are used without mdspan. This commit checks the prerequisites via _GLIBCXX_DEBUG_ASSERTs and adds the required tests. More discussion in the email chain starting at: https://gcc.gnu.org/pipermail/libstdc++/2025-July/062265.html libstdc++-v3/ChangeLog: * include/std/mdspan: Check prerequisites of layout_*::operator() with _GLIBCXX_DEBUG_ASSERTs. * testsuite/23_containers/mdspan/layouts/debug/out_of_bounds_neg.cc: Add tests for prerequisites. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
3 dayslibstdc++: Make debug iterator pointer sequence const [PR116369]François Dumont6-1/+77
In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence have been made mutable to allow attach iterators to const containers. This change completes this fix by also declaring debug unordered container members mutable. Additionally the debug iterator sequence is now a pointer-to-const and so _Safe_sequence_base _M_attach and all other methods are const qualified. Not-const methods exported are preserved for abi backward compatibility. libstdc++-v3/ChangeLog: PR c++/116369 * config/abi/pre/gnu-versioned-namespace.ver: Use new const qualified symbols. * config/abi/pre/gnu.ver: Add new const qualified symbols. * include/debug/safe_base.h (_Safe_iterator_base::_M_sequence): Declare as pointer-to-const. (_Safe_iterator_base::_M_attach, _M_attach_single): New, take pointer-to-const _Safe_sequence_base. (_Safe_sequence_base::_M_detach_all, _M_detach_singular, _M_revalidate_singular) (_M_swap, _M_get_mutex): New, const qualified. (_Safe_sequence_base::_M_attach, _M_attach_single, _M_detach, _M_detach_single): const qualify. * include/debug/safe_container.h (_Safe_container<>::_M_cont): Add const qualifier. (_Safe_container<>::_M_swap_base): New. (_Safe_container(_Safe_container&&, const _Alloc&, std::false_type)): Adapt to use latter. (_Safe_container<>::operator=(_Safe_container&&)): Likewise. (_Safe_container<>::_M_swap): Likewise and take parameter as const reference. * include/debug/safe_unordered_base.h (_Safe_local_iterator_base::_M_safe_container): New. (_Safe_local_iterator_base::_Safe_local_iterator_base): Take _Safe_unordered_container_base as pointer-to-const. (_Safe_unordered_container_base::_M_attach, _M_attach_single): New, take container as _Safe_unordered_container_base pointer-to-const. (_Safe_unordered_container_base::_M_local_iterators, _M_const_local_iterators): Add mutable. (_Safe_unordered_container_base::_M_detach_all, _M_swap): New, const qualify. (_Safe_unordered_container_base::_M_attach_local, _M_attach_local_single) (_M_detach_local, _M_detach_local_single): Add const qualifier. * include/debug/safe_unordered_container.h (_Safe_unordered_container::_M_self()): New. * include/debug/safe_unordered_container.tcc (_Safe_unordered_container::_M_invalidate_if, _M_invalidated_local_if): Use latter. * include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach, _M_attach_single): Take _Safe_sequence_base as pointer-to-const. (_Safe_iterator<>::_M_get_sequence): Add const_cast and comment about it. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>): Replace usages of _M_sequence member by _M_safe_container(). (_Safe_local_iterator<>::_M_attach, _M_attach_single): Take _Safe_unordered_container_base as pointer-to-const. (_Safe_local_iterator<>::_M_get_sequence): Rename into... (_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add necessary const_cast and comment to explain it. (_Safe_local_iterator<>::_M_is_begin, _M_is_end): Adapt. * include/debug/safe_local_iterator.tcc: Adapt. * include/debug/safe_sequence.h (_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if): Add const qualifier. * include/debug/safe_sequence.tcc: Adapt. * include/debug/deque (std::__debug::deque::erase): Adapt to use new const qualified methods. * include/debug/formatter.h: Adapt. * include/debug/forward_list (_Safe_forward_list::_M_this): Add const qualification and return pointer for consistency with 'this' keyword. (_Safe_forward_list::_M_swap_aux): Rename into... (_Safe_forward_list::_S_swap_aux): ...this and take sequence as const reference. (forward_list<>::resize): Adapt to use const methods. * include/debug/list (list<>::resize): Likewise. * src/c++11/debug.cc: Adapt to const qualification. * testsuite/util/testsuite_containers.h (forward_members_unordered::forward_members_unordered): Add check on local_iterator conversion to const_local_iterator. (forward_members::forward_members): Add check on iterator conversion to const_iterator. * testsuite/23_containers/unordered_map/const_container.cc: New test case. * testsuite/23_containers/unordered_multimap/const_container.cc: New test case. * testsuite/23_containers/unordered_multiset/const_container.cc: New test case. * testsuite/23_containers/unordered_set/const_container.cc: New test case. * testsuite/23_containers/vector/debug/mutex_association.cc: Adapt.
3 dayslibstdc++: Make VERIFY a variadic macroJonathan Wakely2-10/+35
This defines the testsuite assertion macro VERIFY so that it allows un-parenthesized expressions containing commas. This matches how assert is defined in C++26, following the approval of P2264R7. The primary motivation is to allow expressions that the preprocessor splits into multiple arguments, e.g. VERIFY( vec == std::vector<int>{1,2,3,4} ); To achieve this, VERIFY is redefined as a variadic macro and then the arguments are grouped together again through the use of __VA_ARGS__. The implementation is complex due to the following points: - The arguments __VA_ARGS__ are contextually-converted to bool, so that scoped enums and types that are not contextually convertible to bool cannot be used with VERIFY. - bool(__VA_ARGS__) is used so that multiple arguments (i.e. those which are separated by top-level commas) are ill-formed. Nested commas are allowed, but likely mistakes such as VERIFY( cond, "some string" ) are ill-formed. - The bool(__VA_ARGS__) expression needs to be unevaluated, so that we don't evaluate __VA_ARGS__ more than once. The simplest way to do that would be just sizeof bool(__VA_ARGS__), without parentheses to avoid a vexing parse for VERIFY(bool(i)). However that wouldn't work for e.g. VERIFY( []{ return true; }() ), because lambda expressions are not allowed in unevaluated contexts until C++20. So we use another conditional expression with bool(__VA_ARGS__) as the unevaluated operand. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_hooks.h (VERIFY): Define as variadic macro. * testsuite/ext/verify_neg.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 dayslibstdc++: Format chrono %a/%A/%b/%h/%B/%p using locale's time_put [PR117214]XU Kailiang2-0/+44
C++ formatting locale could have a custom time_put that performs differently from the C locale, so do not use __timepunct directly, instead all of above specifiers use _M_locale_fmt. For %a/%A/%b/%h/%B, the code handling the exception is now moved to the _M_check_ok function, that is invoked before handling of the conversion specifier. For time_points the values of months/weekday are computed, and thus are always ok(), this information is indicated by new _M_time_point member of the _ChronoSpec. The different behavior of j specifier for durations and time_points/calendar types, is now handled using only _ChronoParts, and _M_time_only in _ChronoSpec is no longer needed, thus it was removed. PR libstdc++/117214 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (_ChronoSpec::_M_time_only): Remove. (_ChronoSpec::_M_time_point): Define. (__formatter_chrono::_M_parse): Use __parts to determine interpretation of j. (__formatter_chrono::_M_check_ok): Define. (__formatter_chrono::_M_format_to): Invoke _M_check_ok. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B): Move exception throwing to _M_check_ok. (__formatter_chrono::_M_j): Use _M_needs to define interpretation. (__formatter_duration::_S_spec_for): Set _M_time_point. * testsuite/std/time/format/format.cc: Test for exception for !ok() months/weekday. * testsuite/std/time/format/pr117214_custom_timeput.cc: New test. Co-authored-by: Tomasz Kaminski <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: XU Kailiang <xu2k3l4@outlook.com> Signed-off-by: Tomasz Kaminski <tkaminsk@redhat.com>
4 dayslibstdc++: Implement ranges::shift_left/right from P2440R1Patrick Palka2-0/+209
The implementation is just a copy of std::shift_left/right with the following changes: - check bidirectional_iterator instead of iterator_category - cope with __last being a distinct sentinel type - for shift_left, return the subrange {__first, X} instead of X - for shift_right, return the subrange {X, ranges::next(__first, __last)} instead of X - use the ranges:: versions of move_backward, move and iter_swap - don't bother std::move'ing any iterators, it's unnecessary since all iterators are forward, it's visually noisy, and in earlier versions of this patch it introduced subtle use-after-move bugs In passing also use the __glibcxx_shift macro to guard the std::shift_left/right implementations. libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (shift_left, shift_right): Guard with __glibcxx_shift >= 201806L. (ranges::__shift_left_fn, ranges::shift_left): Define for C++23. (ranges::__shift_right_fn, ranges::shift_right): Likewise. * include/bits/version.def (shift): Update for C++23. * include/bits/version.h: Regenerate. * src/c++23/std.cc.in: Add ranges::shift_left/right. * testsuite/25_algorithms/shift_left/constrained.cc: New test, based off of 1.cc. * testsuite/25_algorithms/shift_right/constrained.cc: New test, based off of 1.cc. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
7 dayslibstdc++: Update LWG 4166 changes to concat_view::end() [PR120934]Patrick Palka1-0/+13
In r15-4555-gf191c830154565 we proactively implemented the initial proposed resolution for LWG 4166 which later turned out to be insufficient, since we must also require equality_comparable of the underlying iterators before concat_view could be a common range. This patch implements the updated P/R, requiring all underlying iterators to be forward (which implies equality_comparable) before making concat_view common, which fixes the testcase from this PR. PR libstdc++/120934 libstdc++-v3/ChangeLog: * include/std/ranges (concat_view::end): Refine condition for returning an iterator instead of default_sentinel as per the updated P/R for LWG 4166. * testsuite/std/ranges/concat/1.cc (test05): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
7 dayslibstdc++: construct bitset from string_view (P2697) [PR119742]Nathan Myers4-3/+143
Add a bitset constructor from string_view, per P2697. Fix existing tests that would fail to detect incorrect exception behavior. Argument checks that result in exceptions guarded by "#if HOSTED" are made unguarded because the functions called to throw just call terminate() in free-standing builds. Improve readability in Doxygen comments. Generalize a private member argument-checking function to work with string and string_view without mentioning either, obviating need for guards. The version.h symbol is not "hosted" because string_view, though not specified to be available in free-standing builds, is defined there and the feature is useful there. libstdc++-v3/ChangeLog: PR libstdc++/119742 * include/bits/version.def: Add preprocessor symbol. * include/bits/version.h: Add preprocessor symbol. * include/std/bitset: Add constructor. * testsuite/20_util/bitset/cons/1.cc: Fix. * testsuite/20_util/bitset/cons/6282.cc: Fix. * testsuite/20_util/bitset/cons/string_view.cc: Test new ctor. * testsuite/20_util/bitset/cons/string_view_wide.cc: Test new ctor.
8 dayslibstdc++: Fix regression in std::uninitialized_fill for C++98 [PR120931]Jonathan Wakely1-0/+16
A typo in r15-4473-g3abe751ea86e34 made it ill-formed to use std::uninitialized_fill with iterators that aren't pointers (or pointers wrapped in our __normal_iterator) if the value type is a narrow character type. libstdc++-v3/ChangeLog: PR libstdc++/120931 * include/bits/stl_uninitialized.h (__uninitialized_fill<true>): Fix typo resulting in call to __do_uninit_copy instead of __do_uninit_fill. * testsuite/20_util/specialized_algorithms/uninitialized_fill/120931.cc: New test.
9 dayslibstdc++: Use ranges::iter_move in ranges::remove_if [PR120789]Patrick Palka1-0/+36
PR libstdc++/120789 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__remove_if_fn::operator()): Use ranges::iter_move(iter) instead of std::move(*iter). * testsuite/25_algorithms/remove_if/120789.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
9 dayslibstdc++: Use ranges::iter_move in ranges::unique [PR120789]Patrick Palka1-0/+36
PR libstdc++/120789 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__unique_fn::operator()): Use ranges::iter_move(iter) instead of std::move(*iter). * testsuite/25_algorithms/unique/120789.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
9 dayslibstdc++: Implement default_accessor from mdspan.Luc Grosheintz2-0/+122
libstdc++-v3/ChangeLog: * include/std/mdspan (default_accessor): New class. * src/c++23/std.cc.in: Register default_accessor. * testsuite/23_containers/mdspan/accessors/default.cc: New test. * testsuite/23_containers/mdspan/accessors/default_neg.cc: New test. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
13 dayslibstdc++: Directly implement ranges::shuffle [PR100795]Patrick Palka1-0/+25
PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (shuffle_fn::operator()): Reimplement directly, based on the stl_algo.h implementation. * testsuite/25_algorithms/shuffle/constrained.cc (test02): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::sample [PR100795]Patrick Palka1-0/+26
PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__sample_fn::operator()): Reimplement the forward_iterator branch directly, based on the stl_algo.h implementation. Add explicit cast to _Out's difference_type in the !forward_iterator branch. * testsuite/25_algorithms/sample/constrained.cc (test02): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::nth_element [PR100795]Patrick Palka1-0/+31
PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__introselect): New, based on the stl_algo.h implementation. (nth_element_fn::operator()): Reimplement in terms of the above. * testsuite/25_algorithms/nth_element/constrained.cc: Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::stable_partition [PR100795]Patrick Palka1-0/+26
PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__find_if_not_n): New, based on the stl_algo.h implementation. (__detail::__stable_partition_adaptive): Likewise. (__stable_partition_fn::operator()): Reimplement in terms of the above. * testsuite/25_algorithms/stable_partition/constrained.cc (test03): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::stable_sort [PR100795]Patrick Palka1-0/+30
PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__move_merge): New, based on the stl_algo.h implementation. (__detail::__merge_sort_loop): Likewise. (__detail::__chunk_insertion_sort): Likewise. (__detail::__merge_sort_with_buffer): Likewise. (__detail::__stable_sort_adaptive): Likewise. (__detail::__stable_sort_adaptive_resize): Likewise. (__detail::__inplace_stable_sort): Likewise. (__stable_sort_fn::operator()): Reimplement in terms of the above. * testsuite/25_algorithms/stable_sort/constrained.cc: Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::inplace_merge [PR100795]Patrick Palka1-0/+36
As with the previous patch, this patch reimplements ranges::inplace_merge directly instead of incorrectly forwarding to std::inplace_merge. In addition to the compatibility changes listed in the previous patch we also: - explicitly cast the difference type (which can be an integer class) to ptrdiff_t when constructing a _Temporary_buffer PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__move_merge_adaptive): New, based on the stl_algo.h implementation. (__detail::__move_merge_adaptive_backward): Likewise. (__detail::__rotate_adaptive): Likewise. (__detail::__merge_adaptive): Likewise. (__detail::__merge_adaptive_resize): Likewise. (__detail::__merge_without_buffer): Likewise. (__inplace_merge_fn::operator()): Reimplement in terms of the above. * testsuite/25_algorithms/inplace_merge/constrained.cc (test03): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::sort [PR100795]Patrick Palka2-0/+54
As with the previous patch, this patch reimplements ranges::sort directly instead of incorrectly forwarding to std::sort. In addition to the compatibility changes listed in the previous patch we also: - use ranges::iter_swap instead of std::iter_swap - use ranges::move_backward instead of std::move_backward - use __bit_width and __to_unsigned_like instead of __lg PR libstdc++/100795 PR libstdc++/118209 libstdc++-v3/ChangeLog: * include/bits/max_size_type.h (__bit_width): New explicit specialization for __max_size_type. * include/bits/ranges_algo.h (__detail::__move_median_to_first): New, based on the stl_algo.h implementation. (__detail::__unguarded_liner_insert): Likewise. (__detail::__insertion_sort): Likewise. (__detail::__sort_threshold): Likewise. (__detail::__unguarded_insertion_sort): Likewise. (__detail::__final_insertion_sort): Likewise. (__detail::__unguarded_partition): Likewise. (__detail::__unguarded_partition_pivot): Likewise. (__detail::__heap_select): Likewise. (__detail::__partial_sort): Likewise. (__detail::__introsort_loop): Likewise. (__sort_fn::operator()): Reimplement in terms of the above. * testsuite/25_algorithms/sort/118209.cc: New test. * testsuite/25_algorithms/sort/constrained.cc (test03): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Directly implement ranges::heap algos [PR100795]Patrick Palka1-0/+46
ranges::push_heap, ranges::pop_heap, ranges::make_heap and ranges::sort_heap are currently defined in terms of the corresponding STL-style algorithms, but this is incorrect because the STL-style algorithms rely on the legacy iterator system, and so misbehave when passed a narrowly C++20 random access iterator. The other ranges heap algos, ranges::is_heap and ranges::is_heap_until, are implemented directly already and have no known issues. This patch reimplements these ranges:: algos directly instead, based closely on the legacy stl_heap.h implementation, with the following changes for compatibility with the C++20 iterator system: - handle non-common ranges by computing the corresponding end iterator - use ranges::iter_move instead of std::move(*iter) - use iter_value_t / iter_difference_t instead of iterator_traits Besides these changes, the implementation of these algorithms is intended to mirror the stl_heap.h implementations, for ease of maintenance and review. Note that we don't explicitly pass the projection function throughout, instead we just create and pass a composite predicate via __make_comp_proj. PR libstdc++/100795 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__push_heap): New, based on the stl_heap.h implementation. (__push_heap_fn::operator()): Reimplement in terms of the above. (__detail::__adjust_heap): New, based on the stl_heap.h implementation. (__deatil::__pop_heap): Likewise. (__pop_heap_fn::operator()): Reimplement in terms of the above. (__make_heap_fn::operator()): Likewise. (__sort_heap_fn::operator()): Likewise. * testsuite/25_algorithms/heap/constrained.cc (test03): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
13 dayslibstdc++: Fix warnings introduced by type-erasing for chrono commits [PR110739]Tomasz Kamiński1-17/+26
The r16-1709-g4b3cefed1a08344495fedec4982d85168bd8173f caused `-Woverflow` in empty_spec.cc file. This warning is not cause by any issue in shipping code, and results in taking to much shortcut when implementing a test-only custom representation type Rep, where long was always used to store a value. In particular common type for Rep and long long int, was de-facto long. This is addressed by adding Under template parameter, that controls the type of stored value, and handling it properly in common_type specializations. No changes to shipping code are necessary. Secondly, extracting _M_locale_fmt calls in r16-1712-gcaac94, resulted in __ctx format parameter no longer being used. This patch removes such parameter entirely, and replace _FormatContext template parameter, with _OutIter parameter for __out. For consistency type of the __out is decoupled from _FormatContext, for functions that still need context: * to extract locale (_M_A_a, _M_B_b, _M_c, _M_p, _M_r, _M_subsecs) * perform formatting for duration/subseconds (_M_Q, _M_T, _M_S, _M_subsecs) PR libstdc++/110739 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_format_to): Rename _Out to _OutIter for consistency, and update calls to specifier functions. (__formatter_chrono::_M_wi, __formatter_chrono::_M_C_y_Y) (__formatter_chrono::_M_D_x, __formatter_chrono::_M_d_e) (__formatter_chrono::_M_F, __formatter_chrono::_M_g_G) (__formatter_chrono::_M_H_I, __formatter_chrono::_M_j) (__formatter_chrono::_M_m, __formatter_chrono::_M_M) (__formatter_chrono::_M_q, __formatter_chrono::_M_R_X) (__formatter_chrono::_M_u_w, __formatter_chrono::_M_U_V_W) (__formatter_chrono::_M_z, __formatter_chrono::_M_z): Remove _FormatContext parameter, and introduce _OutIter for __out type. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_B_b) (__formatter_chrono::_M_p, __formatter_chrono::_M_Q) (__formatter_chrono::_M_r, __formatter_chrono::_M_S) (__formatter_chrono::_M_subsecs, __formatter_chrono::_M_T): Introduce separate _OutIter template parameter for __out. (__formatter_chrono::_M_c, __formatter_chrono::_M_T): Likewise, and adjust calls to specifiers functions. * testsuite/std/time/format/empty_spec.cc: Make underlying type for Rep configurable.
2025-06-26libstdc++: Type-erase chrono-data for formatting [PR110739]Tomasz Kamiński1-8/+8
This patch reworks the formatting for the chrono types, such that they are all formatted in terms of _ChronoData class, that includes all required fields. Populating each required field is performed in formatter for specific type, based on the chrono-spec used. To facilitate above, the _ChronoSpec now includes additional _M_needed field, that represnts the chrono data that is referenced by format spec (this value is also configured for __defSpec). This value differs from the value of __parts passed to _M_parse, which does include all fields that can be computed from input (e.g. weekday_indexed can be computed for year_month_day). Later it is used to fill _ChronoData, in particular _M_fill_* family of functions, to determine if given field needs to be set, and thus its value needs to be computed. In consequence _ChronoParts enum was extended with additional values, that allows more fine grained identification: * _TimeOfDay is separated into _HoursMinutesSeconds and _Subseconds, * _TimeZone is separated into _ZoneAbbrev and _ZoneOffset, * _LocalDays, _WeekdayIndex are defined and in included in _Date, * _Duration is removed, and instead _EpochUnits and _UnitSuffix are introduced. Furthermore, to avoid name conflicts _ChonoParts is now defined as enum class, with additional operators that simplify uses. In addition to fields that can be printed using chrono-spec, _ChronoData stores: * Total days in wall time (_M_ldays), day of year (_M_day_of_year) - used by struct tm construction, and for ISO calendar computation. * Total seconds in wall time (_M_lseconds) - this value may be different from sum of days, hours, minutes, seconds (e.g. see utc_time below). Included to allow future extension, like printing total minutes. * Total seconds since epoch - due offset different from above. Again to be used with future extension (e.g. %s as proposed in P2945R1). * Subseconds - count of attoseconds (10^(-18)), in addition to printing can be used to compute fractional hours, minutes. The both total seconds fields use single _TotalSeconds enumerator in _ChronoParts, that when present in combination with _EpochUnits or _LocalDays indicates that _M_eseconds (_EpochSeconds) or _M_lseconds (_LocalSeconds) are provided/required. To handle type formatting of time since epoch ('%Q'|_EpochUnits), we use the format_args mechanism, where the result of +d.count() (see LWG4118) is erased into make_format_args to local __arg_store, that is later referenced by _M_ereps (_M_ereps.get(0)). To handle precision values, and in prepartion to allow user to configure ones, we store the precision as third element of _M_ereps (_M_ereps.get(2)), this allows duration with precision to be printed using "{0:{2}}". For subseconds the precision is handled differently depending on the representation: * for integral reps, _M_subseconds value is used to determine fractional value, precision is trimmed to 18 digits; * for floating-points, _M_ereps stores duration<Rep> initialized with only fractional seconds, that is later formatted with precision. Always using _M_subseconds fields for integral duration, means that we do not use formattter for user-defined durations that are considered to be integral (see empty_spec.cc file change). To avoid potentially expensive computation of _M_subseconds, we make sure that _ChronoParts::_Subseconds is set only if _Subseconds are needed. In particular we remove this flag for localized ouput in _M_parse. Construction of the _M_ereps as described above is handled by __formatter_duration, that is then used to format duration, hh_mm_ss and time_points specializations. This class also handles _UnitSuffix, the _M_units_suffix field is populated either with predefined suffix (chrono::__detail::__units_suffix) or one produced locally. Finally, formatters for types listed below contains type specific logic: * hh_mm_ss - we do not compute total duration and seconds, unless explicitly requested, as such computation may overflow; * utc_time - for time during leap second insertion, the _M_seconds field is increased to 60; * __local_time_fmt - exception is thrown if zone offset (_ZoneOffset) or abbrevation (_ZoneAbbrev) is requsted, but corresponding pointer is null, futhermore conversion from `char` to `wchar_t` for abbreviation is performed if needed. PR libstdc++/110739 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__format::__no_timezone_available): Removed, replaced with separate throws in formatter for __local_time_fmt (__format::_ChronoParts): Defined additional enumertors and declared as enum class. (__format::operator&(_ChronoParts, _ChronoParts)) (__format::operator&=(_ChronoParts&, _ChronoParts)) (__format::operator-(_ChronoParts, _ChronoParts)) (__format::operator-=(_ChronoParts&, _ChronoParts)) (__format::operator==(_ChronoParts, decltype(nullptr))) (_ChronoSpec::_M_time_only, _ChronoSpec::_M_floating_point_rep) (_ChronoSpec::_M_custom_rep, _ChronoSpec::_M_needed) (_ChronoSpec::_M_needs, __format::_ChronoData): Define. (__format::__formatter_chrono): Redefine to accept _ChronoData. (__formatter_chrono::_M_format_to_ostream): Moved to __formatter_duration. (__format::__formatter_duration): Define. (__formatter_chrono_info::format): Pass value-constructed _ChronoData. (std::formatter<chrono::day, _CharT>) (std::formatter<chrono::month, _CharT>) (std::formatter<chrono::year, _CharT>) (std::formatter<chrono::weekday, _CharT>) (std::formatter<chrono::weekday_indexed, _CharT>) (std::formatter<chrono::weekday_last, _CharT>) (std::formatter<chrono::month_day, _CharT>) (std::formatter<chrono::month_day_last, _CharT>) (std::formatter<chrono::month_weekday, _CharT>) (std::formatter<chrono::month_weekday_indexed, _CharT>) (std::formatter<chrono::month_weekday_last, _CharT>) (std::formatter<chrono::year_month, _CharT>) (std::formatter<chrono::year_month_day, _CharT>) (std::formatter<chrono::year_month_day_last, _CharT>) (std::formatter<chrono::year_month_weekday, _CharT>) (std::formatter<chrono::year_month_weekday_indexed, _CharT>) (std::formatter<chrono::year_month_weekday_last, _CharT>): Construct _ChronoData in format, and configure _M_needed in _ChronoSpec. (std::formatter<chrono::duration<_Rep, _Period>, _CharT>) (std::formatter<chrono::hh_mm_ss<_Duration>, _CharT>) (std::formatter<chrono::sys_time<_Duration>, _CharT>) (std::formatter<chrono::utc_time<_Duration>, _CharT>) (std::formatter<chrono::tai_time<_Duration>, _CharT>) (std::formatter<chrono::gps_time<_Duration>, _CharT>) (std::formatter<chrono::file_time<_Duration>, _CharT>) (std::formatter<chrono::local_time<_Duration>, _CharT>) (std::formatter<chrono::_detail::__local_time_fmt<_Duration>, _CharT>): Reworked in terms of __formatter_duration and _ChronoData. (std::formatter<chrono::_detail::__utc_leap_second<_Duration>, _CharT>): Removed. (_Parser<_Duration>::operator()): Adjusted for _ChronoParts being enum class. * include/std/chrono (__detail::__utc_leap_second): Removed, replaced with simply bumping _M_seconds in _ChronoData. * testsuite/std/time/format/empty_spec.cc: Updated %S integral ouput. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-26libstdc++: Implement C++26 P2927R3 - Inspecting exception_ptrJakub Jelinek2-0/+82
The following patch attempts to implement the C++26 P2927R3 - Inspecting exception_ptr paper (but not including P3748R0, I plan to play with it incrementally and it will really depend on the Constexpr exceptions patch). The function template is implemented using an out of line private method of exception_ptr, so that P3748R0 then can use if consteval and provide a constant evaluation variant of it. 2025-06-26 Jakub Jelinek <jakub@redhat.com> * include/bits/version.def (exception_ptr_cast): Add. * include/bits/version.h: Regenerate. * libsupc++/exception: Define __glibcxx_want_exception_ptr_cast before including bits/version.h. * libsupc++/exception_ptr.h (std::exception_ptr_cast): Define. (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Declare. * libsupc++/eh_ptr.cc (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Define. * src/c++23/std.cc.in (std::exception_ptr_cast): Export. * config/abi/pre/gnu.ver: Export _ZNKSt15__exception_ptr13exception_ptr21_M_exception_ptr_castERKSt9type_info at CXXABI_1.3.17. * testsuite/util/testsuite_abi.cc (check_version): Allow CXXABI_1.3.17. * testsuite/18_support/exception_ptr/exception_ptr_cast.cc: New test.
2025-06-26c++, libstdc++: Implement C++26 P2830R10 - Constexpr Type OrderingJakub Jelinek1-0/+95
The following patch attempts to implement the C++26 P2830R10 - Constexpr Type Ordering paper, with a minor change that std::type_order<T, U> class template doesn't derive from integer_constant, because std::strong_ordering is not a structural type (except in MSVC), so instead it is just a class template with static constexpr strong_ordering value member and also value_type, type and 2 operators. The paper mostly talks about using something other than mangled names for the ordering, but given that the mangler is part of the GCC C++ FE, using the mangler seems to be the best ordering choice to me. 2025-06-26 Jakub Jelinek <jakub@redhat.com> gcc/cp/ * cp-trait.def: Implement C++26 P2830R10 - Constexpr Type Ordering. (TYPE_ORDER): New. * method.cc (type_order_value): Define. * cp-tree.h (type_order_value): Declare. * semantics.cc (trait_expr_value): Use gcc_unreachable also for CPTK_TYPE_ORDER, adjust comment. (finish_trait_expr): Handle CPTK_TYPE_ORDER. * constraint.cc (diagnose_trait_expr): Likewise. gcc/testsuite/ * g++.dg/cpp26/type-order1.C: New test. * g++.dg/cpp26/type-order2.C: New test. * g++.dg/cpp26/type-order3.C: New test. libstdc++-v3/ * include/bits/version.def (type_order): New. * include/bits/version.h: Regenerate. * libsupc++/compare: Define __glibcxx_want_type_order before including bits/version.h. (std::type_order, std::type_order_v): New trait and template variable. * src/c++23/std.cc.in (std::type_order, std::type_order_v): Export. * testsuite/18_support/comparisons/type_order/1.cc: New test.
2025-06-25libstdc++: Test for %S precision for durations with integral representation.Tomasz Kamiński1-5/+99
Existing test are extented to cover cases where not precision is specified, or it is specified to zero. The precision value is ignored in all cases. libstdc++-v3/ChangeLog: * testsuite/std/time/format/precision.cc: New tests.
2025-06-25libstdc++: Report compilation error on formatting "%d" from month_last ↵Tomasz Kamiński1-0/+164
[PR120650] For month_day we incorrectly reported day information to be available, which lead to format_error being thrown from the call to formatter::format at runtime, instead of making call to format ill-formed. The included test cover most of the combinations of _ChronoParts and format specifiers. PR libstdc++/120650 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (formatter<chrono::month_day_last,_CharT>::parse): Call _M_parse with only Month being available. * testsuite/std/time/format/data_not_present_neg.cc: New test.
2025-06-24libstdc++: Unnecessary type completion in __is_complete_or_unbounded [PR120717]Patrick Palka1-0/+20
When checking __is_complete_or_unbounded on a reference to incomplete type, we overeagerly try to instantiate/complete the referenced type which besides being unnecessary may also produce an unexpected -Wsfinae-incomplete warning (added in r16-1527) if the referenced type is later defined. This patch fixes this by effectively restricting the sizeof check to object (except unknown-bound array) types. In passing simplify the implementation by using is_object instead of is_function/reference/void and introducing a __maybe_complete_object_type helper. PR libstdc++/120717 libstdc++-v3/ChangeLog: * include/std/type_traits (__maybe_complete_object_type): New helper trait, factored out from ... (__is_complete_or_unbounded): ... here. Only check sizeof on a __maybe_complete_object_type type. Fix formatting. * testsuite/20_util/is_complete_or_unbounded/120717.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-06-16c++: add -Wsfinae-incompleteJason Merrill2-2/+2
We already error about a type or function definition causing a concept check to change value, but it would be useful to diagnose this for other SFINAE contexts as well; the memoization problem also affects templates. So -Wsfinae-incomplete remembers if we've failed a requirement for a complete type/deduced return type in a non-tf_error context, and later warns if the type/function becomes complete. This warning is enabled by default; I think the signal-to-noise ratio is high enough to warrant that, and it catches things that are likely to make the program "ill-formed, no diagnostic required". friend87.C is an interesting case; this could be considered a false positive because it is using friend injection to define the auto function to implement a compile-time counter. I think this is sufficiently pathological that it's fine to expect people who want to play this sort of game to suppress the warning. The data for this warning uses GTY((cache)) to persist through GC, but allow entries to be discarded if the key is not otherwise marked. I don't think it's desirable to export/import this information in modules, it makes sense for it to be local to a single TU. -Wsfinae-incomplete=2 adds a warning at the point of failure, which is primarily intended to help with debugging warnings from the default mode. gcc/ChangeLog: * doc/invoke.texi: Document -Wsfinae-incomplete. gcc/c-family/ChangeLog: * c.opt: Add -Wsfinae-incomplete. * c.opt.urls: Regenerate. gcc/cp/ChangeLog: * constraint.cc (failed_completions_map): New. (note_failed_type_completion): Rename from note_failed_type_completion_for_satisfaction. Add -Wsfinae-incomplete handling. (failed_completion_location): New. * class.cc (finish_struct_1): Add -Wsfinae-incomplete warning. * decl.cc (require_deduced_type): Adjust. (finish_function): Add -Wsfinae-incomplete warning. * typeck.cc (complete_type_or_maybe_complain): Adjust. (cxx_sizeof_or_alignof_type): Call note_failed_type_completion. * pt.cc (dependent_template_arg_p): No longer static. * cp-tree.h: Adjust. libstdc++-v3/ChangeLog: * testsuite/20_util/is_complete_or_unbounded/memoization.cc * testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc: Expect -Wsfinae-incomplete. gcc/testsuite/ChangeLog: * g++.dg/template/friend87.C * g++.dg/cpp2a/concepts-complete1.C * g++.dg/cpp2a/concepts-complete2.C * g++.dg/cpp2a/concepts-complete3.C * g++.dg/cpp2a/concepts-complete4.C: Expect -Wsfinae-incomplete.
2025-06-13libstdc++: Fix std::uninitialized_value_construct for arrays [PR120397]Jonathan Wakely2-0/+38
The std::uninitialized_{value,default}_construct{,_n} algorithms should be able to create arrays, but that currently fails because when an exception happens they clean up using std::_Destroy and in C++17 that doesn't support destroying arrays. (For C++20 and later, std::destroy does handle destroying arrays.) This commit adjusts the _UninitDestroyGuard RAII type used by those algos so that in C++17 mode it recursively destroys each rank of an array type, only using std::_Destroy for the last rank when it's destroying non-array objects. libstdc++-v3/ChangeLog: PR libstdc++/120397 * include/bits/stl_uninitialized.h (_UninitDestroyGuard<I,void>): Add new member function _S_destroy and call it from the destructor (for C++17 only). * testsuite/20_util/specialized_algorithms/uninitialized_default_construct/120397.cc: New test. * testsuite/20_util/specialized_algorithms/uninitialized_value_construct/120397.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-13libstdc++: Format %r, %x and %X using locale's time_put facet [PR120648]Tomasz Kamiński1-5/+38
Similarly to issue reported for %c in PR117214, the format string for locale specific time (%r, %X) and date (%x) representations may contain specifiers not accepted by chrono-spec, leading to exception being thrown. This happened for following conversion specifier and locale combinations: * %r, %X for aa_DJ.UTF-8, ar_SA.UTF-8 * %x for ca_AD.UTF-8, my_MM.UTF-8 This fix follows approach from r15-8490-gc24a1d5, and uses time_put to emit localized date format. The existing _M_c is reworked to handle all locale dependent conversion specifies, by accepting them as argument. It is also renamed to _M_c_r_x_X. PR libstdc++/120648 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_format_to): Handle %c, %r, %x and %X by passing them to _M_c_r_x_X. (__formatter_chrono::_M_c_r_x_X): Reworked from _M_c. (__formatter_chrono::_M_c): Renamed into above. (__formatter_chrono::_M_r, __formatter_chrono::_M_x) (__formatter_chrono::_M_X): Removed. * testsuite/std/time/format/pr117214.cc: New tests for %r, %x, %X with date, time and durations.
2025-06-13libstdc++: Replace _CharT template parameter with CharT in format tests.Tomasz Kamiński12-171/+169
As pointed out by Daniel Krügler we do not need to use reserved name in tests. libstdc++-v3/ChangeLog: * testsuite/23_containers/vector/bool/format.cc: Replaced _CharT with CharT. * testsuite/std/format/debug.cc: Likewise. * testsuite/std/format/ranges/adaptors.cc: Likewise. * testsuite/std/format/ranges/formatter.cc: Likewise. * testsuite/std/format/ranges/map.cc: Likewise. * testsuite/std/format/ranges/sequence.cc: Likewise. * testsuite/std/format/ranges/string.cc: Likewise. * testsuite/std/format/tuple.cc: Likewise. * testsuite/std/time/format/empty_spec.cc: Likewise. * testsuite/std/time/format/pr120114.cc: Likewise. * testsuite/std/time/format/pr120481.cc: Likewise. * testsuite/std/time/format/precision.cc: Likewise.
2025-06-13libstdc++: Test chrono-spec containing only whitespaces.Tomasz Kamiński1-0/+56
libstdc++-v3/ChangeLog: * testsuite/std/time/format/whitespace.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: do not use an unreserved name in _Temporary_buffer [PR119496]Giuseppe D'Angelo1-0/+4
As the PR observes, _Temporary_buffer was using an unreserved name for a member function that can therefore clash with macros defined by the user. Avoid that by renaming the member function. PR libstdc++/119496 libstdc++-v3/ChangeLog: * include/bits/stl_algo.h: Adjust calls to requested_size. * include/bits/stl_tempbuf.h (requested_size): Rename with an _M_ prefix. * testsuite/17_intro/names.cc: Add a #define for requested_size. Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2025-06-12libstdc++: add range support to std::optional (P3168)Giuseppe D'Angelo2-0/+181
This commit implements P3168 ("Give std::optional Range Support"), added for C++26. Both begin() and end() are straightforward, implemented using normal_iterator over a raw pointer. std::optional is also a view, so specialize enable_view for it. We also need to disable automatic formatting a std::optional as a range by specializing format_kind. In order to avoid dragging <format> when including <optional>, I've isolated format_kind and some supporting code into <bits/formatfwd.h> so that I can use that (comparatively) lighter header. libstdc++-v3/ChangeLog: * include/bits/formatfwd.h (format_kind): Move the definition (and some supporting code) from <format>. * include/std/format (format_kind): Likewise. * include/bits/version.def (optional_range_support): Add the feature-testing macro. * include/bits/version.h: Regenerate. * include/std/optional (iterator, const_iterator, begin, end): Add range support. (enable_view): Specialize for std::optional. (format_kind): Specialize for std::optional. * testsuite/20_util/optional/range.cc: New test. * testsuite/20_util/optional/version.cc: Test the new feature-testing macro.
2025-06-12libstdc++: Uglify __mapping_alike template parameter and fix test and typo ↵Tomasz Kamiński1-8/+10
in comment. When the static assert was generated from instantiations of default member initializer of class B, the error was not generated for B<1, std::layout_left, std::layout_left> case, only when -D_GLIBCXX_DEBUG was set. Changing B calls to functions fixes that. We also replace class with typename in template head of layout_right::mapping constructors. libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::__mapping_alike): Rename template parameter from M to _M_p. (layout_right::mapping): Replace class with typename in template head. (layout_stride::mapping): Fix typo in comment. * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Changed B to function. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Make layout_left(layout_stride) noexcept.Luc Grosheintz1-19/+14
[mdspan.layout.left.cons] of N4950 states that this ctor is not noexcept. Since, all other ctors of layout_left, layout_right or layout_stride are noexcept, the choice was made, based on [res.on.exception.handling], to make this ctor noexcept. Two other major standard library implementations make the same choice. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_left): Strengthen the exception guarantees of layout_left::mapping(layout_stride::mapping). * testsuite/23_containers/mdspan/layouts/ctors.cc: Simplify tests to reflect the change. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Add tests for layout_stride.Luc Grosheintz5-2/+725
Implements the tests for layout_stride and for the features of the other two layouts that depend on layout_stride. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/layouts/class_mandate_neg.cc: Add tests for layout_stride. * testsuite/23_containers/mdspan/layouts/ctors.cc: Add test for layout_stride and the interaction with other layouts. * testsuite/23_containers/mdspan/layouts/empty.cc: Ditto. * testsuite/23_containers/mdspan/layouts/mapping.cc: Ditto. * testsuite/23_containers/mdspan/layouts/stride.cc: New test. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>