aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
AgeCommit message (Collapse)AuthorFilesLines
2025-04-11libstdc++: Use constexpr-if for std::basic_string::_S_copy_charsJonathan Wakely1-1/+2
For C++11 and later we can remove four overloads of _S_copy_chars and use constexpr-if in the generic _S_copy_chars. This simplifies overload resolution for _S_copy_chars, and also means that we use the optimized memcpy path for other iterators such as std::vector<char>::iterator. We still need all the _S_copy_chars overloads to be part of the explicit instantiation definition, so make them depend on the macro that is defined by src/c++11/string-inst.cc for that purpose. For C++98 the _S_copy_chars overloads are still needed, but the macros _GLIBCXX_NOEXCEPT and _GLIBCXX20_CONSTEXPR do nothing for C++98, so this change removes them from those overloads. When instantiated in src/c++11/string-inst.cc the removed _GLIBCXX_NOEXCEPT macros would expand to 'noexcept', but in practice that doesn't make any difference for those instantiations. At -O2 the instantiations inline all the calls to _S_copy_chars and the presence or absence of noexcept doesn't change anything in the generated code. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (_S_copy_chars): Replace overloads with constexpr-if and extend optimization to all contiguous iterators. * src/c++11/string-inst.cc: Extend comment. Reviewed-by: Tomasz Kaminski <tkaminsk@redhat.com>
2025-03-30Optimize string constructorJan Hubicka1-0/+8
this patch improves code generation on string constructors. We currently have _M_construct which takes as a parameter two iterators (begin/end pointers to other string) and produces new string. This patch adds special case of constructor where instead of begining/end pointers we readily know the string size and also special case when we know that source is 0 terminated. This happens commonly when producing stirng copies. Moreover currently ipa-prop is not able to propagate information that beg-end is known constant (copied string size) which makes it impossible for inliner to spot the common case where string size is known to be shorter than 15 bytes and fits in local buffer. Finally I made new constructor inline. Because it is explicitely instantiated without C++20 constexpr we do not produce implicit instantiation (as required by standard) which prevents inlining, ipa-modref and any other IPA analysis to happen. I think we need to make many of the other functions inline, since optimization accross string manipulation is quite important. There is PR94960 to track this issue. Bootstrapped/regtested x86_64-linux, OK? libstdc++-v3/ChangeLog: PR tree-optimization/103827 PR tree-optimization/80331 PR tree-optimization/87502 * config/abi/pre/gnu.ver: Add version for _M_construct<bool> * include/bits/basic_string.h: (basic_string::_M_construct<bool>): Declare. (basic_string constructors): Use it. * include/bits/basic_string.tcc: (basic_string::_M_construct<bool>): New template. * src/c++11/string-inst.cc: Instantated S::_M_construct<bool>. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/pr80331.C: New test. * g++.dg/tree-ssa/pr87502.C: New test.
2025-03-27libstdc++: Update tzdata to 2025bJonathan Wakely1-2/+16
Import the new 2025b tzdata.zi file. libstdc++-v3/ChangeLog: * src/c++20/tzdata.zi: Import new file from 2025b release.
2025-03-21libstdc++: Fix std.compat exports of <stdbit.h> and <stdckdint.h>Jonathan Wakely1-2/+9
libstdc++-v3/ChangeLog: * src/c++23/std.compat.cc.in: Only export <stdbit.h> and <stdckdint.h> contents for C++26 and later. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-21libstdc++: Add views::cache_latest and views::to_input to std moduleJonathan Wakely1-3/+20
Also export the tuple-like helpers from <complex>, and the std::from_range_t and std::from_range tag. libstdc++-v3/ChangeLog: * src/c++23/std.cc.in (tuple_element, tuple_element_t) (tuple_size, tuple_size_v, get): Export. (ranges::cache_latest_view, views::cache_latest): Export. (ranges::to_input_view, views::to_input): Export. (from_range_t, from_range): Export. Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-03-13libstdc++: Implement <stdckdint.h> for C++26 (P3370R1)Jonathan Wakely1-0/+8
This is the second part of the P3370R1 proposal just approved by the committee in Wrocław. This adds C++ equivalents of the functions added to C23 by WG14 N2683. These functions are in the global namespace, but to avoid collisions with the same functions defined by other standard library implementations, this change defines them in namespace __gnu_cxx and then adds them to the global namespace. libstdc++-v3/ChangeLog: * include/Makefile.am: Add stdckdint.h. * include/Makefile.in: Regenerate. * src/c++23/std.compat.cc.in: Export <stdckdint.h> functions. * include/c_compatibility/stdckdint.h: New file. * testsuite/26_numerics/stdckdint/1.cc: New test. * testsuite/26_numerics/stdckdint/2_neg.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-03-13libstdc++: Implement <stdbit.h> for C++26 (P3370R1)Jonathan Wakely1-0/+29
This is the first part of the P3370R1 proposal just approved by the committee in Wrocław. This adds C++ equivalents of the functions added to C23 by WG14 N3022. These functions are in the global namespace, but to avoid collisions with the same functions defined by other standard library implementations, this change defines them in namespace __gnu_cxx and then adds them to the global namespace. libstdc++-v3/ChangeLog: * include/Makefile.am: Add stdbit.h. * include/Makefile.in: Regenerate. * src/c++23/std.compat.cc.in: Export <stdbit.h> functions. * include/c_compatibility/stdbit.h: New file. * testsuite/20_util/stdbit/1.cc: New test. * testsuite/20_util/stdbit/2_neg.cc: New test. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-03-12libstdc++: Update tzdata to 2025aJonathan Wakely2-847/+839
Import the new 2025a tzdata.zi file. The leapseconds file was also updated to have a new expiry (no new leap seconds were added). libstdc++-v3/ChangeLog: * include/std/chrono (__detail::__get_leap_second_info): Update expiry date for leap seconds list. * src/c++20/tzdata.zi: Import new file from 2025a release. * src/c++20/tzdb.cc (tzdb_list::_Node::_S_read_leap_seconds) Update expiry date for leap seconds list.
2025-03-06Fix 'libstdc++-v3/src/c++20/tzdb.cc' build for '__GTHREADS && ↵Jonathan Wakely1-1/+11
!__GTHREADS_CXX0X' configurations libstdc++-v3/ * src/c++20/tzdb.cc [__GTHREADS && !__GTHREADS_CXX0X]: Use '__gnu_cxx::__mutex'. Co-authored-by: Thomas Schwinge <tschwinge@baylibre.com>
2025-03-06libstdc++: Avoid '-Wunused-parameter' for 'out' in member function ↵Thomas Schwinge1-1/+1
'std::codecvt_base::result std::__format::{anonymous}::__encoding::conv(std::string_view, std::string&) const' In a newlib configuration: ../../../../../source-gcc/libstdc++-v3/src/c++20/format.cc: In member function ‘std::codecvt_base::result std::__format::{anonymous}::__encoding::conv(std::string_view, std::string&) const’: ../../../../../source-gcc/libstdc++-v3/src/c++20/format.cc:100:35: error: unused parameter ‘out’ [-Werror=unused-parameter] 100 | conv(string_view input, string& out) const | ~~~~~~~~^~~ libstdc++-v3/ * src/c++20/format.cc (conv): Tag 'out' as '[[maybe_unused]]'.
2025-03-06libstdc++: Avoid '-Wunused-parameter' for 'is_directory' in member function ↵Thomas Schwinge1-1/+1
'bool std::filesystem::__cxx11::_Dir::do_unlink(bool, std::error_code&) const' In a newlib configuration: ../../../../../source-gcc/libstdc++-v3/src/c++17/fs_dir.cc: In member function ‘bool std::filesystem::__cxx11::_Dir::do_unlink(bool, std::error_code&) const’: ../../../../../source-gcc/libstdc++-v3/src/c++17/fs_dir.cc:147:18: error: unused parameter ‘is_directory’ [-Werror=unused-parameter] 147 | do_unlink(bool is_directory, error_code& ec) const noexcept | ~~~~~^~~~~~~~~~~~ libstdc++-v3/ * src/c++17/fs_dir.cc (do_unlink): Tag 'is_directory' as '[[maybe_unused]]'.
2025-03-06libstdc++: Avoid '-Wunused-parameter' for 'nofollow' in static member ↵Thomas Schwinge1-1/+1
function 'static std::filesystem::__gnu_posix::DIR* std::filesystem::_Dir_base::openat(const _At_path&, bool)' In a newlib configuration: In file included from ../../../../../source-gcc/libstdc++-v3/src/c++17/fs_dir.cc:37, from ../../../../../source-gcc/libstdc++-v3/src/c++17/cow-fs_dir.cc:26: ../../../../../source-gcc/libstdc++-v3/src/c++17/../filesystem/dir-common.h: In static member function ‘static std::filesystem::__gnu_posix::DIR* std::filesystem::_Dir_base::openat(const _At_path&, bool)’: ../../../../../source-gcc/libstdc++-v3/src/c++17/../filesystem/dir-common.h:210:36: error: unused parameter ‘nofollow’ [-Werror=unused-parameter] 210 | openat(const _At_path& atp, bool nofollow) | ~~~~~^~~~~~~~ libstdc++-v3/ * src/filesystem/dir-common.h (openat): Tag 'nofollow' as '[[maybe_unused]]'.
2025-03-05libstdc++: fix possible undefined std::timespec in module stdyxj-github-4371-1/+1
I notice std::timespec and std::timespec_get are used in preprocessor condition _GLIBCXX_HAVE_TIMESPEC_GET. So in module std, it should be the same. libstdc++-v3: * src/c++23/std-clib.cc.in (timespec): Move within preprocessor group guarded by _GLIBCXX_HAVE_TIMESPEC_GET.
2025-02-22libstdc++: Fix bootstrap failure with --enable-vtable-verify [PR118981]Jonathan Wakely1-3/+3
The compiler emits code with init_priority(99) for -fvtable-verify=std and that creates a section conflict with the uses of init_priority(99) that I recently added to src/c++20/tzdb.cc. Change tzdb.cc to use a different priority to avoid the conflict. libstdc++-v3/ChangeLog: PR c++/118981 * src/c++20/tzdb.cc: Use init_priority(98) instead of init_priority(99).
2025-02-22libstdc++: Remove redundant cast in floating_from_chars.ccJonathan Wakely1-2/+1
In r15-7647-g32457bc25fea80 I added a cast and also changed the type of the variable, making the cast redundant. This removes the cast. libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc (__floating_from_chars_hex): Remove redundant cast.
2025-02-20libstdc++: Fix invalid signed arguments to <bit> functionsJonathan Wakely2-3/+5
These should have been unsigned, but the static assertions are only in the public std::bit_ceil and std::bit_width functions, not the internal __bit_ceil and __bit_width ones. libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__find_next_valid_abi): Cast __bit_ceil argument to unsigned. * src/c++17/floating_from_chars.cc (__floating_from_chars_hex): Cast __bit_ceil argument to unsigned. * src/c++17/memory_resource.cc (big_block): Cast __bit_width argument to unsigned.
2025-02-20libstdc++: Remove workaround for reserved init_priority warningsJonathan Wakely4-30/+14
Since r15-7511-g4e7f74225116e7 we can disable the warnings for using a reserved priority using a diagnostic pragma. That means we no longer need to put globals using that attribute into separate files that get included. This replaces the two uses of such separate files by moving the variable definition into the source file and adding the diagnostic pragma. libstdc++-v3/ChangeLog: * src/c++17/memory_resource.cc (default_res): Define here instead of including default_resource.h. * src/c++98/globals_io.cc (__ioinit): Define here instead of including ios_base_init.h. * src/c++17/default_resource.h: Removed. * src/c++98/ios_base_init.h: Removed.
2025-02-20libstdc++: Use init_priority attribute for tzdb globals [PR118811]Jonathan Wakely1-4/+7
When linking statically to libstdc++.a (or to libstdc++_nonshared.a in the RHEL devtoolset compiler) there's a static initialization order problem where user code might be constructed before the std::chrono::tzdb_list globals, and so might try to use them after they've already been destroyed. Use the init_priority attribute on those globals so that they are initialized early. Since r15-7511-g4e7f74225116e7 we can disable the warnings for using a reserved priority using a diagnostic pragma. libstdc++-v3/ChangeLog: PR libstdc++/118811 * src/c++20/tzdb.cc (tzdb_list::_Node): Use init_priority attribute on static data members. * testsuite/std/time/tzdb_list/pr118811.cc: New test.
2025-01-16libstdc++: Implement LWG 2937 for std::filesystem::equivalent [PR118158]Jonathan Wakely1-15/+7
Do not report an error for (is_other(s1) && is_other(s2)) as the standard originally said, nor for (is_other(s1) || is_other(s2)) as libstdc++ was doing. We can compare inode numbers for special files and so give sensible answers. libstdc++-v3/ChangeLog: PR libstdc++/118158 * src/c++17/fs_ops.cc (fs::equivalent): Remove error reporting for is_other(s1) && is_other(s2) case, as per LWG 2937. * testsuite/27_io/filesystem/operations/pr118158.cc: New test.
2025-01-08libstdc++: add missing to_underlying to module std [PR106852]Nicolas Werner1-0/+3
std::to_underlying was missing from the std module introduced in r15-5366-g7db55c0ba1baaf. This patch adds the missing export for this utility. libstdc++-v3/ChangeLog: PR libstdc++/106852 * src/c++23/std.cc.in (to_underlying): Add. Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de>
2025-01-08libstdc++: Use preprocessor conditions in std module [PR118177]Jonathan Wakely2-0/+48
The std-clib.cc module definition file assumes that all names are available unconditionally, but that's not true for all targets. Use the same preprocessor conditions as are present in the <cxxx> headers. A similar change is needed in std.cc.in for the <chrono> features that depend on the SSO std::string, guarded with a __cpp_lib_chrono value indicating full C++20 support. The conditions for <cmath> are omitted from this change, as there are a large number of them. That probably needs to be fixed. libstdc++-v3/ChangeLog: PR libstdc++/118177 * src/c++23/std-clib.cc.in: Use preprocessor conditions for names which are not always defined. * src/c++23/std.cc.in: Likewise.
2025-01-08libstdc++: Fix std::future::wait_until for subsecond negative times [PR118093]Jonathan Wakely1-2/+2
The current check for negative times (i.e. before the epoch) only checks for a negative number of seconds. For a time 1ms before the epoch the seconds part will be zero, but the futex syscall will still fail with an EINVAL error. Extend the check to handle this case. This change adds a redundant check in the headers too, so that we avoid even calling into the library for negative times. Both checks can be marked [[unlikely]]. The check in the headers avoids the cost of splitting the time into seconds and nanoseconds and then making a PLT call. The check inside the library matches where we were checking already, and fixes existing binaries that were compiled against older headers but use a newer libstdc++.so.6 at runtime. libstdc++-v3/ChangeLog: PR libstdc++/118093 * include/bits/atomic_futex.h (_M_load_and_test_until_impl): Return false for times before the epoch. * src/c++11/futex.cc (_M_futex_wait_until): Extend check for negative times to check for subsecond times. Add unlikely attribute. (_M_futex_wait_until_steady): Likewise. * testsuite/30_threads/future/members/118093.cc: New test.
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2025-01-02Update copyright years.Jakub Jelinek140-140/+140
2024-12-19libstdc++: Implement C++23 <flat_set> (P1222R4)Patrick Palka1-0/+11
This implements the C++23 container adaptors std::flat_set and std::flat_multiset from P1222R4. The implementation is essentially an simpler and pared down version of std::flat_map. libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header <flat_set>. * include/Makefile.in: Regenerate. * include/bits/version.def (__cpp_flat_set): Define. * include/bits/version.h: Regenerate * include/precompiled/stdc++.h: Include <flat_set>. * include/std/flat_set: New file. * src/c++23/std.cc.in: Export <flat_set>. * testsuite/23_containers/flat_multiset/1.cc: New test. * testsuite/23_containers/flat_set/1.cc: New test. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-12-19libstdc++: Implement C++23 <flat_map> (P0429R9)Patrick Palka1-0/+11
This implements the C++23 container adaptors std::flat_map and std::flat_multimap from P0429R9. The implementation is shared as much as possible between the two adaptors via a common base class that's parameterized according to key uniqueness. libstdc++-v3/ChangeLog: * include/Makefile.am: Add new header <flat_map>. * include/Makefile.in: Regenerate. * include/bits/alloc_traits.h (__not_allocator_like): New concept. * include/bits/stl_function.h (__transparent_comparator): Likewise. * include/bits/stl_iterator_base_types.h (__has_input_iter_cat): Likewise. * include/bits/uses_allocator.h (__allocator_for): Likewise. * include/bits/utility.h (sorted_unique_t): Define for C++23. (sorted_unique): Likewise. (sorted_equivalent_t): Likewise. (sorted_equivalent): Likewise. * include/bits/version.def (flat_map): Define. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include <flat_map>. * include/std/flat_map: New file. * src/c++23/std.cc.in: Export <flat_map>. * testsuite/23_containers/flat_map/1.cc: New test. * testsuite/23_containers/flat_multimap/1.cc: New test. Co-authored-by: Jonathan Wakely <jwakely@redhat.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-12-12libstdc++: Fix typo in comment in src/c++17/fs_dir.ccJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * src/c++17/fs_dir.cc: Fix typo in comment.
2024-12-02libstdc++: Disable deprecated warnings for std::rel_ops in std.ccJonathan Wakely1-0/+3
This avoids some warnings when building the std module. libstdc++-v3/ChangeLog: * src/c++23/std.cc.in: Disable deprecated warnings when exporting std::rel_ops members.
2024-11-27libstdc++/ranges: make _RangeAdaptorClosure befriend operator|Patrick Palka1-6/+0
This declares the range adaptor pipe operators a friend of the _RangeAdaptorClosure base class so that the std module doesn't need to export them for ADL to find them. Note that we deliberately don't define these pipe operators as hidden friends, see r14-3293-g4a6f3676e7dd9e. libstdc++-v3/ChangeLog: * include/std/ranges (views::__adaptor::_RangeAdaptorClosure): Befriend both operator| overloads. * src/c++23/std.cc.in: Don't export views::__adaptor::operator|. Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-11-27libstdc++: module std fixesJason Merrill1-28/+36
Some tests were failing due to the exported using declaration of iter_move conflicting with friend declarations; the exported using needs to be in the inline namespace, like the customization point itself, rather than std::ranges. Also add a few missing exports. Some tests failed to find some operators defined in implementation-detail namespaces; this exports them as well, but as previously discussed it's probably preferable to make those operators friends so ADL can find them that way. libstdc++-v3/ChangeLog: * src/c++23/std.cc.in: Fix iter_move/swap. Add fold_left_first, to, concat, and some operators.
2024-11-26libstdc++: Move std::error_category symbol to separate file [PR117630]Jonathan Wakely4-15/+56
As described in PR 117630 the cow-stdexcept.cc file pulls in symbols from system_error.cc, which are not actually needed there. Moving the definition of error_category::_M_message to a separate file should solve it. libstdc++-v3/ChangeLog: PR libstdc++/117630 * src/c++11/Makefile.am: Add new file. * src/c++11/Makefile.in: Regnerate. * src/c++11/cow-stdexcept.cc (error_category::_M_message): Move member function definition to ... * src/c++11/cow-system_error.cc: New file.
2024-11-19libstdc++: remove JSON comment.Jason Merrill1-1/+0
Standard JSON doesn't have comments, and it seems this file needs to be conforming, not the common JSON-with-comments dialect. libstdc++-v3/ChangeLog: * src/c++23/libstdc++.modules.json.in: Remove C++ comment.
2024-11-17libstdc++: add module std [PR106852]Jason Merrill6-16/+4137
This patch introduces an installed source form of module std and std.compat. To help a build system find them, we install a libstdc++.modules.json file alongside libstdc++.so, which tells the build system where the files are and any special flags it should use when compiling them (none, in this case). The format is from a proposal in SG15. The build system can find this file with 'gcc -print-file-name=libstdc++.modules.json'. It seems preferable to use a relative path from this file to the sources so that moving the installation doesn't break the reference, but I didn't see any obvious way to compute that without relying on coreutils, perl, or python, so I wrote a POSIX shell script for it. The .. canonicalization bits aren't necessary since I discovered $(abspath), but I guess I might as well leave them in. Currently this installs the sources under $(gxx_include_dir)/bits/, i.e. /usr/include/c++/15/bits. So with my -fsearch-include-path change, std.cc can be compiled with g++ -fsearch-include-path bits/std.cc. Note that if someone actually tries to #include <bits/std.cc> it will fail with "error: module control-line cannot be in included file". Any ideas about a more user-friendly way to express "compile module std" are welcome. The sources currently have the extension .cc, like other source files. std.cc started with m.cencora's implementation in PR114600. I've made some adjustments, but more is probably desirable, e.g. of the <algorithm> handling of namespace ranges, and to remove exports of templates that are only specialized in a particular header. I've filled in a bunch of missing exports, and added some FIXMEs where I noticed bits that are not implemented yet. Since bits/stdc++.h also intends to include the whole standard library, I include it rather than duplicate it. But stdc++.h comments out <execution>, due to TBB issues; I include it separately and suppress TBB usage, so module std won't currently provide parallel execution. It seemed most convenient for the two files to be monolithic so we don't need to worry about include paths. So the C library names that module std.compat exports in both namespace std and :: are a block of code that is appended to both files, adjusted based on whether the macro STD_COMPAT is defined before the block. In this implementation std.compat imports std; it would also be valid for it to duplicate everything in std. I see the libc++ std.compat also imports std. As discussed in the PR, module std is supported in C++20 mode even though it was added in C++23. Changes to test module std will follow in a separate patch. In my testing I've noticed a few compiler bugs that break various testcases, so I don't expect to enable module std testing by default at first. PR libstdc++/106852 libstdc++-v3/ChangeLog: * include/bits/version.def: Add __cpp_lib_modules. * include/bits/version.h: Regenerate. * src/c++23/Makefile.am: Add modules std and std.compat. * src/c++23/Makefile.in: Regenerate. * src/c++23/std-clib.cc.in: New file. * src/c++23/std.cc.in: New file. * src/c++23/std.compat.cc.in: New file. * src/c++23/libstdc++.modules.json.in: New file. contrib/ChangeLog: * relpath.sh: New file.
2024-11-06libstdc++: Enable debug assertions for filesystem directory iteratorsJonathan Wakely1-6/+6
Several member functions of filesystem::directory_iterator and filesystem::recursive_directory_iterator currently dereference their shared_ptr data member without checking for non-null. Because they use operator-> and that function only uses _GLIBCXX_DEBUG_PEDASSERT rather than __glibcxx_assert there is no assertion even when the library is built with _GLIBCXX_ASSERTIONS defined. This means that dereferencing invalid directory iterators gives an unhelpful segfault. By using (*p). instead of p-> we get an assertion when the library is built with _GLIBCXX_ASSERTIONS, with a "_M_get() != nullptr" message. libstdc++-v3/ChangeLog: * src/c++17/fs_dir.cc (fs::directory_iterator::operator*): Use shared_ptr::operator* instead of shared_ptr::operator->. (fs::recursive_directory_iterator::options): Likewise. (fs::recursive_directory_iterator::depth): Likewise. (fs::recursive_directory_iterator::recursion_pending): Likewise. (fs::recursive_directory_iterator::operator*): Likewise. (fs::recursive_directory_iterator::disable_recursion_pending): Likewise.
2024-09-22libstdc++: Silence -Woverloaded-virtual warning in cxx11-ios_failure.ccJonathan Wakely1-0/+2
libstdc++-v3/ChangeLog: * src/c++11/cxx11-ios_failure.cc (__iosfail_type_info): Unhide the three-arg overload of __do_upcast.
2024-09-10libstdc++: Only use std::ios_base_library_init() for ELF [PR116159]Jonathan Wakely1-1/+1
The undefined std::ios_base_library_init() symbol that is referenced by <iostream> is only supposed to be used for targets where symbol versioning is supported. The mingw-w64 target defaults to --enable-symvers=gnu due to using GNU ld but doesn't actually support symbol versioning. This means it tries to emit references to the std::ios_base_library_init() symbol, which isn't really defined in the library. This causes problems when using lld to link user binaries. Disable the undefined symbol reference for non-ELF targets. libstdc++-v3/ChangeLog: PR libstdc++/116159 * include/std/iostream (ios_base_library_init): Only define for ELF targets. * src/c++98/ios_init.cc (ios_base_library_init): Likewise.
2024-09-03libstdc++: Fix error handling in fs::hard_link_count for WindowsJonathan Wakely1-26/+33
The recent change to use auto_win_file_handle for std::filesystem::hard_link_count caused a regression. The std::error_code argument should be cleared if no error occurs, but this no longer happens. Add a call to ec.clear() in fs::hard_link_count to fix this. Also change the auto_win_file_handle class to take a reference to the std::error_code and set it if an error occurs, to slightly simplify the control flow in the fs::equiv_files function. libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc (auto_win_file_handle): Add error_code& member and set it if CreateFileW or GetFileInformationByHandle fails. (fs::equiv_files) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Simplify control flow. (fs::hard_link_count) [_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Clear ec on success. * testsuite/27_io/filesystem/operations/hard_link_count.cc: Check error handling.
2024-08-23libstdc++: Use noexcept insted of throw() in src/c++11/debug.ccJonathan Wakely1-16/+16
libstdc++-v3/ChangeLog: * src/c++11/debug.cc: Replace throw() with noexcept.
2024-08-21libstdc++: Check ios::uppercase for ios::fixed floating-point output [PR114862]Jonathan Wakely1-5/+8
This is LWG 4084 which I filed recently. LWG seems to support making the change, so that std::num_put can use the %F format for floating-point numbers. libstdc++-v3/ChangeLog: PR libstdc++/114862 * src/c++98/locale_facets.cc (__num_base::_S_format_float): Check uppercase flag for fixed format. * testsuite/22_locale/num_put/put/char/lwg4084.cc: New test.
2024-07-31libstdc++: Fix src/c++20/format.cc for non-gthreads targetsJonathan Wakely1-4/+13
libstdc++-v3/ChangeLog: * src/c++20/format.cc [!_GLIBCXX_HAS_GTHREADS] (mutex): Define dummy mutex type. * testsuite/std/time/format_localized.cc: Use loop variable instead of creating the same locale on every iteration.
2024-07-31libstdc++: Handle strerror returning nullJonathan Wakely1-1/+5
The linux man page for strerror says that some systems return NULL for an unknown error number. That violates the C and POSIX standards, but we can esily handle it to avoid a segfault. libstdc++-v3/ChangeLog: * src/c++11/system_error.cc (strerror_string): Handle non-conforming NULL return from strerror.
2024-07-31libstdc++: Handle encodings in localized chrono formatting [PR109162]Jonathan Wakely3-3/+228
This implements the C++23 paper P2419R2 (Clarify handling of encodings in localized formatting of chrono types). The requirement is that when the literal encoding is "a Unicode encoding form" and the formatting locale uses a different encoding, any locale-specific strings such as "août" for std::chrono::August should be converted to the literal encoding. Using the recently-added std::locale::encoding() function we can check the locale's encoding and then use iconv if a conversion is needed. Because nl_langinfo_l and iconv_open both allocate memory, a naive implementation would perform multiple allocations and deallocations for every snippet of locale-specific text that needs to be converted to UTF-8. To avoid that, a new internal locale::facet is defined to store the text_encoding and an iconv_t descriptor, which are then cached in the formatting locale. This requires access to the internals of a std::locale object in src/c++20/format.cc, so that new file needs to be compiled with -fno-access-control, as well as -std=gnu++26 in order to use std::text_encoding. Because the new std::text_encoding and std::locale::encoding() symbols are only in the libstdc++exp.a archive, we need to include src/c++26/text_encoding.cc in the main library, but not export its symbols yet. This means they can be used by the two new functions which are exported from the main library. The encoding conversions are done for C++20, treating it as a DR that resolves LWG 3656. With this change we can increase the value of the __cpp_lib_format macro for C++23. The value should be 202207 for P2419R2, but we already implement P2510R3 (Formatting pointers) so can use the value 202304. libstdc++-v3/ChangeLog: PR libstdc++/109162 * acinclude.m4 (libtool_VERSION): Update to 6:34:0. * config/abi/pre/gnu.ver: Disambiguate old patters. Add new GLIBCXX_3.4.34 symbol version and new exports. * configure: Regenerate. * include/bits/chrono_io.h (_ChronoSpec::_M_locale_specific): Add new accessor functions to use a reserved bit in _Spec. (__formatter_chrono::_M_parse): Use _M_locale_specific(true) when chrono-specs contains locale-dependent conversion specifiers. (__formatter_chrono::_M_format): Open iconv descriptor if conversion to UTF-8 will be needed. (__formatter_chrono::_M_write): New function to write a localized string with possible character conversion. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B) (__formatter_chrono::_M_p, __formatter_chrono::_M_r) (__formatter_chrono::_M_x, __formatter_chrono::_M_X) (__formatter_chrono::_M_locale_fmt): Use _M_write. * include/bits/version.def (format): Update value. * include/bits/version.h: Regenerate. * include/std/format (_GLIBCXX_P2518R3): Check feature test macro instead of __cplusplus. (basic_format_context): Declare __formatter_chrono as friend. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/format.cc: New file. * testsuite/std/time/format_localized.cc: New test. * testsuite/util/testsuite_abi.cc: Add new symbol version.
2024-07-30libstdc++: Fix name of source file in commentJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc: Fix file name in comment.
2024-07-30libstdc++: Fix overwriting files with fs::copy_file on WindowsJonathan Wakely3-33/+68
There are no inode numbers on Windows filesystems, so stat_type::st_ino is always zero and the check for equivalent files in do_copy_file was incorrectly identifying distinct files as equivalent. This caused copy_file to incorrectly report errors when trying to overwrite existing files. The fs::equivalent function already does the right thing on Windows, so factor that logic out into a new function that can be reused by fs::copy_file. The tests for fs::copy_file were quite inadequate, so this also adds checks for that function's error conditions. libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc (auto_win_file_handle): Change constructor parameter from const path& to const wchar_t*. (fs::equiv_files): New function. (fs::equivalent): Use equiv_files. * src/filesystem/ops-common.h (fs::equiv_files): Declare. (do_copy_file): Use equiv_files. * src/filesystem/ops.cc (fs::equiv_files): Define. (fs::copy, fs::equivalent): Use equiv_files. * testsuite/27_io/filesystem/operations/copy.cc: Test overwriting directory contents recursively. * testsuite/27_io/filesystem/operations/copy_file.cc: Test overwriting existing files.
2024-07-30libstdc++: Fix fs::hard_link_count behaviour on MinGW [PR113663]Lennox Shou Hao Ho1-22/+37
std::filesystem::hard_link_count() always returns 1 on mingw-w64ucrt-11.0.1-r3 on Windows 10 19045 hard_link_count() queries _wstat64() on MinGW-w64 The MSFT documentation claims _wstat64() will always return 1 *non*-NTFS volumes https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/14h5k7ff(v=vs.120) My tests suggest that is not always true - hard_link_count()/_wstat64() still returns 1 on NTFS. GetFileInformationByHandle does return the correct result of 2. Please see the PR for a minimal repro. This patch changes the Windows implementation to always call GetFileInformationByHandle. PR libstdc++/113663 libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc (fs::equivalent): Moved helper class auto_handle to anonymous namespace as auto_win_file_handle. (fs::hard_link_count): Changed Windows implementation to use information provided by GetFileInformationByHandle which is more reliable. * testsuite/27_io/filesystem/operations/hard_link_count.cc: New test. Signed-off-by: "Lennox" Shou Hao Ho <lennoxhoe@gmail.com> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2024-07-23libstdc++: Use [[maybe_unused]] attribute in src/c++23/print.ccJonathan Wakely1-2/+2
This avoids some warnings when the preprocessor conditions are not met. libstdc++-v3/ChangeLog: * src/c++23/print.cc (__open_terminal): Use [[maybe_unused]] on parameter.
2024-07-23libstdc++: Do not use isatty on avr [PR115482]Detlef Vollmann1-2/+2
avrlibc has an incomplete unistd.h that doesn't have isatty. So building libstdc++ fails when compiling c++23/print.cc. As a workaround I added a check for AVR. libstdc++-v3/ChangeLog: PR libstdc++/115482 * src/c++23/print.cc (__open_terminal) [__AVR__]: Do not use isatty.
2024-07-10libstdc++: Minor optimization for std::locale::encoding()Jonathan Wakely1-3/+13
For the C locale we know the encoding is ASCII, so we can avoid using newlocale and nl_langinfo_l. Similarly, for an unnamed locale, we aren't going to get a useful answer, so we can just use a default-constrcuted std::text_encoding representing an unknown encoding. libstdc++-v3/ChangeLog: * src/c++26/text_encoding.cc (__locale_encoding): Add to unnamed namespace. (std::locale::encoding): Optimize for "C" and "*" names.
2024-06-28libstdc++: Define __glibcxx_assert_fail for non-verbose build [PR115585]Jonathan Wakely1-1/+9
When the library is configured with --disable-libstdcxx-verbose the assertions just abort instead of calling __glibcxx_assert_fail, and so I didn't export that function for the non-verbose build. However, that option is documented to not change the library ABI, so we still need to export the symbol from the library. It could be needed by programs compiled against the headers from a verbose build. The non-verbose definition can just call abort so that it doesn't pull in I/O symbols, which are unwanted in a non-verbose build. libstdc++-v3/ChangeLog: PR libstdc++/115585 * src/c++11/assert_fail.cc (__glibcxx_assert_fail): Add definition for non-verbose builds.
2024-06-26libstdc++: Fix std::chrono::tzdb to work with vanguard formatJonathan Wakely1-102/+163
I found some issues in the std::chrono::tzdb parser by testing the tzdata "vanguard" format, which uses new features that aren't enabled in the "main" and "rearguard" data formats. Since 2024a the keyword "minimum" is no longer valid for the FROM and TO fields in a Rule line, which means that "m" is now a valid abbreviation for "maximum". Previously we expected either "mi" or "ma". For backwards compatibility, a FROM field beginning with "mi" is still supported and is treated as 1900. The "maximum" keyword is only allowed in TO now, because it makes no sense in FROM. To support these changes the minmax_year and minmax_year2 classes for parsing FROM and TO are replaced with a single years_from_to class that reads both fields. The vanguard format makes use of %z in Zone FORMAT fields, which caused an exception to be thrown from ZoneInfo::set_abbrev because no % or / characters were expected when a Zone doesn't use a named Rule. The ZoneInfo::to(sys_info&) function now uses format_abbrev_str to replace any %z with the current offset. Although format_abbrev_str also checks for %s and STD/DST formats, those only make sense when a named Rule is in effect, so won't occur when ZoneInfo::to(sys_info&) is used. This change also implements a feature that has always been missing from time_zone::_M_get_sys_info: finding the Rule that is active before the specified time point, so that we can correctly handle %s in the FORMAT for the first new sys_info that gets created. This requires implementing a poorly documented feature of zic, to get the LETTERS field from a later transition, as described at https://mm.icann.org/pipermail/tz/2024-April/058891.html In order for this to work we need to be able to distinguish an empty letters field (as used by CE%sT where the variable part is either empty or "S") from "the letters field is not known for this transition". The tzdata file uses "-" for an empty letters field, which libstdc++ was previously replacing with "" when the Rule was parsed. Instead, we now preserve the "-" in the Rule object, so that "" can be used for the case where we don't know the letters (and so need to decide it). libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (minmax_year, minmax_year2): Remove. (years_from_to): New class replacing minmax_year and minmax_year2. (format_abbrev_str, select_std_or_dst_abbrev): Move earlier in the file. Handle "-" for letters. (ZoneInfo::to): Use format_abbrev_str to expand %z. (ZoneInfo::set_abbrev): Remove exception. Change parameter from reference to value. (operator>>(istream&, Rule&)): Do not clear letters when it contains "-". (time_zone::_M_get_sys_info): Add missing logic to find the Rule in effect before the time point. * testsuite/std/time/tzdb/1.cc: Adjust for vanguard format using "GMT" as the Zone name, not as a Link to "Etc/GMT". * testsuite/std/time/time_zone/sys_info_abbrev.cc: New test.