aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
AgeCommit message (Collapse)AuthorFilesLines
5 hoursDaily bump.HEADtrunkmasterGCC Administrator1-0/+76
19 hourslibstdc++: Reuse predicates in std::search and std::is_permutationJonathan Wakely2-25/+18
Hoist construction of the call wrappers out of the loop when we're repeatedly creating a call wrapper with the same bound arguments. We need to be careful about iterators that return proxy references, because bind1st(pred, *first) could bind a reference to a prvalue proxy reference returned by *first. That would then be an invalid reference by the time we invoked the call wrapper. If we dereference the iterator first and store the result of that on the stack, then we don't have a prvalue proxy reference, and can bind it (or the value it refers to) into the call wrapper: auto&& val = *first; // lifetime extension auto wrapper = bind1st(pred, val); for (;;) /* use wrapper */; This ensures that the reference returned from *first outlives the call wrapper, whether it's a proxy reference or not. For C++98 compatibility in __search we can use __decltype(expr) instead of auto&&. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__search, __is_permutation): Reuse predicate instead of creating a new one each time. * include/bits/stl_algo.h (__is_permutation): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
19 hourslibstdc++: Simplify std::erase functions for sequence containersJonathan Wakely4-61/+9
This removes the use of std::ref that meant that __remove_if used an indirection through the reference, which might be a pessimization. Users can always use std::ref to pass expensive predicates into erase_if, but we shouldn't do it unconditionally. We can std::move the predicate so that if it's not cheap to copy and the user didn't use std::ref, then we try to use a cheaper move instead of a copy. There's no reason that std::erase shouldn't just be implemented by forwarding to std::erase_if. I probably should have done that in r12-4083-gacf3a21cbc26b3 when std::erase started to call __remove_if directly. libstdc++-v3/ChangeLog: * include/std/deque (erase_if): Move predicate instead of wrapping with std::ref. (erase): Forward to erase_if. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
19 hourslibstdc++: Eliminate __gnu_cxx::__ops function objectsJonathan Wakely9-614/+404
This removes the indirect functors from <bits/predefined_ops.h> that are used by our STL algorithms. Currently we wrap all predicates and values into callables which accept iterator arguments, and automatically dereference the iterators. With this change we no longer do that dereferencing and so all predicates are passed values not iterators, and the algorithms that invoke those predicates must dereference the iterators. This avoids wrapping user-provided predicates into another predicate that does the dereferencing. User-provided predicates are now passed unchanged to our internal algos like __search_n. For the overloads that take a value instead of a predicate, we still need to create a predicate that does comparison to the value, but we can now use std::less<void> and std::equal_to<void> as the base predicate and bind the value to those base predicates. Because the "transparent operators" std::less<void> and std::equal_to<void> were not added until C++14, this change defines those explicit specializations unconditionally for C++98 and C++11 too (but the default template arguments that make std::less<> and std::equal_to<> refer to those specializations are still only present for C++14 and later, because we don't need to rely on those default template arguments for our internal uses). When binding a predicate and a value into a new call wrapper, we now decide whether to store the predicate by value when it's an empty type or a scalar (such as a function pointer). This avoids a double-indirection through function pointers, and avoids storing and invoking stateless empty functors through a reference. For C++11 and later we also use [[no_unique_address]] to avoid wasted storage for empty predicates (which includes all standard relational ops, such as std::less). The call wrappers in bits/predefined_ops.h all have non-const operator() because we can't be sure that the predicates they wrap are const-invocable. The requirements in [algorithms.requirements] for Predicate and BinaryPredicate template arguments require pred(*i) to be valid, but do not require that std::to_const(pred)(*i) has to be valid, and similarly for binary_pred. libstdc++-v3/ChangeLog: * include/bits/predefined_ops.h (equal_to, less): Define aliases for std::equal_to<void> and std::less<void>. (bind1st, bind2nd, not1, __equal_to): New object generator functions for adapting predicates. (__iter_less_iter, __iter_less_val, __iter_comp_val) (__val_less_iter, __val_comp_iter, __iter_equal_to_iter) (__iter_equal_to_val, __iter_comp_iter, __negate): Remove all object generator functions and the class templates they return. * include/bits/stl_algo.h (__move_median_to_first, __find_if_not) (__find_if_not_n, __search_n_aux, find_end, find_if_not) (__remove_copy_if, remove_copy, remove_copy_if, remove) (remove_if, __adjacent_find, __unique, unique, __unique_copy) (__unique_copy_1, __stable_partition_adaptive, stable_partition) (__heap_select, __partial_sort_copy, partial_sort_copy) (__unguarded_linear_insert, __insertion_sort) (__unguarded_insertion_sort, __unguarded_partition) (lower_bound, __upper_bound, upper_bound, __equal_range) (equal_range, binary_search, __move_merge_adaptive) (__move_merge_adaptive_backward, __merge_adaptive_resize) (__merge_without_buffer, inplace_merge, __move_merge) (__includes, includes, __next_permutation, next_permutation) (__prev_permutation, prev_permutation, __replace_copy_if) (replace_copy, replace_copy_if, __is_sorted_until) (is_sorted_until, __minmax_element, minmax_element, minmax) (is_permutation, __is_permutation, find, find_if, adjacent_find) (count, count_if, search, search_n, unique_copy, partial_sort) (nth_element, sort, __merge, merge, stable_sort, __set_union) (set_union, __set_intersection, set_intersection) (__set_difference, set_difference, __set_symmetric_difference) (set_symmetric_difference, __min_element, min_element) (__max_element, max_element, min, max): Use direct predicates instead of __iter_equal_to_iter, __iter_comp_iter, and __iter_less_iter, __negate etc. Dereference iterators when invoking predicates. * include/bits/stl_algobase.h (__lexicographical_compare_impl) (__lexicographical_compare::__lc, __lower_bound, lower_bound) (lexicographical_compare, __mismatch, mismatch, __find_if) (__count_if, __remove_if, __search, __is_permutation) (is_permutation, search): Likewise. * include/bits/stl_function.h (equal_to<void>, less<void>): Define transparent comparison functions for C++98 and C++11. * include/bits/stl_heap.h (__is_heap_until, __is_heap) (__push_heap, push_heap, __adjust_heap, pop_heap, make_heap) (sort_heap, is_heap_until, is_heap): Likewise. * include/std/deque (erase_if): Remove call to __pred_iter. (erase): Replace __iter_equals_val with __equal_to. * include/std/inplace_vector (erase_if, erase): Likewise. * include/std/string (erase_if, erase): Likewise. * include/std/vector (erase_if, erase): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: François Dumont <frs.dumont@gmail.com>
19 hourslibstdc++: Fix unsafe comma operators in <random> [PR122062]Jonathan Wakely2-2/+18
This fixes a 'for' loop in std::piecewise_linear_distribution that increments two iterators with a comma operator between them, making it vulnerable to evil overloads of the comma operator. It also changes a 'for' loop used by some other distributions, even though those are only used with std::vector<double>::iterator and so won't find any overloaded commas. libstdc++-v3/ChangeLog: PR libstdc++/122062 * include/bits/random.tcc (__detail::__normalize): Use void cast for operands of comma operator. (piecewise_linear_distribution): Likewise. * testsuite/26_numerics/random/piecewise_linear_distribution/cons/122062.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Hewill Kang <hewillk@gmail.com>
29 hoursDaily bump.GCC Administrator1-0/+29
40 hourslibstdc++: Refactor __mdspan::__static_quotient.Luc Grosheintz1-5/+14
For padded layouts we want to check that the product of the padded stride with the remaining extents is representable. Creating a second overload, allows passing in subspans of the static extents and retains the ergonomics for the common case of passing in all static extents. libstdc++-v3/ChangeLog: * include/std/mdspan (__static_quotient): New overload. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
40 hourslibstdc++: Check feature test macro for robust_nonmodifying_seq_opsJonathan Wakely2-4/+4
We should check the relevant feature test macro instead of just the value of __cplusplus. Also add a comment explaining why the __cplusplus check guarding __sample *can't* be changed to check __glibcxx_sample (because __sample is also used in C++14 by std::experimental::sample, not only by C++17 std::sample). libstdc++-v3/ChangeLog: * include/bits/stl_algo.h: Check robust_nonmodifying_seq_ops feature test macro instead of checking __cplusplus value. Add comment to another __cplusplus check. * include/bits/stl_algobase.h: Add comment to #endif.
40 hourslibstdc++: Remove unwanted STDC_HEADERS macro from c++config.h [PR79147]Jonathan Wakely2-2/+2
Similar to r16-4034-g1953939243e1ab, this comments out another macro that Autoconf adds to the generated config.h but which is not wanted in the c++config.h file that we install. There's no benefit to defining _GLIBCXX_STDC_HEADERS in user code, so we should just prevent it from being defined. libstdc++-v3/ChangeLog: PR libstdc++/79147 PR libstdc++/103650 * include/Makefile.am (c++config.h): Adjust sed command to comment out STDC_HEADERS macro. * include/Makefile.in: Regenerate.
40 hourslibstdc++: Prepare mapping layout tests for padded layouts.Luc Grosheintz2-124/+164
Using the existing tests for padded layouts requires the following changes: * The padded layouts are template classes. In order to be able to use partially specialized templates, functions need to be converted to structs. * The layout mapping tests include a check that only applies if is_exhaustive is static. This commit introduces a concept to check if is_exhaustive is a static member function. * Fix a test to not use a hard-coded layout_left. The test empty.cc contains indentation mistakes that are fixed. libstdc++-v3/ChangeLog: * testsuite/23_containers/mdspan/layouts/empty.cc: Fix indent. * testsuite/23_containers/mdspan/layouts/mapping.cc (test_stride_1d): Fix test. (test_stride_2d): Rewrite using a struct. (test_stride_3d): Ditto. (has_static_is_exhaustive): New concept. (test_mapping_properties): Update test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2 daysDaily bump.GCC Administrator1-0/+36
3 dayslibstdc++: Move test for __cpp_lib_not_fn to version.ccLuc Grosheintz2-6/+12
When running the tests without pre-compiled headers (--disable-libstdcxx-pch), the test fails, because the feature testing macro (FTM) isn't defined yet. This commit moves checking the FTM to a dedicated file (version.cc) that's run without PCH. libstdc++-v3/ChangeLog: * testsuite/20_util/function_objects/not_fn/nttp.cc: Move test of feature testing macro to version.cc * testsuite/20_util/function_objects/not_fn/version.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 dayslibstdc++: Reflect operator<< constraints in formatter for local_time.Tomasz Kamiński2-40/+54
The r16-3996-gdc78d691c5e5f7 commit (resolution of LWG4257) constrained the operator<< for local_time, but didn't update the corresponding formatter. This meant it didn't conditionally support formatting with an empty format spec ("{}"), which is defined in terms of operator<<. This patch addresses that by initializing __defSpec for the local_time formatter in the same manner as it's done for sys_time. This functionality is extracted to the _S_spec_for_tp function of __formatter_duration. As formatting of local_time is defined and constrained in terms of operator<< for sys_time, we can check the viability of the ostream operator for sys_time in both cases. As default _M_chrono_spec may now be empty for local_time, the parse method now checks if it was supplied in the format string, similarly to sys_time. The condition for performing runtime check is expressed directly by checking if a empty default is provided. This avoids the need to access the value of __stream_insertable outside of the __defSpec computation. As a note, despite their similar behavior, formatters sys_time and local_time cannot be easily defined in terms of each other, as sys_time provides time zone information while local_time does not. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_duration::_S_spec_for_tp): Extracted from defition of formatter<sys_time>::__defSpec. (formatter<chrono::sys_time<_Duration>, _CharT>::parse): Simplify condition in if contexpr. (formatter<chrono::sys_time<_Duration>, _CharT>::__stream_insertable): Remove. (formatter<chrono::sys_time<_Duration>, _CharT>::__defSpec) (formatter<chrono::local_time<_Duration>, _CharT>::__defSpec): Compute using __formatter_duration::_S_spec_for_tp. (forrmatter<chrono::sys_time<_Duration>, _CharT>::parse): Check if parse _M_chrono_spec * testsuite/std/time/format/empty_spec.cc: Extend tests for floating point and other non-streamable durations (years). Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 dayslibstdc++: Use basic_format_parse_context<_CharT> in internal chrono formatters.Tomasz Kamiński1-261/+259
libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_parse): Replace _ParseContext with basic_format_parse_context<_CharT> and make it non-template. (__formatter_duration::_M_parse): Replace _ParseContext with basic_format_parse_context<_CharT> and remove unused default argument. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
3 dayslibstdc++/testsuite: Unpoison 'u' on s390x in names.cc testPatrick Palka1-0/+2
This is the s390 counterpart to r11-7364-gd0453cf5c68b6a, and fixes the following names.cc failure caused by a use of a poisoned identifier. If we look at the corresponding upstream header[1] it's clear that the problematic identifier is 'u'. In file included from /usr/include/linux/types.h:5, from /usr/include/linux/sched/types.h:5, from /usr/include/bits/sched.h:61, from /usr/include/sched.h:43, from /usr/include/pthread.h:22, from /usr/include/c++/14/s390x-redhat-linux/bits/gthr-default.h:35, from /usr/include/c++/14/s390x-redhat-linux/bits/gthr.h:157, from /usr/include/c++/14/ext/atomicity.h:35, from /usr/include/c++/14/bits/ios_base.h:39, from /usr/include/c++/14/streambuf:43, from /usr/include/c++/14/bits/streambuf_iterator.h:35, from /usr/include/c++/14/iterator:66, from /usr/include/c++/14/s390x-redhat-linux/bits/stdc++.h:54, from /root/rpmbuild/BUILD/gcc-14.3.1-20250617/libstdc++-v3/testsuite/17_intro/names.cc:384: /usr/include/asm/types.h:24: error: expected unqualified-id before '[' token /usr/include/asm/types.h:24: error: expected ')' before '[' token /root/rpmbuild/BUILD/gcc-14.3.1-20250617/libstdc++-v3/testsuite/17_intro/names.cc:101: note: to match this '(' compiler exited with status 1 FAIL: 17_intro/names.cc -std=gnu++98 (test for excess errors) Excess errors: /usr/include/asm/types.h:24: error: expected unqualified-id before '[' token /usr/include/asm/types.h:24: error: expected ')' before '[' token [1]: https://github.com/torvalds/linux/blob/master/arch/s390/include/uapi/asm/types.h libstdc++-v3/ChangeLog: * testsuite/17_intro/names.cc: Undefine 'u' on s390*-linux. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
3 daysDaily bump.GCC Administrator1-0/+109
4 dayslibstdc++: Refactor std::philox_engine member functionsJonathan Wakely17-560/+387
libstdc++-v3/ChangeLog: * include/bits/random.h: Include <bits/ios_base.h> instead of <iomanip>. Change preprocessor checks to use internal feature test macro. (philox_engine): Reword doxygen comments. Use typename instead of class in template parameter lists. Reformat and adjust whitespace. (philox_engine::_If_seed_seq): Replace alias template with __is_seed_seq variable template. (philox_engine::philox_engine(result_type)): Define inline. (philox_engine::seed(result_type), philox_engine::set_counter) (philox_engine::operator(), philox_engine::discard): Likewise. (operator==): Define as defaulted. (operator<<): Reuse widened char. * include/bits/random.tcc: Reformat and adjust whitespace. (philox_engine::_M_philox): Use std::array copy constructor and std::array::fill instead of looping. * testsuite/26_numerics/random/philox4x32.cc: Gate test on feature test macro. Add static_assert to check typedef. * testsuite/26_numerics/random/philox4x64.cc: Likewise. * testsuite/26_numerics/random/philox_engine/cons/copy.cc: Add VERIFY assertions to check copies are equal. Test different seeds. * testsuite/26_numerics/random/philox_engine/cons/default.cc: Add VERIFY assertions to check construction results. * testsuite/26_numerics/random/philox_engine/cons/seed.cc: Likewise. * testsuite/26_numerics/random/philox_engine/operators/equal.cc: Also test inequality. * testsuite/26_numerics/random/philox_engine/operators/serialize.cc: Remove redundant include and return. * testsuite/26_numerics/random/philox_engine/requirements/constants.cc: Check values of all constants. * testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: Check typedefs are correct. * testsuite/26_numerics/random/philox_engine/cons/119794.cc: Removed. * testsuite/26_numerics/random/philox_engine/cons/seed_seq.cc: Removed. * testsuite/26_numerics/random/philox_engine/operators/inequal.cc: Removed. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_data.cc: Removed. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_functions.cc: Removed. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line number.
4 dayslibstdc++: Implement Philox Engine (PR119794)1nfocalypse20-2/+931
Conforms with errata LWG4143, LWG4153 for Philox Engine. PR libstdc++/119794 libstdc++-v3/ChangeLog: * include/bits/random.h (philox_engine): Define. * include/bits/random.tcc (philox_engine): Define member functions. * include/bits/version.def (philox_engine): New macro. * include/bits/version.h: Regenerated. * include/std/random: Define __glibcxx_want_philox_engine and include <bits/version.h>. * testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error line number. * testsuite/26_numerics/random/philox4x32.cc: New test. * testsuite/26_numerics/random/philox4x64.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/119794.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/copy.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/default.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/seed.cc: New test. * testsuite/26_numerics/random/philox_engine/cons/seed_seq.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/equal.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/inequal.cc: New test. * testsuite/26_numerics/random/philox_engine/operators/serialize.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constants.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_data.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/constexpr_functions.cc: New test. * testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc: New test.
4 dayslibstdc++: fix element construction in std::deque::emplace [PR118087]Ben Wu3-2/+81
In order to emplace a value in the middle of a deque, a temporary was previously constructed directly with __args... in _M_emplace_aux. This would not work since std::deque is allocator-aware and should construct elements with _Alloc_traits::construct instead before the element is moved. Using the suggestion in PR118087, we can define _Temporary_value similar to the one used in std::vector, so the temporary can be constructed with uses-allocator construction. PR libstdc++/118087 libstdc++-v3/ChangeLog: * include/bits/deque.tcc: Use _Temporary_value in _M_emplace_aux. * include/bits/stl_deque.h: Introduce _Temporary_value. * testsuite/23_containers/deque/modifiers/emplace/118087.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Ben Wu <soggysocks206@gmail.com>
4 dayslibstdc++: Make function_ref(nontype<f>, r) CTAD SFINAE friendly [PR121940]Tomasz Kamiński2-7/+40
Instantiating the __deduce_funcref function body for function pointers without arguments or member pointers with non-matching object types previously led to hard errors due to the formation of invalid types. The __deduce_funcref function is now adjusted to return void in such cases. The corresponding function_ref deduction guide is constrained to only match if the return type is not void, making it SFINAE friendly. PR libstdc++/121940 libstdc++-v3/ChangeLog: * include/bits/funcwrap.h (__polyfunc::__deduce_funcref): Return void for ill-formed constructs. (function_ref(nontype_t<__f>, _Tp&&)): Constrain on __deduce_funcref producing non-void results. * testsuite/20_util/function_ref/deduction.cc: Negative tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 dayslibstdc++: Remove unwanted PACKAGE macros from c++config.h [PR79147]Jonathan Wakely2-4/+4
Autoconf insists on adding macros like PACKAGE_NAME and PACKAGE_BUG_TARNAME to config.h but those are useless for libstdc++ because it's not a complete package, just a sub-directory of gcc, and we never use any of those strings in our sources. Since we include the generated config.h in our installed c++config.h header, those useless macros are exposed to users. We do transform them to use the reserved _GLIBCXX_ prefix, but they're still just useless noise in the installed header. I don't know any way to get autoconf to not add them to config.h but this change comments them out so they're not defined when users include our headers. Although not really important now that the macro isn't being defined, this change also avoids the double substitution for PACKAGE_VERSION which was resulting in _GLIBCXX_PACKAGE__GLIBCXX_VERSION. libstdc++-v3/ChangeLog: PR libstdc++/79147 * include/Makefile.am (c++config.h): Adjust sed command to comment out all PACKAGE_XXX macros and to avoid adjusting PACKAGE_VERSION twice. * include/Makefile.in: Regenerate.
4 dayslibstdc++: Remove leftover __formatter_chrono base classes.Tomasz Kamiński1-3/+0
This patch removes the __formatter_chrono<_CharT> base class from the formatters for utc_time, gps_time, and tai_time. These formatters are using the __formatter_duration<_CharT> member only. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (formatter<chrono::utc_time, _CharT>): (formatter<chrono::gps_time<_Duration>, _CharT>) (formatter<chrono::tai_time<_Duration>, _CharT): Remove __formatter_chrono base class. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
4 daysDaily bump.GCC Administrator1-0/+20
5 dayslibstdc++: Rework handling of ISO week calendar and week index formatting.Tomasz Kamiński2-43/+97
The handling of ISO week-calendar year specifiers (%G, %g) and ISO week number (%V) was merged into a single _M_g_G_V function, as the latter requires ISO year value, computed by the former. The values for %U and %W, which are based on the number of days since the first Sunday and Monday of the year respectively, are now expressed as an offset from the existing _M_day_of_year field. This reduces redundant computation. The required flags were also updated to only need _DayOfYear and _Weekday. The _M_g_G_V function uses _M_day_of_year to compute __idoy, the day of the year for the nearest Thursday. This value is used to determine if the ISO year is the previous year (__idoy <= 0), the current year (__idoy <= 365/366), next year (__idoy <= 730), or later year. This avoids an expensive conversion from local_days to year_month_day in most cases. If the ISO calendar year is current year, the __idoy value is reused for weekday index computation. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h(__formatter_chrono::_M_parse): Update needed flags for %g, %G, %V, %U, %W. (__formatter_chrono::_M_format_to): Change how %V is handled. (__formatter_chrono::_M_g_G): Merged into _M_g_G_V. (__formatter_chrono::_M_g_G_V): Reworked from _M_g_G. (__formatter_chrono::_M_U_V_W): Changed into _M_U_V. (__formatter_chrono::_M_U_W): Reworked implementation. * testsuite/std/time/year_month_day/io.cc: New tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
5 dayslibstdc++: Move start_lifetime_as functions to bits/stl_construct.h [PR106658]Tomasz Kamiński2-128/+123
This allows inplace_vector to use these functions without including the entire <memory> header. Preprocessor checks are changed to use __glibcxx macros, so new functions are available outside memory header, that exports __cpp_lib macros. PR libstdc++/106658 libstdc++-v3/ChangeLog: * include/bits/stl_construct.h (std::start_lifetime_as_array) (std::start_lifetime_as): Moved from std/memory, with update to guard macros. * include/std/memory (std::start_lifetime_as_array) (std::start_lifetime_as): Moved to bits/stl_construct.h. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
7 daysDaily bump.GCC Administrator1-0/+30
7 dayslibstdc++: Add NTTP bind_front, -back, not_fn (P2714) [PR119744]Nathan Myers12-22/+932
Add non-type template parameter function-object/-pointer argument versions of bind_front, bind_back, and not_fn. This introduces a new internal type _Bind_fn_t to carry the template-argument function object when no arguments are bound, used in both bind_front and bind_back. Otherwise they return a lambda object that has captured the arguments. There is no need to change libstdc++-v3/src/c++23/std.cc.in because existing exports: "using std::bind_front;" etc. export the new overloads. libstdc++-v3/ChangeLog: PR libstdc++/119744 * include/bits/version.def: Redefine __cpp_lib_bind_front etc. * include/bits/version.h: Ditto. * include/std/functional: Add new bind_front etc. overloads * testsuite/20_util/function_objects/bind_back/1.cc: Check plumbing better * testsuite/20_util/function_objects/bind_back/nttp.cc: New test. * testsuite/20_util/function_objects/bind_back/nttp_neg.cc: New test. * testsuite/20_util/function_objects/bind_front/1.cc: Check plumbing better * testsuite/20_util/function_objects/bind_front/nttp.cc: New test. * testsuite/20_util/function_objects/bind_front/nttp_neg.cc: New test. * testsuite/20_util/function_objects/not_fn/nttp.cc: New test. * testsuite/20_util/function_objects/not_fn/nttp_neg.cc: New test. * testsuite/20_util/headers/functional/synopsis.cc: New decls.
7 dayslibstdc++: Constrain operator<< for chrono::local_typeJonathan Wakely2-1/+11
This was reported as LWG 4257 and moved to Tentatively Ready status. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h: Remove unused <iomanip> header. (operator<<): Constrain overload for chrono::local_time. * testsuite/std/time/clock/local/io.cc: Check constraints. Reviewed-by: Patrick Palka <ppalka@redhat.com>
8 dayslibstdc++: Reorder start_lifetime_as macro in version.defJonathan Wakely2-18/+18
libstdc++-v3/ChangeLog: * include/bits/version.def (start_lifetime_as): Move adjacent to other C++23 macros. * include/bits/version.h: Regenerate.
8 daysDaily bump.GCC Administrator1-0/+13
9 dayslibstdc++: Implement C++23 P2590R2 - Explicit lifetime management [PR106658]Jakub Jelinek5-0/+245
As I can't think of how the middle-end would treat __builtin_start_lifetime_as other than a blackbox and probably would need to be implemented as such inline asm in RTL, this patch just implements it using inline asm in the library. If not anything else, it can serve as fallback before we and/or clang get some builtin for it. Right now the inline asms pretend (potential) read from and write to the whole memory region and make optimizers forget where the return value points to. If the optimizers don't know where it points to, I think that should be good enough, but I'm a little bit afraid of possibly future optimizations trying to optimize q->c = 1; q->d = 2; auto p = std::start_lifetime_as<S>(q); if (p == reinterpret_cast<decltype (p)>(q)) return p->a + p->b; that because of the guarding condition or perhaps assertion we could simply use the q pointer in MEM_REFs with S type and be surprised by TBAA. Though if it is a must-alias case, then we should be fine as well. Though guess that would be the same case with a builtin. 2025-09-18 Jakub Jelinek <jakub@redhat.com> PR c++/106658 * include/bits/version.def: Implement C++23 P2590R2 - Explicit lifetime management. (start_lifetime_as): New. * include/bits/version.h: Regenerate. * include/std/memory (std::start_lifetime_as, std::start_lifetime_as_array): New function templates. * src/c++23/std.cc.in (std::start_lifetime_as, std::start_lifetime_as_array): Export. * testsuite/std/memory/start_lifetime_as/start_lifetime_as.cc: New test.
9 daysDaily bump.GCC Administrator1-0/+22
9 dayslibstdc++/ranges: Fix more wrong value type init from reference type [PR111861]Patrick Palka2-5/+5
As in r16-3912-g412a1f78b53709, this fixes some other spots where we wrongly use a deduced type and non-direct-initialization when trying to initialize a value type from an iterator's reference type. PR libstdc++/111861 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (ranges::unique_copy): When initializing a value type object from *iter, use direct-initialization and don't use a deduced type. (ranges::push_heap): Use direct-initialization when initializing a value type object from ranges::iter_move. (ranges::max): As in ranges::unique_copy. * include/bits/ranges_util.h (ranges::min): Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
10 dayslibstdc++: Explicitly pass -Wsystem-headers in tests that need itPatrick Palka5-1/+5
When running libstdc++ tests using an installed gcc (as opposed to an in-tree gcc), we naturally use system stdlib headers instead of the in-tree headers. But warnings from within system headers are suppressed by default, so tests that check for such warnings spuriously fail in such a setup. This patch makes us compile such tests with -Wsystem-headers so that they consistently pass. libstdc++-v3/ChangeLog: * testsuite/20_util/bind/dangling_ref.cc: Compile with -Wsystem-headers. * testsuite/20_util/ratio/operations/ops_overflow_neg.cc: Likewise. * testsuite/20_util/unique_ptr/lwg4148.cc: Likewise. * testsuite/29_atomics/atomic/operators/pointer_partial_void.cc: Likewise. * testsuite/30_threads/packaged_task/cons/dangling_ref.cc: Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
10 daysDaily bump.GCC Administrator1-0/+42
11 dayslibstdc++: Optimize determination of std::tuple_cat return typeJonathan Wakely2-27/+26
The std::tuple_cat function has to determine a std::tuple return type from zero or more tuple-like arguments. This uses the __make_tuple class template to transform a tuple-like type into a std::tuple, and the __combine_tuples class template to combine zero or more std::tuple types into a single std::tuple type. This change optimizes the __make_tuple class template to use an _Index_tuple and pack expansion instead of recursive instantiation, and optimizes __combine_tuples to use fewer levels of recursion. For ranges::adjacent_view's __detail::__repeated_tuple helper we can just use the __make_tuple class template directly, instead of doing overload resolution on std::tuple_cat to get its return type. libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__repeated_tuple): Use __make_tuple helper alias directly, instead of doing overload resolution on std::tuple_cat. * include/std/tuple (__make_tuple_impl): Remove. (__do_make_tuple): Replace recursion with _Index_tuple and pack expansion. (__make_tuple): Adjust to new __do_make_tuple definition. (__combine_tuples<tuple<T1s...>, tuple<T2s...>, Rem...>): Replace with a partial specialization for exactly two tuples and a partial specialization for three or more tuples. Reviewed-by: Patrick Palka <ppalka@redhat.com>
11 dayslibstdc++: ranges::rotate should not use 'auto' with ranges::iter_move ↵Jonathan Wakely1-2/+2
[PR121913] The r16-3835-g7801236069a95c change to use ranges::iter_move should also have used iter_value_t<_Iter> to ensure we get an object of the value type, not a proxy reference. libstdc++-v3/ChangeLog: PR libstdc++/121913 * include/bits/ranges_algo.h (__rotate_fn::operator()): Use auto_value_t<_Iter> instead of deduced type. Reviewed-by: Patrick Palka <ppalka@redhat.com>
11 dayslibstdc++: Fix missing change to views::pairwise from P2165R4 [PR121956]Jonathan Wakely2-3/+14
ranges::adjacent_view::_Iterator::value_type should have been changed by r14-8710-g65b4cba9d6a9ff to always produce std::tuple, even for the N == 2 views::pairwise specialization. libstdc++-v3/ChangeLog: PR libstdc++/121956 * include/std/ranges (adjacent_view::_Iterator::value_type): Always define as std::tuple<T, N>, not std::pair<T, T>. * testsuite/std/ranges/adaptors/adjacent/1.cc: Check value type of views::pairwise. Reviewed-by: Patrick Palka <ppalka@redhat.com>
11 dayslibstdc++: Do not use _GLIBCXX_MAKE_MOVE_ITERATOR for C++17Jonathan Wakely1-6/+6
The _GLIBCXX_MAKE_MOVE_ITERATOR macro is needed for code that needs to compile as C++98, where it just produces the original iterator. In std::uninitialized_move and std::uninitialized_move_n we can just call std::make_move_iterator directly. libstdc++-v3/ChangeLog: * include/bits/stl_uninitialized.h (uninitialized_move) (uninitialized_move_n): Replace _GLIBCXX_MAKE_MOVE_ITERATOR with std::make_move_iterator. Reviewed-by: Patrick Palka <ppalka@redhat.com>
11 dayslibstdc++: Fix more missing uses of iter_difference_t [PR119820]Jonathan Wakely2-2/+2
libstdc++-v3/ChangeLog: PR libstdc++/119820 * include/bits/ranges_algo.h (__shuffle_fn): Use ranges::distance to get difference type value to add to iterator. * include/std/format (__formatter_str::_M_format_range): Use ranges::next to increment iterator by a size_t value. Reviewed-by: Patrick Palka <ppalka@redhat.com>
13 daysDaily bump.GCC Administrator1-0/+9
14 dayslibstdc++: Fix ranges::shuffle for non-sized range [PR121917]Patrick Palka2-28/+56
ranges::shuffle has a two-at-a-time PRNG optimization (copied from std::shuffle) that considers the PRNG width vs the size of the range. But in C++20 a random access sentinel isn't always sized so we can't unconditionally do __last - __first to obtain the size in constant time. We could instead use ranges::distance, but that'd take linear time for a non-sized sentinel which makes the optimization less clear of a win. So this patch instead makes us only consider this optimization for sized ranges. PR libstdc++/121917 libstdc++-v3/ChangeLog: * include/bits/ranges_algo.h (__shuffle_fn::operator()): Only consider the two-at-a-time PRNG optimization if the range is sized. * testsuite/25_algorithms/shuffle/constrained.cc (test03): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-09-13Daily bump.GCC Administrator1-0/+75
2025-09-12libstdc++: ranges::rotate should use ranges::iter_move [PR121913]Jonathan Wakely2-2/+47
Using std::move(*it) is incorrect for iterators that use proxy refs, we should use ranges::iter_move(it) instead. libstdc++-v3/ChangeLog: PR libstdc++/121913 * include/bits/ranges_algo.h (__rotate_fn::operator()): Use ranges::iter_move(it) instead of std::move(*it). * testsuite/25_algorithms/rotate/121913.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-09-12libstdc++: Fix algorithms to use iterators' difference_type for arithmetic ↵Jonathan Wakely20-91/+230
[PR121890] Whenever we use operator+ or similar operators on random access iterators we need to be careful to use the iterator's difference_type rather than some other integer type. It's not guaranteed that an expression with an arbitrary integer type, such as `it + 1u`, has the same effects as `it + iter_difference_t<It>(1)`. Some of our algorithms need changes to cast values to the correct type, or to use std::next or ranges::next instead of `it + n`. Several tests also need fixes where the arithmetic occurs directly in the test. The __gnu_test::random_access_iterator_wrapper class template is adjusted to have deleted operators that make programs ill-formed if the argument to relevant operators is not the difference_type. This will make it easier to avoid regressing in future. libstdc++-v3/ChangeLog: PR libstdc++/121890 * include/bits/ranges_algo.h (ranges::rotate, ranges::shuffle) (__insertion_sort, __unguarded_partition_pivot, __introselect): Use ranges::next to advance iterators. Use local variables in rotate to avoid duplicate expressions. (ranges::push_heap, ranges::pop_heap, ranges::partial_sort) (ranges::partial_sort_copy): Use ranges::prev. (__final_insertion_sort): Use iter_difference_t<Iter> for operand of operator+ on iterator. * include/bits/ranges_base.h (ranges::advance): Use iterator's difference_type for all iterator arithmetic. * include/bits/stl_algo.h (__search_n_aux, __rotate) (__insertion_sort, __unguarded_partition_pivot, __introselect) (__final_insertion_sort, for_each_n, random_shuffle): Likewise. Use local variables in __rotate to avoid duplicate expressions. * include/bits/stl_algobase.h (__fill_n_a, __lc_rai::__newlast1): Likewise. * include/bits/stl_heap.h (push_heap): Likewise. (__is_heap_until): Add static_assert. (__is_heap): Convert distance to difference_type. * include/std/functional (boyer_moore_searcher::operator()): Use iterator's difference_type for iterator arithmetic. * testsuite/util/testsuite_iterators.h (random_access_iterator_wrapper): Add deleted overloads of operators that should be called with difference_type. * testsuite/24_iterators/range_operations/advance.cc: Use ranges::next. * testsuite/25_algorithms/heap/constrained.cc: Use ranges::next and ranges::prev. * testsuite/25_algorithms/nth_element/58800.cc: Use std::next. * testsuite/25_algorithms/nth_element/constrained.cc: Use ptrdiff_t for loop variable. * testsuite/25_algorithms/nth_element/random_test.cc: Use iterator's difference_type instead of int. * testsuite/25_algorithms/partial_sort/check_compare_by_value.cc: Use std::next. * testsuite/25_algorithms/partial_sort/constrained.cc: Use ptrdiff_t for loop variable. * testsuite/25_algorithms/partial_sort/random_test.cc: Use iterator's difference_type instead of int. * testsuite/25_algorithms/partial_sort_copy/constrained.cc: Use ptrdiff_t for loop variable. * testsuite/25_algorithms/partial_sort_copy/random_test.cc: Use iterator's difference_type instead of int. * testsuite/std/ranges/adaptors/drop.cc: Use ranges::next. * testsuite/25_algorithms/fill_n/diff_type.cc: New test. * testsuite/25_algorithms/lexicographical_compare/diff_type.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-09-12libstdc++: Fix memory leak in PSTL TBB backend [PR117276]Jonathan Wakely1-3/+9
Backport of upstream patch: https://github.com/uxlfoundation/oneDPL/pull/1589 libstdc++-v3/ChangeLog: PR libstdc++/117276 * include/pstl/parallel_backend_tbb.h (__func_task::finalize): Make deallocation unconditional.
2025-09-12libstdc++: Constrain __gnu_debug::bitset(const CharT*) constructor [PR121046]Jonathan Wakely1-1/+7
The r16-3435-gbbc0e70b610f19 change (for LWG 4294) needs to be applied to the debug mode __gnu_debug::bitset as well as the normal one. libstdc++-v3/ChangeLog: PR libstdc++/121046 * include/debug/bitset (bitset(const CharT*, ...)): Add constraints on CharT type.
2025-09-12libstdc++: Fix bootstrap failure in atomicity.ccJonathan Wakely1-1/+4
My r16-3810-g6456da6bab8a2c changes broke bootstrap for targets that use the mutex-based atomic helpers. This fixes it by casting away the unnecessary volatile-qualification on the _Atomic_word* before passing it to __exchange_and_add_single. libstdc++-v3/ChangeLog: * config/cpu/generic/atomicity_mutex/atomicity.h (__exchange_and_add): Use const_cast to remove volatile.
2025-09-12Daily bump.GCC Administrator1-0/+79
2025-09-11libstdc++: Trap on std::shared_ptr reference count overflow [PR71945]Jonathan Wakely1-4/+50
This adds checks when incrementing the shared count and weak count and will trap if they would be be incremented past its maximum. The maximum value is the value at which incrementing it produces an invalid use_count(). So that is either the maximum positive value of _Atomic_word, or for targets where we now allow the counters to wrap around to negative values, the "maximum" value is -1, because that is the value at which one more increment overflows the usable range and resets the counter to zero. For the weak count the maximum is always -1 as we always allow that count to use nagative values, so we only tap if it wraps all the way back to zero. libstdc++-v3/ChangeLog: PR libstdc++/71945 * include/bits/shared_ptr_base.h (_Sp_counted_base::_S_chk): Trap if a reference count cannot be incremented any higher. (_Sp_counted_base::_M_add_ref_copy): Use _S_chk. (_Sp_counted_base::_M_add_weak_ref): Likewise. (_Sp_counted_base<_S_mutex>::_M_add_ref_lock_nothrow): Likewise. (_Sp_counted_base<_S_atomic>::_M_add_ref_lock_nothrow): Likewise. (_Sp_counted_base<_S_single>::_M_add_ref_copy): Use _S_chk. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>