aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
AgeCommit message (Collapse)AuthorFilesLines
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 chrono %a/%A/%b/%h/%B/%p using locale's time_put [PR117214]XU Kailiang1-15/+46
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>
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-06libstdc++: Implement ranges::shift_left/right from P2440R1Patrick Palka3-1/+125
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>
2025-07-05libstdc++: Avoid -Wswitch warning from chrono formattersJonathan Wakely1-0/+2
Add a default case to the switch to suppress warnings about unhandled enumeration values. This is a consteval function, so if the default case is ever reached it will be an error not silent miscompilation. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_duration::_S_spec_for): Add default case to switch and use __builtin_unreachable.
2025-07-05libstdc++: Fix typo in __size_to_integer(__GLIBCXX_TYPE_INT_N_3)Jonathan Wakely1-2/+2
The overload taking a signed type was returning unsigned and the overload taking an unsigned type was returning signed. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__size_to_integer): Move misplaced unsigned keyword on __size_to_integer overloads for __GLIBCXX_TYPE_INT_N_3 integer type.
2025-07-03libstdc++: fix bits/version.def typoNathan Myers2-2/+2
bits/version.def was missing a ';'. libstdc++-v3/Changelog: * include/bits/version.def: Fix typo. * include/bits/version.h: Rebuilt.
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 Myers3-28/+72
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-03libstdc++: Fix regression in std::uninitialized_fill for C++98 [PR120931]Jonathan Wakely1-1/+1
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.
2025-07-02libstdc++: Use hidden friends for __normal_iterator operatorsJonathan Wakely1-164/+175
As suggested by Jason, this makes all __normal_iterator operators into friends so they can be found by ADL and don't need to be separately exported in module std. The operator<=> comparing two iterators of the same type is removed entirely, instead of being made a hidden friend. That overload was added by r12-5882-g2c7fb16b5283cf to deal with unconstrained operator overloads found by ADL, as defined in the testsuite_greedy_ops.h header. We don't actually test that case as there's no unconstrained <=> in that header, and it doesn't seem reasonable for anybody to define such an operator<=> in C++20 when they should constrain their overloads properly (e.g. using a requires-clause). The homogeneous operator<=> overloads added for reverse_iterator and move_iterator could also be removed, but that's not part of this commit. I also had to reorder the __attribute__((always_inline)) and [[nodiscard]] attributes on the pre-c++20 operators, because Clang won't allow [[foo]] after __attribute__((bar)) on a friend function: <source>:4:36: error: an attribute list cannot appear here 4 | __attribute__((always_inline)) [[nodiscard]] friend bool | ^~~~~~~~~~~~~ libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__normal_iterator): Make all non-member operators hidden friends, except ... (operator<=>(__normal_iterator<I,C>, __normal_iterator<I,C>)): Remove. * src/c++11/string-inst.cc: Remove explicit instantiations of operators that are no longer templates. * src/c++23/std.cc.in (__gnu_cxx): Do not export operators for __normal_iterator. Reviewed-by: Patrick Palka <ppalka@redhat.com>
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++: Use ranges::iter_move in ranges::remove_if [PR120789]Patrick Palka1-1/+1
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>
2025-07-01libstdc++: Use ranges::iter_move in ranges::unique [PR120789]Patrick Palka1-1/+1
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>
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-27libstdc++: Directly implement ranges::shuffle [PR100795]Patrick Palka1-3/+55
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>
2025-06-27libstdc++: Directly implement ranges::sample [PR100795]Patrick Palka1-7/+63
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>
2025-06-27libstdc++: Directly implement ranges::nth_element [PR100795]Patrick Palka1-5/+42
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>
2025-06-27libstdc++: Directly implement ranges::stable_partition [PR100795]Patrick Palka1-5/+101
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>
2025-06-27libstdc++: Directly implement ranges::stable_sort [PR100795]Patrick Palka1-4/+203
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>
2025-06-27libstdc++: Directly implement ranges::inplace_merge [PR100795]Patrick Palka1-4/+253
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>
2025-06-27libstdc++: Directly implement ranges::sort [PR100795]Patrick Palka2-4/+175
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>
2025-06-27libstdc++: Directly implement ranges::heap algos [PR100795]Patrick Palka1-16/+124
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>
2025-06-27libstdc++: Use runtime format for internal format calls in chrono [PR110739]Tomasz Kamiński1-10/+27
This patch adjust all internal std::format call inside of __formatter_chrono, to use runtime format string and thus avoid compile time checking of validity of the format string. Majority of cases are covered by calling newly introduced _S_empty_fs() function that returns __Runtime_format_string containing _S_empty_spec, instead of passing later directly. In case of _M_j we use _S_str_d3 function (extracted from _S_str_d2), eliminating call to std::format outside of unlikely scenario in which day of year is greater than 1000 (this may happen for year_month_day with month greater than 12). In consequence, outside of handling subseconds, we no longer delegate to std::format or construct temporary strings, when formatting chrono types with ok() values. PR libstdc++/110739 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_S_empty_fs): Define. (__formatter_chrono::_S_str_d2): Use _S_str_d3 for 3+ digits and place allways_inline attribute after comment. (__formatter_chrono::_S_str_d3): Extracted from _S_str_d2. (__formatter_chrono::_M_H_I, __formatter_chrono::_M_R_X): Replace _S_empty_spec with _S_empty_fs(). (__formatter_chrono::_M_j): Likewise and use _S_str_d3 in common case. (__format::operator-(_ChronoParts, _ChronoParts)) (__format::operator-=(_ChronoParts, _ChronoParts)) (__formatter_chrono::_S_fill_two_digits) (__formatter_chrono::_S_str_d1): Place always_inline attribute after comment.
2025-06-27libstdc++: Fix warnings introduced by type-erasing for chrono commits [PR110739]Tomasz Kamiński1-118/+103
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++: Lift chrono localized formatting to main chrono format loop ↵Tomasz Kamiński1-167/+171
[PR110739] This patch extract calls to _M_locale_fmt and construction of the struct tm, from the functions dedicated to each specifier, to main format loop in _M_format_to functions. This removes duplicated code repeated for specifiers. To allow _M_locale_fmt to only be called if localized formatting is enabled ('L' is present in chrono-format-spec), we provide a implementations for locale specific specifiers (%c, %r, %x, %X) that produces the same result as locale::classic(): * %c is implemented as separate _M_c method * %r is implemented as separate _M_r method * %x is implemented together with %D, as they provide same behavior, * %X is implemented together with %R as _M_R_X, as both of them do not include subseconds. The handling of subseconds was also extracted to _M_subsecs function that is used by _M_S and _M_T specifier. The _M_T is now implemented in terms of _M_R_X (printing time without subseconds) and _M_subs. The __mod parameter responsible for triggering localized formatting was removed from methods handling most of specifiers, except: * _M_S (for %S) for which it determines if subseconds should be included, * _M_z (for %z) for which it determines if ':' is used as separator. PR libstdc++/110739 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_use_locale_fmt): Define. (__formatter_chrono::_M_locale_fmt): Moved to front of the class. (__formatter_chrono::_M_format_to): Construct and initialize struct tm and call _M_locale_fmt if needed. (__formatter_chrono::_M_c_r_x_X): Split into separate methods. (__formatter_chrono::_M_c, __formatter_chrono::_M_r): Define. (__formatter_chrono::_M_D): Renamed to _M_D_x. (__formatter_chrono::_M_D_x): Renamed from _M_D. (__formatter_chrono::_M_R_T): Split into _M_R_X and _M_T. (__formatter_chrono::_M_R_X): Extracted from _M_R_T. (__formatter_chrono::_M_T): Define in terms of _M_R_X and _M_subsecs. (__formatter_chrono::_M_subsecs): Extracted from _M_S. (__formatter_chrono::_M_S): Replaced __mod with __subs argument, removed _M_locale_fmt call, and delegate to _M_subsecs. (__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_d_e) (__formatter_chrono::_M_H_I, __formatter_chrono::_M_m) (__formatter_chrono::_M_u_w, __formatter_chrono::_M_U_V_W): Remove __mod argument and call to _M_locale_fmt. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-26libstdc++: Type-erase chrono-data for formatting [PR110739]Tomasz Kamiński2-821/+1157
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/+18
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 Jelinek2-0/+20
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++: Report compilation error on formatting "%d" from month_last ↵Tomasz Kamiński1-2/+1
[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-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++: Fix std::uninitialized_value_construct for arrays [PR120397]Jonathan Wakely1-0/+20
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-94/+34
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++: Optimize __make_comp/pred_proj for empty/scalar typesPatrick Palka1-16/+48
When creating a composite comparator/predicate that invokes a given projection function, we don't need to capture a scalar (such as a function pointer or member pointer) or empty object by reference, instead capture it by value and use [[no_unique_address]] to elide its storage (in the empty case). This makes using __make_comp_proj zero-cost in the common case where both functions are empty/scalars. libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__detail::__by_ref_or_value_fn): New. (__detail::_Comp_proj): New. (__detail::__make_comp_proj): Use it instead. (__detail::_Pred_proj): New. (__detail::__make_pred_proj): Use it instead. Reviewed-by: Tomasz Kamiński <tkaminsk@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-13libstdc++: Rework formatting of empty chrono-spec for duration.Tomasz Kamiński1-43/+45
In contrast to other calendar types if empty chrono-spec is used for duration we are required to format it (and its representation type) via ostream. Handling this case was now moved to be part of the format function for duration. To facilitate that __formatter_chrono::_M_format_to_ostream function was made public. However, for standard integral types, we know the result of inserting them into ostream, and in consequence we can format them directly. This is handled by configuring default format spec to "%Q%q" for such types. As we no longer use __formatter_chrono::_M_format with empty chrono-spec, this function now requires that _M_chrono_specs are not empty, and conditional call to _M_format_to_ostream is removed. This allows _M_format_to_ostream to be reduced to accept only duration. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_format): Remove handling of empty _M_chrono_specs. (__formatter_chrono::_M_format_to_ostream): Changed to accept only chrono::duration and made public. (std::formatter<chrono::duration<_Rep, _Period>, _CharT>): Configure __defSpec and handle empty chrono-spec locally. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-13libstdc++: Format empty chrono-spec for the sys_info and local_info directly.Tomasz Kamiński1-15/+85
This patch change implementation of the formatters for sys_info and local_info, so they no longer delegate to operator<< for ostream in case of empty spec. As this types may be only formatted with chrono-spec containing only %%, %t, %n specifiers and fill characters, we use a separate __formatter_chrono_info formatter. For empty chron-spec __formatter_chrono_info formats sys_info using format_to call with format specifier extracted from corresponding operator<<, that now delegates to format with empty spec. For local_info we replicate functionality of the operator<<. The alignment and padding is handled using an _Padding_sink. For non-empty spec, we delegate to __formatter_chrono::_M_format. As non-of the format specifiers depends on the formatted object, we pass chrono::day to avoid triggering additional specializations. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__format::__formatter_chrono_info) [_GLIBCXX_USE_CXX11_ABI || ! _GLIBCXX_USE_DUAL_ABI]: Define. (std::formatter<chrono::sys_info, _CharT>) (std::formatter<chrono::local_inf, _CharT>): Delegate to __format::__formatter_chrono_info. (std::operator<<(basic_ostream<_CharT, _Traits>& const sys_info&)): Use format on sys_info with empty format spec. 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'Angelo2-3/+3
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'Angelo5-26/+91
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++: Format empty chrono-spec for the time points and hh_mm_ss directly.Tomasz Kamiński1-85/+135
This patch change implementation of the formatters for time points and hh_mm_ss, so they no longer delegate to operator<< for ostream in case of empty chrono-spec. As in case of calendar types, the formatters for specific type now provide __formatter_chrono with default _ChronoSpec that are used in case if empty chrono-spec. The configuration of __defSpec is straight forward, except for the sys_time, and local_time that print time, if the duration is convertible to days, which is equivalent to setting _M_chrono_specs "%F" instead of "%F %T". Furthermore, certain sys_time<Dur> do not support ostream operator, and should not be formattable with empty spec - in such case default _M_chrono_spec, allowing the issue to still be detected in _M_parse. Finally, _ChronoFormats are extended to cover required format strings. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (_ChronoFormats::_S_ftz) (_ChronoFormats::_S_ft, _ChronoFormats::_S_t): Define. (__formatter_chrono::_M_format_to_ostream): Remove handling for time_points. (std::formatter<chrono::hh_mm_ss<_Dur>, _CharT>) (std::formatter<chrono::sys_time<_Dur>, _CharT>) (std::formatter<chrono::utc_time<_Dur>, _CharT>) (std::formatter<chrono::tai_time<_Dur>, _CharT>) (std::formatter<chrono::gps_time<_Dur>, _CharT>) (std::formatter<chrono::file_time<_Dur>, _CharT>) (std::formatter<chrono::local_time<_Dur>, _CharT>) (std::formatter<chrono::__detail::__local_time_fmt<_Dur>, _CharT>) (std::formatter<chrono::zoned_time<_Dur>, _CharT>): Define __defSpec, and pass it as argument to _M_prase and constructor of __formatter_chrono.
2025-06-12libstdc++: Format empty chrono-spec for the calendar types directly.Tomasz Kamiński1-37/+361
This patch change implementation of the formatters for the calendar types, so they no longer delegate to operator<< for ostream in case of empty chrono-spec. Instead of that, we define the behavior in terms of format specifiers supplied by each formatter as an argument to _M_parse. Similarly each formatter constructs its __formatter_chrono from a relevant default spec, preserving the functionality of calling format on default constructed formatters. Expressing the existing functionality of the operator ostream, requires providing two additional features: * printing "is not a valid sth" for !ok objects, * printing a weekday index in the month. The formatter functionality is enabled by setting spec _M_debug (corresponding to '?') that is currently unused. This is currently supported only for subset of format specifiers used by the ostream operators. In future, we could make this user configurable (by adding '?' after 'L') and cover all flags. For the handling of the weekday index (for weekday_indexed, month_weekday, year_month_weekday), we need to introduce a new format specifier. To not conflict with future extension we use '%\0' (embedded null) as this character cannot be placed in valid format spec. Finally, the format strings for calendar types subsets each other, e.g. year_month_weekday_last ("%Y/%b/%a[last])" contains month_weekday_last, weekday_last, weekday, e.t.c.. We introduce a _ChronoFormats class that provide consteval accessors to format specs, internally sharing they representations. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__format::_ChronoFormats): Define. (__formatter_chrono::__formatter_chrono()) (__formatter_chrono::__formatter_chrono(_ChronoSpec<_CharT>)): Define. (__formatter_chrono::_M_parse): Add parameter with default spec, and merge it with new values. Handle '%\0' as weekday index specifier. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B) (__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_d_e) (__formatter_chrono::_M_F): Support _M_debug flag. (__formatter_chrono::_M_wi, __formatter_chrono::_S_weekday_index): Define. (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_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_last, _CharT>): Define __defSpec, and pass it as argument to _M_parse and constructor of __formatter_chrono. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
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++: Replace some uses of std::__addressof with std::addressofJonathan Wakely2-22/+22
Since r16-154-gc91eb5a5c13f14 std::addressof is no less efficient than std::__addressof, so change some uses of the latter to the former. We can't change them all, because some uses need to compile as C++98 which only has std::__addressof. Similarly, since r16-848-gb2aeeb2803f97b std::is_constant_evaluated is no less efficient than std::__is_constant_evaluated. libstdc++-v3/ChangeLog: * include/bits/stl_construct.h: Replace std::__addressof with std::addressof in code that doesn't need to compile as C++98. Replace std::__is_constant_evaluated with std::is_constant_evaluated in code that doesn't need to compile as C++17 or earlier. * include/bits/stl_uninitialized.h: Likewise for __addressof.