aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/util
AgeCommit message (Collapse)AuthorFilesLines
8 dayslibstdc++: Fix algorithms to use iterators' difference_type for arithmetic ↵Jonathan Wakely1-0/+18
[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-07-24libstdc++: Expand compile-time ranges tests for vector and basic_string.Tomasz Kamiński1-0/+5
This replaces most test_constexpr invocations with direct calls to test_ranges(), which is also used for runtime tests. SimpleAllocator was made constexpr to simplify this refactoring. Other test allocators, like uneq_allocator (used in from_range constructor tests), were not updated. libstdc++-v3/ChangeLog: * testsuite/21_strings/basic_string/cons/from_range.cc: Replace test_constexpr with test_ranges inside static_assert. * testsuite/21_strings/basic_string/modifiers/append/append_range.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/assign/assign_range.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/insert/insert_range.cc: Likewise. * testsuite/21_strings/basic_string/modifiers/replace/replace_with_range.cc: Likewise. * testsuite/23_containers/vector/bool/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/assign/assign_range.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/insert/insert_range.cc: Likewise. * testsuite/23_containers/vector/cons/from_range.cc: Likewise. * testsuite/23_containers/vector/modifiers/assign/assign_range.cc: Likewise. * testsuite/23_containers/vector/modifiers/insert/insert_range.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc: Run full test_ranges instead of span-only in test_constexpr. * testsuite/23_containers/vector/modifiers/append_range.cc: Replace test_constexpr with calls to test_ranges and test_overlapping. * testsuite/util/testsuite_allocator.h (__gnu_test::SimpleAllocator): Declared member functions as constexpr.
2025-07-22libstdc++: Make testsuite_iterators constexpr and expand inplace_vector ↵Tomasz Kamiński1-46/+127
tests [PR119137] All functions in testsuite_iterators.h are now marked constexpr, targeting the earliest possible standard. Most functions use C++14 due to multi-statement bodies, with exceptions: * BoundsContainer and some constructors are C++11 compatible. * OutputContainer is C++20 due to operator new/delete usage. Before C++23, each constexpr templated function requires a constexpr -suitable instantiation. Functions delegating to _GLIBCXX14_CONSTEXPR must also be _GLIBCXX14_CONSTEXPR; e.g., forward_iterator_wrapper's constructor calling input_iterator_wrapper's constructor, or operator-> calling operator*. For classes defined C++20 or later (e.g., test_range), constexpr is applied unconditionally. PR libstdc++/119137 libstdc++-v3/ChangeLog: * testsuite/23_containers/inplace_vector/cons/from_range.cc: Run iterators and range test at compile-time. * testsuite/23_containers/inplace_vector/modifiers/assign.cc: Likewise. * testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc: Likewise. * testsuite/util/testsuite_iterators.h (__gnu_test::BoundsContainer) (__gnu_test::OutputContainer, __gnu_test::WritableObject) (__gnu_test::output_iterator_wrapper, __gnu_test::input_iterator_wrapper) (__gnu_test::forward_iterator_wrapper) (__gnu_test::bidirectional_iterator_wrapper) (__gnu_test::random_access_iterator_wrapper) (__gnu_test::test_container): Add appropriate _GLIBCXXNN_CONSTEXPR macros to member functions. (__gnu_test::contiguous_iterator_wrapper) (__gnu_test::input_iterator_wrapper_rval) (__gnu_test::test_range, __gnu_test::test_range_nocopy) (__gnu_test::test_sized_range_sized_sent) (__gnu_test::test_sized_range): Add constexpr specifier to member functions.
2025-07-18libstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]Jonathan Wakely1-0/+6
Implement std::inplace_vector as specified in P0843R14, without follow up papers, in particular P3074R7 (trivial unions). In consequence inplace_vector<T, N> can be used inside constant evaluations only if T is trivial or N is equal to zero. We provide a separate specialization for inplace_vector<T, 0> to meet the requirements of N5008 [inplace.vector.overview] p5. In particular objects of such types needs to be empty. To allow constexpr variable of inplace_vector v, where v.size() < v.capacity(), we need to guaranteed that all elements of the storage array are initialized, even ones in range [v.data() + v.size(), v.data() + v.capacity()). This is perfoirmed by _M_init function, that is called by each constructor. By storing the array in anonymous union, we can perform this initialization in constant evaluation, avoiding the impact on runtime path. The size() function conveys the information that _M_size <= _Nm to compiler, by calling __builtin_unreachable(). In particular this allows us to eliminate FP warnings by using _Nm - size() instead of _Nm - _M_size, when computing available elements. The included test cover almost all code paths at runtime, however some compile time evaluation test are not yet implemented: * operations on range, they depend on making testsuite_iterators constexpr * negative test for invoking operations with preconditions at compile time, especially for zero size specialization. PR libstdc++/119137 libstdc++-v3/ChangeLog: * doc/doxygen/user.cfg.in (INPUT): Add new header. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/bits/stl_iterator_base_types.h (__any_input_iterator): Define. * include/bits/version.def (inplace_vector): Define. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include new header. * src/c++23/std.cc.in: Export contents if new header. * include/std/inplace_vector: New file. * testsuite/23_containers/inplace_vector/access/capacity.cc: New file. * testsuite/23_containers/inplace_vector/access/elem.cc: New file. * testsuite/23_containers/inplace_vector/access/elem_neg.cc: New file. * testsuite/23_containers/inplace_vector/cons/1.cc: New file. * testsuite/23_containers/inplace_vector/cons/from_range.cc: New file. * testsuite/23_containers/inplace_vector/cons/throws.cc: New file. * testsuite/23_containers/inplace_vector/copy.cc: New file. * testsuite/23_containers/inplace_vector/erasure.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/assign.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/erase.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc: New file. * testsuite/23_containers/inplace_vector/modifiers/single_insert.cc: New file. * testsuite/23_containers/inplace_vector/move.cc: New file. * testsuite/23_containers/inplace_vector/relops.cc: New file. * testsuite/23_containers/inplace_vector/version.cc: New file. * testsuite/util/testsuite_iterators.h (input_iterator_wrapper::base): Define. Reviewed-by: Patrick Palka <ppalka@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-08libstdc++: Make debug iterator pointer sequence const [PR116369]François Dumont1-0/+6
In revision a35dd276cbf6236e08bcf6e56e62c2be41cf6e3c the debug sequence have been made mutable to allow attach iterators to const containers. This change completes this fix by also declaring debug unordered container members mutable. Additionally the debug iterator sequence is now a pointer-to-const and so _Safe_sequence_base _M_attach and all other methods are const qualified. Not-const methods exported are preserved for abi backward compatibility. libstdc++-v3/ChangeLog: PR c++/116369 * config/abi/pre/gnu-versioned-namespace.ver: Use new const qualified symbols. * config/abi/pre/gnu.ver: Add new const qualified symbols. * include/debug/safe_base.h (_Safe_iterator_base::_M_sequence): Declare as pointer-to-const. (_Safe_iterator_base::_M_attach, _M_attach_single): New, take pointer-to-const _Safe_sequence_base. (_Safe_sequence_base::_M_detach_all, _M_detach_singular, _M_revalidate_singular) (_M_swap, _M_get_mutex): New, const qualified. (_Safe_sequence_base::_M_attach, _M_attach_single, _M_detach, _M_detach_single): const qualify. * include/debug/safe_container.h (_Safe_container<>::_M_cont): Add const qualifier. (_Safe_container<>::_M_swap_base): New. (_Safe_container(_Safe_container&&, const _Alloc&, std::false_type)): Adapt to use latter. (_Safe_container<>::operator=(_Safe_container&&)): Likewise. (_Safe_container<>::_M_swap): Likewise and take parameter as const reference. * include/debug/safe_unordered_base.h (_Safe_local_iterator_base::_M_safe_container): New. (_Safe_local_iterator_base::_Safe_local_iterator_base): Take _Safe_unordered_container_base as pointer-to-const. (_Safe_unordered_container_base::_M_attach, _M_attach_single): New, take container as _Safe_unordered_container_base pointer-to-const. (_Safe_unordered_container_base::_M_local_iterators, _M_const_local_iterators): Add mutable. (_Safe_unordered_container_base::_M_detach_all, _M_swap): New, const qualify. (_Safe_unordered_container_base::_M_attach_local, _M_attach_local_single) (_M_detach_local, _M_detach_local_single): Add const qualifier. * include/debug/safe_unordered_container.h (_Safe_unordered_container::_M_self()): New. * include/debug/safe_unordered_container.tcc (_Safe_unordered_container::_M_invalidate_if, _M_invalidated_local_if): Use latter. * include/debug/safe_iterator.h (_Safe_iterator<>::_M_attach, _M_attach_single): Take _Safe_sequence_base as pointer-to-const. (_Safe_iterator<>::_M_get_sequence): Add const_cast and comment about it. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>): Replace usages of _M_sequence member by _M_safe_container(). (_Safe_local_iterator<>::_M_attach, _M_attach_single): Take _Safe_unordered_container_base as pointer-to-const. (_Safe_local_iterator<>::_M_get_sequence): Rename into... (_Safe_local_iterator<>::_M_get_ucontainer): ...this. Add necessary const_cast and comment to explain it. (_Safe_local_iterator<>::_M_is_begin, _M_is_end): Adapt. * include/debug/safe_local_iterator.tcc: Adapt. * include/debug/safe_sequence.h (_Safe_sequence<>::_M_invalidate_if, _M_transfer_from_if): Add const qualifier. * include/debug/safe_sequence.tcc: Adapt. * include/debug/deque (std::__debug::deque::erase): Adapt to use new const qualified methods. * include/debug/formatter.h: Adapt. * include/debug/forward_list (_Safe_forward_list::_M_this): Add const qualification and return pointer for consistency with 'this' keyword. (_Safe_forward_list::_M_swap_aux): Rename into... (_Safe_forward_list::_S_swap_aux): ...this and take sequence as const reference. (forward_list<>::resize): Adapt to use const methods. * include/debug/list (list<>::resize): Likewise. * src/c++11/debug.cc: Adapt to const qualification. * testsuite/util/testsuite_containers.h (forward_members_unordered::forward_members_unordered): Add check on local_iterator conversion to const_local_iterator. (forward_members::forward_members): Add check on iterator conversion to const_iterator. * testsuite/23_containers/unordered_map/const_container.cc: New test case. * testsuite/23_containers/unordered_multimap/const_container.cc: New test case. * testsuite/23_containers/unordered_multiset/const_container.cc: New test case. * testsuite/23_containers/unordered_set/const_container.cc: New test case. * testsuite/23_containers/vector/debug/mutex_association.cc: Adapt.
2025-07-07libstdc++: Make VERIFY a variadic macroJonathan Wakely1-10/+7
This defines the testsuite assertion macro VERIFY so that it allows un-parenthesized expressions containing commas. This matches how assert is defined in C++26, following the approval of P2264R7. The primary motivation is to allow expressions that the preprocessor splits into multiple arguments, e.g. VERIFY( vec == std::vector<int>{1,2,3,4} ); To achieve this, VERIFY is redefined as a variadic macro and then the arguments are grouped together again through the use of __VA_ARGS__. The implementation is complex due to the following points: - The arguments __VA_ARGS__ are contextually-converted to bool, so that scoped enums and types that are not contextually convertible to bool cannot be used with VERIFY. - bool(__VA_ARGS__) is used so that multiple arguments (i.e. those which are separated by top-level commas) are ill-formed. Nested commas are allowed, but likely mistakes such as VERIFY( cond, "some string" ) are ill-formed. - The bool(__VA_ARGS__) expression needs to be unevaluated, so that we don't evaluate __VA_ARGS__ more than once. The simplest way to do that would be just sizeof bool(__VA_ARGS__), without parentheses to avoid a vexing parse for VERIFY(bool(i)). However that wouldn't work for e.g. VERIFY( []{ return true; }() ), because lambda expressions are not allowed in unevaluated contexts until C++20. So we use another conditional expression with bool(__VA_ARGS__) as the unevaluated operand. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_hooks.h (VERIFY): Define as variadic macro. * testsuite/ext/verify_neg.cc: New test. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-06-26libstdc++: Implement C++26 P2927R3 - Inspecting exception_ptrJakub Jelinek1-0/+1
The following patch attempts to implement the C++26 P2927R3 - Inspecting exception_ptr paper (but not including P3748R0, I plan to play with it incrementally and it will really depend on the Constexpr exceptions patch). The function template is implemented using an out of line private method of exception_ptr, so that P3748R0 then can use if consteval and provide a constant evaluation variant of it. 2025-06-26 Jakub Jelinek <jakub@redhat.com> * include/bits/version.def (exception_ptr_cast): Add. * include/bits/version.h: Regenerate. * libsupc++/exception: Define __glibcxx_want_exception_ptr_cast before including bits/version.h. * libsupc++/exception_ptr.h (std::exception_ptr_cast): Define. (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Declare. * libsupc++/eh_ptr.cc (std::__exception_ptr::exception_ptr::_M_exception_ptr_cast): Define. * src/c++23/std.cc.in (std::exception_ptr_cast): Export. * config/abi/pre/gnu.ver: Export _ZNKSt15__exception_ptr13exception_ptr21_M_exception_ptr_castERKSt9type_info at CXXABI_1.3.17. * testsuite/util/testsuite_abi.cc (check_version): Allow CXXABI_1.3.17. * testsuite/18_support/exception_ptr/exception_ptr_cast.cc: New test.
2025-05-30libstdc++: Move atomic wait/notify entry points into the libraryJonathan Wakely1-0/+1
This moves the implementation details of atomic wait/notify functions into the library, so that only a small API surface is exposed to users. This also fixes some race conditions present in the design for proxied waits: - The stores to _M_ver in __notify_impl must be protected by the mutex, and the loads from _M_ver in __wait_impl and __wait_until_impl to check for changes must also be protected by the mutex. This ensures that checking _M_ver for updates and waiting on the condition_variable happens atomically. Otherwise it's possible to have: _M_ver == old happens-before {++_M_ver; cv.notify;} which happens-before cv.wait. That scenario results in a missed notification, and so the waiting function never wakes. This wasn't a problem for Linux, because the futex wait call re-checks the _M_ver value before sleeping, so the increment cannot interleave between the check and the wait. - The initial load from _M_ver that reads the 'old' value used for the _M_ver == old checks must be done before loading and checking the value of the atomic variable. Otherwise it's possible to have: var.load() == val happens-before {++_M_ver; _M_cv.notify_all();} happens-before {old = _M_ver; lock mutex; if (_M_ver == old) cv.wait}. This results in the waiting thread seeing the already-incremented value of _M_ver and then waiting for it to change again, which doesn't happen. This race was present even for Linux, because using a futex instead of mutex+condvar doesn't prevent the increment from happening before the waiting threads checks for the increment. The first race can be solved locally in the waiting and notifying functions, by acquiring the mutex lock earlier in the function. The second race cannot be fixed locally, because the load of the atomic variable and the check for updates to _M_ver happen in different functions (one in a function template in the headers and one in the library). We do have an _M_old data member in the __wait_args_base struct which was previously only used for non-proxy waits using a futex. We can add a new entry point into the library to look up the waitable state for the address and then load its _M_ver into the _M_old member. This allows the inline function template to ensure that loading _M_ver happens-before testing whether the atomic variable has been changed, so that we can reliably tell if _M_ver changes after we've already tested the atomic variable. This isn't 100% reliable, because _M_ver could be incremented 2^32 times and wrap back to the same value, but that seems unlikely in practice. If/when we support waiting on user-defined predicates (which could execute long enough for _M_ver to wrap) we might want to always wait with a timeout, so that we get a chance to re-check the predicate even in the rare case that _M_ver wraps. Another change is to make the __wait_until_impl function take a __wait_clock_t::duration instead of a __wait_clock_t::time_point, so that the __wait_until_impl function doesn't depend on the symbol name of chrono::steady_clock. Inside the library it can be converted back to a time_point for the clock. This would potentially allow using a different clock, if we made a different __abi_version in the __wait_args imply waiting with a different clock. This also adds a void* to the __wait_args_base structure, so that __wait_impl can store the __waitable_state* in there the first time it's looked up for a given wait, so that it doesn't need to be retrieved again on each loop. This requires passing the __wait_args_base structure by non-const reference. The __waitable_state::_S_track function can be removed now that it's all internal to the library, and namespace-scope RAII types added for locking and tracking contention. libstdc++-v3/ChangeLog: * config/abi/pre/gnu.ver: Add new symbol version and exports. * include/bits/atomic_timed_wait.h (__platform_wait_until): Move to atomic.cc. (__cond_wait_until, __spin_until_impl): Likewise. (__wait_until_impl): Likewise. Change __wait_args_base parameter to non-const reference and change third parameter to __wait_clock_t::duration. (__wait_until): Change __wait_args_base parameter to non-const reference. Change Call time_since_epoch() to get duration from time_point. (__wait_for): Change __wait_args_base parameter to non-const reference. (__atomic_wait_address_until): Call _M_prep_for_wait_on on args. (__atomic_wait_address_for): Likewise. (__atomic_wait_address_until_v): Qualify call to avoid ADL. Do not forward __vfn. * include/bits/atomic_wait.h (__platform_wait_uses_type): Use alignof(T) not alignof(T*). (__futex_wait_flags, __platform_wait, __platform_notify) (__waitable_state, __spin_impl, __notify_impl): Move to atomic.cc. (__wait_impl): Likewise. Change __wait_args_base parameter to non-const reference. (__wait_args_base::_M_wait_state): New data member. (__wait_args_base::_M_prep_for_wait_on): New member function. (__wait_args_base::_M_load_proxy_wait_val): New member function. (__wait_args_base::_S_memory_order_for): Remove member function. (__atomic_wait_address): Call _M_prep_for_wait_on on args. (__atomic_wait_address_v): Qualify call to avoid ADL. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/atomic.cc: New file. * testsuite/17_intro/headers/c++1998/49745.cc: Remove XFAIL for C++20 and later. * testsuite/29_atomics/atomic/wait_notify/100334.cc: Remove use of internal implementation details. * testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.35 version.
2025-05-22libstdc++: Fix PSTL test iteratorsJonathan Wakely1-3/+3
These were fixed upstream by: https://github.com/uxlfoundation/oneDPL/pull/534 https://github.com/uxlfoundation/oneDPL/pull/546 libstdc++-v3/ChangeLog: * testsuite/util/pstl/test_utils.h (ForwardIterator::operator++): Fix return type. (BidirectionalIterator::operator++): Likewise. (BidirectionalIterator::operator--): Likewise.
2025-05-02libstdc++: Make __gnu_test::default_init_allocator usable in constexprJonathan Wakely1-7/+10
If we make this test allocator usable in constant expressions then we'll get an error if the 'state' data member isn't initialized. This makes it a more reliable check that allocators are correctly value-initialized when they're required to be. libstdc++-v3/ChangeLog: * testsuite/23_containers/vector/allocator/default_init.cc: Add a check using constant evaluation. * testsuite/23_containers/vector/bool/allocator/default_init.cc: Likewise. * testsuite/util/testsuite_allocator.h (default_init_allocator): Make all member functions and equality ops constexpr.
2025-04-24libstdc++: Add std::deque<>::shrink_to_fit testFrançois Dumont1-0/+8
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-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 Dumont1-39/+113
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-16libstdc++: Implement formatters for pair and tuple [PR109162]Tomasz Kamiński1-0/+3
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++: 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-03-13libstdc++: Add P1206R7 from_range members to container adaptors [PR111055]Jonathan Wakely1-0/+11
This is another piece of P1206R7, adding new members to std::stack, std::queue, and std::priority_queue. PR libstdc++/111055 libstdc++-v3/ChangeLog: * include/bits/stl_queue.h (queue(from_range_t, _Rg&&)) (queue(from_range_t, _Rg&&, const _Alloc&), push_range): Define. (priority_queue(from_range_t, R&&, const Compare&)) (push_range): Define. * include/bits/stl_stack.h (stack(from_range_t, R&&)) (stack(from_range_t, R&&, const Alloc&), push_range): Define. * testsuite/util/testsuite_iterators.h (test_range_nocopy): Define. * testsuite/23_containers/priority_queue/cons_from_range.cc: New test. * testsuite/23_containers/priority_queue/members/push_range.cc: New test. * testsuite/23_containers/queue/cons_from_range.cc: New test. * testsuite/23_containers/queue/members/push_range.cc: New test. * testsuite/23_containers/stack/cons_from_range.cc: New test. * testsuite/23_containers/stack/members/push_range.cc: New test. Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-02-05libstdc++: Fix gnu.ver CXXABI_1.3.16 for Solaris [PR118701]Rainer Orth1-0/+2
This patch commit c6977f765838a5ca8d321d916221a7368622bdd9 Author: Andreas Schwab <schwab@suse.de> Date: Tue Jan 21 23:50:15 2025 +0100 libstdc++: correct symbol version of typeinfo for bfloat16_t on RISC-V broke the libstdc++-abi/abi_check test on Solaris: the log shows 1 incompatible symbols 0 Argument "{CXXABI_1.3.15}" isn't numeric in numeric eq (==) at /vol/gcc/src/hg/master/local/libstdc++-v3/scripts/extract_symvers.pl line 129. version status: incompatible type: uncategorized status: added The problem has two parts: * The patch above introduced a new version in libstdc++.so, CXXABI_1.3.16, which everywhere but on RISC-V contains no symbols (a weak version). This is the first time this happened in libstdc++. * Solaris uses scripts/extract_symvers.pl to determine the version info. The script currently chokes on the pvs output for weak versions: libstdc++.so.6.0.34 - CXXABI_1.3.16 [WEAK]: {CXXABI_1.3.15}; instead of libstdc++.so.6.0.34 - CXXABI_1.3.16: {CXXABI_1.3.15}; While this patch hardens the script to cope with weak versions, there's no reason to introduce them in the first place. So the new version is only created on __riscv. Tested on i386-pc-solaris2.11, sparc-sun-solaris2.11, and x86_64-pc-linux-gnu. 2025-01-29 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> Jonathan Wakely <jwakely@redhat.com> libstdc++-v3: PR libstdc++/118701 * config/abi/pre/gnu.ver (CXXABI_1.3.16): Move __riscv guard around version. * scripts/extract_symvers.pl: Allow for weak versions. * testsuite/util/testsuite_abi.cc (check_version): Wrap CXXABI_1.3.16 in __riscv.
2025-01-27libstdc++: correct symbol version of typeinfo for bfloat16_t on RISC-VAndreas Schwab1-0/+1
RISC-V only gained support for bfloat16_t after gcc 14. Passes libstdc++/check_abi on {x86_64,aarch64,ppc64le,riscv64,s390x}-suse-linux. PR libstdc++/118563 * testsuite/util/testsuite_abi.cc (check_version): Add CXXABI_1.3.16. * config/abi/pre/gnu.ver (CXXABI_1.3.14) [__riscv]: Exclude typeinfo for bfloat16_t. (CXXABI_1.3.16) [__riscv]: Add it here.
2025-01-02Update copyright years.Jakub Jelinek120-120/+120
2024-11-28libstdc++: Deprecate std::rel_ops namespace for C++20Jonathan Wakely1-0/+9
This is deprecated in the C++20 standard and will be removed at some point. libstdc++-v3/ChangeLog: * include/bits/stl_relops.h (rel_ops): Add deprecated attribute. * testsuite/20_util/headers/utility/using_namespace_std_rel_ops.cc: Add dg-warning for -Wdeprecated warnings. * testsuite/20_util/rel_ops.cc: Likewise. * testsuite/util/testsuite_containers.h: Disable -Wdeprecated warnings when using rel_ops.
2024-11-13libstdc++: Fix calculation of system time in performance testsJonathan Wakely1-1/+4
The system_time() function used the wrong element of the splits array. Also add a comment about the units for time measurements. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_performance.h (time_counter): Add comment about times. (time_counter::system_time): Use correct split value.
2024-11-13libstdc++: Use __is_single_threaded() in performance testsJonathan Wakely1-6/+3
With recent glibc releases the __gthread_active_p() function is always true, so we always append "-thread" onto performance benchmark names. Use the __gnu_cxx::__is_single_threaded() function instead. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_performance.h: Use __gnu_cxx::__is_single_threaded instead of __gthread_active_p().
2024-11-13libstdc++: Stop using std::unary_function in perf testsJonathan Wakely1-1/+4
This fixes some -Wdeprecated-declarations warnings. libstdc++-v3/ChangeLog: * testsuite/performance/ext/pb_ds/hash_int_erase_mem.cc: Replace std::unary_function with result_type and argument_type typedefs. * testsuite/util/performance/assoc/multimap_common_type.hpp: Likewise.
2024-10-27libstdc++: Add P1206R7 from_range members to std::vector [PR111055]Jonathan Wakely1-0/+20
This is another piece of P1206R7, adding new members to std::vector and std::vector<bool>. The __uninitialized_copy_a extension needs to be enhanced to support passing non-common ranges (i.e. a sentinel that is a different type from the iterator) and move-only input iterators. libstdc++-v3/ChangeLog: PR libstdc++/111055 * include/bits/ranges_base.h (__container_compatible_range): New concept. * include/bits/stl_bvector.h (vector(from_range, R&&, const Alloc&)) (assign_range, insert_range, append_range): Define. * include/bits/stl_uninitialized.h (__do_uninit_copy): Support non-common ranges. (__uninitialized_copy_a): Likewise. * include/bits/stl_vector.h (_Vector_base::_M_append_range_to): New function. (_Vector_base::_M_append_range): Likewise. (vector(from_range, R&&, const Alloc&), assign_range): Define. (append_range): Define. (insert_range): Declare. * include/debug/vector (vector(from_range, R&&, const Alloc&)) (assign_range, insert_range, append_range): Define. * include/bits/vector.tcc (insert_range): Define. * testsuite/util/testsuite_iterators.h (input_iterator_wrapper_rval): New class template. * testsuite/23_containers/vector/bool/cons/from_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc: New test. * testsuite/23_containers/vector/bool/modifiers/insert/insert_range.cc: New test. * testsuite/23_containers/vector/cons/from_range.cc: New test. * testsuite/23_containers/vector/modifiers/append_range.cc: New test. * testsuite/23_containers/vector/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/vector/modifiers/insert/insert_range.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-07-31libstdc++: Handle encodings in localized chrono formatting [PR109162]Jonathan Wakely1-0/+1
This implements the C++23 paper P2419R2 (Clarify handling of encodings in localized formatting of chrono types). The requirement is that when the literal encoding is "a Unicode encoding form" and the formatting locale uses a different encoding, any locale-specific strings such as "août" for std::chrono::August should be converted to the literal encoding. Using the recently-added std::locale::encoding() function we can check the locale's encoding and then use iconv if a conversion is needed. Because nl_langinfo_l and iconv_open both allocate memory, a naive implementation would perform multiple allocations and deallocations for every snippet of locale-specific text that needs to be converted to UTF-8. To avoid that, a new internal locale::facet is defined to store the text_encoding and an iconv_t descriptor, which are then cached in the formatting locale. This requires access to the internals of a std::locale object in src/c++20/format.cc, so that new file needs to be compiled with -fno-access-control, as well as -std=gnu++26 in order to use std::text_encoding. Because the new std::text_encoding and std::locale::encoding() symbols are only in the libstdc++exp.a archive, we need to include src/c++26/text_encoding.cc in the main library, but not export its symbols yet. This means they can be used by the two new functions which are exported from the main library. The encoding conversions are done for C++20, treating it as a DR that resolves LWG 3656. With this change we can increase the value of the __cpp_lib_format macro for C++23. The value should be 202207 for P2419R2, but we already implement P2510R3 (Formatting pointers) so can use the value 202304. libstdc++-v3/ChangeLog: PR libstdc++/109162 * acinclude.m4 (libtool_VERSION): Update to 6:34:0. * config/abi/pre/gnu.ver: Disambiguate old patters. Add new GLIBCXX_3.4.34 symbol version and new exports. * configure: Regenerate. * include/bits/chrono_io.h (_ChronoSpec::_M_locale_specific): Add new accessor functions to use a reserved bit in _Spec. (__formatter_chrono::_M_parse): Use _M_locale_specific(true) when chrono-specs contains locale-dependent conversion specifiers. (__formatter_chrono::_M_format): Open iconv descriptor if conversion to UTF-8 will be needed. (__formatter_chrono::_M_write): New function to write a localized string with possible character conversion. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B) (__formatter_chrono::_M_p, __formatter_chrono::_M_r) (__formatter_chrono::_M_x, __formatter_chrono::_M_X) (__formatter_chrono::_M_locale_fmt): Use _M_write. * include/bits/version.def (format): Update value. * include/bits/version.h: Regenerate. * include/std/format (_GLIBCXX_P2518R3): Check feature test macro instead of __cplusplus. (basic_format_context): Declare __formatter_chrono as friend. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/format.cc: New file. * testsuite/std/time/format_localized.cc: New test. * testsuite/util/testsuite_abi.cc: Add new symbol version.
2024-07-10libstdc++: ranges::find needs explicit conversion to size_t [PR115799]Jonathan Wakely1-10/+32
For an integer-class type we need to use an explicit conversion to size_t. libstdc++-v3/ChangeLog: PR libstdc++/115799 * include/bits/ranges_util.h (__find_fn): Make conversion from difference type ti size_t explicit. * testsuite/25_algorithms/find/bytes.cc: Check ranges::find with __gnu_test::test_contiguous_range. * testsuite/std/ranges/range.cc: Adjust expected difference_type for __gnu_test::test_contiguous_range. * testsuite/util/testsuite_iterators.h (contiguous_iterator_wrapper): Use __max_diff_type as difference type. (test_range::sentinel, test_sized_range_sized_sent::sentinel): Ensure that operator- returns difference_type.
2024-06-21libstdc++: Initialize base in test allocator's constructorJonathan Wakely1-1/+1
This fixes a warning from one of the test allocators: warning: base class 'class std::allocator<__gnu_test::copy_tracker>' should be explicitly initialized in the copy constructor [-Wextra] libstdc++-v3/ChangeLog: * testsuite/util/testsuite_allocator.h (tracker_allocator): Initialize base class in copy constructor.
2024-05-07libstdc++: Update ABI test to disallow adding to released symbol versionsJonathan Wakely1-2/+2
If we update the list of "active" symbols versions now, rather than when adding a new symbol version, we will notice if new symbols get added to the wrong version (as in PR 114692). libstdc++-v3/ChangeLog: * testsuite/util/testsuite_abi.cc: Update latest versions to new versions that should be used in future.
2024-04-11libstdc++: Export std::__basic_file::native_handle as GLIBCXX_3.4.33 [PR114692]Jonathan Wakely1-1/+2
I added this new symbol in the wrong version. GLIBCXX_3.4.32 was already used for the GCC 13.2.0 release, so the new symbol should have been in a new GLIBCXX_3.4.33 version. Additionally, the pattern doesn't need to use [cw] because we only ever use __basic_file<char>, even for std::basic_filebuf<wchar_t>. libstdc++-v3/ChangeLog: PR libstdc++/114692 * config/abi/pre/gnu.ver (GLIBCXX_3.4.32): Move new exports for __basic_file::native_handle to ... (GLIBCXX_3.4.33): ... here. Adjust to not match wchar_t specialization, which isn't used. * testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.33 and update latest version check.
2024-03-19libstdc++: Fix typos in MemoryChecker assertion messages in PSTL testsJonathan Wakely1-7/+7
This has been reported upstream. libstdc++-v3/ChangeLog: * testsuite/util/pstl/test_utils.h: Fix typos in comments.
2024-03-07libstdc++: Replace unnecessary uses of built-ins in testsuiteJonathan Wakely1-6/+5
I don't see why we should rely on __builtin_memset etc. in tests. We can just include <cstring> and use the public API. libstdc++-v3/ChangeLog: * testsuite/23_containers/deque/allocator/default_init.cc: Use std::memset instead of __builtin_memset. * testsuite/23_containers/forward_list/allocator/default_init.cc: Likewise. * testsuite/23_containers/list/allocator/default_init.cc: Likewise. * testsuite/23_containers/map/allocator/default_init.cc: Likewise. * testsuite/23_containers/set/allocator/default_init.cc: Likewise. * testsuite/23_containers/unordered_map/allocator/default_init.cc: Likewise. * testsuite/23_containers/unordered_set/allocator/default_init.cc: Likewise. * testsuite/23_containers/vector/allocator/default_init.cc: Likewise. * testsuite/23_containers/vector/bool/allocator/default_init.cc: Likewise. * testsuite/29_atomics/atomic/compare_exchange_padding.cc: Likewise. * testsuite/util/atomic/wait_notify_util.h: Likewise.
2024-02-02libstdc++: Avoid reusing moved-from iterators in PSTL tests [PR90276]Jonathan Wakely1-5/+5
The reverse_invoker utility for PSTL tests uses forwarding references for all parameters, but some of those parameters get forwarded to move constructors which then leave the objects in a moved-from state. When the parameters are forwarded a second time that results in making new copies of moved-from iterators. For libstdc++ debug mode iterators, the moved-from state is singular, which means copying them will abort at runtime. The fix is to make copies of iterator arguments instead of forwarding them. The callers of reverse_invoker::operator() also forward the iterators multiple times, but that's OK because reverse_invoker accepts them by forwarding reference but then breaks the chain of forwarding and copies them as lvalues. libstdc++-v3/ChangeLog: PR libstdc++/90276 * testsuite/util/pstl/test_utils.h (reverse_invoker): Do not use perfect forwarding for iterator arguments.
2024-01-03Update copyright years.Jakub Jelinek120-120/+120
2023-11-23libstdc++: Fix access error in __gnu_test::uneq_allocatorJonathan Wakely1-1/+1
The operator== function is only a friend of the LHS argument, so cannot access the private member of the RHS argument. Use the public accessor instead. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_allocator.h (uneq_allocator): Fix equality operator for heterogeneous comparisons.
2023-09-07libstdc++: Avoid -Wunused-parameter warning in testsuite helperJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * testsuite/util/testsuite_iterators.h (is_customization_point_object): Remove parameter name.
2023-08-23libstdc++: Fix tests relying on operator new/delete overloadFrançois Dumont1-0/+20
Fix tests that are checking for an expected allocation plan. They are failing if an allocation is taking place outside the test main. libstdc++-v3/ChangeLog * testsuite/util/replacement_memory_operators.h (counter::scope): New, capture and reset counter count at construction and restore it at destruction. (counter::check_new): Add scope instantiation. * testsuite/23_containers/unordered_map/96088.cc (main): Add counter::scope instantiation. * testsuite/23_containers/unordered_multimap/96088.cc (main): Likewise. * testsuite/23_containers/unordered_multiset/96088.cc (main): Likewise. * testsuite/23_containers/unordered_set/96088.cc (main): Likewise. * testsuite/ext/malloc_allocator/deallocate_local.cc (main): Likewise. * testsuite/ext/new_allocator/deallocate_local.cc (main): Likewise. * testsuite/ext/throw_allocator/deallocate_local.cc (main): Likewise. * testsuite/ext/pool_allocator/allocate_chunk.cc (started): New global. (operator new(size_t)): Check started. (main): Set/Unset started. * testsuite/17_intro/no_library_allocation.cc: New test case.
2023-06-26libstdc++: Synchronize PSTL with upstreamThomas Rodgers1-7/+87
This patch rebases the C++17 parallel algorithms implementation (pstl) against the current upstream version, commit 843c12d6a. This version does not currently include the recently added OpenMP backend, that will be considered for a future version. libstdc++-v3/ChangeLog: * include/pstl/algorithm_fwd.h: Synchronize with upstream. * include/pstl/algorithm_impl.h: Likewise. * include/pstl/execution_defs.h: Likewise. * include/pstl/execution_impl.h: Likewise. * include/pstl/glue_algorithm_impl.h: Likewise. * include/pstl/glue_execution_defs.h: Likewise. * include/pstl/glue_memory_impl.h: Likewise. * include/pstl/glue_numeric_impl.h: Likewise. * include/pstl/memory_impl.h: Likewise. * include/pstl/numeric_fwd.h: Likewise. * include/pstl/numeric_impl.h: Likewise. * include/pstl/parallel_backend.h: Likewise. * include/pstl/parallel_backend_serial.h: Likewise. * include/pstl/parallel_backend_tbb.h: Likewise. * include/pstl/parallel_impl.h: Likewise. * include/pstl/pstl_config.h: Likewise. * include/pstl/unseq_backend_simd.h: Likewise. * include/pstl/utils.h: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_fill_destroy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Likewise. * testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/fill.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/generate.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/remove_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/swap_ranges.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/transform_binary.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/transform_unary.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/adjacent_find.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/for_each.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/mismatch.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/includes.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/is_sorted.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/minmax_element.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/sort.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc: Likewise. * testsuite/util/pstl/test_utils.h: Likewise.
2023-06-07libstdc++: Restore accidentally removed version in abi-checkJonathan Wakely1-0/+1
In r14-1583-g192665feef7129 I meant to add CXXABI_1.3.15 but instead I replaced CXXABI_1.3.14 with it. This restores the CXXABI_1.3.14 version. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_abi.cc (check_version): Re-add CXXABI_1.3.14.
2023-06-06libstdc++: Update list of known symbol versions for abi-checkJonathan Wakely1-5/+2
Add the recently added CXXABI_1.3.15 version. Also remove two "frozen" versions from the latestp list, as no more symbols should be added to those now. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_abi.cc (check_version): Add CXXABI_1.3.15 symver and make it the latestp. Remove GLIBCXX_IEEE128_3.4.31 and GLIBCXX_LDBL_3.4.31 from latestp.
2023-05-31libstdc++: Stop using _GLIBCXX_USE_C99_MATH_TR1 in <cmath>Jonathan Wakely1-3/+3
Similar to the three commits r14-908, r14-909 and r14-910, the _GLIBCXX_USE_C99_MATH_TR1 macro is misleading when it is also used for <cmath>, not only for <tr1/cmath> headers. It is also wrong, because the configure checks for TR1 use -std=c++98 and a target might define the C99 features for C++11 but not for C++98. Add separate configure checks for the <math.h> functions using -std=c++11 for the checks. Use the new macro defined by those checks in the C++11-specific parts of <cmath>, and in <complex>, <random> etc. The check that defines _GLIBCXX_NO_C99_ROUNDING_FUNCS is only needed for the C++11 <cmath> checks, so remove that from GLIBCXX_CHECK_C99_TR1 and only do it for GLIBCXX_ENABLE_C99. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_C99): Add checks for C99 math functions and define _GLIBCXX_USE_C99_MATH_FUNCS. Move checks for C99 rounding functions to here. (GLIBCXX_CHECK_C99_TR1): Remove checks for C99 rounding functions from here. * config.h.in: Regenerate. * configure: Regenerate. * include/bits/random.h: Use _GLIBCXX_USE_C99_MATH_FUNCS instead of _GLIBCXX_USE_C99_MATH_TR1. * include/bits/random.tcc: Likewise. * include/c_compatibility/math.h: Likewise. * include/c_global/cmath: Likewise. * include/ext/random: Likewise. * include/ext/random.tcc: Likewise. * include/std/complex: Likewise. * testsuite/20_util/from_chars/4.cc: Likewise. * testsuite/20_util/from_chars/8.cc: Likewise. * testsuite/26_numerics/complex/proj.cc: Likewise. * testsuite/26_numerics/headers/cmath/60401.cc: Likewise. * testsuite/26_numerics/headers/cmath/types_std_c++0x.cc: Likewise. * testsuite/lib/libstdc++.exp (check_v3_target_cstdint): Likewise. * testsuite/util/testsuite_random.h: Likewise.
2023-05-26libstdc++: Add relational operators to __gnu_test::PointerBaseJonathan Wakely1-0/+9
The Cpp17Allocator requirements say that an allocator's pointer and const_pointer types must meet the Cpp17RandomAccessIterator requirements. That means our PointerBase helper for defining fancy pointer types should support the full set of relational operators. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_allocator.h (PointerBase): Add relational operators.
2023-04-28libstdc++: Another attempt to ensure g++ 13+ compiled programs enforce gcc ↵Jakub Jelinek1-1/+2
13.2+ libstdc++.so.6 [PR108969] GCC used to emit an instance of an empty ios_base::Init class in every TU which included <iostream> to ensure it is std::cout etc. is initialized, but thanks to Patrick work on some targets (which have init_priority attribute support) it is now initialized only inside of libstdc++.so.6/libstdc++.a. This causes a problem if people do something that has never been supported, try to run GCC 13 compiled C++ code against GCC 12 or earlier libstdc++.so.6 - std::cout etc. are then never initialized because code including <iostream> expects the library to initialize it and the library expects code including <iostream> to do that. The following patch is second attempt to make this work cheaply as the earlier attempt of aliasing the std::cout etc. symbols with another symbol version didn't work out due to copy relocation breaking the aliases appart. The patch forces just a _ZSt21ios_base_library_initv undefined symbol into all *.o files which include <iostream> and while there is no runtime relocation against that, it seems to enforce the right version of libstdc++.so.6. /home/jakub/src/gcc/obj08i/usr/local/ is the install directory of trunk patched with this patch, /home/jakub/src/gcc/obj06/ is builddir of trunk without this patch, system g++ is GCC 12.1.1. $ cat /tmp/hw.C #include <iostream> int main () { std::cout << "Hello, world!" << std::endl; } $ cd /home/jakub/src/gcc/obj08i/usr/local/bin $ ./g++ -o /tmp/hw /tmp/hw.C $ readelf -Wa /tmp/hw 2>/dev/null | grep initv 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZSt21ios_base_library_initv@GLIBCXX_3.4.32 (4) 71: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZSt21ios_base_library_initv@GLIBCXX_3.4.32 $ /tmp/hw /tmp/hw: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /tmp/hw) $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj08i/usr/local/lib64/ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/ /tmp/hw /tmp/hw: /home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /tmp/hw) $ g++ -o /tmp/hw /tmp/hw.C $ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj08i/usr/local/lib64/ /tmp/hw Hello, world! On sparc-sun-solaris2.11 one I've actually checked a version which had defined(_GLIBCXX_SYMVER_SUN) next to defined(_GLIBCXX_SYMVER_GNU), but init_priority attribute doesn't seem to be supported there and so I couldn't actually test how this works there. Using gas and Sun ld, Rainer, does one need to use gas + gld for init_priority or something else? 2023-04-28 Jakub Jelinek <jakub@redhat.com> PR libstdc++/108969 * config/abi/pre/gnu.ver (GLIBCXX_3.4.32): Export _ZSt21ios_base_library_initv. * testsuite/util/testsuite_abi.cc (check_version): Add GLIBCXX_3.4.32 symver and make it the latestp. * src/c++98/ios_init.cc (ios_base_library_init): New alias. * acinclude.m4 (libtool_VERSION): Change to 6:32:0. * include/std/iostream: If init_priority attribute is supported and _GLIBCXX_SYMVER_GNU, force undefined _ZSt21ios_base_library_initv symbol into the object. * configure: Regenerated.
2023-04-27libstdc++: Make std::random_device throw std::system_error [PR105081]Jonathan Wakely1-1/+2
This changes std::random_device constructors to throw std::system_error (with EINVAL as the error code) when the constructor argument is invalid. We can also throw std::system_error when read(2) fails so that the exception includes the additional information provided by errno. As noted in the PR, this is consistent with libc++, and doesn't break any existing code which catches std::runtime_error, because those handlers will still catch std::system_error. libstdc++-v3/ChangeLog: PR libstdc++/105081 * src/c++11/random.cc (__throw_syserr): New function. (random_device::_M_init, random_device::_M_init_pretr1): Use new function for bad tokens. (random_device::_M_getval): Use new function for read errors. * testsuite/util/testsuite_random.h (random_device_available): Change catch handler to use std::system_error.
2023-01-16Update copyright years.Jakub Jelinek120-120/+120
2023-01-15libstdc++: [_GLIBCXX_DEBUG] Complete deadlock fix on safe iterators [PR108288]François Dumont1-0/+34
Complete fix on all _Safe_iterator post-increment and post-decrement implementations and on _Safe_local_iterator. libstdc++-v3/ChangeLog: PR libstdc++/108288 * include/debug/safe_iterator.h (_Safe_iterator<>::operator++(int)): Extend deadlock fix to other iterator category. (_Safe_iterator<>::operator--(int)): Likewise. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>::operator++(int)): Fix deadlock. * testsuite/util/debug/unordered_checks.h (invalid_local_iterator_pre_increment): New. (invalid_local_iterator_post_increment): New. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_post_increment_neg.cc: New test. * testsuite/23_containers/unordered_map/debug/invalid_local_iterator_pre_increment_neg.cc: New test.
2023-01-13libstdc++: Fix exports for IEEE128 versions of __try_use_facet [PR108327]Jonathan Wakely1-3/+6
The new symbols need to be exported, as well as some of the std::locale::facet::id globals, which are not new but were presumably not needed by any inline functions before now. libstdc++-v3/ChangeLog: PR libstdc++/108327 * config/os/gnu-linux/ldbl-extra.ver (GLIBCXX_LDBL_3.4.31): Export __try_use_facet specializations for facets in namespace __gnu_cxx_ldbl128. * config/os/gnu-linux/ldbl-ieee128-extra.ver (GLIBCXX_IEEE128_3.4.31): Likewise for facets in namespace __gnu_cxx_ieee128. * testsuite/util/testsuite_abi.cc: Add to lists of known and latest versions.
2022-12-15c++, libstdc++: Add typeinfo for _Float{16,32,64,128,32x,64x} and __bf16 ↵Jakub Jelinek1-1/+2
types [PR108075] The following patch adds typeinfos for the extended floating point types and _Float{32,64}x. 2022-12-15 Jakub Jelinek <jakub@redhat.com> PR libstdc++/108075 gcc/cp/ * rtti.cc (emit_support_tinfos): Add pointers to {bfloat16,float{16,32,64,128,32x,64x,128x}}_type_node to fundamentals array. gcc/testsuite/ * g++.dg/cpp23/ext-floating13.C: New test. libstdc++-v3/ * config/abi/pre/gnu.ver (CXXABI_1.3.14): Export _ZTIDF[0-9]*[_bx], _ZTIPDF[0-9]*[_bx] and _ZTIPKDF[0-9]*[_bx]. * testsuite/util/testsuite_abi.cc (check_version): Handle CXXABI_1.3.14.
2022-10-12libstdc++: Add __gnu_debug::basic_string<>::compare overloadsFrançois Dumont1-1/+1
Rather than adding those implementations we are adding a: using _Base::compare; so that any compare method not implemented at __gnu_debug::basic_string level are injected from the base class. Also review how __gnu_debug::basic_string is tested. Now require to define _GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'. libstdc++-v3/ChangeLog * include/debug/string: Add using _Base::compare. (__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)): Remove. (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&, size_type, size_type)): Remove. * testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include <debug/string>. * testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h and use __gnu_test::string. * testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc: Include testsuite_string.h and use __gnu_test::wstring. * testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise. * testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise.
2022-09-12libstdc++: Outline the overlapping case of string _M_replace into a separate ↵Jakub Jelinek1-1/+2
function [PR105329] The following patch is partially a workaround for bogus warnings when the compiler isn't able to fold _M_disjunct call into constant false, but also an optimization attempt - assuming _M_disjunct (__s) is rare, the patch should shrink code size for the common case and use library or for non-standard instantiations an out of line function to handle the rare case. 2022-09-12 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/105329 * acinclude.m4 (libtool_VERSION): Change to 6:31:0. * config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Don't export std::basic_string methods with name length of 15. (GLIBCXX_3.4.31): Export std::basic_string::_M_replace_cold. * testsuite/util/testsuite_abi.cc (check_version): Handle GLIBCXX_3.4.31. * include/bits/basic_string.h (std::basic_string::_M_replace_cold): Declare. * include/bits/basic_string.tcc (std::basic_string::_M_replace_cold): Define and export even for C++20. (std::basic_string::_M_replace): Use __builtin_expect, outline the overlapping case to _M_replace_cold. * configure: Regenerated.
2022-09-08libstdc++: mallinfo deprecated, use mallinfo2 when glibc => 2.33François Dumont1-33/+30
glibc mallinfo is now deprecated resulting in make check-performance failure. When glibc => 2.33 prefer mallinfo2. libstdc++-v3/ChangeLog: * testsuite/util/testsuite_performance.h (__gnu_test::MallocInfo): New. (__gnu_test::malloc_info): New, replace mallinfo on current platform supporting it and use mallinfo2 when glibc >= 2.33.