aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2025-04-25libstdc++: Remove c++26 dg-error lines for -Wdelete-incomplete errorsJonathan Wakely1-3/+0
This fixes: FAIL: tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc -std=gnu++26 (test for errors, line 283) FAIL: tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc -std=gnu++26 (test for errors, line 305) This is another consequence of r16-133-g8acea9ffa82ed8 which prevents the -Wdelete-incomplete errors that happen after the first error. libstdc++-v3/ChangeLog: * testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Remove dg-error directives for additional c++26 errors.
2025-04-25libstdc++: Minimalize temporary allocations when width is specified [PR109162]Tomasz Kamiński4-5/+655
When width parameter is specified for formatting range, tuple or escaped presentation of string, we used to format characters to temporary string, and write produce sequence padded according to the spec. However, once the estimated width of formatted representation of input is larger than the value of spec width, it can be written directly to the output. This limits size of required allocation, especially for large ranges. Similarly, if precision (maximum) width is provided for string presentation, only a prefix of sequence with estimated width not greater than precision, needs to be buffered. To realize above, this commit implements a new _Padding_sink specialization. This sink holds an output iterator, a value of padding width, (optionally) maximum width and a string buffer inherited from _Str_sink. Then any incoming characters are treated in one of following ways, depending of estimated width W of written sequence: * written to string if W is smaller than padding width and maximum width (if present) * ignored, if W is greater than maximum width * written to output iterator, if W is greater than padding width The padding sink is used instead of _Str_sink in __format::__format_padded, __formatter_str::_M_format_escaped functions. Furthermore __formatter_str::_M_format implementation was reworked, to: * reduce number of instantiations by delegating to _Rg& and const _Rg& overloads, * non-debug presentation is written to _Out directly or via _Padding_sink * if maximum width is specified for debug format with non-unicode encoding, string size is limited to that number. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/bits/formatfwd.h (__simply_formattable_range): Moved from std/format. * include/std/format (__formatter_str::_format): Extracted escaped string handling to separate method... (__formatter_str::_M_format_escaped): Use __Padding_sink. (__formatter_str::_M_format): Adjusted implementation. (__formatter_str::_S_trunc): Extracted as namespace function... (__format::_truncate): Extracted from __formatter_str::_S_trunc. (__format::_Seq_sink): Removed forward declarations, made members protected and non-final. (_Seq_sink::_M_trim): Define. (_Seq_sink::_M_span): Renamed from view. (_Seq_sink::view): Returns string_view instead of span. (__format::_Str_sink): Moved after _Seq_sink. (__format::__format_padded): Use _Padding_sink. * testsuite/std/format/debug.cc: Add timeout and new tests. * testsuite/std/format/ranges/sequence.cc: Specify unicode as encoding and new tests. * testsuite/std/format/ranges/string.cc: Likewise. * testsuite/std/format/tuple.cc: Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-25libstdc++: Replace leftover std::queue with Adaptor in ranges/adaptors.cc.Tomasz Kamiński1-1/+1
This was leftover from work-in-progress state, where only std::queue was tested. libstdc++-v3/ChangeLog: * testsuite/std/format/ranges/adaptors.cc: Updated test.
2025-04-25libstdc++: Remove c++98_only dg-errorJonathan Wakely1-1/+0
This fixes FAIL: 22_locale/ctype/is/string/89728_neg.cc -std=gnu++98 (test for errors, line ) Since r16-133-g8acea9ffa82ed8 we don't keep issuing more errors after the first one, so this dg-error no longer matches anything. libstdc++-v3/ChangeLog: * testsuite/22_locale/ctype/is/string/89728_neg.cc: Remove dg-error for c++98_only effective target.
2025-04-25libstdc++: Constrain formatter for thread::id [PR119918]Tomasz Kamiński1-0/+30
This patch add constraint __formatter::__char to _CharT type parameter of formatter<thread::id, _CharT> specialization, matching the constraint of formatting of integer/pointers that are used as native handles. The dependency on <format> header, is changed to <bits/formatfwd.h>. To achieve that, formatting of pointers is extracted from void const* specialization to internal __formatter_ptr<_CharT>, that can be forward declared. Finally, the handle representation is now printed directly to __fc.out(), by the formatter for handle type. To support this, internal formatters can now be constructed from _Spec object as alternative to invoking parse method. PR libstdc++/119918 libstdc++-v3/ChangeLog: * include/bits/formatfwd.h (__format::_Align): Moved from std/format. (std::__throw_format_error, __format::__formatter_str) (__format::__formatter_ptr): Declare. * include/std/format (__format::_Align): Moved to bits/formatfwd.h. (__formatter_int::__formatter_int): Define. (__format::__formatter_ptr): Extracted from formatter for const void*. (std::formatter<const void*, _CharT>, formatter<void*, _CharT>) (std::formatter<nullptr_t, _CharT>): Delegate to __formatter_ptr<_CharT>. * include/std/thread (std::formatter<thread::id, _CharT>): Constrain _CharT template parameter. (formatter<thread::id, _CharT>::parse): Specify default aligment, and qualify __throw_format_error to disable ADL. (formatter<thread::id, _CharT>::format): Use formatters to write directly to output. * testsuite/30_threads/thread/id/output.cc: Tests for formatting thread::id representing not-a-thread with padding and formattable concept. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-25libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]Tomasz Kamiński4-3/+12
As P2286R8 and P2585R1 as now fully implemented, we now define __cpp_lib_format_ranges feature test macro with __cpp_lib_format_ranges. This macro is provided only in <format>. Uses of internal __glibcxx_format_ranges are also updated. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/bits/version.def (format_ranges): Remove no_stdname and update value. * include/bits/version.h: Regenerate. * src/c++23/std.cc.in: Replace __glibcxx_format_ranges with __cpp_lib_format_ranges. * testsuite/std/format/formatter/lwg3944.cc: Likewise. * testsuite/std/format/parse_ctx.cc: Likewise. * testsuite/std/format/string.cc: Likewise. * testsuite/std/format/ranges/feature_test.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-25libstdc++: Implement formatters for queue, priority_queue and stack [PR109162]Tomasz Kamiński1-0/+156
This patch implements formatter specializations for standard container adaptors (queue, priority_queue and stack) from P2286R8. To be able to access the protected `c` member, the adaptors befriend corresponding formatter specializations. Note that such specialization may be disable if the container is formattable, in such case specializations are unharmful. As in the case of previous commits, the signatures of the user-facing parse and format methods of the provided formatters deviate from the standard by constraining types of parameters: * _CharT is constrained __formatter::__char * basic_format_parse_context<_CharT> for parse argument * basic_format_context<_Out, _CharT> for format second argument The standard specifies all above as unconstrained types. In particular _CharT constrain, allow us to befriend all allowed specializations. Furthermore the standard specifies these formatters as delegating to formatter<ranges::ref_view<const? _Container>, charT>, which in turn delegates to range_formatter. This patch avoids one level of indirection, and dependency of ranges::ref_view. This is technically observable if user specializes formatter<std::ref_view<PD>> where PD is program defined container, but I do not think this is the case worth extra indirection. This patch also moves the formattable and it's dependencies to the formatfwd.h, so it can be used in adapters formatters, without including format header. The definition of _Iter_for is changed from alias to denoting back_insert_iterator<basic_string<_CharT>>, to struct with type nested typedef that points to same type, that is forward declared. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/bits/formatfwd.h (__format::__parsable_with) (__format::__formattable_with, __format::__formattable_impl) (__format::__has_debug_format, __format::__const_formattable_range) (__format::__maybe_const_range, __format::__maybe_const) (std::formattable): Moved from std/format. (__format::Iter_for, std::range_formatter): Forward declare. * include/bits/stl_queue.h (std::formatter): Forward declare. (std::queue, std::priority_queue): Befriend formatter specializations. * include/bits/stl_stack.h (std::formatter): Forward declare. (std::stack): Befriend formatter specializations. * include/std/format (__format::_Iter_for): Define as struct with (__format::__parsable_with, __format::__formattable_with) (__format::__formattable_impl, __format::__has_debug_format) (_format::__const_formattable_range, __format::__maybe_const_range) (__format::__maybe_const, std::formattable): Moved to bits/formatfwd.h. (std::range_formatter): Remove default argument specified in declaration in bits/formatfwd.h. * include/std/queue: Include bits/version.h before bits/stl_queue.h. (formatter<queue<_Tp, _Container, _Compare>, _CharT>) (formatter<priority_queue<_Tp, _Container, _Compare>, _CharT>): Define. * include/std/stack: Include bits/version.h before bits/stl_stack.h (formatter<stack<_Tp, _Container, _Compare>, _CharT>): Define. * testsuite/std/format/ranges/adaptors.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-25libstdc++: Improve diagnostics for std::packaged_task invocable checksJonathan Wakely2-7/+6
Moving the static_assert that checks is_invocable_r_v into _Task_state means it is checked when we instantiate that class template. Replacing the __create_task_state function with a static member function _Task_state::_S_create ensures we instantiate _Task_state and trigger the static_assert immediately, not deep inside the implementation of std::allocate_shared. This results in shorter diagnostics that don't show deeply-nested template instantiations before the static_assert failure. Placing the static_assert at class scope also helps us to fail earlier than waiting until when the _Task_state::_M_run virtual function is instantiated. That also makes the diagnostics shorter and easier to read (although for C++11 and C++14 modes the class-scope static_assert doesn't check is_invocable_r, so dangling references aren't detected until _M_run is instantiated). libstdc++-v3/ChangeLog: * include/std/future (__future_base::_Task_state): Check invocable requirement here. (__future_base::_Task_state::_S_create): New static member function. (__future_base::_Task_state::_M_reset): Use _S_create. (__create_task_state): Remove. (packaged_task): Use _Task_state::_S_create instead of __create_task_state. * testsuite/30_threads/packaged_task/cons/dangling_ref.cc: Adjust dg-error patterns. * testsuite/30_threads/packaged_task/cons/lwg4154_neg.cc: Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-24libstdc++: Remove unnecessary dg-prune-output from testsJonathan Wakely4-4/+0
There are no errors matching this pattern in these tests (only in the deque/48101_neg.cc and vector/48101_neg.cc tests). libstdc++-v3/ChangeLog: * testsuite/23_containers/forward_list/48101_neg.cc: Remove dg-prune-output that doesn't match anything. * testsuite/23_containers/list/48101_neg.cc: Likewise. * testsuite/23_containers/multiset/48101_neg.cc: Likewise. * testsuite/23_containers/set/48101_neg.cc: Likewise.
2025-04-24libstdc++: Add lvalue overload for generator::yield_valueJonathan Wakely1-0/+57
This was approved in Wrocław as LWG 3899. This avoids creating a new coroutine frame to co_yield the elements of an lvalue generator. libstdc++-v3/ChangeLog: * include/std/generator (generator::yield_value): Add overload taking lvalue element_of view, as per LWG 3899. * testsuite/24_iterators/range_generators/lwg3899.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Arsen Arsenović <arsen@aarsen.me>
2025-04-24libstdc++: Add std::deque<>::shrink_to_fit testFrançois Dumont2-6/+40
The existing test is currently testing std::vector. Adapt it for std::deque. libstdc++-v3/ChangeLog: * testsuite/util/replacement_memory_operators.h: Adapt for -fno-exceptions context. * testsuite/23_containers/deque/capacity/shrink_to_fit.cc: Adapt test to check std::deque shrink_to_fit method. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
2025-04-22Revert "libstdc++: Optimize std::projected<I, std::identity>" [PR119888]Patrick Palka1-5/+0
This non-standard optimization breaks real-world code that expects the result of std::projected to always (be a class type and) have a value_type member, which isn't true for e.g. I=int*, so revert it for now. PR libstdc++/119888 This reverts commit 51761c50f843d5be4e24172535e4524b5072f24c.
2025-04-22libstdc++: Increase timeouts for format and flat_maps testsTomasz Kamiński5-0/+5
Test for format parse format string and compile time, flat_maps ones test all functionality in single test file. libstdc++-v3/ChangeLog: * testsuite/23_containers/flat_map/1.cc: Add dg-timeout-factor 2. * testsuite/23_containers/flat_multimap/1.cc: Likewise. * testsuite/std/format/ranges/map.cc: Likewise. * testsuite/std/format/ranges/sequence.cc: Likewise. * testsuite/std/format/ranges/string.cc: Likewise.
2025-04-22libstdc++: Finalize GCC 15 ABIAndreas Schwab1-2/+2
Disallow adding new symbols to GLIBCXX_3.4.34 and CXXABI_1.3.16 versions. * testsuite/util/testsuite_abi.cc (check_version): Update latestp to use GLIBCXX_3.4.35 and CXXABI_1.3.17.
2025-04-18libstdc++: Add _GLIBCXX_DEBUG checks on unordered container local_iteratorFrançois Dumont33-49/+531
Complete tests on _GLIBCXX_DEBUG checks in include/debug/safe_local_iterator.h. Fix several tests not testing the container corresponding to their location in the testsuite directory. libstdc++-v3/ChangeLog: * testsuite/util/debug/unordered_checks.h (fill_container): New helper method. (use_erased_local_iterator, invalid_local_iterator_pre_increment) (invalid_local_iterator_post_increment, invalid_local_iterator_compare) (invalid_local_iterator_range): Use latter. (fill_and_get_local_iterator): New, use fill_container. (use_invalid_local_iterator): Use latter. (invalid_local_iterator_arrow_operator): New test function. (invalid_local_iterator_copy_instantiation): New test function. (invalid_local_iterator_move_instantiation): New test function. (invalid_local_iterator_copy_assignment): New test function. (invalid_local_iterator_move_assignment): New test function. (invalid_local_iterator_const_conversion): New test function. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_arrow_operator_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_const_conversion_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_copy_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_copy_construction_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_move_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_move_construction_neg.cc: New test case. * testsuite/23_containers/unordered_map/debug/max_load_factor_neg.cc: Test unordered_map. * testsuite/23_containers/unordered_multimap/debug/begin2_neg.cc: Test unordered_multimap. * testsuite/23_containers/unordered_multimap/debug/bucket_size_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/cbegin_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/cend_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/end1_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/end2_neg.cc: Likewise. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_arrow_operator_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_const_conversion_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_copy_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_copy_construction_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_move_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/invalid_local_iterator_move_construction_neg.cc: New test case. * testsuite/23_containers/unordered_multimap/debug/max_load_factor_neg.cc: Test unordered_multimap. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_arrow_operator_neg.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_const_conversion_neg.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_copy_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_copy_construction_neg.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_move_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_multiset/debug/invalid_local_iterator_move_construction_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_arrow_operator_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_const_conversion_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_copy_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_copy_construction_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_move_assignment_neg.cc: New test case. * testsuite/23_containers/unordered_set/debug/invalid_local_iterator_move_construction_neg.cc: New test case. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-04-17c++: improve pack index diagnosticsJason Merrill1-1/+1
While looking at pack-indexing16.C I thought it would be helpful to print the problematic type/value. gcc/cp/ChangeLog: * semantics.cc (finish_type_pack_element): Add more info to diagnostics. libstdc++-v3/ChangeLog: * testsuite/20_util/tuple/element_access/get_neg.cc: Adjust diagnostic. gcc/testsuite/ChangeLog: * g++.dg/cpp26/pack-indexing2.C: Adjust diagnostics. * g++.dg/ext/type_pack_element2.C: Likewise. * g++.dg/ext/type_pack_element4.C: Likewise.
2025-04-17libstdc++: Do not use 'not' alternative token in <format>Jonathan Wakely1-0/+13
This fixes: FAIL: 17_intro/headers/c++1998/operator_names.cc -std=gnu++23 (test for excess errors) FAIL: 17_intro/headers/c++1998/operator_names.cc -std=gnu++26 (test for excess errors) The purpose of 'not defined<format_kind<R>>' is to be ill-formed (as required by [format.range.fmtkind]) and to give an error that includes the string "not defined<format_kind<R>>". That was intended to tell you that format_kind<R> is not defined, just like it says! But user code can use -fno-operator-names so we can't use 'not' here, and "! defined" in the diagnostic doesn't seem as user-friendly. It also raises questions about whether it was intended to be the preprocessor token 'defined' (it's not) or where 'defined' is defined (it's not). Replace it with __primary_template_not_defined<format_kind<R>> and a comment, which seems to give a fairly clear diagnostic with both GCC and Clang. The diagnostic now looks like: .../include/c++/15.0.1/format:5165:7: error: use of 'std::format_kind<int>' before deduction of 'auto' 5165 | format_kind<_Rg> // you can specialize this for non-const input ranges | ^~~~~~~~~~~~~~~~ .../include/c++/15.0.1/format:5164:35: error: '__primary_template_not_defined' was not declared in this scope 5164 | __primary_template_not_defined( | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 5165 | format_kind<_Rg> // you can specialize this for non-const input ranges | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5166 | ); | ~ libstdc++-v3/ChangeLog: * include/std/format (format_kind): Do not use 'not' alternative token to make the primary template ill-formed. Use the undeclared identifier __primary_template_not_defined and a comment that will appear in diagnostics. * testsuite/std/format/ranges/format_kind_neg.cc: New test.
2025-04-16libstdc++: Fix constification in range_formatter::format [PR109162]Tomasz Kamiński1-0/+22
The _Rg is deduced to lvalue reference for the lvalue arguments, and in such case __format::__maybe_const_range<_Rg, _CharT> is always _Rg (adding const to reference does not change behavior). Now we correctly check if _Range = remove_reference_t<_Rg> is const formattable range, furthermore as range_formatter<T> can only format ranges of values of type (possibly const) _Tp, we additional check if the remove_cvref_t<range_reference_t<const _Range>> is _Tp. The range_reference_t<R> and range_reference_t<const R> have different types (modulo remove_cvref_t) for std::vector<bool> (::reference and bool) or flat_map<T, U> (pair<const T&, U&> and pair<const T&, const U&>). PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/std/format (range_formatter::format): Format const range, only if reference type is not changed. * testsuite/std/format/ranges/formatter.cc: New tests. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-16libstdc++: Implement formatters for pair and tuple [PR109162]Tomasz Kamiński5-19/+510
This patch implements formatter specializations for pair and tuple form P2286R8. In addition using 'm` and range_format::map (from P2585R1) for ranges are now supported. The formatters for pairs and tuples whose corresponding elements are the same (after applying remove_cvref_t) derive from the same __tuple_formatter class. This reduce the code duplication, as most of the parsing and formatting is the same in such cases. We use a custom reduced implementation of the tuple (__formatters_storage) to store the elements formatters. Handling of the padding (width and fill) options, is extracted to __format::__format_padded function, that is used both by __tuple_formatter and range_formatter. To reduce number of instantations range_formatter::format triggers, we cast incoming range to __format::__maybe_const_range<_Rg, _CharT>&, before formatting it. As in the case of previous commits, the signatures of the user-facing parse and format methods of the provided formatters deviate from the standard by constraining types of parameters: * _CharT is constrained __formatter::__char * basic_format_parse_context<_CharT> for parse argument * basic_format_context<_Out, _CharT> for format second argument The standard specifies last three of above as unconstrained types. Finally, test for tuple-like std::array and std::ranges::subrange, that illustrate that they remain formatted as ranges. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/std/format (__formatter_int::_M_format_character_escaped) (__formatter_str::format): Use __sink.out() to produce _Sink_iter. (__format::__const_formattable_range): Moved closer to range_formatter. (__format::__maybe_const_range): Use `__conditional_t` and moved closer to range_formatter. (__format::__format_padded, __format::maybe_const) (__format::__indexed_formatter_storage, __format::__tuple_formatter) (std::formatter<pair<_Fp, _Sp>, _CharT>>) (std::formatter<tuple<_Tps...>, _CharT): Define. (std::formatter<_Rg, _CharT>::format): Cast incoming range to __format::__maybe_const_range<_Rg, _CharT>&. (std::formatter<_Rg, _CharT>::_M_format): Extracted from format, and use __format_padded. (std::formatter<_Rg, _CharT>::_M_format_no_padding): Rename... (std::formatter<_Rg, _CharT>::_M_format_elems): ...to this. (std::formatter<_Rg, _CharT>::_M_format_with_padding): Extracted as __format_padded. * testsuite/util/testsuite_iterators.h (test_input_range_nocopy): Define. * testsuite/std/format/ranges/formatter.cc: Tests for `m` specifier. * testsuite/std/format/ranges/sequence.cc: Tests for array and subrange. * testsuite/std/format/ranges/map.cc: New test. * testsuite/std/format/tuple.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-15libstdc++: Do not declare namespace ranges in <numeric> unconditionallyJonathan Wakely1-0/+4
Move namespace ranges inside the feature test macro guard, because 'ranges' is not a reserved name before C++20. libstdc++-v3/ChangeLog: * include/std/numeric (ranges): Only declare namespace for C++23 and later. (ranges::iota_result): Fix indentation. * testsuite/17_intro/names.cc: Check ranges is not used as an identifier before C++20.
2025-04-15libstdc++: Implement formatter for ranges and range_formatter [PR109162]Tomasz Kamiński7-8/+671
This patch implements formatter specialization for input_ranges and range_formatter class from P2286R8, as adjusted by P2585R1. The formatter for pair/tuple is not yet provided, making maps not formattable. This introduces an new _M_format_range member to internal __formatter_str, that formats range as _CharT as string, according to the format spec. This function transform any contiguous range into basic_string_view directly, by computing size if necessary. Otherwise, for ranges for which size can be computed (forward_range or sized_range) we use a stack buffer, if they are sufficiently small. Finally, we create a basic_string<_CharT> from the range, and format its content. In case when padding is specified, this is handled by firstly formatting the content of the range to the temporary string object. However, this can be only implemented if the iterator of the basic_format_context is internal type-erased iterator used by implementation. Otherwise a new basic_format_context would need to be created, which would require rebinding of handles stored in the arguments: note that format spec for element type could retrieve any format argument from format context, visit and use handle to format it. As basic_format_context provide no user-facing constructor, the user are not able to construct object of that type with arbitrary iterators. The signatures of the user-facing parse and format methods of the provided formatters deviate from the standard by constraining types of params: * _CharT is constrained __formatter::__char * basic_format_parse_context<_CharT> for parse argument * basic_format_context<_Out, _CharT> for format second argument The standard specifies last three of above as unconstrained types. These types are later passed to possibly user-provided formatter specializations, that are required via formattable concept to only accept above types. Finally, the formatter<input_range, _CharT> specialization is implemented without using specialization of range-default-formatter exposition only template as base class, while providing same functionality. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/std/format (__format::__has_debug_format, _Pres_type::_Pres_seq) (_Pres_type::_Pres_str, __format::__Stackbuf_size): Define. (_Separators::_S_squares, _Separators::_S_parens, _Separators::_S_comma) (_Separators::_S_colon): Define additional constants. (_Spec::_M_parse_fill_and_align): Define overload accepting list of excluded characters for fill, and forward existing overload. (__formatter_str::_M_format_range): Define. (__format::_Buf_sink) Use __Stackbuf_size for size of array. (__format::__is_map_formattable, std::range_formatter) (std::formatter<_Rg, _CharT>): Define. * src/c++23/std.cc.in (std::format_kind, std::range_format) (std::range_formatter): Export. * testsuite/std/format/formatter/lwg3944.cc: Guarded tests with __glibcxx_format_ranges. * testsuite/std/format/formatter/requirements.cc: Adjusted for standard behavior. * testsuite/23_containers/vector/bool/format.cc: Test vector<bool> formatting. * testsuite/std/format/ranges/format_kind.cc: New test. * testsuite/std/format/ranges/formatter.cc: New test. * testsuite/std/format/ranges/sequence.cc: New test. * testsuite/std/format/ranges/string.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-15libstdc++: Fix std::string construction from volatile char* [PR119748]Jonathan Wakely2-0/+42
My recent r15-9381-g648d5c26e25497 change assumes that a contiguous iterator with the correct value_type can be converted to a const charT* but that's not true for volatile charT*. The optimization should only be done if it can be converted to the right pointer type. Additionally, some generic loops for non-contiguous iterators need an explicit cast to deal with iterator reference types that do not bind to the const charT& parameter of traits_type::assign. libstdc++-v3/ChangeLog: PR libstdc++/119748 * include/bits/basic_string.h (_S_copy_chars): Only optimize for contiguous iterators that are convertible to const charT*. Use explicit conversion to charT after dereferencing iterator. (_S_copy_range): Likewise for contiguous ranges. * include/bits/basic_string.tcc (_M_construct): Use explicit conversion to charT after dereferencing iterator. * include/bits/cow_string.h (_S_copy_chars): Likewise. (basic_string(from_range_t, R&&, const Allocator&)): Likewise. Only optimize for contiguous iterators that are convertible to const charT*. * testsuite/21_strings/basic_string/cons/char/119748.cc: New test. * testsuite/21_strings/basic_string/cons/wchar_t/119748.cc: New test. Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
2025-04-15libstdc++: Enable __gnu_test::test_container constructor for C++98Jonathan Wakely1-3/+1
The only reason this constructor wasn't defined for C++98 is that it uses constructor delegation, but that isn't necessary. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_iterators.h (test_container): Define array constructor for C++98 as well.
2025-04-14libstdc++: Use UTF-32BE as wide encoding for big-endian machines [PR119725]Tomasz Kamiński2-2/+3
This changes the `dg-options` line so UTF-32 with byte order native to the machine is used as wide encoding. We still do not handle mismatch in the byte order of the Unicode encodings (UTF32-BE on little-endian machines). This would require larger changes, as for example `unicode-data.h` tables are encoded with native byte order. PR libstdc++/119725 libstdc++-v3/ChangeLog: * testsuite/std/format/debug.cc: Updated dg-options. * testsuite/std/format/debug_nonunicode.cc: Updated dg-options. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-11libstdc++: Define __cpp_lib_containers_ranges in appropriate headers [PR111055]Tomasz Kamiński17-12/+97
This is final piece of P1206R7, adding a feature test macros, as range constructors and member operations are now implemented for all containers and adaptors. For consistency with the proposal, all new container operations and helpers are now defined if __glibcxx_containers_ranges, instead of __glibcxx_ranges_to_container. PR libstdc++/111055 libstdc++-v3/ChangeLog: * include/bits/version.def (containers_ranges): Define. * include/bits/version.h: Regenerate. * include/bits/ranges_base.h (__detail::__container_compatible_range) (__detail::__range_to_alloc_type, __detail::__range_mapped_type) (__detail::__range_key_type): Depend on __glibcxx_containers_ranges instead of __glibcxx_ranges_to_container. * include/bits/basic_string.h: Replace __glibcxx_ranges_to_container with __glibcxx_containers_ranges. * include/bits/cow_string.h: Likewise. * include/bits/deque.tcc: Likewise. * include/bits/forward_list.h: Likewise. * include/bits/stl_bvector.h: Likewise. * include/bits/stl_deque.h: Likewise. * include/bits/stl_list.h: Likewise. * include/bits/stl_map.h: Likewise. * include/bits/stl_multimap.h: Likewise. * include/bits/stl_multiset.h: Likewise. * include/bits/stl_queue.h: Likewise. * include/bits/stl_set.h: Likewise. * include/bits/stl_stack.h: Likewise. * include/bits/stl_vector.h: Likewise. * include/bits/unordered_map.h: Likewise. * include/bits/unordered_set.h: Likewise. * include/bits/vector.tcc: Likewise. * include/debug/deque: Likewise. * include/debug/forward_list: Likewise. * include/debug/list: Likewise. * include/debug/map.h: Likewise. * include/debug/multimap.h: Likewise. * include/debug/multiset.h: Likewise. * include/debug/set.h: Likewise. * include/debug/unordered_map: Likewise. * include/debug/unordered_set: Likewise. * include/debug/vector: Likewise. * include/std/deque: Provide __cpp_lib_containers_ranges. * include/std/forward_list: Likewise. * include/std/list: Likewise. * include/std/map: Likewise. * include/std/queue: Likewise. * include/std/set: Likewise. * include/std/stack: Likewise. * include/std/string: Likewise. * include/std/unordered_map: Likewise. * include/std/unordered_set: Likewise. * include/std/vector: Likewise. * testsuite/21_strings/basic_string/cons/from_range.cc: Test for value __cpp_lib_containers_ranges. * testsuite/23_containers/deque/cons/from_range.cc: Likewise. * testsuite/23_containers/forward_list/cons/from_range.cc: Likewise. * testsuite/23_containers/list/cons/from_range.cc: Likewise. * testsuite/23_containers/map/cons/from_range.cc: Likewise. * testsuite/23_containers/multimap/cons/from_range.cc: Likewise. * testsuite/23_containers/multiset/cons/from_range.cc: Likewise. * testsuite/23_containers/priority_queue/cons_from_range.cc: Likewise. * testsuite/23_containers/queue/cons_from_range.cc: Likewise. * testsuite/23_containers/set/cons/from_range.cc: Likewise. * testsuite/23_containers/stack/cons_from_range.cc: Likewise. * testsuite/23_containers/unordered_map/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_multimap/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_multiset/cons/from_range.cc: Likewise. * testsuite/23_containers/unordered_set/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/bool/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/cons/from_range.cc: Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-11libstdc++: Add P1206R7 from_range members to std::string [PR111055]Jonathan Wakely5-0/+628
This is the last piece of P1206R7, adding new members to std::basic_string. libstdc++-v3/ChangeLog: PR libstdc++/111055 * include/bits/basic_string.h (_S_copy_range): New function. (basic_string(from_range_t, R%%, const Alloc&)): New constructor. (append_range, assign_range, insert_range, replace_with_range): New functions. * include/bits/cow_string.h: Likewise. * testsuite/21_strings/basic_string/cons/from_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/append/append_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/assign/assign_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/insert/insert_range.cc: New test. * testsuite/21_strings/basic_string/modifiers/replace/replace_with_range.cc: New test. Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-11libstdc++: Implement debug format for strings and characters formatters ↵Tomasz Kamiński5-4/+462
[PR109162] This patch implements part P2286R8 that specified debug (escaped) format for the strings and characters sequences. This include both handling of the '?' format specifier and set_debug_format member. To indicate partial support we define __glibcxx_format_ranges macro value 1, without defining __cpp_lib_format_ranges. We provide two separate escaping routines depending on the literal encoding for the corresponding character types. If the character encoding is Unicode, we follow the specification for the standard (__format::__write_escaped_unicode). For other encodings, we escape only characters in range [0x00, 0x80), interpreting them as ASCII values: [0x00, 0x20), 0x7f and '\t', '\r', '\n', '\\', '"', '\'' are escaped. We assume every character outside this range is printable (__format::_write_escaped_ascii). In particular we do not yet implement special handling of shift sequences. For Unicode escaping a new __unicode::__escape_edges table is introduced, that encodes information if character belongs to General_Category that is escaped by the standard (Control or Other). This table is generated from DerivedGeneralCategory.txt provided by Unicode. Only boolean flag is preserved to reduce the number of entries. The additional rules for escaping are handled by __format::__should_escape_unicode. When width or precision is specified, we emit escaped string to the temporary buffer and format the resulting string according to the format spec. For characters use a fixed size stack buffer, for which a new _Fixedbuf_sink is introduced. For strings, we use _Str_sink and to avoid allocations, we compute the estimated size of (possibly truncated) input, and if it is larger than width field we print directly. PR libstdc++/109162 contrib/ChangeLog: * unicode/README: Mentioned DerivedGeneralCategory.txt. * unicode/gen_libstdcxx_unicode_data.py: Generation __escape_edges table from DerivedGeneralCategory.txt. Update file name in comments. * unicode/DerivedGeneralCategory.txt: Copy of file distributed by Unicode Consortium. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__detail::_Widen): Moved to std/format file. * include/bits/unicode-data.h: Regnerate. * include/bits/unicode.h (__unicode::_Utf_iterator::_M_units) (__unicode::__should_escape_category): Define. * include/std/format (_GLIBCXX_WIDEN_, _GLIBCXX_WIDEN): Copied from include/bits/chrono_io.h. (__format::_Widen): Moved from include/bits/chrono_io.h. (__format::_Term_char, __format::_Escapes, __format::_Separators) (__format::__should_escape_ascii, __format::__should_escape_unicode) (__format::__write_escape_seq, __format::__write_escaped_char) (__format::__write_escaped_acii, __format::__write_escaped_unicode) (__format::__write_escaped): Define. (__formatter_str::_S_trunc): Extracted truncation of character sequences. (__formatter_str::format): Handle _Pres_esc. (__formatter_int::_M_do_parse) [__glibcxx_format_ranges]: Parse '?'. (__formatter_int::_M_format_character_escaped): Define. (formatter<_CharT, _CharT>::format, formatter<char, wchar_t>::format): Handle _Pres_esc. (__formatter_str::set_debug_format, formatter<...>::set_debug_format) Guard with __glibcxx_format_ranges. (__format::_Fixedbuf_sink): Define. * testsuite/23_containers/vector/bool/format.cc: Use __format::_Widen and remove unnecessary <chrono> include. * testsuite/std/format/debug.cc: New test. * testsuite/std/format/debug_nonunicode.cc: New test. * testsuite/std/format/parse_ctx.cc (escaped_strings_supported): Define to true if __glibcxx_format_ranges is defined. * testsuite/std/format/string.cc (escaped_strings_supported): Define to true if __glibcxx_format_ranges is defined. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-10libstdc++: Adjust value of __cpp_lib_constrained_equality for C++20Jonathan Wakely1-1/+1
The P3379R0 bump to __cpp_lib_constrained_equality relates to changes that only affect std::expected, so there's no reason to define the updated value in C++20. This change restores the previous value (202403) for C++20, and only uses the new value (202411) for C++23 and later. Also remove the TODO comments, because I correctly predicted that the final value would be 202411. libstdc++-v3/ChangeLog: * include/bits/version.def (constrained_equality): Only define as 202411 for C++23 and later, use 202403 for C++20. * include/bits/version.h: Regenerate. * testsuite/20_util/expected/equality_constrained.cc: Remove TODO comment.
2025-04-09libstdc++: Fix constraint recursion in basic_const_iterator operator- [PR115046]Patrick Palka1-0/+13
It was proposed in PR112490 to also adjust basic_const_iterator's friend operator-(sent, iter) overload alongside the r15-7757-g4342c50ca84ae5 adjustments to its comparison operators, but we lacked a concrete testcase demonstrating fixable constraint recursion there. It turns out Hewill Kang's PR115046 is such a testcase! So this patch makes the same adjustments to that overload as well, fixing PR115046. The LWG 4218 P/R will need to get adjusted too. PR libstdc++/115046 PR libstdc++/112490 libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (basic_const_iterator::operator-): Replace non-dependent basic_const_iterator function parameter with a dependent one of type basic_const_iterator<_It2> where _It2 matches _It. * testsuite/std/ranges/adaptors/as_const/1.cc (test04): New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-04-08libstdc++: Fix use-after-free in std::format [PR119671]Jonathan Wakely1-0/+12
When formatting floating-point values to wide strings there's a case where we invalidate a std::wstring buffer while a std::wstring_view is still referring to it. libstdc++-v3/ChangeLog: PR libstdc++/119671 * include/std/format (__formatter_fp::format): Do not invalidate __wstr unless _M_localized returns a valid string. * testsuite/std/format/functions/format.cc: Check wide string formatting of floating-point types with classic locale. Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
2025-04-04libstdc++: Avoid redundant value_type object in flat_set::emplace [PR119620]Patrick Palka2-0/+42
flat_set::emplace (and flat_multiset's) currently unconditionally constructs an object outside of the container, but if we're passed a value_type object we can and should avoid that. PR libstdc++/119620 libstdc++-v3/ChangeLog: * include/std/flat_set (_Flat_set_impl::_M_try_emplace): Split out into two overloads, one taking at least one argument and one taking zero arguments. Turn __k into an auto&& reference bound to __arg if it's already a value_type and otherwise bound to a lifetime-extended value_type temporary. * testsuite/23_containers/flat_multiset/1.cc (test08): New test. * testsuite/23_containers/flat_set/1.cc (test08): New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-04-04libstdc++: Replace use of __mindist in ranges::uninitialized_xxx algos ↵Jonathan Wakely2-2/+57
[PR101587] In r15-8980-gf4b6acfc36fb1f I introduced a new function object for finding the smaller of two distances. In bugzilla Hewill Kang pointed out that we still need to explicitly convert the result back to the right difference type, because the result might be an integer-like class type that doesn't convert to an integral type explicitly. Rather than doing that conversion in the __mindist function object, I think it's simpler to remove it again and just do a comparison and assignment. We always want the result to have a specific type, so we can just check if the value of the other type is smaller, and then convert that to the other type if so. libstdc++-v3/ChangeLog: PR libstdc++/101587 * include/bits/ranges_uninitialized.h (__detail::__mindist): Remove. (ranges::uninitialized_copy, ranges::uninitialized_copy_n) (ranges::uninitialized_move, ranges::uninitialized_move_n): Use comparison and assignment instead of __mindist. * testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc: Check with ranges that use integer-like class type for difference type. * testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc: Likewise. Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com> Reviewed-by: Hewill Kang <hewillk@gmail.com>
2025-04-04libstdc++: Provide formatter for vector<bool>::reference [PR109162]Tomasz Kamiński1-0/+67
This patch implement formatter for vector<bool>::reference which is part of P2286R8. To indicate partial support we define __glibcxx_format_ranges macro value 1, without defining __cpp_lib_format_ranges. To avoid including the whole content of the <format> header, we introduce new bits/formatfwd.h forward declares classes required for newly introduce formatter. The signatures of the user-facing parse and format method of the provided formatters deviate from the standard by constraining types of params: * _Bit_reference instead T satisfying is-vector-bool-reference<T> * _CharT is constrained __formatter::__char * basic_format_parse_context<_CharT> for parse argument * basic_format_context<_Out, _CharT> for format second argument The standard specifies last three of above as unconstrained types, which leads to formattable<vector<bool>::reference, char32_t> (and any other type as char) being true. PR libstdc++/109162 libstdc++-v3/ChangeLog: * include/Makefile.am: Add bits/formatfwd.h. * include/Makefile.in: Add bits/formatfwd.h. * include/bits/version.def: Define __glibcxx_format_ranges without corresponding std name. * include/bits/version.h: Regenerate. * include/std/format (basic_format_context, __format::__char): Move declartions to bits/formatfwd.h. (formatter<_Tp, _CharT>): Remove default argument for _CharT parameter, now specified in forward declaration in bits/formatfwd.h. * include/std/vector (formatter<_Bit_reference, _CharT>): Define. * include/bits/formatfwd.h: New file with forward declarations for bits of std/format. * testsuite/23_containers/vector/bool/format.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-03libstdc++: Restored accidentally removed test case.Tomasz Kamiński1-0/+1
It was removed by accident r15-9178-g5c7f6272f43f42. libstdc++-v3/ChangeLog: * testsuite/std/format/functions/format.cc: Restored line.
2025-04-03libstdc++: Fix handling of field width for wide strings and characters ↵Tomasz Kamiński1-2/+6
[PR119593] This patch corrects handling of UTF-32LE and UTF32-BE in __unicode::__literal_encoding_is_unicode<_CharT>, so they are recognized as unicode and functions produces correct result for wchar_t. Use `__unicode::__field_width` to compute the estimated witdh of the charcter for unicode wide encoding. PR libstdc++/119593 libstdc++-v3/ChangeLog: * include/bits/unicode.h (__unicode::__literal_encoding_is_unicode<_CharT>): Corrected handing for UTF-16 and UTF-32 with "LE" or "BE" suffix. * include/std/format (__formatter_str::_S_character_width): Define. (__formatter_str::_S_character_width): Updated passed char length. * testsuite/std/format/functions/format.cc: Test for wchar_t. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-04-02libstdc++, testsuite, Darwin: Prune a new linker warning present form XCode 16.Iain Sandoe1-0/+3
Darwin's linker now warns when duplicate rpaths are presented - which happens when we emit duplicate '-B' paths. In principle, we should avoid this in the test-suite, however at present we tend to have duplicates because different parts of the machinery add them. At some point, it might be nice to have an "add_option_if_missing" and apply that across the whole of the test infra. However this is not something for late in stage 4. So the solution here is to prune the warning - the effect of the duplicate in the libstdc++ testsuite is not important; it will make the exes very slightly larger but it won't alter the paths that are presented for loading the runtimes. libstdc++-v3/ChangeLog: * testsuite/lib/prune.exp: Prune ld warning about duplicatei rpaths. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
2025-04-01libstdc++: Fix -Warray-bounds warning in std::vector::resize [PR114945]Jonathan Wakely1-0/+36
This is yet another false positive warning fix. This time the compiler can't prove that when the vector has sufficient excess capacity to append new elements, the pointer to the existing storage is not null. libstdc++-v3/ChangeLog: PR libstdc++/114945 * include/bits/vector.tcc (vector::_M_default_append): Add unreachable condition so the compiler knows that _M_finish is not null. * testsuite/23_containers/vector/capacity/114945.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-31libstdc++: Fix -Warray-bounds warning in std::vector<bool> [PR110498]Jonathan Wakely1-0/+18
In this case, we need to tell the compiler that the current size is not larger than the new size so that all the existing elements can be copied to the new storage. This avoids bogus warnings about overflowing the new storage when the compiler can't tell that that cannot happen. We might as well also hoist the loads of begin() and end() before the allocation too. All callers will have loaded at least begin() before calling _M_reallocate. libstdc++-v3/ChangeLog: PR libstdc++/110498 * include/bits/vector.tcc (vector<bool, A>::_M_reallocate): Hoist loads of begin() and end() before allocation and use them to state an unreachable condition. * testsuite/23_containers/vector/bool/capacity/110498.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-31libstdc++: Fix -Wstringop-overread warning in std::vector<bool> [PR114758]Jonathan Wakely1-0/+12
As in r13-4393-gcca06f0d6d76b0 and a few other commits, we can avoid bogus warnings in std::vector<bool> by hoisting some loads to before the allocation that calls operator new. This means that the compiler has enough info to remove the dead branches that trigger bogus warnings. On trunk this is only needed with -fno-assume-sane-operators-new-delete but it will help on the branches where that option doesn't exist. libstdc++-v3/ChangeLog: PR libstdc++/114758 * include/bits/vector.tcc (vector<bool, A>::_M_fill_insert): Hoist loads of begin() and end() before allocation. * testsuite/23_containers/vector/bool/capacity/114758.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-31libstdc++: Make operator== for std::tuple convert to bool [PR119545]Jonathan Wakely1-0/+24
The boolean-testable requirements don't require the type to be copyable, so we need to convert to bool before it might need to be copied. libstdc++-v3/ChangeLog: PR libstdc++/119545 * include/std/tuple (operator==): Convert comparison results to bool. * testsuite/20_util/tuple/comparison_operators/119545.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-31libstdc++: Constrain formatters for chrono types [PR119517]Tomasz Kamiński1-0/+43
The formatters for chrono types defined the parse/format methods as accepting unconstrained types, this in combination with lack of constrain on _CharT lead to them falsely satisfying formattable requirements for any type used as character. This patch adjust the fromatter<T, CharT>::parse signature to: constexpr typename basic_format_parse_context<_CharT>::iterator parse(basic_format_parse_context<_CharT>& __pc); And formatter<T, CharT>::format to: template<typename _Out> typename basic_format_context<_Out, _CharT>::iterator format(const T& __t, basic_format_context<_Out, _CharT>& __fc) const; Furthermore we _CharT with __format::__char (char or wchar_t), PR libstdc++/119517 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (formatter): Add __format::__char for _CharT and adjust parse and format method signatures. * testsuite/std/time/format/pr119517.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-28libstdc++: Add testcase for bogus -Wstringop-overflow in std::vector [PR117983]Jonathan Wakely1-0/+17
This was fixed on trunk by r15-4473-g3abe751ea86e34, just add the testcase. libstdc++-v3/ChangeLog: PR libstdc++/117983 * testsuite/23_containers/vector/modifiers/insert/117983.cc: New test.
2025-03-27libstdc++-v3 testsuite: fix malformed dg-require-static-libstdcxx directivesDavid Malcolm5-5/+5
I believe these don't get detected by DejaGnu's regexp. Found by dg-lint. libstdc++-v3/ChangeLog: * testsuite/17_intro/shared_with_static_deps.cc: Fix malformed dg-require-static-libstdcxx directive. * testsuite/17_intro/static.cc: Likewise. * testsuite/18_support/type_info/110572.cc: Likewise. * testsuite/20_util/to_chars/4.cc: Likewise. * testsuite/std/time/tzdb_list/pr118811.cc: Likewise. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
2025-03-27libstdc++: Replace use of std::min in ranges::uninitialized_xxx algos [PR101587]Jonathan Wakely2-0/+26
Because ranges can have any signed integer-like type as difference_type, it's not valid to use std::min(diff1, diff2). Instead of calling std::min with an explicit template argument, this adds a new __mindist helper that determines the common type and uses that with std::min. libstdc++-v3/ChangeLog: PR libstdc++/101587 * include/bits/ranges_uninitialized.h (__detail::__mindist): New function object. (ranges::uninitialized_copy, ranges::uninitialized_copy_n) (ranges::uninitialized_move, ranges::uninitialized_move_n): Use __mindist instead of std::min. * testsuite/20_util/specialized_algorithms/uninitialized_copy/constrained.cc: Check ranges with difference difference types. * testsuite/20_util/specialized_algorithms/uninitialized_move/constrained.cc: Likewise.
2025-03-27testsuite: fix dg-* typosSam James1-1/+1
I have a handful more of these left but those introduce FAILs, while these all introduce new PASSes. libstdc++-v3/ChangeLog: * testsuite/std/format/string_neg.cc: Add missing brace for dg-error. gcc/testsuite/ChangeLog: * gcc.dg/analyzer/fd-datagram-socket.c: Fix 'dg-message' spelling. * gcc.dg/analyzer/out-of-bounds-zero.c: Fix whitespace in 'dg-additional-options'. * gcc.dg/analyzer/strchr-1.c: Fix 'dg-message' whitespace. * gnat.dg/sso/q11.adb: Fix 'dg-output' whitespace.
2025-03-27libstdc++: re-bump the feature-test macro for P2562R1 [PR119488]Giuseppe D'Angelo1-1/+1
Now that the algorithms have been merged we can advertise full support for P2562R1. This effectively reverts r15-8933-ga264c270fde292. libstdc++-v3/ChangeLog: PR libstdc++/119488 * include/bits/version.def (constexpr_algorithms): Bump the feature-testing macro. * include/bits/version.h: Regenerate. * testsuite/25_algorithms/cpp_lib_constexpr.cc: Test the bumped value for the feature-testing macro.
2025-03-27libstdc++: add constexpr stable_partitionGiuseppe D'Angelo2-0/+45
This completes the implementation of P2562R1 for C++26. Unlike the other constexpr algorithms of the same family, stable_partition does not have a constexpr-friendly version "ready to use" during constant evaluation. In fact, it is not even available on freestanding, because it always allocates a temporary memory buffer. This commit implements the simplest possible strategy: during constant evaluation allocate a buffer of length 1 on the stack, and use that as a working area. libstdc++-v3/ChangeLog: * include/bits/algorithmfwd.h (stable_partition): Mark it as constexpr for C++26. * include/bits/ranges_algo.h (__stable_partition_fn): Likewise. * include/bits/stl_algo.h (stable_partition): Mark it as constexpr for C++26; during constant evaluation use a new codepath where a temporary buffer of 1 element is used. * testsuite/25_algorithms/headers/algorithm/synopsis.cc (stable_partition): Add constexpr. * testsuite/25_algorithms/stable_partition/constexpr.cc: New test.
2025-03-27libstdc++: add constexpr inplace_mergeGiuseppe D'Angelo2-0/+74
This commit adds support for constexpr inplace_merge, added by P2562R1 for C++26. The implementation strategy is the same as for constexpr stable_sort: use if consteval to detect if we're in constant evaluation, and dispatch to a suitable path (same one as freestanding). libstdc++-v3/ChangeLog: * include/bits/algorithmfwd.h (inplace_merge): Mark it as constexpr for C++26. * include/bits/ranges_algo.h (__inplace_merge_fn): Likewise. * include/bits/stl_algo.h (inplace_merge): Mark it as constexpr; during constant evaluation, dispatch to the non-allocating codepath. * testsuite/25_algorithms/headers/algorithm/synopsis.cc (inplace_merge): Add constexpr. * testsuite/25_algorithms/inplace_merge/constexpr.cc: New test.
2025-03-27libstdc++: Fix std::ranges::iter_move for function references [PR119469]Jonathan Wakely1-0/+11
The result of std::move (or a cast to an rvalue reference) on a function reference is always an lvalue. Because std::ranges::iter_move was using the type std::remove_reference_t<X>&& as the result of std::move, it was giving the wrong type for function references. Use a decltype-specifier with declval<remove_reference_t<X>>() instead of just using the remove_reference_t<X>&& type directly. This gives the right result, while still avoiding the cost of doing overload resolution for std::move. libstdc++-v3/ChangeLog: PR libstdc++/119469 * include/bits/iterator_concepts.h (_IterMove::__result): Use decltype-specifier instead of an explicit type. * testsuite/24_iterators/customization_points/iter_move.cc: Check results for function references. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-26libstdc++: do not advertise full P2562R1 supportGiuseppe D'Angelo1-1/+1
P2562R1 ("constexpr Stable Sorting") adds constexpr to stable_sort, stable_partition and inplace_merge. However only the first is already implemented in libstdc++, so we shouldn't bump the feature-testing macro to the bumped C++26 value. This commit sets it to one less than the final value. Amends r15-7708-gff43f9853d3b10. libstdc++-v3/ChangeLog: * include/bits/version.def (constexpr_algorithms): Change the value of the feature-testing macro. * include/bits/version.h: Regenerate. * testsuite/25_algorithms/cpp_lib_constexpr.cc: Amend the check of the feature-testing macro.