aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
AgeCommit message (Collapse)AuthorFilesLines
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-07Daily bump.GCC Administrator1-0/+14
2025-07-06libstdc++: Implement ranges::shift_left/right from P2440R1Patrick Palka6-3/+340
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-05Daily bump.GCC Administrator1-0/+11
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-04Daily bump.GCC Administrator1-0/+33
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 Palka2-2/+15
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 Myers7-31/+215
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 Wakely2-1/+17
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-03Daily bump.GCC Administrator1-0/+16
2025-07-02libstdc++: Use hidden friends for __normal_iterator operatorsJonathan Wakely3-184/+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-02Daily bump.GCC Administrator1-0/+21
2025-07-01libstdc++: Use ranges::iter_move in ranges::remove_if [PR120789]Patrick Palka2-1/+37
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 Palka2-1/+37
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 Grosheintz4-1/+155
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-28Daily bump.GCC Administrator1-0/+262
2025-06-27libstdc++: Directly implement ranges::shuffle [PR100795]Patrick Palka2-3/+80
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 Palka2-7/+89
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 Palka2-5/+73
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 Palka2-5/+127
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 Palka2-4/+233
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 Palka2-4/+289
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 Palka4-4/+229
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 Palka2-16/+170
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ński2-135/+129
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-27libstdc++: Fix Darwin bootstrap by simplifying ver file syntax.Iain Sandoe1-3/+2
The symbol parsing script does not handle the closing brace of a new symbol group and the identifier for the inherited group to be on different lines, which r16-1708-gaf5b72cf9f564 introduced. Fixed by making the conditional encompass both the brace and the identifier. libstdc++-v3/ChangeLog: * config/abi/pre/gnu.ver: Keep the closing brace of the CXXABI_1.3.17 symbol group together with the identifier for the inherited group. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
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ński3-829/+1165
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 Jelinek9-0/+158
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 Jelinek5-0/+142
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-26Daily bump.GCC Administrator1-0/+12
2025-06-25libstdc++: Test for %S precision for durations with integral representation.Tomasz Kamiński1-5/+99
Existing test are extented to cover cases where not precision is specified, or it is specified to zero. The precision value is ignored in all cases. libstdc++-v3/ChangeLog: * testsuite/std/time/format/precision.cc: New tests.
2025-06-25libstdc++: Report compilation error on formatting "%d" from month_last ↵Tomasz Kamiński2-2/+165
[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-25Daily bump.GCC Administrator1-0/+10
2025-06-24libstdc++: Unnecessary type completion in __is_complete_or_unbounded [PR120717]Patrick Palka2-17/+42
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-17Daily bump.GCC Administrator1-0/+6
2025-06-16c++: add -Wsfinae-incompleteJason Merrill2-2/+2
We already error about a type or function definition causing a concept check to change value, but it would be useful to diagnose this for other SFINAE contexts as well; the memoization problem also affects templates. So -Wsfinae-incomplete remembers if we've failed a requirement for a complete type/deduced return type in a non-tf_error context, and later warns if the type/function becomes complete. This warning is enabled by default; I think the signal-to-noise ratio is high enough to warrant that, and it catches things that are likely to make the program "ill-formed, no diagnostic required". friend87.C is an interesting case; this could be considered a false positive because it is using friend injection to define the auto function to implement a compile-time counter. I think this is sufficiently pathological that it's fine to expect people who want to play this sort of game to suppress the warning. The data for this warning uses GTY((cache)) to persist through GC, but allow entries to be discarded if the key is not otherwise marked. I don't think it's desirable to export/import this information in modules, it makes sense for it to be local to a single TU. -Wsfinae-incomplete=2 adds a warning at the point of failure, which is primarily intended to help with debugging warnings from the default mode. gcc/ChangeLog: * doc/invoke.texi: Document -Wsfinae-incomplete. gcc/c-family/ChangeLog: * c.opt: Add -Wsfinae-incomplete. * c.opt.urls: Regenerate. gcc/cp/ChangeLog: * constraint.cc (failed_completions_map): New. (note_failed_type_completion): Rename from note_failed_type_completion_for_satisfaction. Add -Wsfinae-incomplete handling. (failed_completion_location): New. * class.cc (finish_struct_1): Add -Wsfinae-incomplete warning. * decl.cc (require_deduced_type): Adjust. (finish_function): Add -Wsfinae-incomplete warning. * typeck.cc (complete_type_or_maybe_complain): Adjust. (cxx_sizeof_or_alignof_type): Call note_failed_type_completion. * pt.cc (dependent_template_arg_p): No longer static. * cp-tree.h: Adjust. libstdc++-v3/ChangeLog: * testsuite/20_util/is_complete_or_unbounded/memoization.cc * testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc: Expect -Wsfinae-incomplete. gcc/testsuite/ChangeLog: * g++.dg/template/friend87.C * g++.dg/cpp2a/concepts-complete1.C * g++.dg/cpp2a/concepts-complete2.C * g++.dg/cpp2a/concepts-complete3.C * g++.dg/cpp2a/concepts-complete4.C: Expect -Wsfinae-incomplete.
2025-06-14Daily bump.GCC Administrator1-0/+75
2025-06-13libstdc++: Fix std::uninitialized_value_construct for arrays [PR120397]Jonathan Wakely3-0/+58
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ński2-99/+72
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++: Replace _CharT template parameter with CharT in format tests.Tomasz Kamiński12-171/+169
As pointed out by Daniel Krügler we do not need to use reserved name in tests. libstdc++-v3/ChangeLog: * testsuite/23_containers/vector/bool/format.cc: Replaced _CharT with CharT. * testsuite/std/format/debug.cc: Likewise. * testsuite/std/format/ranges/adaptors.cc: Likewise. * testsuite/std/format/ranges/formatter.cc: Likewise. * testsuite/std/format/ranges/map.cc: Likewise. * testsuite/std/format/ranges/sequence.cc: Likewise. * testsuite/std/format/ranges/string.cc: Likewise. * testsuite/std/format/tuple.cc: Likewise. * testsuite/std/time/format/empty_spec.cc: Likewise. * testsuite/std/time/format/pr120114.cc: Likewise. * testsuite/std/time/format/pr120481.cc: Likewise. * testsuite/std/time/format/precision.cc: Likewise.
2025-06-13libstdc++: 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-13libstdc++: Test chrono-spec containing only whitespaces.Tomasz Kamiński1-0/+56
libstdc++-v3/ChangeLog: * testsuite/std/time/format/whitespace.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>