aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std
AgeCommit message (Collapse)AuthorFilesLines
12 hourslibstdc++: Fix style issues in <mdspan>.Luc Grosheintz1-13/+4
libstdc++-v3/ChangeLog: * include/std/mdspan: Small stylistic adjustments. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
15 hourslibstdc++: Support braces as arguments for std::erase on inplace_vector ↵Tomasz Kamiński1-1/+1
[PR121196] PR libstdc++/121196 libstdc++-v3/ChangeLog: * include/std/inplace_vector (std::erase): Provide default argument for _Up parameter. * testsuite/23_containers/inplace_vector/erasure.cc: Add test for using braces-init-list as arguments to erase_if and use function to verify content of inplace_vector Reviewed-by: Patrick Palka <ppalka@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
7 dayslibstdc++: Fix obvious mistake in inplace_vector::assign_range [PR119137]Tomasz Kamiński1-1/+1
In case of input iterators, the loop that assigns to existing elements should run up to number of elements in vector (_M_size) not capacity (_Nm). PR libstdc++/119137 libstdc++-v3/ChangeLog: * include/std/inplace_vector (inplace_vector::assign_range): Replace _Nm with _M_size in the assigment loop.
7 dayslibstdc++: Make the default ctor of mdspan conditionally noexcept.Luc Grosheintz1-7/+5
Previously, the default ctor of mdspan was never noexcept, even if all members of mdspan were nothrow default constructible. This commit makes mdspan conditionally nothrow default constructible. A similar strengthening happens in libc++. libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan::mdspan): Make default ctor conditionally noexcept. * testsuite/23_containers/mdspan/mdspan.cc: Add tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
7 dayslibstdc++: Strengthen exception guarantee for mdspan methods.Luc Grosheintz1-6/+16
The mdspan::is_{,always}_{unique,strided,exhaustive} methods only call their counterparts in mdspan::mapping_type. The standard specifies that the methods of mdspan::mapping_type are noexcept, but doesn't specify if the methods of mdspan are noexcept. Libc++ strengthened the exception guarantee for these mdspan methods. This commit conditionally strengthens these methods for libstdc++. libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan::is_always_unique): Make conditionally noexcept. (mdspan::is_always_exhaustive): Ditto. (mdspan::is_always_strided): Ditto. (mdspan::is_unique): Ditto. (mdspan::is_exhaustive): Ditto. (mdspan::is_strided): Ditto. * testsuite/23_containers/mdspan/layout_like.h: Make noexcept configurable. Add ThrowingLayout. * testsuite/23_containers/mdspan/mdspan.cc: Add tests for noexcept. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
10 dayslibstdc++: Qualify addressof calls in inplace_vector [PR119137]Tomasz Kamiński1-2/+2
PR libstdc++/119137 libstdc++-v3/ChangeLog: * include/std/inplace_vector (inplace_vector::operator=): Qualify call to std::addressof.
11 dayslibstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]Jonathan Wakely1-0/+1379
Implement std::inplace_vector as specified in P0843R14, without follow up papers, in particular P3074R7 (trivial unions). In consequence inplace_vector<T, N> can be used inside constant evaluations only if T is trivial or N is equal to zero. We provide a separate specialization for inplace_vector<T, 0> to meet the requirements of N5008 [inplace.vector.overview] p5. In particular objects of such types needs to be empty. To allow constexpr variable of inplace_vector v, where v.size() < v.capacity(), we need to guaranteed that all elements of the storage array are initialized, even ones in range [v.data() + v.size(), v.data() + v.capacity()). This is perfoirmed by _M_init function, that is called by each constructor. By storing the array in anonymous union, we can perform this initialization in constant evaluation, avoiding the impact on runtime path. The size() function conveys the information that _M_size <= _Nm to compiler, by calling __builtin_unreachable(). In particular this allows us to eliminate FP warnings by using _Nm - size() instead of _Nm - _M_size, when computing available elements. The included test cover almost all code paths at runtime, however some compile time evaluation test are not yet implemented: * operations on range, they depend on making testsuite_iterators constexpr * negative test for invoking operations with preconditions at compile time, especially for zero size specialization. PR libstdc++/119137 libstdc++-v3/ChangeLog: * doc/doxygen/user.cfg.in (INPUT): Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/stl_iterator_base_types.h (__any_input_iterator): Define. * include/bits/version.def (inplace_vector): Define. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include new header. * src/c++23/std.cc.in: Export contents if new header. * include/std/inplace_vector: New file. * testsuite/23_containers/inplace_vector/access/capacity.cc: New file. * testsuite/23_containers/inplace_vector/access/elem.cc: New file. * testsuite/23_containers/inplace_vector/access/elem_neg.cc: New file. * testsuite/23_containers/inplace_vector/cons/1.cc: New file. * testsuite/23_containers/inplace_vector/cons/from_range.cc: New file. * testsuite/23_containers/inplace_vector/cons/throws.cc: New file. * testsuite/23_containers/inplace_vector/copy.cc: New file. * testsuite/23_containers/inplace_vector/erasure.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/assign.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/erase.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/single_insert.cc: New file. * testsuite/23_containers/inplace_vector/move.cc: New file. * testsuite/23_containers/inplace_vector/relops.cc: New file. * testsuite/23_containers/inplace_vector/version.cc: New file. * testsuite/util/testsuite_iterators.h (input_iterator_wrapper::base): Define. Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
11 dayslibstdc++: Fix forwarding of custom IndexType in mdspan [PR121061]Luc Grosheintz1-4/+4
The second bug report in PR121061 is that the conversion of custom OtherIndexType to IndexType is incorrectly not done via r-value references. This commit fixes the forwarding issue, adds a custom IndexType called RValueInt, which only allows conversion to int via r-value reference. PR libstdc++/121061 libstdc++-v3/ChangeLog: * include/std/mdspan (extents::extents): Perform conversion to index_type of an r-value reference. (layout_left::mapping::operator()): Ditto. (layout_right::mapping::operator()): Ditto. (layout_stride::mapping::operator()): Ditto. * testsuite/23_containers/mdspan/extents/custom_integer.cc: Add tests for RValueInt and MutatingInt. * testsuite/23_containers/mdspan/int_like.h (RValueInt): Add. * testsuite/23_containers/mdspan/layouts/mapping.cc: Test with RValueInt. * 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>
11 dayslibstdc++: Fix constraint for custom integer types in mdspan [PR121061]Luc Grosheintz1-14/+20
PR121061 consists of two bugs for mdspan related code. This commit fixes the first one. Namely, when passing custom IndexType as an array or span, the conversion to int must be const. Prior to this commit the constraint incorrectly also allowed non-const conversion. This commit updates all related constraints to check __valid_index_type<const OtherIndexType&, index_type> in those cases. Also adds a MutatingInt to int_like.h which only supports non-const conversion to int and updates the tests. PR libstdc++/121061 libstdc++-v3/ChangeLog: * include/std/mdspan (extents::extents): Fix constraint to prevent non-const conversion to index_type. (layout_stride::mapping::mapping): Ditto. (mdspan::mdspan): Ditto. (mdspan::operator[]): Ditto. * testsuite/23_containers/mdspan/extents/custom_integer.cc: Add test for MutatingInt. * testsuite/23_containers/mdspan/int_like.h (MutatingInt): Add. * testsuite/23_containers/mdspan/layouts/mapping.cc: Add test for MutatingInt. * testsuite/23_containers/mdspan/layouts/stride.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>
12 dayslibstdc++: Use basic_string_view for std::bitset deduced typesJonathan Wakely1-1/+4
This change was part of by P2697R1 (Interfacing bitset with string_view) and should be slightly cheaper to instantiate. We should consider using basic_string_view for C++17, C++20, and C++23 as well. This patch just conservatively changes it for C++26 to match the working draft. It's conceivable that a program-defined specialization of basic_string<_CharT> or basic_string_view<_CharT> will observe a difference and be affected by this change. libstdc++-v3/ChangeLog: * include/std/bitset (__bitset::__string) [__cpp_lib_bitset]: Change alias to refer to basic_string_view instead. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
13 dayslibstdc++: Add missing initializers for __maybe_present_t members [PR119962]Patrick Palka1-3/+6
Data members of type __maybe_present_t where the conditionally present type might be an aggregate or fundamental type need to be explicitly value-initialized (rather than implicitly default-initialized), so that default-initialization of the containing class always results in an completely initialized object. PR libstdc++/119962 libstdc++-v3/ChangeLog: * include/std/ranges (join_view::_Iterator::_M_outer): Initialize. (lazy_split_view::_OuterIter::_M_current): Initialize. (join_with_view::_Iterator::_M_outer_it): Initialize. * testsuite/std/ranges/adaptors/join.cc (test15): New test. * testsuite/std/ranges/adaptors/join_with/1.cc (test05): New test. * testsuite/std/ranges/adaptors/lazy_split.cc (test13): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
14 dayslibstdc++: Ensure std::make_unsigned<Enum> works for 128-bit enumJonathan Wakely1-1/+6
Another follow-up to r16-2190-g4faa42ac0dee2c, ensuring that make_signed and make_unsigned work on enumeration types with 128-bit integers as their underlying type. libstdc++-v3/ChangeLog: * include/std/type_traits (__make_unsigned_selector): Add unsigned __int128 to type list. * testsuite/20_util/make_unsigned/int128.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-14libstdc++: Add comments to deleted std::swap overloads for LWG 2766Jonathan Wakely4-1/+9
We pre-emptively implemented part of LWG 2766, which still hasn't been approved. Add comments to the deleted swap overloads saying why they're there, because the standard doesn't require them. libstdc++-v3/ChangeLog: * include/bits/stl_pair.h (swap): Add comment to deleted overload. * include/bits/unique_ptr.h (swap): Likewise. * include/std/array (swap): Likewise. * include/std/optional (swap): Likewise. * include/std/tuple (swap): Likewise. * include/std/variant (swap): Likewise. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers.
2025-07-11libstdc++: Always treat __float128 as a floating-point typeJonathan Wakely1-1/+1
Similar to the previous commit that made is_integral_v<__int128> unconditionally true, this makes is_floating_point_v<__float128> unconditionally true. With the new extended floating-point types in C++23 (std::float64_t etc.) it seems unhelpful for is_floating_point_v to be true for them, but not for __float128. Especially as it is true on some targets, because __float128 is just a typedef for long double. This change makes is_floating_point_v<__float128> true whenever the type is defined, giving less surprising and more portable behaviour. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_floating<__float128>): Do not depend on __STRICT_ANSI__. * include/bits/stl_algobase.h (__size_to_integer(__float128)): Likewise. * include/std/type_traits (__is_floating_point_helper<__float128>): Likewise. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-07-11libstdc++: Treat __int128 as a real integral type [PR96710]Jonathan Wakely4-16/+30
Since LWG 3828 (included in C++23) implementations are allowed to have extended integer types that are wider than intmax_t. This means we no longer have to make is_integral_v<__int128> false for strict -std=c++23 mode, removing the confusing inconsistency with -std=gnu++23 (where is_integral_v<__int128> is true). This change makes __int128 a true integral type for all modes, treating LWG 3828 as a DR for previous standards. Most of the change just involves removing special cases where we wanted to treat __int128 and unsigned __int128 as integral types even when is_integral_v was false. There are still some preprocessor conditionals needed, because on some targets the compiler defines the macro __GLIBCXX_TYPE_INT_N_0 as __int128 in non-strict modes. Because we define explicit specializations of templates such as is_integral for all the INT_N types, we already have a specialization of is_integral<__int128> in non-strict modes, and so to avoid a redefinition we only must only define is_integral<__int128> for strict modes. libstdc++-v3/ChangeLog: PR libstdc++/96710 * include/bits/cpp_type_traits.h (__is_integer): Define explicit specializations for __int128. (__memcpyable_integer): Remove explicit specializations for __int128. * include/bits/iterator_concepts.h (incrementable_traits): Likewise. (__is_signed_int128, __is_unsigned_int128, __is_int128): Remove. (__is_integer_like, __is_signed_integer_like): Remove check for __int128. * include/bits/max_size_type.h: Remove all uses of __is_int128 in constraints. * include/bits/ranges_base.h (__to_unsigned_like): Remove overloads for __int128. (ranges::ssize): Remove special case for __int128. * include/bits/stl_algobase.h (__size_to_integer): Define __int128 overloads for strict modes. * include/ext/numeric_traits.h (__is_integer_nonstrict): Remove explicit specializations for __int128. * include/std/charconv (to_chars): Define overloads for __int128. * include/std/format (__format::make_unsigned_t): Remove. (__format::to_chars): Remove. * include/std/limits (numeric_limits): Define explicit specializations for __int128. * include/std/type_traits (__is_integral_helper): Likewise. (__make_unsigned, __make_signed): Likewise. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-07-09libstdc++: Add more template keywords to <mdspan> for ClangJonathan Wakely1-2/+2
This fixes: include/c++/16.0.0/mdspan:1182:33: error: use 'template' keyword to treat 'mapping' as a dependent template name 1182 | const typename _OLayout::mapping<_OExtents>&> | ^ include/c++/16.0.0/mdspan:1185:31: error: use 'template' keyword to treat 'mapping' as a dependent template name 1185 | const typename _OLayout::mapping<_OExtents>&, mapping_type> | ^ libstdc++-v3/ChangeLog: * include/std/mdspan (mdspan): Add template keyword for dependent name.
2025-07-09libstdc++: Do not use list-initialization in std::span members [PR120997]Jonathan Wakely1-7/+8
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.
2025-07-09libstdc++: Add smart ptr owner_equals and owner_hash [PR117403]Paul Keir1-0/+1
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>
2025-07-08libstdc++: Do not expose set_brackets/set_separator for formatter with ↵Tomasz Kamiński1-2/+2
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.
2025-07-08libstdc++: Better CTAD for span and mdspan [PR120914].Luc Grosheintz2-7/+21
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>
2025-07-08libstdc++: Implement mdspan and tests [PR107761].Luc Grosheintz1-0/+285
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>
2025-07-08libstdc++: Implement __mdspan::__size.Luc Grosheintz1-4/+8
The current code uses __mdspan::__fwd_prod(__exts, __rank) to express computing the size of an extent. This commit adds an function __mdspan:: __size(__exts) to express the idea more directly. libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::__size): New function. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-07-08libstdc++: Check prerequisite of extents::extents.Luc Grosheintz1-0/+13
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>
2025-07-08libstdc++: Check prerequisites of layout_*::operator().Luc Grosheintz1-0/+5
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>
2025-07-08libstdc++: Document that LWG 3881 is resolved, by using different apporach.Tomasz Kamiński1-2/+8
libstdc++-v3/ChangeLog: * include/std/queue (formatter<queue<_Tp, _Container>, _CharT>) (formatter<priority_queue<_Tp, _Container, _Compare>, _CharT>): Add _GLIBCXX_RESOLVE_LIB_DEFECTS comments.
2025-07-07libstdc++: Use template keyword in __mapping_of alias templateJonathan Wakely1-1/+1
This is needed to fix an error with Clang 19: include/c++/16.0.0/mdspan:512:30: error: use 'template' keyword to treat 'mapping' as a dependent template name 512 | is_same_v<typename _Layout::mapping<typename _Mapping::extents_type>, | ^ libstdc++-v3/ChangeLog: * include/std/mdspan (__mapping_of): Add template keyword.
2025-07-07libstdc++: Format __float128 as _Float128 only when long double is not 128 ↵Tomasz Kamiński1-8/+3
IEEE [PR120976] For powerpc64 and sparc architectures that both have __float128 and 128bit long double, the __float128 is same type as long double/__ieee128 and already formattable. The remaining specialization makes __float128 formattable on x86_64 via _Float128, however __float128 is now not formattable on x86_32 (-m32) with -mlong-double-128, where __float128 is distinct type from long double that is 128bit IEEE. PR libstdc++/120976 libstdc++-v3/ChangeLog: * include/std/format (formatter<__float128, _Char_T): Define if _GLIBCXX_FORMAT_F128 == 2. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-03libstdc++: Update LWG 4166 changes to concat_view::end() [PR120934]Patrick Palka1-2/+2
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>
2025-07-03libstdc++: construct bitset from string_view (P2697) [PR119742]Nathan Myers1-28/+54
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.
2025-07-02libstdc++: make range view ctors explicit (P2711) [PR119744]Nathan Myers1-16/+16
Make range view constructors explicit, per P2711. Technically, this is a breaking change, but it is unlikely to break any production code, as reliance on non-explicit construction is unidiomatic.. libstdc++-v3/ChangeLog PR libstdc++/119744 * include/std/ranges: View ctors become explicit.
2025-07-01libstdc++: Implement default_accessor from mdspan.Luc Grosheintz1-0/+31
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>
2025-06-26libstdc++: Type-erase chrono-data for formatting [PR110739]Tomasz Kamiński1-24/+0
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-24libstdc++: Unnecessary type completion in __is_complete_or_unbounded [PR120717]Patrick Palka1-17/+22
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-13libstdc++: add a workaround for format_kind<optional<T>> [PR120644]Giuseppe D'Angelo1-1/+1
The specialization of format_kind for optional is causing a problem when optional is imported and included. The comments on the PR strongly suggest that this is a frontend bug; this commit just works around the issue by specifying the type of format_kind<optional<T>> to be `range_format`, rather than leaving the compiler deduce it via `auto`. PR c++/120644 libstdc++-v3/ChangeLog: * include/std/optional (format_kind): Do not use `auto`.
2025-06-12libstdc++: add range support to std::optional (P3168)Giuseppe D'Angelo2-26/+47
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-11/+11
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-1/+2
[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++: Implement layout_stride from mdspan.Luc Grosheintz1-1/+248
Implements the remaining parts of layout_left and layout_right; and all of layout_stride. The implementation of layout_stride::mapping::is_exhaustive applies the following change to the standard: 4266. layout_stride::mapping should treat empty mappings as exhaustive https://cplusplus.github.io/LWG/issue4266 The preconditions for layout_stride(extents, strides) are not checked. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_stride): New class. * src/c++23/std.cc.in: Add layout_stride. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Implement layout_right from mdspan.Luc Grosheintz1-1/+152
Implement the parts of layout_left that depend on layout_right; and the parts of layout_right that don't depend on layout_stride. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_right): New class. * src/c++23/std.cc.in: Add layout_right. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Implement layout_left from mdspan.Luc Grosheintz1-1/+302
Implements the parts of layout_left that don't depend on any of the other layouts. libstdc++-v3/ChangeLog: * include/std/mdspan (layout_left): New class. * src/c++23/std.cc.in: Add layout_left. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Improve naming, whitespace and silence warnings for extents.Luc Grosheintz1-12/+12
libstdc++-v3/ChangeLog: * include/std/mdspan(__mdspan::_ExtentsStorage): Change name of private member _M_dynamic_extens to _M_dyn_exts. (extents): Change name of private member from _M_dynamic_extents to _M_exts. Fix two instances of whitespace errors. * testsuite/23_containers/mdspan/extents/ctor_default.cc: Fix integer comparison with cmp_equal. Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-12libstdc++: Do not specialize std::formatter for incomplete type [PR120625]Jonathan Wakely1-7/+11
Using an incomplete type as the template argument for std::formatter specializations causes problems for program-defined specializations of std::formatter which have constraints. When the compiler has to find which specialization of std::formatter to use for the incomplete type it considers the program-defined specializations and checks to see if their constraints are satisfied, which can give errors if the constraints cannot be checked for incomplete types. This replaces the base class of the disabled specializations with a concrete class __formatter_disabled, so there is no need to match a specialization and no more incomplete type. libstdc++-v3/ChangeLog: PR libstdc++/120625 * include/std/format (__format::__disabled): Remove. (__formatter_disabled): New type. (formatter<char*, wchar_t>, formatter<const char*, wchar_t>) (formatter<char[N], wchar_t>, formatter<string, wchar_t>) (formatter<string_view, wchar_t>): Use __formatter_disabled as base class instead of formatter<__disabled, wchar_t>. * testsuite/std/format/formatter/120625.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-11libstdc++: Fix mismatched @cond and @endcond in <type_traits>Jonathan Wakely1-0/+3
I messed up the Doxygen conditionals in r16-1077-gb32bf304793047. libstdc++-v3/ChangeLog: * include/std/type_traits: Restore @cond and @endcond balance.
2025-06-11libstdc++: Fix whitespace before comments in <sstream>Jonathan Wakely1-6/+6
libstdc++-v3/ChangeLog: * include/std/sstream: Adjust whitespace.
2025-06-10libstdc++: Implement LWG3528 make_from_tuple can perform (the equivalent of) ↵Yihan Wang1-2/+22
a C-style cast Implement LWG3528 to make std::make_from_tuple SFINAE friendly. libstdc++-v3/ChangeLog: * include/std/tuple (__can_make_from_tuple): New variable template. (__make_from_tuple_impl): Add static_assert. (make_from_tuple): Constrain using __can_make_from_tuple. * testsuite/20_util/tuple/dr3528.cc: New test. Signed-off-by: Yihan Wang <yronglin777@gmail.com> Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-09libstdc++: sstream from string_view (P2495R3) [PR119741]Nathan Myers1-18/+184
Add constructors to stringbuf, stringstream, istringstream, and ostringstream, and a matching overload of str(sv) in each, that take anything convertible to a string_view in places where the existing ctors and function take a string. Note this change omits the constraint applied to the istringstream constructor from string cited as a "drive-by" in P2495R3, as we have determined it is redundant. libstdc++-v3/ChangeLog: PR libstdc++/119741 * include/std/sstream: full implementation, really just decls, requires clause and plumbing. * include/bits/version.def, include/bits/version.h: new preprocessor symbol __cpp_lib_sstream_from_string_view. * testsuite/27_io/basic_stringbuf/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/char/string_view.cc: New tests. * testsuite/27_io/basic_stringbuf/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_istringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_ostringstream/cons/wchar_t/string_view.cc: New tests. * testsuite/27_io/basic_stringstream/cons/wchar_t/string_view.cc: New tests. Reviewed-by: Jonathan Wakely
2025-06-06libstdc++: Use std::conditional_t instead of lambda to select semaphore ↵Jonathan Wakely1-2/+2
implementation The lambda expression causes testsuite failures such as: FAIL g++.dg/modules/xtreme-header-2_b.C -std=c++26 (test for excess errors) libstdc++-v3/ChangeLog: * include/bits/semaphore_base.h (_Select_semaphore_impl): Rename to _Semaphore_impl and use std::conditional_t instead of an immediately invoked lambda expression. * include/std/semaphore (counting_semaphore): Adjust to use new name.
2025-06-06libstdc++: Fix flat_map::operator[] for const lvalue keys [PR120432]Patrick Palka1-3/+3
The const lvalue operator[] overload wasn't properly forwarding the key type to the generic overload, causing a hard error for const keys. Rather than correcting the forwarded type this patch just makes the non-template overloads call try_emplace directly instead. That way we can remove the non-standard same_as constraint on the generic overload and match the spec more closely. PR libstdc++/120432 libstdc++-v3/ChangeLog: * include/std/flat_map (flat_map::operator[]): Make the non-template overloads call try_emplace directly. Remove non-standard same_as constraint on the template overload. * testsuite/23_containers/flat_map/1.cc (test08): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-06-06libstdc++: Optimize std::counting_semaphore for futex pathJonathan Wakely1-3/+2
Rename __semaphore_base to __semaphore_impl, because it's not used as a base class. Replace the three identical lambda expressions with a named class, __semaphore_impl::_Available, which stores the most recent value of the counter as a data member, and provides call operators that test whether the value is decrementable (i.e. whether the semaphore can be acquired). Add a new __platform_semaphore_impl class template to be used when __platform_wait is available, which uses __platform_wait_t for the counter and uses more efficient atomic waits for the acquire functions. For a binary semaphore some members are further optimized because we know the counter can only be zero or one. Also add a bare wait flag to __atomic_wait_address_v, for consistency with __atomic_wait_address_until_v and __atomic_wait_address_for_v and to allow semaphores to use it without the redundant overhead of tracking waiters. libstdc++-v3/ChangeLog: * include/bits/atomic_wait.h (__atomic_wait_address_v): Add bare wait flag. * include/bits/semaphore_base.h (__semaphore_base): Rename to __semaphore_impl. Replace local variable and predicate lambdas with _Available struct. (__platform_semaphore_impl): New class template. (__semaphore_impl): Remove alias template. (_Select_semaphore_impl): New alias template. * include/std/semaphore (counting_semaphore): Use _Select_semaphore_impl.
2025-06-05libstdc++: Fix std::format thousands separators when sign present [PR120548]Jonathan Wakely1-2/+9
The leading sign character should be skipped when deciding whether to insert thousands separators into a floating-point format. libstdc++-v3/ChangeLog: PR libstdc++/120548 * include/std/format (__formatter_fp::_M_localize): Do not include a leading sign character in the string to be grouped. * testsuite/std/format/functions/format.cc: Check grouping when sign is present in the output. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>