aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
AgeCommit message (Collapse)AuthorFilesLines
2024-10-27libstdc++: Fix std::vector<bool>::emplace to forward parameterJonathan Wakely1-2/+2
If the parameter is not lvalue-convertible to bool then the current code will fail to compile. The parameter should be forwarded to restore the original value category. libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (emplace_back, emplace): Forward parameter pack to preserve value category. * testsuite/23_containers/vector/bool/emplace_rvalue.cc: New test.
2024-10-25libstdc++: implement concatenation of strings and string_viewsGiuseppe D'Angelo3-1/+59
This adds support for P2591R5, merged for C++26. libstdc++-v3/ChangeLog: * include/bits/basic_string.h: Implement the four operator+ overloads between basic_string and (types convertible to) basic_string_view. * include/bits/version.def: Bump the feature-testing macro. * include/bits/version.h: Regenerate. * testsuite/21_strings/basic_string/operators/char/op_plus_fspath_neg.cc: New test. * testsuite/21_strings/basic_string/operators/char/op_plus_string_view.cc: New test. * testsuite/21_strings/basic_string/operators/char/op_plus_string_view_compat.cc: New test. Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2024-10-25non-gcc: Remove trailing whitespaceJakub Jelinek87-903/+903
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-24libstdc++: Simplify std::__throw_bad_variant_accessJonathan Wakely1-17/+15
This removes the overload of __throw_bad_variant_access that must be called with a string literal. This avoids a potential source of undefined behaviour if that function got misused. The other overload that takes a bool parameter can be adjusted to take an integer index selecting one of the four possible string literals to use, ensuring that the std::bad_variant_access constructor is only called with those literals. Passing an index outside the range [0,3] is bogus, but will still select a valid string literal and avoid undefined behaviour. libstdc++-v3/ChangeLog: * include/std/variant (__throw_bad_variant_access(unsigned)): Define new function as inline friend, with namespace-scope declaration using noreturn attribute. (__throw_bad_variant_access(const char*)): Remove. (__throw_bad_variant_access(bool)): Remove. (visit, visit<R>): Adjust calls to __throw_bad_variant_access. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-23libstdc++: Replace std::__to_address in C++20 branch in <string>Jonathan Wakely1-1/+1
As noted by Patrick, r15-4546-g85e5b80ee2de80 should have changed the usage of std::__to_address to std::to_address in the C++20-specific branch that works on types satisfying std::contiguous_iterator. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (assign(Iter, Iter)): Call std::to_address instead of __to_address. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-23libstdc++: Always instantiate key_type to compute hash code [PR115285]François Dumont1-4/+1
Even if it is possible to compute a hash code from the inserted arguments we need to instantiate the key_type to guaranty hash code consistency. Preserve the lazy instantiation of the mapped_type in the context of associative containers. libstdc++-v3/ChangeLog: PR libstdc++/115285 * include/bits/hashtable.h (_S_forward_key<_Kt>): Always return a temporary key_type instance. * testsuite/23_containers/unordered_map/96088.cc: Adapt to additional instanciation. Also check that mapped_type is not instantiated when there is no insertion. * testsuite/23_containers/unordered_multimap/96088.cc: Adapt to additional instanciation. * testsuite/23_containers/unordered_multiset/96088.cc: Likewise. * testsuite/23_containers/unordered_set/96088.cc: Likewise. * testsuite/23_containers/unordered_set/pr115285.cc: New test case.
2024-10-22libstdc++: Implement LWG 4166 changes to concat_view::end()Patrick Palka1-4/+6
This patch proactively implements the proposed resolution for this LWG issue, which seems straightforward and slated to get approved as-is. (No _GLIBCXX_RESOLVE_LIB_DEFECTS code comment is added since concat_view is C++26, so this isn't a defect against a published standard.) libstdc++-v3/ChangeLog: * include/std/ranges (concat_view::begin): Add space after 'requires' starting a requires-clause. (concat_view::end): Likewise. Refine condition for returning an iterator rather than default_sentinel as per LWG 4166. * testsuite/std/ranges/concat/1.cc (test03): Verify LWG 4166 example. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-22libstdc++: Avoid using std::__to_address with iteratorsJonathan Wakely7-43/+31
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-10-21libstdc++: Simplify C++98 std::vector::_M_data_ptr overload setJonathan Wakely1-11/+1
We don't need separate overloads for returning a const or non-const pointer. We can make the member function const and return a non-const pointer, and let vector::data() const convert it to const as needed. libstdc++-v3/ChangeLog: * include/bits/stl_vector.h (vector::_M_data_ptr): Remove non-const overloads. Always return non-const pointer.
2024-10-21libstdc++: Fix order of [[...]] and __attribute__((...)) attrs [PR117220]Jonathan Wakely1-23/+23
GCC allows these in either order, but Clang doesn't like the C++11-style [[__nodiscard__]] coming after __attribute__((__always_inline__)). libstdc++-v3/ChangeLog: PR libstdc++/117220 * include/bits/stl_iterator.h: Move _GLIBCXX_NODISCARD annotations after __attribute__((__always_inline__)).
2024-10-18libstdc++: Reuse std::__assign_one in <bits/ranges_algobase.h>Jonathan Wakely1-16/+6
Use std::__assign_one instead of ranges::__assign_one. Adjust the uses, because std::__assign_one has the arguments in the opposite order (the same order as an assignment expression). libstdc++-v3/ChangeLog: * include/bits/ranges_algobase.h (ranges::__assign_one): Remove. (__copy_or_move, __copy_or_move_backward): Use std::__assign_one instead of ranges::__assign_one. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Add always_inline to some one-liners in <bits/stl_algobase.h>Jonathan Wakely1-0/+14
We implement std::copy, std::fill etc. as a series of calls to other overloads which incrementally peel off layers of iterator wrappers. This adds a high abstraction penalty for -O0 and potentially even -O1. Add the always_inline attribute to several functions that are just a single return statement (and maybe a static_assert, or some concept-checking assertions which are disabled by default). libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__copy_move_a1, __copy_move_a) (__copy_move_backward_a1, __copy_move_backward_a, move_backward) (__fill_a1, __fill_a, fill, __fill_n_a, fill_n, __equal_aux): Add always_inline attribute to one-line forwarding functions. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Add nodiscard to std::findJonathan Wakely1-1/+1
I missed this one out in r14-9478-gdf483ebd24689a but I don't think that was intentional. I see no reason std::find shouldn't be [[nodiscard]]. libstdc++-v3/ChangeLog: * include/bits/stl_algo.h (find): Add nodiscard. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Inline memmove optimizations for std::copy etc. [PR115444]Jonathan Wakely2-222/+214
This removes all the __copy_move class template specializations that decide how to optimize std::copy and std::copy_n. We can inline those optimizations into the algorithms, using if-constexpr (and macros for C++98 compatibility) and remove the code dispatching to the various class template specializations. Doing this means we implement the optimization directly for std::copy_n instead of deferring to std::copy, That avoids the unwanted consequence of advancing the iterator in copy_n only to take the difference later to get back to the length that we already had in copy_n originally (as described in PR 115444). With the new flattened implementations, we can also lower contiguous iterators to pointers in std::copy/std::copy_n/std::copy_backwards, so that they benefit from the same memmove optimizations as pointers. There's a subtlety though: contiguous iterators can potentially throw exceptions to exit the algorithm early. So we can only transform the loop to memmove if dereferencing the iterator is noexcept. We don't check that incrementing the iterator is noexcept because we advance the contiguous iterators before using memmove, so that if incrementing would throw, that happens first. I am writing a proposal (P3349R0) which would make this unnecessary, so I hope we can drop the nothrow requirements later. This change also solves PR 114817 by checking is_trivially_assignable before optimizing copy/copy_n etc. to memmove. It's not enough to check that the types are trivially copyable (a precondition for using memmove at all), we also need to check that the specific assignment that would be performed by the algorithm is also trivial. Replacing a non-trivial assignment with memmove would be observable, so not allowed. libstdc++-v3/ChangeLog: PR libstdc++/115444 PR libstdc++/114817 * include/bits/stl_algo.h (__copy_n): Remove generic overload and overload for random access iterators. (copy_n): Inline generic version of __copy_n here. Do not defer to std::copy for random access iterators. * include/bits/stl_algobase.h (__copy_move): Remove. (__nothrow_contiguous_iterator, __memcpyable_iterators): New concepts. (__assign_one, _GLIBCXX_TO_ADDR, _GLIBCXX_ADVANCE): New helpers. (__copy_move_a2): Inline __copy_move logic and conditional memmove optimization into the most generic overload. (__copy_n_a): Likewise. (__copy_move_backward): Remove. (__copy_move_backward_a2): Inline __copy_move_backward logic and memmove optimization into the most generic overload. * testsuite/20_util/specialized_algorithms/uninitialized_copy/114817.cc: New test. * testsuite/20_util/specialized_algorithms/uninitialized_copy_n/114817.cc: New test. * testsuite/25_algorithms/copy/114817.cc: New test. * testsuite/25_algorithms/copy/115444.cc: New test. * testsuite/25_algorithms/copy_n/114817.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Make __normal_iterator constexpr, always_inline, nodiscardJonathan Wakely1-45/+71
The __gnu_cxx::__normal_iterator type we use for std::vector::iterator is not specified by the standard, it's an implementation detail. This means it's not constrained by the rule that forbids strengthening constexpr. We can make it meet the constexpr iterator requirements for older standards, not only when it's required to be for C++20. For the non-const member functions they can't be constexpr in C++11, so use _GLIBCXX14_CONSTEXPR for those. For all constructors, const members and non-member operator overloads, use _GLIBCXX_CONSTEXPR or just constexpr. We can also liberally add [[nodiscard]] and [[gnu::always_inline]] attributes to those functions. Also change some internal helpers for std::move_iterator which can be unconditionally constexpr and marked nodiscard. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__normal_iterator): Make all members and overloaded operators constexpr before C++20, and add always_inline attribute (__to_address): Add nodiscard and always_inline attributes. (__make_move_if_noexcept_iterator): Add nodiscard and make unconditionally constexpr. (__niter_base(__normal_iterator), __niter_base(Iter)): Add nodiscard and always_inline attributes. (__niter_base(reverse_iterator), __niter_base(move_iterator)) (__miter_base): Add inline. (__niter_wrap(From, To)): Add nodiscard attribute. (__niter_wrap(const Iter&, Iter)): Add nodiscard and always_inline attributes. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Refactor std::uninitialized_{copy,fill,fill_n} algos [PR68350]Jonathan Wakely1-90/+289
This refactors the std::uninitialized_copy, std::uninitialized_fill and std::uninitialized_fill_n algorithms to directly perform memcpy/memset optimizations instead of dispatching to std::copy/std::fill/std::fill_n. The reasons for this are: - Use 'if constexpr' to simplify and optimize compilation throughput, so dispatching to specialized class templates is only needed for C++98 mode. - Use memcpy instead of memmove, because the conditions on non-overlapping ranges are stronger for std::uninitialized_copy than for std::copy. Using memcpy might be a minor optimization. - No special case for creating a range of one element, which std::copy needs to deal with (see PR libstdc++/108846). The uninitialized algos create new objects, which reuses storage and is allowed to clobber tail padding. - Relax the conditions for using memcpy/memset, because the C++20 rules on implicit-lifetime types mean that we can rely on memcpy to begin lifetimes of trivially copyable types. We don't need to require trivially default constructible, so don't need to limit the optimization to trivial types. See PR 68350 for more details. - Remove the dependency on std::copy and std::fill. This should mean that stl_uninitialized.h no longer needs to include all of stl_algobase.h. This isn't quite true yet, because we still use std::fill in __uninitialized_default and still use std::fill_n in __uninitialized_default_n. That will be fixed later. Several tests need changes to the diagnostics matched by dg-error because we no longer use the __constructible() function that had a static assert in. Now we just get straightforward errors for attempting to use a deleted constructor. Two tests needed more signficant changes to the actual expected results of executing the tests, because they were checking for old behaviour which was incorrect according to the standard. 20_util/specialized_algorithms/uninitialized_copy/64476.cc was expecting std::copy to be used for a call to std::uninitialized_copy involving two trivially copyable types. That was incorrect behaviour, because a non-trivial constructor should have been used, but using std::copy used trivial default initialization followed by assignment. 20_util/specialized_algorithms/uninitialized_fill_n/sizes.cc was testing the behaviour with a non-integral Size passed to uninitialized_fill_n, but I wrote the test looking at the requirements of uninitialized_copy_n which are not the same as uninitialized_fill_n. The former uses --n and tests n > 0, but the latter just tests n-- (which will never be false for a floating-point value with a fractional part). libstdc++-v3/ChangeLog: PR libstdc++/68350 PR libstdc++/93059 * include/bits/stl_uninitialized.h (__check_constructible) (_GLIBCXX_USE_ASSIGN_FOR_INIT): Remove. [C++98] (__unwrappable_niter): New trait. (__uninitialized_copy<true>): Replace use of std::copy. (uninitialized_copy): Fix Doxygen comments. Open-code memcpy optimization for C++11 and later. (__uninitialized_fill<true>): Replace use of std::fill. (uninitialized_fill): Fix Doxygen comments. Open-code memset optimization for C++11 and later. (__uninitialized_fill_n<true>): Replace use of std::fill_n. (uninitialized_fill_n): Fix Doxygen comments. Open-code memset optimization for C++11 and later. * testsuite/20_util/specialized_algorithms/uninitialized_copy/64476.cc: Adjust expected behaviour to match what the standard specifies. * testsuite/20_util/specialized_algorithms/uninitialized_fill_n/sizes.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_copy/1.cc: Adjust dg-error directives. * testsuite/20_util/specialized_algorithms/uninitialized_copy/89164.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_copy_n/89164.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_fill/89164.cc: Likewise. * testsuite/20_util/specialized_algorithms/uninitialized_fill_n/89164.cc: Likewise. * testsuite/23_containers/vector/cons/89164.cc: Likewise. * testsuite/23_containers/vector/cons/89164_c++17.cc: Likewise. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-18libstdc++: Move std::__niter_base and std::__niter_wrap to stl_iterator.hJonathan Wakely2-80/+103
Move the functions for unwrapping and rewrapping __normal_iterator objects to the same file as the definition of __normal_iterator itself. This will allow a later commit to make use of std::__niter_base in other headers without having to include all of <bits/stl_algobase.h>. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (__niter_base, __niter_wrap): Move to ... * include/bits/stl_iterator.h: ... here. (__niter_base, __miter_base): Move all overloads to the end of the header. * testsuite/24_iterators/normal_iterator/wrapping.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-15libstdc++: Implement LWG 3798 for range adaptors [PR106676]Jonathan Wakely2-6/+16
LWG 3798 modified the iterator_category of the iterator types for transform_view, join_with_view, zip_transform_view and adjacent_transform_view, to allow the iterator's reference type to be an rvalue reference. libstdc++-v3/ChangeLog: PR libstdc++/106676 * include/bits/iterator_concepts.h (__cpp17_fwd_iterator): Use is_reference instead of is_value_reference. rvalue references. * include/std/ranges (transform_view:__iter_cat::_S_iter_cat): Likewise. (zip_transform_view::__iter_cat::_S_iter_cat): Likewise. (adjacent_transform_view::__iter_cat::_S_iter_cat): Likewise. (join_with_view::__iter_cat::_S_iter_cat): Likewise. * testsuite/std/ranges/adaptors/transform.cc: Check iterator_category when the transformation function returns an rvalue reference type. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-14libstdc++: Implement LWG 3564 for ranges::transform_viewJonathan Wakely1-2/+7
The _Iterator<true> type returned by begin() const uses const F& to transform the elements, so it should use const F& to determine the iterator's value_type and iterator_category as well. This was accepted into the WP in July 2022. libstdc++-v3/ChangeLog: * include/std/ranges (transform_view:_Iterator): Use const F& to determine value_type and iterator_category of _Iterator<true>, as per LWG 3564. * testsuite/std/ranges/adaptors/transform.cc: Check value_type and iterator_category. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2024-10-14libstdc++: Constrain std::expected comparisons (P3379R0)Jonathan Wakely3-9/+28
This proposal of mine has been approved by LEWG and forwarded to LWG. I expect it to be voted into the draft without significant changes. libstdc++-v3/ChangeLog: * include/bits/version.def (constrained_equality): Bump value. * include/bits/version.h: Regenerate. * include/std/expected (operator==): Add constraints and noexcept specifiers. * testsuite/20_util/optional/relops/constrained.cc: Adjust check for feature test macro. * testsuite/20_util/pair/comparison_operators/constrained.cc: Likewise. * testsuite/20_util/tuple/comparison_operators/constrained.cc: Likewise. * testsuite/20_util/variant/relops/constrained.cc: Likewise. * testsuite/20_util/expected/equality_constrained.cc: New test.
2024-10-14libstdc++: Use std::move for iterator in ranges::fill [PR117094]Jonathan Wakely1-1/+1
Input iterators aren't required to be copyable. libstdc++-v3/ChangeLog: PR libstdc++/117094 * include/bits/ranges_algobase.h (__fill_fn): Use std::move for iterator that might not be copyable. * testsuite/25_algorithms/fill/constrained.cc: Check non-copyable iterator with sized sentinel.
2024-10-14libstdc++: Enable memset optimizations for distinct character types [PR93059]Jonathan Wakely1-8/+12
Currently we only optimize std::fill to memset when the source and destination types are the same byte-sized type. This means that we fail to optimize cases like std::fill(buf. buf+n, 0) because the literal 0 is not the same type as the character buffer. Such cases can safely be optimized to use memset, because assigning an int (or other integer) to a narrow character type has the same effects as converting the integer to unsigned char then copying it with memset. This patch enables the optimized code path when the fill character is a memcpy-able integer (using the new __memcpyable_integer trait). We still need to check is_same<U, T> to enable the memset optimization for filling a range of std::byte with a std::byte value, because that isn't a memcpyable integer. libstdc++-v3/ChangeLog: PR libstdc++/93059 * include/bits/stl_algobase.h (__fill_a1(T*, T*, const T&)): Change template parameters and enable_if condition to allow the fill value to be an integer.
2024-10-14libstdc++: Enable memcpy optimizations for distinct integral types [PR93059]Jonathan Wakely1-2/+87
Currently we only optimize std::copy, std::copy_n etc. to memmove when the source and destination types are the same. This means that we fail to optimize copying between distinct 1-byte types, e.g. copying from a buffer of unsigned char to a buffer of char8_t or vice versa. This patch adds more partial specializations of the __memcpyable trait so that we allow memcpy between integers of equal widths. This will enable memmove for copies between narrow character types and also between same-width types like int and unsigned. Enabling the optimization needs to be based on the width of the integer type, not just the size in bytes. This is because some targets define non-standard integral types such as __int20 in msp430, which has padding bits. It would not be safe to memcpy between e.g. __int20 and int32_t, even though sizeof(__int20) == sizeof(int32_t). A new trait is introduced to define the width, __memcpyable_integer, and then the __memcpyable trait compares the widths. It's safe to copy between signed and unsigned integers of the same width, because GCC only supports two's complement integers. I initially though it would be useful to define the specialization __memcpyable_integer<byte> to enable copying between narrow character types and std::byte. But that isn't possible with std::copy, because is_assignable<char&, std::byte> is false. Optimized copies using memmove will already happen for copying std::byte to std::byte, because __memcpyable<T*, T*> is true. libstdc++-v3/ChangeLog: PR libstdc++/93059 * include/bits/cpp_type_traits.h (__memcpyable): Add partial specialization for pointers to distinct types. (__memcpyable_integer): New trait to control which types can use cross-type memcpy optimizations.
2024-10-13libstdc++: Fix ranges::copy_backward for a single memcpyable element [PR117121]Jonathan Wakely1-2/+3
The result iterator needs to be decremented before writing to it. Improve the PR 108846 tests for all of std::copy, std::copy_n, std::copy_backward, and the std::ranges versions. libstdc++-v3/ChangeLog: PR libstdc++/117121 * include/bits/ranges_algobase.h (copy_backward): Decrement output iterator before assigning one element through it. * testsuite/25_algorithms/copy/108846.cc: Ensure the algorithm's effects are correct for a single memcpyable element. * testsuite/25_algorithms/copy_backward/108846.cc: Likewise. * testsuite/25_algorithms/copy_n/108846.cc: Likewise.
2024-10-11libstdc++: Rearrange std::move_iterator helpers in stl_iterator.hJonathan Wakely1-32/+31
The __niter_base(move_iterator<I>) overload and __is_move_iterator trait were originally immediately after the definition of move_iterator. The addition of C++20 features after move_iterator meant that those helpers were no longer anywhere near move_iterator. This change puts them back where they used to be, before all the new C++20 additions. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (__niter_base(move_iterator<I>)) (__is_move_iterator, __miter_base, _GLIBCXX_MAKE_MOVE_ITERATOR) (_GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR): Move earlier in the file.
2024-10-11libstdc++: Use appropriate feature test macro for std::byteJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_byte<byte>): Guard with __glibcxx_byte macro instead of checking __cplusplus.
2024-10-11libstdc++: Fix localized %c formatting for <chrono> [PR117085]Jonathan Wakely1-6/+8
When formatting a time point with %c we call std::vformat_to using the formatting locale's D_T_FMT string, but we weren't adding the L option to the format string. This meant we always interpreted D_T_FMT in the C locale, instead of using the formatting locale as obviously intended when %c is used. libstdc++-v3/ChangeLog: PR libstdc++/117085 * include/bits/chrono_io.h (__formatter_chrono::_M_c): Add L option to format string. * testsuite/std/time/format.cc: Move to... * testsuite/std/time/format/format.cc: ...here. * testsuite/std/time/format_localized.cc: Move to... * testsuite/std/time/format/localized.cc: ...here. * testsuite/std/time/format/pr117085.cc: New test.
2024-10-09libstdc++: Drop format attribute from snprintf wrapper [PR116969]Jonathan Wakely1-5/+8
When __LONG_DOUBLE_IEEE128__ is defined we need to declare a wrapper for Glibc's 'snprintf' symbol, so we can call the original definition that works with the IBM128 format of long double. Because we were declaring the wrapper using __typeof__(__builtin_snprintf) it inherited the __attribute__((format(printf, 3, 4))) decoration, and then we got a warning for calling that wrapper with an __ibm128 argument for a %Lf conversion specifier. The warning is bogus, because the function we're calling really does want __ibm128 for %Lf, but there's no "printf but with a different long double format" archetype for the attribute. In r15-4039-g28911f626864e7 I added a diagnostic pragma to suppress the warning, but it would be better to just declare the wrapper without the attribute, and not have to suppress a warning for code that we know is actually correct. libstdc++-v3/ChangeLog: PR libstdc++/116969 * include/bits/locale_facets_nonio.tcc (money_put::__do_put): Remove diagnostic pragmas. (__glibcxx_snprintfibm128): Declare type manually, instead of using __typeof__(__builtin_snprintf).
2024-10-09libstdc++: Ignore _GLIBCXX_USE_POSIX_SEMAPHORE if not supported [PR116992]Jonathan Wakely1-0/+3
If _GLIBCXX_HAVE_POSIX_SEMAPHRE is undefined then users get an error when defining _GLIBCXX_USE_POSIX_SEMAPHORE. We can just ignore it instead (and warn them it's being ignored). This fixes a testsuite failure on hppa64-hp-hpux11.11 (and probably some other targets): FAIL: 30_threads/semaphore/platform_try_acquire_for.cc -std=gnu++20 (test for excess errors) Excess errors: semaphore:49: error: '__semaphore_impl' has not been declared libstdc++-v3/ChangeLog: PR libstdc++/116992 * include/bits/semaphore_base.h (_GLIBCXX_USE_POSIX_SEMAPHORE): Undefine and issue a warning if POSIX sem_t is not supported. * testsuite/30_threads/semaphore/platform_try_acquire_for.cc: Prune new warning.
2024-10-09libstdc++: Fix -Wnarrowing in <complex> [PR116991]Jonathan Wakely1-1/+1
When _GLIBCXX_USE_C99_COMPLEX_ARC is undefined we use the generic __complex_acos function template for _Float32 etc. and that gives a -Wnarrowing warning: complex:2043: warning: ISO C++ does not allow converting to '_Float32' from 'long double' with greater conversion rank [-Wnarrowing] Use a cast to do the conversion so that it doesn't warn. libstdc++-v3/ChangeLog: PR libstdc++/116991 * include/std/complex (__complex_acos): Cast literal to destination type.
2024-10-09libstdc++: Fix -Wsign-compare in std::latch::count_downJonathan Wakely1-1/+5
Also add assertions for the precondition on the parameter's value. libstdc++-v3/ChangeLog: * include/std/latch (latch::count_down): Add assertions for preconditions. Cast parameter to avoid -Wsign-compare on some targets.
2024-10-09libstdc++: Enable _GLIBCXX_ASSERTIONS by default for -O0 [PR112808]Jonathan Wakely1-2/+7
Too many users don't know about -D_GLIBCXX_ASSERTIONS and so are missing valuable checks for C++ standard library preconditions. This change enables libstdc++ assertions by default when compiling with -O0 so that we diagnose more bugs by default. When users enable optimization we don't add the assertions by default (because they have non-zero overhead) so they still need to enable them manually. For users who really don't want the assertions even in unoptimized builds, defining _GLIBCXX_NO_ASSERTIONS will prevent them from being enabled automatically. libstdc++-v3/ChangeLog: PR libstdc++/112808 * doc/xml/manual/using.xml (_GLIBCXX_ASSERTIONS): Document implicit definition for -O0 compilation. (_GLIBCXX_NO_ASSERTIONS): Document. * doc/html/manual/using_macros.html: Regenerate. * include/bits/c++config [!__OPTIMIZE__] (_GLIBCXX_ASSERTIONS): Define for unoptimized builds.
2024-10-09libstdc++: Simplify std::aligned_storage and fix for versioned namespace ↵Jonathan Wakely1-24/+59
[PR61458] This simplifies the implementation of std::aligned_storage. For the unstable ABI it also fixes the bug where its size is too large when the default alignment is used. We can't fix that for the stable ABI though, so just add a comment about the bug. libstdc++-v3/ChangeLog: PR libstdc++/61458 * doc/doxygen/user.cfg.in (GENERATE_BUGLIST): Set to NO. * include/std/type_traits (__aligned_storage_msa): Remove. (__aligned_storage_max_align_t): New struct. (__aligned_storage_default_alignment): New function. (aligned_storage): Use __aligned_storage_default_alignment for default alignment. Replace union with a struct containing an aligned buffer. Improve Doxygen comment. (aligned_storage_t): Use __aligned_storage_default_alignment for default alignment.
2024-10-09libstdc++: Do not cast away const-ness in std::construct_at (LWG 3870)Jonathan Wakely3-11/+12
This change also requires implementing the proposed resolution of LWG 3216 so that std::make_shared and std::allocate_shared still work, and the proposed resolution of LWG 3891 so that std::expected still works. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_base.h: Remove cv-qualifiers from type managed by _Sp_counted_ptr_inplace, as per LWG 3210. * include/bits/stl_construct.h: Do not cast away cv-qualifiers when passing pointer to placement new. * include/std/expected: Use remove_cv_t for union member, as per LWG 3891. * testsuite/20_util/allocator/void.cc: Do not test construction via const pointer.
2024-10-09libstdc++: Make std::construct_at support arrays (LWG 3436)Jonathan Wakely1-3/+17
The issue was approved at the recent St. Louis meeting, requiring support for bounded arrays, but only without arguments to initialize the array elements. libstdc++-v3/ChangeLog: * include/bits/stl_construct.h (construct_at): Support array types (LWG 3436). * testsuite/20_util/specialized_algorithms/construct_at/array.cc: New test. * testsuite/20_util/specialized_algorithms/construct_at/array_neg.cc: New test. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-opt1.C: Adjust for different diagnostics from std::construct_at by adding -fconcepts-diagnostics-depth=2.
2024-10-09libstdc++: Tweak %c formatting for chrono typesJonathan Wakely1-2/+2
libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_c): Add [[unlikely]] attribute to condition for missing %c format in locale. Use %T instead of %H:%M:%S in fallback.
2024-10-09libstdc++: Fix formatting of chrono::duration with character rep [PR116755]Jonathan Wakely1-2/+7
Implement Peter Dimov's suggestion for resolving LWG 4118, which is to use +d.count() so that character types are promoted to an integer type before formatting them. This didn't have unanimous consensus in the committee as Howard Hinnant proposed that we should format the rep consistently with std::format("{}", d.count()) instead. That ends up being more complicated, because it makes std::formattable a precondition of operator<< which was not previously the case, and it means that ios_base::fmtflags from the stream would be ignored because std::format doesn't use them. libstdc++-v3/ChangeLog: PR libstdc++/116755 * include/bits/chrono_io.h (operator<<): Use +d.count() for duration inserter. (__formatter_chrono::_M_format): Likewise for %Q format. * testsuite/20_util/duration/io.cc: Test durations with character types as reps.
2024-10-08contrib, libcpp, libstdc++: Update to Unicode 16.0Jakub Jelinek2-318/+389
It is autumn again and there is a new Unicode version 16.0. The following patch updates our Unicode stuff in contrib, libcpp and libstdc++ from that Unicode version. 2024-10-08 Jakub Jelinek <jakub@redhat.com> contrib/ * unicode/README: Update glibc git commit hash, replace Unicode 15 or 15.1 versions with 16. * unicode/gen_libstdcxx_unicode_data.py: Use 160000 instead of 150100 in _GLIBCXX_GET_UNICODE_DATA test. * unicode/from_glibc/utf8_gen.py: Updated from glibc 064c708c78cc2a6b5802dce73108fc0c1c6bfc80 commit. * unicode/DerivedCoreProperties.txt: Updated from Unicode 16.0. * unicode/emoji-data.txt: Likewise. * unicode/PropList.txt: Likewise. * unicode/GraphemeBreakProperty.txt: Likewise. * unicode/DerivedNormalizationProps.txt: Likewise. * unicode/NameAliases.txt: Likewise. * unicode/UnicodeData.txt: Likewise. * unicode/EastAsianWidth.txt: Likewise. gcc/testsuite/ * c-c++-common/cpp/named-universal-char-escape-1.c: Add tests for some Unicode 16.0 characters, both normal and generated. libcpp/ * makeucnid.cc (write_copyright): Update Unicode Copyright years. * makeuname2c.cc (generated_ranges): Adjust Unicode version from 15.1 to 16.0. Add EGYPTIAN HIEROGLYPH- generated range, adjust indexes in following entries. (write_copyright): Update Unicode Copyright years. * generated_cpp_wcwidth.h: Regenerated. * ucnid.h: Regenerated. * uname2c.h: Regenerated. libstdc++-v3/ * include/bits/unicode.h (std::__unicode::__v15_1_0): Rename inline namespace to ... (std::__unicode::__v16_0_0): ... this. (_GLIBCXX_GET_UNICODE_DATA): Change from 150100 to 160000. * include/bits/unicode-data.h: Regenerated. * testsuite/ext/unicode/properties.cc: Check for _Gcb_SpacingMark on U+11F03 rather than U+1D16D as the latter lost SpacingMark property in Unicode 16.0.
2024-10-05libstdc++: add std::is_virtual_base_ofGiuseppe D'Angelo3-0/+33
Added by P2985R0 for C++26. This simply exposes the compiler builtin, and adds the feature-testing macro. libstdc++-v3/ChangeLog: * include/bits/version.def: Added the feature-testing macro. * include/bits/version.h: Regenerated. * include/std/type_traits: Add support for std::is_virtual_base_of and std::is_virtual_base_of_v, implemented in terms of the compiler builtin. * testsuite/20_util/is_virtual_base_of/value.cc: New test. Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-05libstdc++: Implement LWG 3664 changes to ranges::distancePatrick Palka1-7/+7
libstdc++-v3/ChangeLog: * include/bits/ranges_base.h (__distance_fn::operator()): Adjust iterator/sentinel overloads as per LWG 3664. * testsuite/24_iterators/range_operations/distance.cc: Test LWG 3664 example. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-04libstdc++/ranges: Implement various small LWG issuesPatrick Palka1-8/+76
This implements the following small LWG issues: 3848. adjacent_view, adjacent_transform_view and slide_view missing base accessor 3851. chunk_view::inner-iterator missing custom iter_move and iter_swap 3947. Unexpected constraints on adjacent_transform_view::base() 4001. iota_view should provide empty 4012. common_view::begin/end are missing the simple-view check 4013. lazy_split_view::outer-iterator::value_type should not provide default constructor 4035. single_view should provide empty 4053. Unary call to std::views::repeat does not decay the argument 4054. Repeating a repeat_view should repeat the view libstdc++-v3/ChangeLog: * include/std/ranges (single_view::empty): Define as per LWG 4035. (iota_view::empty): Define as per LWG 4001. (lazy_split_view::_OuterIter::value_type): Remove default constructor and make other constructor private as per LWG 4013. (common_view::begin): Disable non-const overload for simple views as per LWG 4012. (common_view::end): Likewise. (adjacent_view::base): Define as per LWG 3848. (adjacent_transform_view::base): Likewise. (chunk_view::_InnerIter::iter_move): Define as per LWG 3851. (chunk_view::_InnerIter::itep_swap): Likewise. (slide_view::base): Define as per LWG 3848. (repeat_view): Adjust deduction guide as per LWG 4053. (_Repeat::operator()): Adjust single-parameter overload as per LWG 4054. * testsuite/std/ranges/adaptors/adjacent/1.cc: Verify existence of base member function. * testsuite/std/ranges/adaptors/adjacent_transform/1.cc: Likewise. * testsuite/std/ranges/adaptors/chunk/1.cc: Test LWG 3851 example. * testsuite/std/ranges/adaptors/slide/1.cc: Verify existence of base member function. * testsuite/std/ranges/iota/iota_view.cc: Test LWG 4001 example. * testsuite/std/ranges/repeat/1.cc: Test LWG 4053/4054 examples. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-04libstdc++: Fix some Parallel Mode testsuite failuresJonathan Wakely8-3/+26
Some of these are due to no longer using #pragma GCC system_header in libstdc++ headers, some have been failing for longer and weren't noticed. libstdc++-v3/ChangeLog: * include/parallel/algobase.h (search): Use sequential algorithm for constant evaluation. * include/parallel/algorithmfwd.h (search): Add _GLIBCXX20_CONSTEXPR. * include/parallel/multiway_merge.h: Remove stray semi-colon. * include/parallel/multiseq_selection.h: Add diagnostic pragmas for -Wlong-long warning. * include/parallel/quicksort.h: Likewise. * include/parallel/random_number.h: Likewise. * include/parallel/settings.h: Likewise. * include/parallel/workstealing.h: Replace ++ and -- on volatile variables. * testsuite/17_intro/names.cc: Skip names defined by <tr1/random>. * testsuite/20_util/pair/dangling_ref.cc: Skip test if Parallel Mode is enabled. * testsuite/20_util/tuple/dangling_ref.cc: Likewise.
2024-10-04libstdc++: Replace implicit lambda capture of 'this' [PR116964]Jonathan Wakely1-6/+6
C++20 deprecates implicit capture of 'this', so change [=] to [this] for all lambda expressions in <shared_mutex>. This only shows up on targets where _GLIBCXX_USE_PTHREAD_RWLOCK_T is not defined, as we have an alternative implementation of shared mutexes in that case. libstdc++-v3/ChangeLog: PR libstdc++/116964 * include/std/shared_mutex (__shared_mutex_cv): Use [this] for lambda captures. (shared_timed_mutex) [!_GLIBCXX_USE_PTHREAD_RWLOCK_T]: Likewise.
2024-10-03libstdc++: Make Unicode utils work with Parallel ModeJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * include/bits/unicode.h (__unicode::__is_incb_linker): Use _GLIBCXX_STD_A namespace for std::find.
2024-10-03libstdc++: Fix -Wdeprecated-declarations warning for Parallel Mode [PR116944]Jonathan Wakely1-3/+3
The pragmas to disable warnings need to be moved before the first use of the deprecated classes. libstdc++-v3/ChangeLog: PR libstdc++/116944 * include/parallel/base.h: Move diagnostic pragmas earlier.
2024-10-03libstdc++: Fix some warnings seen during bootstrapJonathan Wakely2-1/+4
libstdc++-v3/ChangeLog: * include/bits/locale_facets_nonio.tcc (money_put::__do_get): Ignore -Wformat warning for __ibm128 arguments. * include/tr1/tuple (ignore): Ignore -Wunused warning.
2024-10-03libstdc++: [_Hashtable] Fix some implementation inconsistenciesFrançois Dumont2-27/+29
Get rid of the different usages of the mutable keyword except in _Prime_rehash_policy where it is preserved for abi compatibility reason. Fix comment to explain that we need the computation of bucket index noexcept to be able to rehash the container when needed. For Standard instantiations through std::unordered_xxx containers we already force caching of hash code when hash functor is not noexcep so it is guarantied. The static_assert purpose in _Hashtable on _M_bucket_index is thus limited to usages of _Hashtable with exotic _Hashtable_traits. libstdc++-v3/ChangeLog: * include/bits/hashtable_policy.h (_NodeBuilder<>::_S_build): Remove const qualification on _NodeGenerator instance. (_ReuseOrAllocNode<>::operator()(_Args&&...)): Remove const qualification. (_ReuseOrAllocNode<>::_M_nodes): Remove mutable. (_Insert_base<>::_M_insert_range): Remove _NodeGetter const qualification. (_Hash_code_base<>::_M_bucket_index(const _Hash_node_value<>&, size_t)): Simplify noexcept declaration, we already static_assert that _RangeHash functor is noexcept. * include/bits/hashtable.h: Rework comments. Remove const qualifier on _NodeGenerator& arguments. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-10-02libstdc++: Fix rounding in chrono::parseJonathan Wakely1-7/+57
I noticed that chrono::parse was using duration_cast and time_point_cast to convert the parsed value to the result. Those functions truncate towards zero, which is not generally what you want. Especially for negative times before the epoch, where truncating towards zero rounds "up" towards the next duration/time_point. Using chrono::round is typically better, as that rounds to nearest. However, while testing the fix I realised that rounding to the nearest can give surprising results in some cases. For example if we parse a chrono::sys_days using chrono::parse("F %T", "2024-09-22 18:34:56", tp) then we will round up to the next day, i.e. sys_days(2024y/09/23). That seems surprising, and I think 2024-09-22 is what most users would expect. This change attempts to provide a hybrid rounding heuristic where we use chrono::round for the general case, but when the result has a period that is one of minutes, hours, days, weeks, or years then we truncate towards negative infinity using chrono::floor. This means that we truncate "2024-09-22 18:34:56" to the start of the current minute/hour/day/week/year, instead of rounding up to 2024-09-23, or to 18:35, or 17:00. For a period of months chrono::round is used, because the months duration is defined as a twelfth of a year, which is not actually the length of any calendar month. We don't want to truncate to a whole number of "months" if that can actually go from e.g. 2023-03-01 to 2023-01-31, because February is shorter than chrono::months(1). libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__detail::__use_floor): New function. (__detail::__round): New function. (from_stream): Use __detail::__round. * testsuite/std/time/clock/file/io.cc: Check for expected rounding in parse. * testsuite/std/time/clock/gps/io.cc: Likewise.
2024-10-02libstdc++: Fix -Wlong-long warning in <bits/postypes.h>Jonathan Wakely1-0/+3
For 32-bit targets __INT64_TYPE__ expands to long long, which gives a pedwarn for C++98 mode, causing: FAIL: 17_intro/headers/c++1998/all_pedantic_errors.cc -std=gnu++98 (test for excess errors) Excess errors: .../bits/postypes.h:64: error: ISO C++ 1998 does not support 'long long' [-Wlong-long] libstdc++-v3/ChangeLog: * include/bits/postypes.h: Fix -Wlong-long warning.
2024-09-27libstdc++: Fix more pedwarns in headers for C++98Jonathan Wakely17-15/+97
Some tests e.g. 17_intro/headers/c++1998/all_pedantic_errors.cc FAIL with GLIBCXX_TESTSUITE_STDS=98 due to numerous C++11 extensions still in use in the library headers. The recent changes to not make them system headers means we get warnings now. This change adds more diagnostic pragmas to suppress those warnings. libstdc++-v3/ChangeLog: * include/bits/istream.tcc: Add diagnostic pragmas around uses of long long and extern template. * include/bits/locale_facets.h: Likewise. * include/bits/locale_facets.tcc: Likewise. * include/bits/locale_facets_nonio.tcc: Likewise. * include/bits/ostream.tcc: Likewise. * include/bits/stl_algobase.h: Likewise. * include/c_global/cstdlib: Likewise. * include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp: Likewise. * include/ext/pointer.h: Likewise. * include/ext/stdio_sync_filebuf.h: Likewise. * include/std/istream: Likewise. * include/std/ostream: Likewise. * include/tr1/cmath: Likewise. * include/tr1/type_traits: Likewise. * include/tr1/functional_hash.h: Likewise. Remove semi-colons at namespace scope that aren't needed after macro expansion. * include/tr1/tuple: Remove semi-colon at namespace scope. * include/bits/vector.tcc: Change LL suffix to just L.