aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/debug
AgeCommit message (Collapse)AuthorFilesLines
7 dayslibstdc++: provide debug impl of P2697 ctor [PR119742]Nathan Myers1-0/+11
This adds the new bitset constructor from string_view defined in P2697 to the debug version of the type. libstdc++-v3/Changelog: PR libstdc++/119742 * include/debug/bitset: Add new ctor.
2025-07-08libstdc++: Fix _GLIBCXX_DEBUG std::forward_list build regressionJonathan Wakely1-4/+4
Commit 2fd6f42c17a8040dbd3460ca34d93695dacf8575 broke _GLIBCXX_DEBUG std::forward_list implementation. libstdc++-v3/ChangeLog: * include/debug/forward_list (_Safe_forward_list<>::_M_swap): Adapt to _M_this() signature change.
2025-07-08libstdc++: Make debug iterator pointer sequence const [PR116369]François Dumont14-156/+257
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-05-06libstdc++: Fix -Wmismatched-tags warnings for _Safe_iterator [PR120112]Jonathan Wakely1-1/+1
This causes an ICE as shown in the PR, but it should be fixed in the library code anyway. libstdc++-v3/ChangeLog: PR c++/120112 * include/bits/ptr_traits.h (_Safe_iterator_base): Use class keyword in class-head of declaration. * include/debug/debug.h (_Safe_iterator): Likewise.
2025-04-28libstdc++: Implement missing allocator-aware constructors for unordered ↵Tomasz Kamiński2-0/+76
containers. This patch implements remainder of LWG2713 (after r15-8293-g64f5c854597759) by adding missing allocator aware version of unordered associative containers constructors accepting pair of iterators or initializer_list, and corresponding deduction guides. libstdc++-v3/ChangeLog: * include/bits/unordered_map.h (unordered_map): Define constructors accepting: (_InputIterator, _InputIterator, const allocator_type&), (initializer_list<value_type>, const allocator_type&), (unordered_multimap): Likewise. * include/debug/unordered_map (unordered_map): Likewise. (unordered_multimap): Likewise. * include/bits/unordered_set.h (unordered_set): Define constructors and deduction guide accepting: (_InputIterator, _InputIterator, const allocator_type&), (initializer_list<value_type>, const allocator_type&), (unordered_multiset): Likewise. * include/debug/unordered_set (unordered_set): Likewise. (unordered_multiset): Likewise. * testsuite/23_containers/unordered_map/cons/66055.cc: New tests. * testsuite/23_containers/unordered_map/cons/deduction.cc: New tests. * testsuite/23_containers/unordered_multimap/cons/66055.cc: New tests. * testsuite/23_containers/unordered_multimap/cons/deduction.cc: New tests. * testsuite/23_containers/unordered_multiset/cons/66055.cc: New tests. * testsuite/23_containers/unordered_multiset/cons/deduction.cc: New tests. * testsuite/23_containers/unordered_set/cons/66055.cc: New tests. * testsuite/23_containers/unordered_set/cons/deduction.cc: New tests. 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ński10-33/+33
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-03-26libstdc++: Add P1206R7 range operations to std::deque [PR111055]Tomasz Kamiński1-0/+51
This is another piece of P1206R7, adding from_range constructor, append_range, prepend_range, insert_range, and assign_range members to std::deque. For append_front of input non-sized range, we are emplacing element at the front and then reverse inserted elements. This does not existing elements, and properly handle aliasing ranges. For insert_range, the handling of insertion in the middle of input-only ranges that are sized could be optimized, we still insert nodes one-by-one in such case. For forward and stronger ranges, we reduce them to common_range case, by computing the iterator when computing the distance. This is slightly suboptimal, as it require range to be iterated for non-common forward ranges that are sized, but reduces number of instantiations. This patch extract _M_range_prepend, _M_range_append helper functions that accepts (iterator, sentinel) pair. This all used in all standard modes. PR libstdc++/111055 libstdc++-v3/ChangeLog: * include/bits/deque.tcc (deque::prepend_range, deque::append_range) (deque::insert_range, __advance_dist): Define. (deque::_M_range_prepend, deque::_M_range_append): Extract from _M_range_insert_aux for _ForwardIterator(s). * include/bits/stl_deque.h (deque::assign_range): Define. (deque::prepend_range, deque::append_range, deque::insert_range): Declare. (deque(from_range_t, _Rg&&, const allocator_type&)): Define constructor and deduction guide. * include/debug/deque (deque::prepend_range, deque::append_range) (deque::assign_range): Define. (deque(from_range_t, _Rg&&, const allocator_type&)): Define constructor and deduction guide. * testsuite/23_containers/deque/cons/from_range.cc: New test. * testsuite/23_containers/deque/modifiers/append_range.cc: New test. * testsuite/23_containers/deque/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/deque/modifiers/prepend_range.cc: New test. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-25libstdc++: Adjust how __gnu_debug::vector detects invalidationJonathan Wakely1-8/+6
The new C++23 member functions assign_range, insert_range and append_range were checking whether the begin() iterator changed after calling the base class member. That works, but is technically undefined when the original iterator has been invalidated by a change in capacity. We can just check the capacity directly, because reallocation only occurs if a change in capacity is required. N.B. we can't use data() either because std::vector<bool> doesn't have it. libstdc++-v3/ChangeLog: * include/debug/vector (vector::assign_range): Use change in capacity to detect reallocation. (vector::insert_range, vector::append_range): Likewise. Remove unused variables. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-20libstdc++: Add from_range_t constructors to debug unordered containersTomasz Kamiński2-0/+272
libstdc++-v3/ChangeLog: * include/debug/unordered_map (unordered_map): Add from_range constructors and deduction guides. (unordered_multimap): Likewise. * include/debug/unordered_set (unordered_set): Add from_range constructors and deduction guides. (unordered_multiset): Likewise. Reviewed-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-20libstdc++: Add from_range_t constructors to debug ordered containersJonathan Wakely4-1/+133
libstdc++-v3/ChangeLog: * include/debug/map.h (map): Add from_range constructors and deduction guides. * include/debug/multimap.h (multimap): Likewise. * include/debug/multiset.h (multiset): Likewise. * include/debug/set.h (set): Likewise. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-01-02Update copyright years.Jakub Jelinek33-33/+33
2024-12-17libstdc++: Fix -Wparentheses warning in Debug Mode macroJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * include/debug/safe_local_iterator.h (_GLIBCXX_DEBUG_VERIFY_OPERANDS): Add parentheses to avoid -Wparentheses warning.
2024-12-11libstdc++: Disable __gnu_debug::__is_singular(T*) in constexpr [PR109517]Jonathan Wakely1-0/+5
Because of PR c++/85944 we have several bugs where _GLIBCXX_DEBUG causes errors for constexpr code. Although Bug 117966 could be fixed by avoiding redundant debug checks in std::span, and Bug 106212 could be fixed by avoiding redundant debug checks in std::array, there are many more cases where similar __glibcxx_requires_valid_range checks fail to compile and removing the checks everywhere isn't desirable. This just disables the __gnu_debug::__check_singular(T*) check during constant evaluation. Attempting to dereference a null pointer will certainly fail during constant evaluation (if it doesn't fail then it's a compiler bug and not the library's problem). Disabling this check during constant evaluation shouldn't do any harm. libstdc++-v3/ChangeLog: PR libstdc++/109517 PR libstdc++/109976 * include/debug/helper_functions.h (__valid_range_aux): Treat all input iterator ranges as valid during constant evaluation.
2024-12-09libstdc++: Fix debug containers for constant evaluation [PR117962]Jonathan Wakely1-4/+7
Using a stateful allocator with std::vector would fail in Debug Mode, because the allocator-extended move constructor tries to swap all the attached safe iterators, but that uses a non-inline function which isn't constexpr. We don't actually need to swap any iterators in constant expressions, because we never attach them to the container in the first place. This bug went unnoticed because the tests for constexpr std::vector were using a stateful allocator with a std::allocator base class, but were failing to override the inherited is_always_equal trait from std::allocator. That meant that the allocators took the always-equal code paths, and didn't try to use the buggy constructor. In C++26 the std::allocator::is_always_equal trait goes away, and so the tests changed behaviour, revealing the bug. libstdc++-v3/ChangeLog: PR libstdc++/117962 * include/debug/safe_container.h: Make allocator-extended move constructor a no-op during constant evaluation.
2024-11-27libstdc++: Add cold attribute to assertion failure functions [PR117650]Jonathan Wakely1-1/+1
This helps the compiler to split the cold path into a separate clone, so that the hot path is a smaller function that uses less icache, and the cold path is only fetched into the icache if actually executed. libstdc++-v3/ChangeLog: PR libstdc++/117650 * include/bits/c++config (__glibcxx_assert_fail): Add cold attribute. * include/debug/formatter.h (_Error_formatter::_M_error): Likewise.
2024-11-08libstdc++: Do not define _Insert_base::try_emplace before C++17Jonathan Wakely2-2/+2
This is not a reserved name in C++11 and C++14, so must not be defined. Also use the appropriate feature test macros for the try_emplace members of the Debug Mode maps. libstdc++-v3/ChangeLog: * include/bits/hashtable_policy.h (_Insert_base::try_emplace): Do not define for C++11 and C++14. * include/debug/map.h (try_emplace): Use feature test macro. * include/debug/unordered_map (try_emplace): Likewise. * testsuite/17_intro/names.cc: Define try_emplace before C++17.
2024-11-01libstdc++: Add P1206R7 from_range members to std::list and std::forward_list ↵Jonathan Wakely2-0/+119
[PR111055] This is another piece of P1206R7, adding new members to std::list and std::forward_list. libstdc++-v3/ChangeLog: PR libstdc++/111055 * include/bits/forward_list.h (forward_list(from_range, R&&, const Alloc&), assign_range) (prepend_range, insert_range_after): Define. * include/bits/stl_list.h (list(from_range, R&&, const Alloc&)) (assign_range, prepend_range, append_range, insert_range): Define. * include/debug/forward_list (forward_list(from_range, R&&, const Alloc&), assign_range) (prepend_range, insert_range_after): Define. * include/debug/list (list(from_range, R&&, const Alloc&)) (assign_range, prepend_range, append_range, insert_range): Define. * testsuite/23_containers/forward_list/cons/from_range.cc: New test. * testsuite/23_containers/forward_list/modifiers/assign_range.cc: New test. * testsuite/23_containers/forward_list/modifiers/insert_range_after.cc: New test. * testsuite/23_containers/forward_list/modifiers/prepend_range.cc: New test. * testsuite/23_containers/list/cons/from_range.cc: New test. * testsuite/23_containers/list/modifiers/append_range.cc: New test. * testsuite/23_containers/list/modifiers/assign/assign_range.cc: New test. * testsuite/23_containers/list/modifiers/insert/insert_range.cc: New test. * testsuite/23_containers/list/modifiers/prepend_range.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-27libstdc++: Add P1206R7 from_range members to std::vector [PR111055]Jonathan Wakely1-0/+70
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-10-25non-gcc: Remove trailing whitespaceJakub Jelinek1-2/+2
I've tried to build stage3 with -Wleading-whitespace=blanks -Wtrailing-whitespace=blank -Wno-error=leading-whitespace=blanks -Wno-error=trailing-whitespace=blank added to STRICT_WARN and that expectably resulted in about 2744 unique trailing whitespace warnings and 124837 leading whitespace warnings when excluding *.md files (which obviously is in big part a generator issue). Others from that are generator related, I think those need to be solved later. The following patch just fixes up the easy case (trailing whitespace), which could be easily automated: for i in `find . -name \*.h -o -name \*.cc -o -name \*.c | xargs grep -l '[ ]$' | grep -v testsuite/`; do sed -i -e 's/[ ]*$//' $i; done I've excluded files which I knew are obviously generated or go FE. Is there anything else we'd want to avoid the changes? Due to patch size, I've split it between gcc/ part and rest (include/, libiberty/, libgcc/, libcpp/, libstdc++-v3/; this part). 2024-10-24 Jakub Jelinek <jakub@redhat.com> include/ * dyn-string.h: Remove trailing whitespace. * libiberty.h: Likewise. * xregex.h: Likewise. * splay-tree.h: Likewise. * partition.h: Likewise. * plugin-api.h: Likewise. * demangle.h: Likewise. * vtv-change-permission.h: Likewise. * fibheap.h: Likewise. * hsa_ext_image.h: Likewise. * hashtab.h: Likewise. * libcollector.h: Likewise. * sort.h: Likewise. * symcat.h: Likewise. * hsa_ext_amd.h: Likewise. libcpp/ * directives.cc: Remove trailing whitespace. * mkdeps.cc: Likewise. * line-map.cc: Likewise. * internal.h: Likewise. * files.cc: Likewise. * init.cc: Likewise. * makeucnid.cc: Likewise. * system.h: Likewise. * include/line-map.h: Likewise. * include/symtab.h: Likewise. * include/cpplib.h: Likewise. * expr.cc: Likewise. * charset.cc: Likewise. * macro.cc: Likewise. * errors.cc: Likewise. * lex.cc: Likewise. * traditional.cc: Likewise. libgcc/ * crtstuff.c: Remove trailing whitespace. * libgcov.h: Likewise. * config/alpha/crtfastmath.c: Likewise. * config/alpha/vms-gcc_shell_handler.c: Likewise. * config/alpha/vms-unwind.h: Likewise. * config/pa/linux-atomic.c: Likewise. * config/pa/linux-unwind.h: Likewise. * config/pa/quadlib.c: Likewise. * config/pa/fptr.c: Likewise. * config/s390/32/_fixsfdi.c: Likewise. * config/s390/32/_fixunssfdi.c: Likewise. * config/s390/32/_fixunsdfdi.c: Likewise. * config/c6x/pr-support.c: Likewise. * config/lm32/_udivsi3.c: Likewise. * config/lm32/libgcc_lm32.h: Likewise. * config/lm32/_udivmodsi4.c: Likewise. * config/lm32/_mulsi3.c: Likewise. * config/lm32/_modsi3.c: Likewise. * config/lm32/_umodsi3.c: Likewise. * config/lm32/_divsi3.c: Likewise. * config/darwin-crt3.c: Likewise. * config/msp430/mpy.c: Likewise. * config/ia64/tf-signs.c: Likewise. * config/ia64/fde-vms.c: Likewise. * config/ia64/unwind-ia64.c: Likewise. * config/ia64/vms-unwind.h: Likewise. * config/ia64/sfp-exceptions.c: Likewise. * config/ia64/quadlib.c: Likewise. * config/ia64/unwind-ia64.h: Likewise. * config/rl78/vregs.h: Likewise. * config/arm/bpabi.c: Likewise. * config/arm/unwind-arm.c: Likewise. * config/arm/pr-support.c: Likewise. * config/arm/linux-atomic.c: Likewise. * config/arm/bpabi-lib.h: Likewise. * config/frv/frvend.c: Likewise. * config/frv/cmovw.c: Likewise. * config/frv/frvbegin.c: Likewise. * config/frv/cmovd.c: Likewise. * config/frv/cmovh.c: Likewise. * config/aarch64/cpuinfo.c: Likewise. * config/i386/crtfastmath.c: Likewise. * config/i386/cygming-crtend.c: Likewise. * config/i386/32/tf-signs.c: Likewise. * config/i386/crtprec.c: Likewise. * config/i386/sfp-exceptions.c: Likewise. * config/i386/w32-unwind.h: Likewise. * config/m32r/initfini.c: Likewise. * config/sparc/crtfastmath.c: Likewise. * config/gcn/amdgcn_veclib.h: Likewise. * config/nios2/linux-atomic.c: Likewise. * config/nios2/linux-unwind.h: Likewise. * config/nios2/lib2-mul.c: Likewise. * config/nios2/lib2-nios2.h: Likewise. * config/xtensa/unwind-dw2-xtensa.c: Likewise. * config/rs6000/darwin-fallback.c: Likewise. * config/rs6000/ibm-ldouble.c: Likewise. * config/rs6000/sfp-machine.h: Likewise. * config/rs6000/darwin-asm.h: Likewise. * config/rs6000/darwin-crt2.c: Likewise. * config/rs6000/aix-unwind.h: Likewise. * config/rs6000/sfp-exceptions.c: Likewise. * config/gthr-vxworks.c: Likewise. * config/riscv/atomic.c: Likewise. * config/visium/memcpy.c: Likewise. * config/darwin-crt-tm.c: Likewise. * config/stormy16/lib2funcs.c: Likewise. * config/arc/ieee-754/divtab-arc-sf.c: Likewise. * config/arc/ieee-754/divtab-arc-df.c: Likewise. * config/arc/initfini.c: Likewise. * config/sol2/gmon.c: Likewise. * config/microblaze/divsi3_table.c: Likewise. * config/m68k/fpgnulib.c: Likewise. * libgcov-driver.c: Likewise. * unwind-dw2.c: Likewise. * fp-bit.c: Likewise. * dfp-bit.h: Likewise. * dfp-bit.c: Likewise. * libgcov-driver-system.c: Likewise. libgcc/config/libbid/ * _le_td.c: Remove trailing whitespace. * bid128_compare.c: Likewise. * bid_div_macros.h: Likewise. * bid64_to_bid128.c: Likewise. * bid64_to_uint32.c: Likewise. * bid128_to_uint64.c: Likewise. * bid64_div.c: Likewise. * bid128_round_integral.c: Likewise. * bid_binarydecimal.c: Likewise. * bid128_string.c: Likewise. * bid_flag_operations.c: Likewise. * bid128_to_int64.c: Likewise. * _mul_sd.c: Likewise. * bid64_mul.c: Likewise. * bid128_noncomp.c: Likewise. * _gt_dd.c: Likewise. * bid64_add.c: Likewise. * bid64_string.c: Likewise. * bid_from_int.c: Likewise. * bid128.c: Likewise. * _ge_dd.c: Likewise. * _ne_sd.c: Likewise. * _dd_to_td.c: Likewise. * _unord_sd.c: Likewise. * bid64_to_uint64.c: Likewise. * _gt_sd.c: Likewise. * _sd_to_td.c: Likewise. * _addsub_td.c: Likewise. * _ne_td.c: Likewise. * bid_dpd.c: Likewise. * bid128_add.c: Likewise. * bid128_next.c: Likewise. * _lt_sd.c: Likewise. * bid64_next.c: Likewise. * bid128_mul.c: Likewise. * _lt_dd.c: Likewise. * _ge_td.c: Likewise. * _unord_dd.c: Likewise. * bid64_sqrt.c: Likewise. * bid_sqrt_macros.h: Likewise. * bid64_fma.c: Likewise. * _sd_to_dd.c: Likewise. * bid_conf.h: Likewise. * bid64_noncomp.c: Likewise. * bid_gcc_intrinsics.h: Likewise. * _gt_td.c: Likewise. * _ge_sd.c: Likewise. * bid128_minmax.c: Likewise. * bid128_quantize.c: Likewise. * bid32_to_bid64.c: Likewise. * bid_round.c: Likewise. * _td_to_sd.c: Likewise. * bid_inline_add.h: Likewise. * bid128_fma.c: Likewise. * _eq_td.c: Likewise. * bid32_to_bid128.c: Likewise. * bid64_rem.c: Likewise. * bid128_2_str_tables.c: Likewise. * _mul_dd.c: Likewise. * _dd_to_sd.c: Likewise. * bid128_div.c: Likewise. * _lt_td.c: Likewise. * bid64_compare.c: Likewise. * bid64_to_int32.c: Likewise. * _unord_td.c: Likewise. * bid128_rem.c: Likewise. * bid_internal.h: Likewise. * bid64_to_int64.c: Likewise. * _eq_dd.c: Likewise. * _td_to_dd.c: Likewise. * bid128_to_int32.c: Likewise. * bid128_to_uint32.c: Likewise. * _ne_dd.c: Likewise. * bid64_quantize.c: Likewise. * _le_dd.c: Likewise. * bid64_round_integral.c: Likewise. * _le_sd.c: Likewise. * bid64_minmax.c: Likewise. libgcc/config/avr/libf7/ * f7-renames.h: Remove trailing whitespace. libstdc++-v3/ * include/debug/debug.h: Remove trailing whitespace. * include/parallel/base.h: Likewise. * include/parallel/types.h: Likewise. * include/parallel/settings.h: Likewise. * include/parallel/multiseq_selection.h: Likewise. * include/parallel/partition.h: Likewise. * include/parallel/random_number.h: Likewise. * include/parallel/find_selectors.h: Likewise. * include/parallel/partial_sum.h: Likewise. * include/parallel/list_partition.h: Likewise. * include/parallel/search.h: Likewise. * include/parallel/algorithmfwd.h: Likewise. * include/parallel/random_shuffle.h: Likewise. * include/parallel/multiway_mergesort.h: Likewise. * include/parallel/sort.h: Likewise. * include/parallel/algobase.h: Likewise. * include/parallel/numericfwd.h: Likewise. * include/parallel/multiway_merge.h: Likewise. * include/parallel/losertree.h: Likewise. * include/bits/basic_ios.h: Likewise. * include/bits/stringfwd.h: Likewise. * include/bits/ostream_insert.h: Likewise. * include/bits/stl_heap.h: Likewise. * include/bits/unordered_map.h: Likewise. * include/bits/hashtable_policy.h: Likewise. * include/bits/stl_iterator_base_funcs.h: Likewise. * include/bits/valarray_before.h: Likewise. * include/bits/regex.h: Likewise. * include/bits/postypes.h: Likewise. * include/bits/stl_iterator.h: Likewise. * include/bits/localefwd.h: Likewise. * include/bits/stl_algo.h: Likewise. * include/bits/ios_base.h: Likewise. * include/bits/stl_function.h: Likewise. * include/bits/basic_string.h: Likewise. * include/bits/hashtable.h: Likewise. * include/bits/valarray_after.h: Likewise. * include/bits/char_traits.h: Likewise. * include/bits/gslice.h: Likewise. * include/bits/locale_facets_nonio.h: Likewise. * include/bits/mask_array.h: Likewise. * include/bits/specfun.h: Likewise. * include/bits/random.h: Likewise. * include/bits/slice_array.h: Likewise. * include/bits/valarray_array.h: Likewise. * include/tr1/float.h: Likewise. * include/tr1/functional_hash.h: Likewise. * include/tr1/math.h: Likewise. * include/tr1/hashtable_policy.h: Likewise. * include/tr1/stdio.h: Likewise. * include/tr1/complex.h: Likewise. * include/tr1/stdbool.h: Likewise. * include/tr1/stdarg.h: Likewise. * include/tr1/inttypes.h: Likewise. * include/tr1/fenv.h: Likewise. * include/tr1/stdlib.h: Likewise. * include/tr1/wchar.h: Likewise. * include/tr1/tgmath.h: Likewise. * include/tr1/limits.h: Likewise. * include/tr1/wctype.h: Likewise. * include/tr1/stdint.h: Likewise. * include/tr1/ctype.h: Likewise. * include/tr1/random.h: Likewise. * include/tr1/shared_ptr.h: Likewise. * include/ext/mt_allocator.h: Likewise. * include/ext/sso_string_base.h: Likewise. * include/ext/debug_allocator.h: Likewise. * include/ext/vstring_fwd.h: Likewise. * include/ext/pointer.h: Likewise. * include/ext/pod_char_traits.h: Likewise. * include/ext/malloc_allocator.h: Likewise. * include/ext/vstring.h: Likewise. * include/ext/bitmap_allocator.h: Likewise. * include/ext/pool_allocator.h: Likewise. * include/ext/type_traits.h: Likewise. * include/ext/ropeimpl.h: Likewise. * include/ext/codecvt_specializations.h: Likewise. * include/ext/throw_allocator.h: Likewise. * include/ext/extptr_allocator.h: Likewise. * include/ext/atomicity.h: Likewise. * include/ext/concurrence.h: Likewise. * include/c_compatibility/wchar.h: Likewise. * include/c_compatibility/stdint.h: Likewise. * include/backward/hash_fun.h: Likewise. * include/backward/binders.h: Likewise. * include/backward/hashtable.h: Likewise. * include/backward/auto_ptr.h: Likewise. * libsupc++/eh_arm.cc: Likewise. * libsupc++/unwind-cxx.h: Likewise. * libsupc++/si_class_type_info.cc: Likewise. * libsupc++/vec.cc: Likewise. * libsupc++/class_type_info.cc: Likewise. * libsupc++/vmi_class_type_info.cc: Likewise. * libsupc++/guard_error.cc: Likewise. * libsupc++/bad_typeid.cc: Likewise. * libsupc++/eh_personality.cc: Likewise. * libsupc++/atexit_arm.cc: Likewise. * libsupc++/pmem_type_info.cc: Likewise. * libsupc++/vterminate.cc: Likewise. * libsupc++/eh_terminate.cc: Likewise. * libsupc++/bad_cast.cc: Likewise. * libsupc++/exception_ptr.h: Likewise. * libsupc++/eh_throw.cc: Likewise. * libsupc++/bad_alloc.cc: Likewise. * libsupc++/nested_exception.cc: Likewise. * libsupc++/pointer_type_info.cc: Likewise. * libsupc++/pbase_type_info.cc: Likewise. * libsupc++/bad_array_new.cc: Likewise. * libsupc++/pure.cc: Likewise. * libsupc++/eh_exception.cc: Likewise. * libsupc++/bad_array_length.cc: Likewise. * libsupc++/cxxabi.h: Likewise. * libsupc++/guard.cc: Likewise. * libsupc++/eh_catch.cc: Likewise. * libsupc++/cxxabi_forced.h: Likewise. * libsupc++/tinfo.h: Likewise.
2024-10-22libstdc++: Avoid using std::__to_address with iteratorsJonathan Wakely1-17/+0
In r12-3935-g82626be2d633a9 I added the partial specialization std::pointer_traits<__normal_iterator<It, Cont>> so that __to_address would work with __normal_iterator objects. Soon after that, François replaced it in r12-6004-g807ad4bc854cae with an overload of __to_address that served the same purpose, but was less complicated and less wrong. I now think that both commits were mistakes, and that instead of adding hacks to make __normal_iterator work with __to_address, we should not be using __to_address with iterators at all before C++20. The pre-C++20 std::__to_address function should only be used with pointer-like types, specifically allocator_traits<A>::pointer types. Those pointer-like types are guaranteed to be contiguous iterators, so that getting a raw memory address from them is OK. For arbitrary iterators, even random access iterators, we don't know that it's safe to lower the iterator to a pointer e.g. for std::deque iterators it's not, because (it + n) == (std::to_address(it) + n) only holds within the same block of the deque's storage. For C++20, std::to_address does work correctly for contiguous iterators, including __normal_iterator, and __to_address just calls std::to_address so also works. But we have to be sure we have an iterator that satisfies the std::contiguous_iterator concept for it to be safe, and we can't check that before C++20. So for pre-C++20 code the correct way to handle iterators that might be pointers or might be __normal_iterator is to call __niter_base, and if necessary use is_pointer to check whether __niter_base returned a real pointer. We currently have some uses of std::__to_address with iterators where we've checked that they're either pointers, or __normal_iterator wrappers around pointers, or satisfy std::contiguous_iterator. But this seems a little fragile, and it would be better to just use std::__niter_base for the pointers and __normal_iterator cases, and use C++20 std::to_address when the C++20 std::contiguous_iterator concept is satisfied. This patch does that. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (basic_string::assign): Replace use of __to_address with __niter_base or std::to_address as appropriate. * include/bits/ptr_traits.h (__to_address): Add comment. * include/bits/shared_ptr_base.h (__shared_ptr): Qualify calls to __to_address. * include/bits/stl_algo.h (find): Replace use of __to_address with __niter_base or std::to_address as appropriate. Only use either of them when the range is not empty. * include/bits/stl_iterator.h (__to_address): Remove overload for __normal_iterator. * include/debug/safe_iterator.h (__to_address): Remove overload for _Safe_iterator. * include/std/ranges (views::counted): Replace use of __to_address with std::to_address. * testsuite/24_iterators/normal_iterator/to_address.cc: Removed.
2024-09-25libstdc++: #ifdef out #pragma GCC system_headerJason Merrill11-0/+22
In r15-3714-gd3a7302ec5985a I added -Wsystem-headers to the libstdc++ build flags to help catch problems in the library. This patch takes a different approach, of disabling the #pragma system_header unless _GLIBCXX_SYSHDR is defined. As a result, the testsuites will treat them as non-system-headers to get better warning coverage during regression testing of both gcc and libstdc++, not just when building the library. My rationale for the #ifdef instead of just removing the #pragma is the three G++ tests that want to test libstdc++ system header behavior, so we need a way to select it. This doesn't affect installed libraries, as they get their system-header status from the lookup path. But testsuite_flags --build-includes gives -I directives rather than -isystem. This patch doesn't change the headers in config/ because I'm not compiling with most of them, so won't see any warnings that need fixing. Adjusting them could happen later, or we can not bother. libstdc++-v3/ChangeLog: * acinclude.m4 (WARN_FLAGS): Remove -Wsystem-headers. * configure: Regenerate. * include/bits/algorithmfwd.h: #ifdef out #pragma GCC system_header. * include/bits/atomic_base.h * include/bits/atomic_futex.h * include/bits/atomic_timed_wait.h * include/bits/atomic_wait.h * include/bits/basic_ios.h * include/bits/basic_string.h * include/bits/boost_concept_check.h * include/bits/char_traits.h * include/bits/charconv.h * include/bits/chrono.h * include/bits/chrono_io.h * include/bits/codecvt.h * include/bits/concept_check.h * include/bits/cpp_type_traits.h * include/bits/elements_of.h * include/bits/enable_special_members.h * include/bits/erase_if.h * include/bits/forward_list.h * include/bits/functional_hash.h * include/bits/gslice.h * include/bits/gslice_array.h * include/bits/hashtable.h * include/bits/indirect_array.h * include/bits/invoke.h * include/bits/ios_base.h * include/bits/iterator_concepts.h * include/bits/locale_classes.h * include/bits/locale_facets.h * include/bits/locale_facets_nonio.h * include/bits/localefwd.h * include/bits/mask_array.h * include/bits/max_size_type.h * include/bits/memory_resource.h * include/bits/memoryfwd.h * include/bits/move_only_function.h * include/bits/node_handle.h * include/bits/ostream_insert.h * include/bits/out_ptr.h * include/bits/parse_numbers.h * include/bits/postypes.h * include/bits/quoted_string.h * include/bits/range_access.h * include/bits/ranges_base.h * include/bits/refwrap.h * include/bits/sat_arith.h * include/bits/semaphore_base.h * include/bits/slice_array.h * include/bits/std_abs.h * include/bits/std_function.h * include/bits/std_mutex.h * include/bits/std_thread.h * include/bits/stl_iterator_base_funcs.h * include/bits/stl_iterator_base_types.h * include/bits/stl_tree.h * include/bits/stream_iterator.h * include/bits/streambuf_iterator.h * include/bits/stringfwd.h * include/bits/this_thread_sleep.h * include/bits/unique_lock.h * include/bits/uses_allocator_args.h * include/bits/utility.h * include/bits/valarray_after.h * include/bits/valarray_array.h * include/bits/valarray_before.h * include/bits/version.h * include/c_compatibility/fenv.h * include/c_compatibility/inttypes.h * include/c_compatibility/stdint.h * include/decimal/decimal.h * include/experimental/bits/net.h * include/experimental/bits/shared_ptr.h * include/ext/aligned_buffer.h * include/ext/alloc_traits.h * include/ext/atomicity.h * include/ext/concurrence.h * include/ext/numeric_traits.h * include/ext/pod_char_traits.h * include/ext/pointer.h * include/ext/stdio_filebuf.h * include/ext/stdio_sync_filebuf.h * include/ext/string_conversions.h * include/ext/type_traits.h * include/ext/vstring.h * include/ext/vstring_fwd.h * include/ext/vstring_util.h * include/parallel/algorithmfwd.h * include/parallel/numericfwd.h * include/tr1/functional_hash.h * include/tr1/hashtable.h * include/tr1/random.h * libsupc++/exception.h * libsupc++/hash_bytes.h * include/bits/basic_ios.tcc * include/bits/basic_string.tcc * include/bits/fstream.tcc * include/bits/istream.tcc * include/bits/locale_classes.tcc * include/bits/locale_facets.tcc * include/bits/locale_facets_nonio.tcc * include/bits/ostream.tcc * include/bits/sstream.tcc * include/bits/streambuf.tcc * include/bits/string_view.tcc * include/bits/version.tpl * include/experimental/bits/string_view.tcc * include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp * include/ext/random.tcc * include/ext/vstring.tcc * include/tr2/bool_set.tcc * include/tr2/dynamic_bitset.tcc * include/bits/c++config * include/c/cassert * include/c/cctype * include/c/cerrno * include/c/cfloat * include/c/ciso646 * include/c/climits * include/c/clocale * include/c/cmath * include/c/csetjmp * include/c/csignal * include/c/cstdarg * include/c/cstddef * include/c/cstdio * include/c/cstdlib * include/c/cstring * include/c/ctime * include/c/cuchar * include/c/cwchar * include/c/cwctype * include/c_global/cassert * include/c_global/ccomplex * include/c_global/cctype * include/c_global/cerrno * include/c_global/cfenv * include/c_global/cfloat * include/c_global/cinttypes * include/c_global/ciso646 * include/c_global/climits * include/c_global/clocale * include/c_global/cmath * include/c_global/csetjmp * include/c_global/csignal * include/c_global/cstdalign * include/c_global/cstdarg * include/c_global/cstdbool * include/c_global/cstddef * include/c_global/cstdint * include/c_global/cstdio * include/c_global/cstdlib * include/c_global/cstring * include/c_global/ctgmath * include/c_global/ctime * include/c_global/cuchar * include/c_global/cwchar * include/c_global/cwctype * include/c_std/cassert * include/c_std/cctype * include/c_std/cerrno * include/c_std/cfloat * include/c_std/ciso646 * include/c_std/climits * include/c_std/clocale * include/c_std/cmath * include/c_std/csetjmp * include/c_std/csignal * include/c_std/cstdarg * include/c_std/cstddef * include/c_std/cstdio * include/c_std/cstdlib * include/c_std/cstring * include/c_std/ctime * include/c_std/cuchar * include/c_std/cwchar * include/c_std/cwctype * include/debug/array * include/debug/bitset * include/debug/deque * include/debug/forward_list * include/debug/list * include/debug/map * include/debug/set * include/debug/string * include/debug/unordered_map * include/debug/unordered_set * include/debug/vector * include/decimal/decimal * include/experimental/algorithm * include/experimental/any * include/experimental/array * include/experimental/buffer * include/experimental/chrono * include/experimental/contract * include/experimental/deque * include/experimental/executor * include/experimental/filesystem * include/experimental/forward_list * include/experimental/functional * include/experimental/internet * include/experimental/io_context * include/experimental/iterator * include/experimental/list * include/experimental/map * include/experimental/memory * include/experimental/memory_resource * include/experimental/net * include/experimental/netfwd * include/experimental/numeric * include/experimental/propagate_const * include/experimental/ratio * include/experimental/regex * include/experimental/scope * include/experimental/set * include/experimental/socket * include/experimental/string * include/experimental/string_view * include/experimental/synchronized_value * include/experimental/system_error * include/experimental/timer * include/experimental/tuple * include/experimental/type_traits * include/experimental/unordered_map * include/experimental/unordered_set * include/experimental/vector * include/ext/algorithm * include/ext/cmath * include/ext/functional * include/ext/iterator * include/ext/memory * include/ext/numeric * include/ext/random * include/ext/rb_tree * include/ext/rope * include/parallel/algorithm * include/std/algorithm * include/std/any * include/std/array * include/std/atomic * include/std/barrier * include/std/bit * include/std/bitset * include/std/charconv * include/std/chrono * include/std/codecvt * include/std/complex * include/std/concepts * include/std/condition_variable * include/std/coroutine * include/std/deque * include/std/execution * include/std/expected * include/std/filesystem * include/std/format * include/std/forward_list * include/std/fstream * include/std/functional * include/std/future * include/std/generator * include/std/iomanip * include/std/ios * include/std/iosfwd * include/std/iostream * include/std/istream * include/std/iterator * include/std/latch * include/std/limits * include/std/list * include/std/locale * include/std/map * include/std/memory * include/std/memory_resource * include/std/mutex * include/std/numbers * include/std/numeric * include/std/optional * include/std/ostream * include/std/print * include/std/queue * include/std/random * include/std/ranges * include/std/ratio * include/std/regex * include/std/scoped_allocator * include/std/semaphore * include/std/set * include/std/shared_mutex * include/std/span * include/std/spanstream * include/std/sstream * include/std/stack * include/std/stacktrace * include/std/stdexcept * include/std/streambuf * include/std/string * include/std/string_view * include/std/syncstream * include/std/system_error * include/std/text_encoding * include/std/thread * include/std/tuple * include/std/type_traits * include/std/typeindex * include/std/unordered_map * include/std/unordered_set * include/std/utility * include/std/valarray * include/std/variant * include/std/vector * include/std/version * include/tr1/array * include/tr1/cfenv * include/tr1/cinttypes * include/tr1/cmath * include/tr1/complex * include/tr1/cstdbool * include/tr1/cstdint * include/tr1/cstdio * include/tr1/cstdlib * include/tr1/cwchar * include/tr1/cwctype * include/tr1/functional * include/tr1/memory * include/tr1/random * include/tr1/regex * include/tr1/tuple * include/tr1/type_traits * include/tr1/unordered_map * include/tr1/unordered_set * include/tr1/utility * include/tr2/bool_set * include/tr2/dynamic_bitset * include/tr2/type_traits * libsupc++/atomic_lockfree_defines.h * libsupc++/compare * libsupc++/cxxabi.h * libsupc++/cxxabi_forced.h * libsupc++/cxxabi_init_exception.h * libsupc++/exception * libsupc++/initializer_list * libsupc++/new * libsupc++/typeinfo: Likewise. * testsuite/20_util/ratio/operations/ops_overflow_neg.cc * testsuite/23_containers/array/tuple_interface/get_neg.cc * testsuite/23_containers/vector/cons/destructible_debug_neg.cc * testsuite/24_iterators/operations/prev_neg.cc * testsuite/ext/type_traits/add_unsigned_floating_neg.cc * testsuite/ext/type_traits/add_unsigned_integer_neg.cc * testsuite/ext/type_traits/remove_unsigned_floating_neg.cc * testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Adjust line numbers. gcc/testsuite/ChangeLog * g++.dg/analyzer/fanalyzer-show-events-in-system-headers-default.C * g++.dg/analyzer/fanalyzer-show-events-in-system-headers-no.C * g++.dg/diagnostic/disable.C: #define _GLIBCXX_SYSHDR.
2024-08-23libstdc++: Make debug sequence members mutable [PR116369]Jonathan Wakely1-2/+2
We need to be able to attach debug mode iterators to const containers, so the safe iterator constructor uses const_cast to get a modifiable pointer to the container. If the container was defined as const, that const_cast to access its members results in undefined behaviour. PR 116369 shows a case where it results in a segfault because the container is in a rodata section (which shouldn't have happened, but the undefined behaviour in the library still exists in any case). This makes the _M_iterators and _M_const_iterators data members mutable, so that it's safe to modify them even if the declared type of the container is a const type. Ideally we would not need the const_cast at all. Instead, the _M_attach member (and everything it calls) should be const-qualified. That would work fine now, because the members that it ends up modifying are mutable. Making that change would require a number of new exports from the shared library, and would require retaining the old non-const member functions (maybe as symbol aliases) for backwards compatibility. That might be worth changing at some point, but isn't done here. libstdc++-v3/ChangeLog: PR c++/116369 * include/debug/safe_base.h (_Safe_sequence_base::_M_iterators): Add mutable specifier. (_Safe_sequence_base::_M_const_iterators): Likewise.
2024-06-27libstdc++: Enable more debug assertions during constant evaluation [PR111250]Jonathan Wakely1-6/+8
Some of our debug assertions expand to nothing unless _GLIBCXX_ASSERTIONS is defined, which means they are not checked during constant evaluation. By making them unconditionally expand to a __glibcxx_assert expression they will be checked during constant evaluation. This allows us to diagnose more instances of undefined behaviour at compile-time, such as accessing a vector past-the-end. libstdc++-v3/ChangeLog: PR libstdc++/111250 * include/debug/assertions.h (__glibcxx_requires_non_empty_range) (__glibcxx_requires_nonempty, __glibcxx_requires_subscript): Define to __glibcxx_assert expressions or to debug mode __glibcxx_check_xxx expressions. * testsuite/23_containers/array/element_access/constexpr_c++17.cc: Add checks for out-of-bounds accesses in constant expressions. * testsuite/23_containers/vector/element_access/constexpr.cc: Likewise.
2024-06-21libstdc++: Remove std::__is_void class template [PR115497]Jonathan Wakely1-3/+2
This removes the std::__is_void trait, as it conflicts with a Clang built-in. There is only one use of the trait, which can easily be replaced by simpler code. Although Clang has a hack to make the class template work despite using a reserved name, removing std::__is_void will allow that hack to be dropped at some future date. libstdc++-v3/ChangeLog: PR libstdc++/115497 * include/bits/cpp_type_traits.h (__is_void): Remove. * include/debug/helper_functions.h (_Distance_traits): Adjust partial specialization to match void directly, instead of using __is_void<T>::__type and matching __true_type.
2024-03-18libstdc++: Fix N3344 behavior on _Safe_iterator::_M_can_advanceFrançois Dumont1-0/+3
We shall be able to advance from a 0 offset a value-initialized iterator. libstdc++-v3/ChangeLog: * include/debug/safe_iterator.tcc (_Safe_iterator<>::_M_can_advance): Accept 0 offset advance on value-initialized iterator. * testsuite/23_containers/vector/debug/n3644.cc: New test case.
2024-03-18libstdc++: Fix _Safe_local_iterator<>::_M_valid_rangeFrançois Dumont1-1/+7
Unordered container local_iterator range shall not contain any singular iterator unless both iterators are both value-initialized. libstdc++-v3/ChangeLog: * include/debug/safe_local_iterator.tcc (_Safe_local_iterator::_M_valid_range): Add _M_value_initialized and _M_singular checks. * testsuite/23_containers/unordered_set/debug/114316.cc: New test case.
2024-03-17libstdc++: Implement N3644 on _Safe_iterator<> [PR114316]François Dumont1-0/+12
Consider range of value-initialized iterators as valid and empty. libstdc++-v3/ChangeLog: PR libstdc++/114316 * include/debug/safe_iterator.tcc (_Safe_iterator<>::_M_valid_range): First check if both iterators are value-initialized before checking if singular. * testsuite/23_containers/set/debug/114316.cc: New test case. * testsuite/23_containers/vector/debug/114316.cc: New test case.
2024-02-28libstdc++: Add more nodiscard uses in <vector>Jonathan Wakely1-1/+7
Add [[nodiscard]] to vector::at and to comparison operators. libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (vector<bool, A>::at): Add nodiscard. * include/bits/stl_vector.h (vector<T, A>::at): Likewise. (operator==, operator<=>, operator<, operator!=, operator>) (operator<=, operator>=): Likewise. * include/debug/vector (operator==, operator<=>, operator<) (operator!=, operator>, operator<=, operator>=): Likewise. * testsuite/23_containers/vector/nodiscard.cc: New test.
2024-02-17libstdc++: [_GLIBCXX_DEBUG] Fix std::__niter_base behaviorFrançois Dumont1-1/+17
std::__niter_base is used in _GLIBCXX_DEBUG mode to remove _Safe_iterator<> wrapper on random access iterators. But doing so it should also preserve original behavior to remove __normal_iterator wrapper. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (std::__niter_base): Redefine the overload definitions for __gnu_debug::_Safe_iterator. * include/debug/safe_iterator.tcc (std::__niter_base): Adapt declarations.
2024-01-18libstdc++/debug: Fix constexpr _Safe_iterator in C++20 mode [PR109536]Patrick Palka2-13/+36
Some _Safe_iterator member functions define a variable of non-literal type __gnu_cxx::__scoped_lock, which automatically disqualifies them from being constexpr in C++20 mode even if that code path is never constant evaluated. This restriction was lifted by P2242R3 for C++23, but we need to work around it in C++20 mode. To that end this patch defines a pair of macros that encapsulate the lambda-based workaround mentioned in that paper and uses it to make these functions valid C++20 constexpr functions. The augmented std::vector test element_access/constexpr.cc now successfully compiles in C++20 mode with -D_GLIBCXX_DEBUG (and it should test all member functions modified by this patch). PR libstdc++/109536 libstdc++-v3/ChangeLog: * include/debug/safe_base.h (_Safe_sequence_base::_M_swap): Remove _GLIBCXX20_CONSTEXPR from non-inline member function. * include/debug/safe_iterator.h (_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_BEGIN): Define. (_GLIBCXX20_CONSTEXPR_NON_LITERAL_SCOPE_END): Define. (_Safe_iterator::operator=): Use them around the code path that defines a variable of type __gnu_cxx::__scoped_lock. (_Safe_iterator::operator++): Likewise. (_Safe_iterator::operator--): Likewise. (_Safe_iterator::operator+=): Likewise. (_Safe_iterator::operator-=): Likewise. * testsuite/23_containers/vector/element_access/constexpr.cc (test_iterators): Test more iterator operations. * testsuite/23_containers/vector/bool/element_access/constexpr.cc (test_iterators): Likewise. * testsuite/std/ranges/adaptors/all.cc (test08) [_GLIBCXX_DEBUG]: Remove. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-01-03Update copyright years.Jakub Jelinek33-33/+33
2023-12-14libstdc++: Make __gnu_debug::vector usable in constant expressions [PR109536]Jonathan Wakely7-55/+352
This makes constexpr std::vector (mostly) work in Debug Mode. All safe iterator instrumentation and checking is disabled during constant evaluation, because it requires mutex locks and calls to non-inline functions defined in libstdc++.so. It should be OK to disable the safety checks, because most UB should be detected during constant evaluation anyway. We could try to enable the full checking in constexpr, but it would mean wrapping all the non-inline functions like _M_attach with an inline _M_constexpr_attach that does the iterator housekeeping inline without mutex locks when called for constant evaluation, and calls the non-inline function at runtime. That could be done in future if we find that we've lost safety or useful checking by disabling the safe iterators. There are a few test failures in C++20 mode, which I'm unable to explain. The _Safe_iterator::operator++() member gives errors for using non-constexpr functions during constant evaluation, even though those functions are guarded by std::is_constant_evaluated() checks. The same code works fine for C++23 and up. libstdc++-v3/ChangeLog: PR libstdc++/109536 * include/bits/c++config (__glibcxx_constexpr_assert): Remove macro. * include/bits/stl_algobase.h (__niter_base, __copy_move_a) (__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux) (__lexicographical_compare_aux): Add constexpr to overloads for debug mode iterators. * include/debug/helper_functions.h (__unsafe): Add constexpr. * include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Remove macro, folding it into ... (_GLIBCXX_DEBUG_VERIFY_AT_F): ... here. Do not use __glibcxx_constexpr_assert. * include/debug/safe_base.h (_Safe_iterator_base): Add constexpr to some member functions. Omit attaching, detaching and checking operations during constant evaluation. * include/debug/safe_container.h (_Safe_container): Likewise. * include/debug/safe_iterator.h (_Safe_iterator): Likewise. * include/debug/safe_iterator.tcc (__niter_base, __copy_move_a) (__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux) (__lexicographical_compare_aux): Add constexpr. * include/debug/vector (_Safe_vector, vector): Add constexpr. Omit safe iterator operations during constant evaluation. * testsuite/23_containers/vector/bool/capacity/constexpr.cc: Remove dg-xfail-if for debug mode. * testsuite/23_containers/vector/bool/cmp_c++20.cc: Likewise. * testsuite/23_containers/vector/bool/cons/constexpr.cc: Likewise. * testsuite/23_containers/vector/bool/element_access/1.cc: Likewise. * testsuite/23_containers/vector/bool/element_access/constexpr.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/constexpr.cc: Likewise. * testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc: Likewise. * testsuite/23_containers/vector/capacity/constexpr.cc: Likewise. * testsuite/23_containers/vector/cmp_c++20.cc: Likewise. * testsuite/23_containers/vector/cons/constexpr.cc: Likewise. * testsuite/23_containers/vector/data_access/constexpr.cc: Likewise. * testsuite/23_containers/vector/element_access/constexpr.cc: Likewise. * testsuite/23_containers/vector/modifiers/assign/constexpr.cc: Likewise. * testsuite/23_containers/vector/modifiers/constexpr.cc: Likewise. * testsuite/23_containers/vector/modifiers/swap/constexpr.cc: Likewise. * testsuite/23_containers/vector/cons/destructible_debug_neg.cc: Adjust dg-error line number.
2023-06-26libstdc++: Qualify calls to debug mode helpersJonathan Wakely1-11/+21
These functions should be qualified to disable unwanted ADL. The overload of __check_singular_aux for safe iterators was previously being found by ADL, because it wasn't declared before __check_singular. Add a declaration so that it can be found by qualified lookup. libstdc++-v3/ChangeLog: * include/debug/helper_functions.h (__get_distance) (__check_singular, __valid_range_aux, __valid_range): Qualify calls to disable ADL. (__check_singular_aux(const _Safe_iterator_base*)): Declare overload that was previously found via ADL.
2023-01-23libstdc++: [_GLIBCXX_DEBUG] Remove useless constructor checksFrançois Dumont2-16/+34
Creating a safe iterator from a normal iterator is done within the library where we already know that it is done correctly. The rare situation where a user would use safe iterators for his own purpose is non-Standard code so outside _GLIBCXX_DEBUG scope. For those reasons the __msg_init_singular is useless and can be removed. Additionally in the copy constructor used for post-increment and post-decrement operators the __msg_init_copy_singular check can also be ommitted because of the preliminary __msg_bad_incr and __msg_bad_decr checks. libstdc++-v3/ChangeLog: * include/debug/safe_iterator.h (_Safe_iterator<>::_Unchecked): New. (_Safe_iterator(const _Safe_iterator&, _Unchecked)): New. (_Safe_iterator::operator++(int)): Use latter. (_Safe_iterator::operator--(int)): Likewise. (_Safe_iterator(_Iterator, const _Safe_sequence_base*)): Remove !_M_insular() check. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>::_Unchecked): New. (_Safe_local_iterator(const _Safe_local_iterator&, _Unchecked)): New. (_Safe_local_iterator::operator++(int)): Use latter. * src/c++11/debug.cc (_S_debug_messages): Add as comment the _Debug_msg_id entry associated to the array entry.
2023-01-16Update copyright years.Jakub Jelinek33-33/+33
2023-01-15libstdc++: [_GLIBCXX_DEBUG] Complete deadlock fix on safe iterators [PR108288]François Dumont2-40/+18
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-06libstdc++: Fix deadlock in debug iterator increment [PR108288]Jonathan Wakely1-12/+6
With -fno-elide-constructors the debug iterator post-increment and post-decrement operators are susceptible to deadlock. They take a mutex lock and then return a temporary, which also attempts to take a lock to attach itself to the sequence. If the return value and *this happen to collide and use the same mutex from the pool, then you get a deadlock trying to lock a mutex that is already held by the current thread. The solution is to construct the return value before taking the lock. The copy constructor and pre-inc/pre-dec operators already manage locks correctly, without deadlock, so just implement post-inc/post-dec in the conventional way, taking a copy then modifying *this, then returning the copy. libstdc++-v3/ChangeLog: PR libstdc++/108288 * include/debug/safe_iterator.h (_Safe_iterator::operator++(int)) (_Safe_iterator::operator--(int)): Do not hold lock around construction of return value.
2022-12-07libstdc++: Pass error handler to libbacktrace functionsJonathan Wakely1-23/+12
Also pass threaded=1 to __glibcxx_backtrace_create_state and remove some of the namespace scope declarations in the header. Co-authored-by: François Dumont <frs.dumont@gmail.com> libstdc++-v3/ChangeLog: * include/debug/formatter.h [_GLIBCXX_DEBUG_BACKTRACE] (_Error_formatter::_Error_formatter): Pass error handler to __glibcxx_backtrace_create_state. Pass 1 for threaded argument. (_Error_formatter::_S_err): Define empty function. * src/c++11/debug.cc (_Error_formatter::_M_error): Pass error handler to __glibcxx_backtrace_full.
2022-10-12libstdc++: Add __gnu_debug::basic_string<>::compare overloadsFrançois Dumont1-14/+5
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-23libstdc++: Enable constexpr std::bitset for debug modeJonathan Wakely1-5/+38
We already disable all debug mode checks for C++11 and later, so we can easily make everything constexpr. This fixes the FAIL results for the new tests when using -D_GLIBCXX_DEBUG. Also fix some other tests failing with non-default test flags. libstdc++-v3/ChangeLog: * include/debug/bitset (__debug::bitset): Add constexpr to all member functions. (operator&, operator|, operator^): Add inline and constexpr. (operator>>, operator<<): Add inline. * testsuite/20_util/bitset/access/constexpr.cc: Only check using constexpr std::string for the cxx11 ABI. * testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise. * testsuite/20_util/headers/bitset/synopsis.cc: Check constexpr for C++23.
2022-09-16libstdc++: Add preprocessor conditions for freestanding [PR106953]Jonathan Wakely2-10/+8
This adds checks for _GLIBCXX_HOSTED to a number of headers which are not currently installed for freestanding, but need to be for P1642R11 support. For example, <iterator> needs to be installed for C++23 freestanding mode, but without stream iterators and streambuf iterators. Similarly, <memory> needs to be installed, but without std::allocator and std::shared_ptr. This change disables the non-freestanding parts of those headers. libstdc++-v3/ChangeLog: PR libstdc++/106953 * include/backward/auto_ptr.h [!_GLIBCXX_HOSTED]: Do not define shared_ptr members. * include/bits/alloc_traits.h [!_GLIBCXX_HOSTED]: Do not declare std::allocator_traits<std::allocator<T>> specializations for freestanding. * include/bits/memoryfwd.h [!_GLIBCXX_HOSTED] (allocator): Do not declare for freestanding. * include/bits/stl_algo.h [!_GLIBCXX_HOSTED] (stable_partition): Do not define for freestanding. [!_GLIBCXX_HOSTED] (merge, stable_sort): Do not use temporary buffers for freestanding. * include/bits/stl_algobase.h [!_GLIBCXX_HOSTED]: Do not declare streambuf iterators and overloaded algorithms using them. * include/bits/stl_uninitialized.h [!_GLIBCXX_HOSTED]: Do not define specialized overloads for std::allocator. * include/bits/unique_ptr.h [!_GLIBCXX_HOSTED] (make_unique) (make_unique_for_overwrite, operator<<): Do not define for freestanding. * include/c_global/cstdlib [!_GLIBCXX_HOSTED] (_Exit): Declare. Use _GLIBCXX_NOTHROW instead of throw(). * include/debug/assertions.h [!_GLIBCXX_HOSTED]: Ignore _GLIBCXX_DEBUG for freestanding. * include/debug/debug.h [!_GLIBCXX_DEBUG]: Likewise. * include/std/bit [!_GLIBCXX_HOSTED]: Do not use the custom __int_traits if <ext/numeric_traits.h> is available. * include/std/functional [!_GLIBCXX_HOSTED]: Do not include headers that aren't valid for freestanding. (boyer_moore_searcher, boyer_moore_horspool_searcher): Do not define for freestanding. * include/std/iterator [!_GLIBCXX_HOSTED]: Do not include headers that aren't valid for freestanding. * include/std/memory [!_GLIBCXX_HOSTED]: Likewise. * include/std/ranges [!_GLIBCXX_HOSTED] (istream_view): Do not define for freestanding. (views::__detail::__is_basic_string_view) [!_GLIBCXX_HOSTED]: Do not define partial specialization for freestanding.
2022-09-16libstdc++: Do not use nullptr in C++03-compatible codeJonathan Wakely1-2/+1
This has to be valid as C++98/C++03. libstdc++-v3/ChangeLog: * include/debug/formatter.h [_GLIBCXX_DEBUG_BACKTRACE] (_Error_formatter): Use 0 as null pointer constant.
2022-09-13libstdc++: Avoid -Wparentheses warning with debug iteratorsPatrick Palka1-1/+1
I noticed compiling e.g. std/ranges/adaptors/join.cc with -D_GLIBCXX_DEBUG -Wsystem-headers -Wall gives the warning: gcc/libstdc++-v3/include/debug/safe_iterator.h:477:9: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses] libstdc++-v3/ChangeLog: * include/debug/safe_iterator.h (_GLIBCXX_DEBUG_VERIFY_OPERANDS): Add parentheses to avoid -Wparentheses warning.
2022-08-31libstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnosticsFrançois Dumont2-4/+32
Review null string checks to show: _String != nullptr rather than: _String != 0 libstdc++-v3/ChangeLog: * include/debug/debug.h: Use nullptr rather than '0' in checks in post-C++11. * include/debug/string: Likewise. * testsuite/21_strings/basic_string/operations/ends_with/char.cc: Use __gnu_test::string. * testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc: Likewise. * testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/char.cc: Likewise..
2022-08-31libstdc++: [_GLIBCXX_DEBUG] Add backtrace generation on demandFrançois Dumont1-0/+44
Add _GLIBCXX_DEBUG_BACKTRACE macro to activate backtrace generation on _GLIBCXX_DEBUG assertions. Prerequisite is to have configure the lib with: --enable-libstdcxx-backtrace=yes libstdc++-v3/ChangeLog: * include/debug/formatter.h [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_state): Declare. [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_create_state): Declare. [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_callback): Define. [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_error_callback): Define. [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full_func): Define. [_GLIBCXX_HAVE_STACKTRACE](__glibcxx_backtrace_full): Declare. [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_state): New. [_GLIBCXX_HAVE_STACKTRACE](_Error_formatter::_M_backtrace_full): New. * src/c++11/debug.cc [_GLIBCXX_HAVE_STACKTRACE](print_backtrace): New. (_Error_formatter::_M_error()): Adapt. * src/libbacktrace/Makefile.am: Add backtrace.c. * src/libbacktrace/Makefile.in: Regenerate. * src/libbacktrace/backtrace-rename.h (backtrace_full): New. * testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc: New test. * doc/xml/manual/debug_mode.xml: Document _GLIBCXX_DEBUG_BACKTRACE. * doc/xml/manual/using.xml: Likewise.
2022-08-08libstdc++: [_GLIBCXX_DEBUG] Do not consider detached iterators as ↵François Dumont3-16/+37
value-initialized An attach iterator has its _M_version set to something != 0, the container version. This value shall be preserved when detaching it so that the iterator does not look like a value-initialized one. libstdc++-v3/ChangeLog: * include/debug/formatter.h (__singular_value_init): New _Iterator_state enum entry. (_Parameter<>(const _Safe_iterator<>&, const char*, _Is_iterator)): Check if iterator parameter is value-initialized. (_Parameter<>(const _Safe_local_iterator<>&, const char*, _Is_iterator)): Likewise. * include/debug/safe_iterator.h (_Safe_iterator<>::_M_value_initialized()): New. Adapt checks. * include/debug/safe_local_iterator.h (_Safe_local_iterator<>::_M_value_initialized()): New. Adapt checks. * src/c++11/debug.cc (_Safe_iterator_base::_M_reset): Do not reset _M_version. (print_field(PrintContext&, const _Parameter&, const char*)): Adapt state_names. * testsuite/23_containers/deque/debug/iterator1_neg.cc: New test. * testsuite/23_containers/deque/debug/iterator2_neg.cc: New test. * testsuite/23_containers/forward_list/debug/iterator1_neg.cc: New test. * testsuite/23_containers/forward_list/debug/iterator2_neg.cc: New test. * testsuite/23_containers/forward_list/debug/iterator3_neg.cc: New test.
2022-07-19libstdc++: Complete __gnu_debug::string Standard conformityFrançois Dumont3-59/+45
Add testsuite/testsuite_string.h header to help testing __gnu_debug::basic_string like std::basic_string depending on _GLIBCXX_DEBUG. Add using of base type methods in __gnu_debug::basic_string to make use of the method overloads when there is no debug version. Fix _GLIBCXX_DEBUG_PEDANTIC assertions in <debug/string>. This header has to be used directly like __gnu_debug::string, it is not included by _GLIBCXX_DEBUG. It means that _GLIBCXX_DEBUG_PEDANTIC is not considered to define __glibcxx_check_string and __glibcxx_check_string_len which are then empty macros. Now those macros are defined directly in <debug/string> and properly consider _GLIBCXX_DEBUG_PEDANTIC. libstdc++-v3/ChangeLog: * include/debug/debug.h [_GLIBCXX_DEBUG](__glibcxx_requires_string): Define using _GLIBCXX_DEBUG_PEDASSERT. [_GLIBCXX_DEBUG](__glibcxx_requires_string_len): Likewise. * include/debug/macros.h (__glibcxx_check_string, __glibcxx_check_string_len): Move... * include/debug/string (__glibcxx_check_string, __glibcxx_check_string_len): ...here. And define depending on _GLIBCXX_DEBUG_PEDANTIC no matter if _GLIBCXX_DEBUG is defined. Add using of std::string find, rfind, find_first_of, find_last_of, find_first_not_of and find_last_not_of. Remove debug implementations having no debug assertion. * testsuite/util/testsuite_string.h: New file. Provides __gnu_test::string and __gnu_test::wtring which definition depends on _GLIBCXX_DEBUG. * testsuite/21_strings/basic_string/debug/find1_neg.cc: New test case. * testsuite/21_strings/basic_string/debug/find2_neg.cc: New test case. * testsuite/21_strings/basic_string/operations/find/char/1.cc: Include <testsuite_string.h> and use __gnu_test::string. * testsuite/21_strings/basic_string/operations/find/char/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/char/3.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/char/4.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/char/5.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/char/6.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/1.cc: Include <testsuite_string.h> and use __gnu_test::wstring. * testsuite/21_strings/basic_string/operations/find/wchar_t/2.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/3.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/4.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/5.cc: Likewise. * testsuite/21_strings/basic_string/operations/find/wchar_t/6.cc: Likewise.
2022-01-03Update copyright years.Jakub Jelinek33-33/+33
2021-12-15libstdc++: Overload std::__to_address for __gnu_cxx::__normal_iterator.François Dumont1-0/+17
Prefer to overload __to_address to partially specialize std::pointer_traits because std::pointer_traits would be mostly useless. Moreover partial specialization of pointer_traits<__normal_iterator<P, C>> fails to rebind C, so you get incorrect types like __normal_iterator<long*, vector<int>>. In the case of __gnu_debug::_Safe_iterator the to_pointer method is impossible to implement correctly because we are missing the parent container to associate the iterator to. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (std::pointer_traits<__gnu_cxx::__normal_iterator<>>): Remove. (std::__to_address(const __gnu_cxx::__normal_iterator<>&)): New for C++11 to C++17. * include/debug/safe_iterator.h (std::__to_address(const __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<>, _Sequence>&)): New for C++11 to C++17. * testsuite/24_iterators/normal_iterator/to_address.cc: Add check on std::vector::iterator to validate both __gnu_cxx::__normal_iterator<> __to_address overload in normal mode and __gnu_debug::_Safe_iterator in _GLIBCXX_DEBUG mode.
2021-12-01libstdc++: Define std::__is_constant_evaluated() for internal useJonathan Wakely1-12/+3
This adds std::__is_constant_evaluated() as a C++11 wrapper for __builtin_is_constant_evaluated, but just returning false if the built-in isn't supported by the compiler. This allows us to use it throughout the library without checking __has_builtin every time. Some uses in std::vector and std::string can only be constexpr when the std::is_constant_evaluated() function actually works, so we might as well guard them with a relevant macro and call that function directly, rather than the built-in or std::__is_constant_evaluated(). The remaining checks of the __cpp_lib_is_constant_evaluated macro could now be replaced by checking __cplusplus >= 202002 instead, but there's no practical difference. We still need some kind of preprocessor check there anyway. libstdc++-v3/ChangeLog: * doc/doxygen/user.cfg.in (PREDEFINED): Change macro name. * include/bits/allocator.h (allocate, deallocate): Use std::__is_constant_evaluated() unconditionally, instead of checking whether std::is_constant_evaluated() (or the built-in) can be used. * include/bits/basic_string.h: Check new macro. call std::is_constant_evaluated() directly in C++20-only code that is guarded by a suitable macro. * include/bits/basic_string.tcc: Likewise. * include/bits/c++config (__is_constant_evaluated): Define. (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Replace with ... (_GLIBCXX_HAVE_IS_CONSTANT_EVALUATED): New macro. * include/bits/char_traits.h (char_traits): Replace conditional calls to std::is_constant_evaluated with unconditional calls to std::__is_constant_evaluated. * include/bits/cow_string.h: Use new macro. * include/bits/ranges_algobase.h (__copy_or_move): Replace conditional calls to std::is_constant_evaluated with unconditional calls to std::__is_constant_evaluated. (__copy_or_move_backward, __fill_n_fn): Likewise. * include/bits/ranges_cmp.h (ranges::less): Likewise. * include/bits/stl_algobase.h (lexicographical_compare_three_way): Likewise. * include/bits/stl_bvector.h: Call std::is_constant_evaluated directly in C++20-only code that is guarded by a suitable macro. * include/bits/stl_construct.h (_Construct, _Destroy, _Destroy_n): Replace is_constant_evaluated with __is_constant_evaluated. * include/bits/stl_function.h (greater, less, greater_equal) (less_equal): Replace __builtin_is_constant_evaluated and __builtin_constant_p with __is_constant_evaluated. * include/bits/stl_vector.h: Call std::is_constant_evaluated() in C++20-only code. * include/debug/helper_functions.h (__check_singular): Use __is_constant_evaluated instead of built-in, or remove check entirely. * include/std/array (operator<=>): Use __is_constant_evaluated unconditionally. * include/std/bit (__bit_ceil): Likewise. * include/std/type_traits (is_constant_evaluated): Define using 'if consteval' if possible. * include/std/version: Use new macro. * libsupc++/compare: Use __is_constant_evaluated instead of __builtin_is_constant_evaluated. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error lines.