aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
AgeCommit message (Collapse)AuthorFilesLines
2022-03-09libstdc++: Avoid implicit narrowing from uint128_t [PR104859]Patrick Palka1-3/+3
We need to be explicit about narrowing conversions from uint128_t since, on targets that lack __int128, this type is defined as an integer-class type that is only _explicitly_ convertible to the builtin integer types. This issue was latent until r12-7563-ge32869a17b788b made the frontend correctly reject explicit conversion functions during (dependent) copy-initialization. PR libstdc++/104859 libstdc++-v3/ChangeLog: * src/c++17/floating_to_chars.cc (__floating_to_chars_hex): Be explicit when narrowing the shifted effective_mantissa, since it may have an integer-class type.
2022-02-14libstdc++: Fix std::to_chars for IEEE128 long doubleJonathan Wakely1-6/+2
The preprocessor check for _GLIBCXX_USE_FLOAT128 is the wrong condition, because when the compiler is built with --with-long-double-format=ieee configure determines that __float128 is the same as long double, and so should not be used. But we do want the std::to_chars overloads for __float128 in that case, because the floating_to_chars.cc file is built with -mabi=ibmlongdouble and so the __float128 overloads are actually the 'long double' ones for -mabi=ieeelongdouble code. This fixes missing definitions of the __float128 overloads of std::to_chars for --with-long-double-format=ieee builds. Without this, there are symbols present in the --with-long-double-abi=ibm build which are missing from the --with-long-double-abi=ieee build. libstdc++-v3/ChangeLog: * src/c++17/floating_to_chars.cc (FLOAT128_TO_CHARS): Depend on LONG_DOUBLE_ALT128_COMPAT instead of USE_FLOAT128.
2022-02-10libstdc++: Fix directory iterator build for newlibJonathan Wakely1-0/+2
When building for newlib HAVE_OPENAT and HAVE_UNLINKAT are (sometimes?) defined, but <fcntl.h> is only included when HAVE_DIRENT_H is defined. Since directory iterators are completely useless without <dirent.h>, just override the HAVE_OPENAT and HAVE_UNLINKAT detection when we don't have <dirent.h>. libstdc++-v3/ChangeLog: * src/filesystem/dir-common.h (_GLIBCXX_HAVE_DIRFD): Undefine when <dirent.h> is not available. (_GLIBCXX_HAVE_UNLINKAT): Likewise.
2022-02-08libstdc++: Simplify resource management in directory iteratorsJonathan Wakely3-6/+4
This replaces the _Dir constructor that takes ownership of an existing DIR* resource with one that takes a _Dir_base rvalue instead. This means a raw DIR* is never passed around, but is always owned by a _Dir_base object. libstdc++-v3/ChangeLog: * src/c++17/fs_dir.cc (_Dir(DIR*, const path&)): Change first parameter to _Dir_base&&. * src/filesystem/dir-common.h (_Dir_base(DIR*)): Remove. * src/filesystem/dir.cc (_Dir(DIR*, const path&)): Change first parameter to _Dir_base&&.
2022-02-08libstdc++: Fix filesystem::remove_all for Windows [PR104161]Jonathan Wakely3-11/+42
The recursive_directory_iterator::__erase member was failing for Windows, because the entry._M_type value is always file_type::none (because _Dir_base::advance doesn't populate it for Windows) and top.unlink uses fs::remove which sets an error using the system_category. That meant that ec.value() was a Windows error code and not an errno value, so the comparisons to EPERM and EISDIR failed. Instead of depending on a specific Windows error code for attempting to remove a directory, just use directory_entry::refresh() to query the type first. This doesn't avoid the TOCTTOU races with directory symlinks, but we can't avoid them on Windows without openat and unlinkat, and creating symlinks requires admin privs on Windows anyway. This also fixes the fs::remove_all(const path&) overload, which was supposed to use the same logic as the other overload, but I forgot to change it before my previous commit. libstdc++-v3/ChangeLog: PR libstdc++/104161 * src/c++17/fs_dir.cc (fs::recursive_directory_iterator::__erase): [i_GLIBCXX_FILESYSTEM_IS_WINDOWS]: Refresh entry._M_type member, instead of checking for errno values indicating a directory. * src/c++17/fs_ops.cc (fs::remove_all(const path&)): Use similar logic to non-throwing overload. (fs::remove_all(const path&, error_code&)): Add comments. * src/filesystem/ops-common.h: Likewise.
2022-02-04libstdc++: Fix std::filesystem build failure for WindowsJonathan Wakely1-1/+1
The std::filesystem code needs to use posix::DIR not ::DIR, as that is an alias for _WDIR on Windows. libstdc++-v3/ChangeLog: * src/filesystem/dir-common.h (_Dir_base::openat): Change return type to use portable posix::DIR alias.
2022-02-04libstdc++: Remove un-implementable noexcept from Filesystem TS operationsJonathan Wakely1-3/+3
LWG 3014 removed these incorrect noexcept specifications from the C++17 std::filesystem operations. They are also incorrect on the experimental TS versions and should be removed from them too. libstdc++-v3/ChangeLog: * include/experimental/bits/fs_ops.h (fs::copy_file): Remove noexcept. (fs::create_directories): Likewise. (fs::remove_all): Likewise. * src/filesystem/ops.cc (fs::copy_file): Remove noexcept. (fs::create_directories): Likewise. (fs::remove_all): Likewise.
2022-02-04libstdc++: Fix filesystem::remove_all races [PR104161]Jonathan Wakely5-228/+415
This fixes the remaining filesystem::remove_all race condition by using POSIX openat to recurse into sub-directories and using POSIX unlinkat to remove files. This avoids the remaining race where the directory being removed is replaced with a symlink after the directory has been opened, so that the filesystem::remove("subdir/file") resolves to "target/file" instead, because "subdir" has been removed and replaced with a symlink. The previous patch only fixed the case where the directory was replaced with a symlink before we tried to open it, but it still used the full (potentially compromised) path as an argument to filesystem::remove. The first part of the fix is to use openat when recursing into a sub-directory with recursive_directory_iterator. This means that opening "dir/subdir" uses the file descriptor for "dir", and so is sure to open "dir/subdir" and not "symlink/subdir". (The previous patch to use O_NOFOLLOW already ensured we won't open "dir/symlink/" here.) The second part of the fix is to use unlinkat for the remove_all operation. Previously we used a directory_iterator to get the name of each file in a directory and then used filesystem::remove(iter->path()) on that name. This meant that any checks (e.g. O_NOFOLLOW) done by the iterator could be invalidated before the remove operation on that pathname. The directory iterator contains an open DIR stream, which we can use to obtain a file descriptor to pass to unlinkat. This ensures that the file being deleted really is contained within the directory we're iterating over, rather than using a pathname that could resolve to some other file. The filesystem::remove_all function previously used a (non-recursive) filesystem::directory_iterator for each directory, and called itself recursively for sub-directories. The new implementation uses a single filesystem::recursive_directory_iterator object, and calls a new __erase member function on that iterator. That new __erase member function does the actual work of removing a file (or a directory after its contents have been iterated over and removed) using unlinkat. That means we don't need to expose the DIR stream or its file descriptor to the remove_all function, it's still encapuslated by the iterator class. It would be possible to add a __rewind member to directory iterators too, to call rewinddir after each modification to the directory. That would make it more likely for filesystem::remove_all to successfully remove everything even if files are being written to the directory tree while removing it. It's unclear if that is actually prefereable, or if it's better to fail and report an error at the first opportunity. The necessary APIs (openat, unlinkat, fdopendir, dirfd) are defined in POSIX.1-2008, and in Glibc since 2.10. But if the target doesn't provide them, the original code (with race conditions) is still used. This also reduces the number of small memory allocations needed for std::filesystem::remove_all, because we do not store the full path to every directory entry that is iterated over. The new filename_only option means we only store the filename in the directory entry, as that is all we need in order to use openat or unlinkat. Finally, rather than duplicating everything for the Filesystem TS, the std::experimental::filesystem::remove_all implementation now just calls std::filesystem::remove_all to do the work. libstdc++-v3/ChangeLog: PR libstdc++/104161 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for dirfd and unlinkat. * config.h.in: Regenerate. * configure: Regenerate. * include/bits/fs_dir.h (recursive_directory_iterator): Declare remove_all overloads as friends. (recursive_directory_iterator::__erase): Declare new member function. * include/bits/fs_fwd.h (remove, remove_all): Declare. * src/c++17/fs_dir.cc (_Dir): Add filename_only parameter to constructor. Pass file descriptor argument to base constructor. (_Dir::dir_and_pathname, _Dir::open_subdir, _Dir::do_unlink) (_Dir::unlink, _Dir::rmdir): Define new member functions. (directory_iterator): Pass filename_only argument to _Dir constructor. (recursive_directory_iterator::_Dir_stack): Adjust constructor parameters to take a _Dir rvalue instead of creating one. (_Dir_stack::orig): Add data member for storing original path. (_Dir_stack::report_error): Define new member function. (__directory_iterator_nofollow): Move here from dir-common.h and fix value to be a power of two. (__directory_iterator_filename_only): Define new constant. (recursive_directory_iterator): Construct _Dir object and move into _M_dirs stack. Pass skip_permission_denied argument to first advance call. (recursive_directory_iterator::increment): Use _Dir::open_subdir. (recursive_directory_iterator::__erase): Define new member function. * src/c++17/fs_ops.cc (ErrorReporter, do_remove_all): Remove. (fs::remove_all): Use new recursive_directory_iterator::__erase member function. * src/filesystem/dir-common.h (_Dir_base): Add int parameter to constructor and use openat to implement nofollow semantics. (_Dir_base::fdcwd, _Dir_base::set_close_on_exec, _Dir_base::openat): Define new member functions. (__directory_iterator_nofollow): Move to fs_dir.cc. * src/filesystem/dir.cc (_Dir): Pass file descriptor argument to base constructor. (_Dir::dir_and_pathname, _Dir::open_subdir): Define new member functions. (recursive_directory_iterator::_Dir_stack): Adjust constructor parameters to take a _Dir rvalue instead of creating one. (recursive_directory_iterator): Check for new nofollow option. Construct _Dir object and move into _M_dirs stack. Pass skip_permission_denied argument to first advance call. (recursive_directory_iterator::increment): Use _Dir::open_subdir. * src/filesystem/ops.cc (fs::remove_all): Use C++17 remove_all.
2022-02-02libstdc++: Fix -Wunused-variable warning for -fno-exceptions buildJonathan Wakely2-2/+2
If _GLIBCXX_THROW_OR_ABORT expands to just __builtin_abort() then the bool variable used in the filesystem_error constructor is unused. Mark it as maybe_unused to there's no warning for -fno-exceptions builds. libstdc++-v3/ChangeLog: * src/c++17/fs_dir.cc (fs::recursive_directory_iterator::pop): Add [[maybe_unused]] attribute. * src/filesystem/dir.cc (fs::recursive_directory_iterator::pop): Likewise.
2022-02-01libstdc++: Reset filesystem::recursive_directory_iterator on errorJonathan Wakely2-4/+20
The standard requires directory iterators to become equal to the end iterator value if they report an error. Some members functions of filesystem::recursive_directory_iterator fail to do that. libstdc++-v3/ChangeLog: * src/c++17/fs_dir.cc (recursive_directory_iterator::increment): Reset state to past-the-end iterator on error. (fs::recursive_directory_iterator::pop(error_code&)): Likewise. (fs::recursive_directory_iterator::pop()): Check _M_dirs before it might get reset. * src/filesystem/dir.cc (recursive_directory_iterator): Likewise, for the TS implementation. * testsuite/27_io/filesystem/iterators/error_reporting.cc: New test. * testsuite/experimental/filesystem/iterators/error_reporting.cc: New test.
2022-01-25libstdc++: Define _GNU_SOURCE for secure_getenv on Cygwin [PR104217]Jonathan Wakely3-0/+12
For GNU/Linux G++ defines _GNU_SOURCE automatically, but not for Cygwin. This means secure_getenv is not declared by Cygwin's <stdlib.h>, even though autoconf detected it is present in the library. Define it in the source files that want to use secure_getenv. libstdc++-v3/ChangeLog: PR libstdc++/104217 * src/c++17/fs_ops.cc (_GNU_SOURCE): Define. * src/filesystem/dir.cc (_GNU_SOURCE): Define. * src/filesystem/ops.cc (_GNU_SOURCE): Define.
2022-01-25libstdc++: Avoid symlink race in filesystem::remove_all [PR104161]Jonathan Wakely5-28/+64
This adds a new internal flag to the filesystem::directory_iterator constructor that makes it fail if the path is a symlink that resolves to a directory. This prevents filesystem::remove_all from following a symlink to a directory, rather than deleting the symlink itself. We can also use that new flag in recursive_directory_iterator to ensure that we don't follow symlinks if the follow_directory_symlink option is not set. This also moves an error check in filesystem::remove_all after the while loop, so that errors from the directory_iterator constructor are reproted, instead of continuing to the filesystem::remove call below. libstdc++-v3/ChangeLog: PR libstdc++/104161 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for fdopendir. * config.h.in: Regenerate. * configure: Regenerate. * src/c++17/fs_dir.cc (_Dir): Add nofollow flag to constructor and pass it to base class constructor. (directory_iterator): Pass nofollow flag to _Dir constructor. (fs::recursive_directory_iterator::increment): Likewise. * src/c++17/fs_ops.cc (do_remove_all): Use nofollow option for directory_iterator constructor. Move error check outside loop. * src/filesystem/dir-common.h (_Dir_base): Add nofollow flag to constructor and when it's set use ::open with O_NOFOLLOW and O_DIRECTORY. * src/filesystem/dir.cc (_Dir): Add nofollow flag to constructor and pass it to base class constructor. (directory_iterator): Pass nofollow flag to _Dir constructor. (fs::recursive_directory_iterator::increment): Likewise. * src/filesystem/ops.cc (remove_all): Use nofollow option for directory_iterator constructor. Move error check outside loop.
2022-01-23libstdc++: Use fast_float for long double if it uses binary64 formatJonathan Wakely1-6/+32
We can use the new from_chars implementation when long double and double have the same representation. libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc (USE_STRTOD_FOR_FROM_CHARS): Define macro for case where std::from_chars is implemented in terms of strtod, strtof or strtold. (buffer_resource, valid_fmt, find_end_of_float, pattern) (from_chars_impl, make_result, reserve_string): Do not define unless USE_STRTOD_FOR_FROM_CHARS is defined. (from_chars): Define when at least one of USE_LIB_FAST_FLOAT and USE_STRTOD_FOR_FROM_CHARS is defined, instead of _GLIBCXX_HAVE_USELOCALE. Use fast_float for long double when it is binary64.
2022-01-20libstdc++: Use Clang attribute instead of __constinitJonathan Wakely4-0/+16
Clang doesn't support the __constinit extension that we use pre-C++20, but it does have its own equivalent attribute that can be used instead. This makes it a little easier to use Clang to build libstdc++ (which isn't supported. but is sometimes attempted for esoteric targets). libstdc++-v3/ChangeLog: * src/c++11/cxx11-ios_failure.cc (__constinit): Define as equivalent attribute for Clang. * src/c++11/future.cc (__constinit): Likewise. * src/c++11/system_error.cc (__constinit): Likewise. * src/c++17/memory_resource.cc (__constinit): Likewise.
2022-01-19libstdc++: Fix libbacktrace build filesJonathan Wakely4-75/+130
This makes it possible to combine --enable-libstdcxx-debug with --enable-libstdcxx-backtrace, by adding a rule to src/Makefile to copy the backtrace-supported.h header into the src/debug/libbacktrace directory. Add libbacktrace path to testsuite flags so the tests can link without having the library installed. Also fix some warnings when running automake for the libbacktrace makefile. Use a per-library CPPFLAGS variable to fix: src/libbacktrace/Makefile.am:38: warning: AM_CPPFLAGS multiply defined in condition TRUE ... fragment.am:43: ... 'AM_CPPFLAGS' previously defined here src/libbacktrace/Makefile.am:32: 'fragment.am' included from here Create symlinks to the libbacktrace sources to fix: src/libbacktrace/Makefile.am:55: warning: source file '../../../libbacktrace/atomic.c' is in a subdirectory, src/libbacktrace/Makefile.am:55: but option 'subdir-objects' is disabled libstdc++-v3/ChangeLog: * scripts/testsuite_flags.in: Add src/libbacktrace/.libs to linker search paths. * src/Makefile.am: Fix src/debug/libbacktrace build. * src/Makefile.in: Regenerate. * src/libbacktrace/Makefile.am: Use per-library CPPFLAGS variable. Use symlinks for the source files. * src/libbacktrace/Makefile.in: Regenerate.
2022-01-18libstdc++: Use GCC's predefined macro for endianness [PR104080]Jonathan Wakely2-1/+4
Instead of hardcoded preprocessor conditionals with explicit target checks, just rely on the fact that __BYTE_ORDER__ is always defined by GCC. libstdc++-v3/ChangeLog: PR libstdc++/104080 * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.h (FASTFLOAT_IS_BIG_ENDIAN): Define in terms of __BYTE_ORDER__.
2022-01-18libstdc++: Fix deduction failure for std::min call [PR104080]Jonathan Wakely2-1/+2
libstdc++-v3/ChangeLog: PR libstdc++/104080 * src/c++17/fast_float/LOCAL_PATCHES: UPDATE. * src/c++17/fast_float/fast_float.h (round): Use explicit template argument list for std::min.
2022-01-17libstdc++: Use fast_float in std::from_chars for binary32/64Patrick Palka1-4/+27
This makes our std::from_chars implementation use fast_float for decimal parsing of binary32/64 numbers. For other floating-point formats we still use the fallback implementation that goes through the strtod family of functions. libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc: (USE_LIB_FAST_FLOAT): Conditionally define, and use it to conditionally include fast_float. (from_chars): Use fast_float for float and double when USE_LIB_FAST_FLOAT.
2022-01-17libstdc++: Adjust fast_float's over/underflow behavior for conformancePatrick Palka2-0/+10
This changes fast_float's handling of overflow/underflow to be consistent with the standard: instead of returning errc{} and setting value to +-0 or +-infinity, just return errc::result_out_of_range and don't modify value, as per [charconv.from.chars]/1. libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.h (from_chars_advanced): In case of over/underflow, return errc::result_out_of_range and don't modify 'value'.
2022-01-17libstdc++: Apply modifications to our local copy of fast_floatPatrick Palka2-56/+7
This performs the following modifications to our local copy of fast_float in order to make it more readily usable in our std::from_chars implementation: * Remove system #includes * Replace stray call to assert * Use the standard chars_format and from_chars_result types libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: Update. * src/c++17/fast_float/fast_float.h: Apply local modifications.
2022-01-17libstdc++: Import the fast_float libraryPatrick Palka4-0/+3166
We're going to use the fast_float library[1] in our (compiled-in) floating-point std::from_chars implementation for faster and more portable parsing of binary32/64 decimal strings. The single file fast_float.h is an amalgamation of the entire library, which can be (re)generated with the amalgamate.py script (from the fast_float repository) via the command python3 ./script/amalgamate.py --license=MIT \ > $GCC_SRC/libstdc++-v3/c++17/fast_float/fast_float.h The code has a GPL-compatible license. [1]: https://github.com/fastfloat/fast_float libstdc++-v3/ChangeLog: * src/c++17/fast_float/LOCAL_PATCHES: New file. * src/c++17/fast_float/MERGE: New file. * src/c++17/fast_float/README.md: New file, copied from the fast_float repository. * src/c++17/fast_float/fast_float.h: New file, an amalgamation of the fast_float library. Signed-off-by: Patrick Palka <ppalka@redhat.com>
2022-01-17libstdc++: Directly implement hexfloat std::from_chars for binary32/64Patrick Palka1-0/+374
libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc: Include <bit>. (ascii_to_hexit, starts_with_ci): Conditionally define. (__floating_from_chars_hex): Conditionally define. (from_chars): Use __floating_from_chars_hex for chars_format::hex parsing of binary32/64 float/double. (testsuite/20_util/from_chars/7.cc): New test.
2022-01-17libstdc++: Define <stacktrace> header for C++23Jonathan Wakely12-3/+1304
Add the <stacktrace> header and a new libstdc++_libbacktrace.a library that provides the implementation. For now, the new library is only built if --enable-libstdcxx-backtrace=yes is used. As with the Filesystem TS, the new library is only provided as a static archive. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): New macro. * configure.ac: Use GLIBCXX_ENABLE_BACKTRACE. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/std/stacktrace: New header. * include/std/version (__cpp_lib_stacktrace): Define. * Makefile.in: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * doc/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.am: Regenerate. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++17/Makefile.in: Regenerate. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/filesystem/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * src/libbacktrace/Makefile.am: New file. * src/libbacktrace/Makefile.in: New file. * src/libbacktrace/backtrace-rename.h: New file. * src/libbacktrace/backtrace-supported.h.in: New file. * src/libbacktrace/config.h.in: New file. * testsuite/lib/libstdc++.exp (check_effective_target_stacktrace): New proc. * testsuite/20_util/stacktrace/entry.cc: New test. * testsuite/20_util/stacktrace/synopsis.cc: New test. * testsuite/20_util/stacktrace/version.cc: New test.
2022-01-12libstdc++: Avoid overflow in bounds checks [PR103955]Patrick Palka1-13/+33
We currently crash when the floating-point to_chars overloads are passed a precision value near INT_MAX, ultimately due to overflow in the bounds checks that verify the output range is large enough. The simplest portable fix seems to be to replace bounds checks of the form A >= B + C (where B + C may overflow) with the otherwise equivalent check A >= B && A - B >= C, which is the approach this patch takes. Before we could do this in __floating_to_chars_hex, there we first need to track the unbounded "excess" precision (i.e. the number of trailing fractional digits in the output that are guaranteed to be '0') separately from the bounded "effective" precision (i.e. the number of significant fractional digits in the output), like we do in __f_t_c_precision. PR libstdc++/103955 libstdc++-v3/ChangeLog: * src/c++17/floating_to_chars.cc (__floating_to_chars_hex): Track the excess precision separately from the effective precision. Avoid overflow in bounds check by splitting it into two checks. (__floating_to_chars_precision): Avoid overflow in bounds checks similarly. * testsuite/20_util/to_chars/103955.cc: New test.
2022-01-10libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760]Jakub Jelinek1-0/+110
glibc strptime passes around some state, what fields in struct tm have been set and what needs to be finalized through possibly recursive calls, and at the end performs various finalizations, like applying %p so that it works for both %I %p and %p %I orders, or applying century so that both %C %y and %y %C works, or computation of missing fields from others (e.g. from %Y and %j one can compute tm_mon, tm_mday and tm_wday, from %Y %U %w, %Y %W %w, %Y %U %a, or %Y %W %w one can compute tm_mon, tm_mday, tm_yday or e.g. from %Y %m %d one can compute tm_wday and tm_yday. As the finalization is quite large and doesn't need to be a template (doesn't depend on any iterators or char types), I've put it into libstdc++, and left some padding in the state struct, so that perhaps in the future we can track some more state without changing ABI. Unfortunately, there is an ugly problem that the standard mandates that get method calls the do_get virtual method and I don't see how we can cary on any state in between those calls (even if we did an ABI change for the facets, the methods are const, so that I think multiple threads could use the same time_get objects and we couldn't store state in there). There is a hack for that for GCC (seems to work with ICC too, doesn't work with clang++) if the do_get method isn't overriden we can pass the state around. For both do_get_year and per IRC discussions also for %y, the behavior is if 1-2 digits are parsed, the year is treated according to POSIX 2008 %y rules (0-68 is 2000-2068, 69-99 is 1969-1999), if 3-4 digits are parsed, it is treated as %Y. 2022-01-10 Jakub Jelinek <jakub@redhat.com> PR libstdc++/77760 * include/bits/locale_facets_nonio.h (__time_get_state): New struct. (time_get::_M_extract_via_format): Declare new method with __time_get_state& as an extra argument. * include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Add __state argument, set various fields in it while parsing. Handle %j, %U, %w and %W, fix up handling of %y, %Y and %C, don't adjust tm_hour for %p immediately. Add a wrapper around the method without the __state argument for backwards compatibility. (_M_extract_num): Remove all __len == 4 special cases. (time_get::do_get_time, time_get::do_get_date, time_get::do_get): Zero initialize __state, pass it to _M_extract_via_format and finalize it at the end. (do_get_year): For 1-2 digit parsed years, map 0-68 to 2000-2068, 69-99 to 1969-1999. For 3-4 digit parsed years use that as year. (get): If do_get isn't overloaded from the locale_facets_nonio.tcc version, don't call do_get but call _M_extract_via_format instead to pass around state. * config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export _M_extract_via_format with extra __time_get_state and __time_get_state::_M_finalize_state. * src/c++98/locale_facets.cc (is_leap, day_of_the_week, day_of_the_year): New functions in anon namespace. (mon_yday): New var in anon namespace. (__time_get_state::_M_finalize_state): Define. * testsuite/22_locale/time_get/get/char/4.cc: New test. * testsuite/22_locale/time_get/get/wchar_t/4.cc: New test. * testsuite/22_locale/time_get/get_year/char/1.cc (test01): Parse 197 as year 197AD instead of error. * testsuite/22_locale/time_get/get_year/char/5.cc (test01): Parse 1 as year 2001 instead of error. * testsuite/22_locale/time_get/get_year/char/6.cc: New test. * testsuite/22_locale/time_get/get_year/wchar_t/1.cc (test01): Parse 197 as year 197AD instead of error. * testsuite/22_locale/time_get/get_year/wchar_t/5.cc (test01): Parse 1 as year 2001 instead of error. * testsuite/22_locale/time_get/get_year/wchar_t/6.cc: New test.
2022-01-10libstdc++: Fix and simplify freestanding configuration [PR103866]Jonathan Wakely6-0/+6
This fixes the --disable-hosted-libstdcxx build so that it works with --without-headers. Currently you need to also use --with-newlib, which is confusing for users who aren't actually using newlib. The AM_PROG_LIBTOOL checks are currently skipped for --with-newlib and --with-avrlibc builds, with this change they are also skipped when using --without-headers. It would be nice if using --disable-hosted-libstdcxx automatically skipped those checks, but GLIBCXX_ENABLE_HOSTED comes too late to make the AM_PROG_LIBTOOL checks depend on $is_hosted. The checks for EOF, SEEK_CUR etc. cause the build to fail if there is no <stdio.h> available. Unlike most headers, which get a HAVE_FOO_H macro, <stdio.h> is in autoconf's default includes, so every check tries to include it unconditionally. This change skips those checks for freestanding builds. Similarly, the checks for <stdint.h> types done by GCC_HEADER_STDINT try to include <stdio.h> and fail for --without-headers builds. This change skips the use of GCC_HEADER_STDINT for freestanding. We can probably stop using GCC_HEADER_STDINT entirely, since only one file uses the gstdint.h header that is generated, and that could easily be changed to use <stdint.h> instead. That can wait for stage 1. We also need to skip the GLIBCXX_CROSSCONFIG stage if --without-headers was used, since we don't have any of the functions it deals with. The end result of the changes above is that it should not be necessary for a --disable-hosted-libstdcxx --without-headers build to also use --with-newlib. Finally, compile libsupc++ with -ffreestanding when --without-headers is used, so that <stdint.h> will use <gcc-stdint.h> instead of expecting it to come from libc. libstdc++-v3/ChangeLog: PR libstdc++/103866 * acinclude.m4 (GLIBCXX_COMPUTE_STDIO_INTEGER_CONSTANTS): Do nothing for freestanding builds. (GLIBCXX_ENABLE_HOSTED): Define FREESTANDING_FLAGS. * configure.ac: Do not use AC_LIBTOOL_DLOPEN when configured with --without-headers. Do not use GCC_HEADER_STDINT for freestanding builds. * libsupc++/Makefile.am (HOSTED_CXXFLAGS): Use -ffreestanding for freestanding builds. * configure: Regenerate. * Makefile.in: Regenerate. * doc/Makefile.in: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++17/Makefile.in: Regenerate. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/filesystem/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
2022-01-10libstdc++: Add -nostdinc++ for c++17 sources [PR100017]Jonathan Wakely2-2/+2
When building a build!=host compiler, the just-built gcc can't be used to build the target libstdc++ (because it is built for the host triplet, not the build triplet). The top-level configure.ac sets up the build flags for libstdc++ (and other "raw_cxx" libs) like this: GCC_TARGET_TOOL(c++ for libstdc++, RAW_CXX_FOR_TARGET, CXX, [gcc/xgcc -shared-libgcc -B$$r/$(HOST_SUBDIR)/gcc -nostdinc++ -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs -L$$r/$(TARGET_SUBDIR)/libstdc++-v3/libsupc++/.libs], c++) The -nostdinc++ flag is only used for the IN-TREE-TOOL, i.e. when using the just-built gcc/xgcc compiler. This means that the cross-compiler used to build libstdc++ will add its own libstdc++ headers to the include path. That results in the #include <cfenv> in src/c++17/floating_to_chars.cc and src/c++17/floating_from_chars.cc doing #include_next <fenv.h> and finding the libstdc++ fenv.h wrapper from the host compiler. Because that has the same include guard as the <fenv.h> in the libstdc++ we're trying to build, we never reach the underlying <fenv.h> from libc. That results in several errors of the form: error: 'fenv_t' has not been declared in '::' The most correct fix would be to add -nostdinc++ to the RAW_CXX_FOR_TARGET variable in configure.ac, or the RAW_CXX_TARGET_EXPORTS variable in Makefile.tpl. Another solution would be to make the libstdc++ <fenv.h> wrapper use _GLIBCXX_INCLUDE_NEXT_C_HEADERS like our <stdlib.h> and other C header wrappers. For now though, the simplest and safest solution is to just add -nostdinc++ to the CXXFLAGS used for src/c++17/*.cc, which is what this does. libstdc++-v3/ChangeLog: PR libstdc++/100017 * src/c++17/Makefile.am (AM_CXXFLAGS): Add -nostdinc++. * src/c++17/Makefile.in: Regenerate.
2022-01-05libstdc++: Optimize operations on small size hashtable [PR 68303]François Dumont1-0/+1
When hasher is identified as slow and the number of elements is limited in the container use a brute-force loop on those elements to look for a given key using the key_equal functor. For the moment the default threshold to consider the container as small is 20. libstdc++-v3/ChangeLog: PR libstdc++/68303 * include/bits/hashtable_policy.h (_Hashtable_hash_traits<_Hash>): New. (_Hash_code_base<>::_M_hash_code(const _Hash_node_value<>&)): New. (_Hashtable_base<>::_M_key_equals): New. (_Hashtable_base<>::_M_equals): Use latter. (_Hashtable_base<>::_M_key_equals_tr): New. (_Hashtable_base<>::_M_equals_tr): Use latter. * include/bits/hashtable.h (_Hashtable<>::__small_size_threshold()): New, use _Hashtable_hash_traits. (_Hashtable<>::find): Loop through elements to look for key if size is lower than __small_size_threshold(). (_Hashtable<>::_M_emplace(true_type, _Args&&...)): Likewise. (_Hashtable<>::_M_insert_unique(_Kt&&, _Args&&, const _NodeGenerator&)): Likewise. (_Hashtable<>::_M_compute_hash_code(const_iterator, const key_type&)): New. (_Hashtable<>::_M_emplace(const_iterator, false_type, _Args&&...)): Use latter. (_Hashtable<>::_M_find_before_node(const key_type&)): New. (_Hashtable<>::_M_erase(true_type, const key_type&)): Use latter. (_Hashtable<>::_M_erase(false_type, const key_type&)): Likewise. * src/c++11/hashtable_c++0x.cc: Include <bits/functional_hash.h>. * testsuite/util/testsuite_performance.h (report_performance): Use 9 width to display memory. * testsuite/performance/23_containers/insert_erase/unordered_small_size.cc: New performance test case.
2022-01-05libstdc++: Improvements to standard error category objects (part deux)Jonathan Wakely2-20/+31
In r12-3860 the error categories in <system_error> were made final and immortal, but I missed the categories for <future> and <ios>. This makes the same changes to those. libstdc++-v3/ChangeLog: * src/c++11/cxx11-ios_failure.cc (io_error_category): Define class and virtual functions as 'final'. (io_category_instance): Use constinit union to make the object immortal. * src/c++11/future.cc (future_error_category): Define class and virtual functions as 'final'. (future_category_instance): Use constinit union.
2022-01-05libstdc++: Improve std::regex_error::what() stringsJonathan Wakely1-1/+46
This replaces the vague "regex_error" for std::regex_error::what() with a string that corresponds to the error_type enum passed to the constructor. This allows us to remove many of the strings passed to __throw_regex_error, because the default string is at least as good. When a string argument to __throw_regex_error is kept it should add some context-specific detail absent from the default string. Also remove full stops (periods) from the end of those strings, to make it easier to include them in logs and other output. I've left them starting with an upper-case letter, which is consistent with strerror output for (at least) Glibc, Solaris and BSD. I'm ambivalent whether that's the right choice. This also adds the missing noreturn attribute to __throw_regex_error. libstdc++-v3/ChangeLog: * include/bits/regex_compiler.tcc: Adjust all calls to __throw_regex_error. * include/bits/regex_error.h (__throw_regex_error): Add noreturn attribute. * include/bits/regex_scanner.tcc: Likewise. * src/c++11/regex.cc (desc): New helper function. (regex_error::regex_error(error_type)): Use desc to get a string corresponding to the error code.
2022-01-03Update copyright years.Jakub Jelinek131-131/+131
2021-12-09libstdc++: Allow std::condition_variable waits to be cancelled [PR103382]Jonathan Wakely2-1/+32
std::condition_variable::wait(unique_lock<mutex>&) is incorrectly marked noexcept, which means that the __forced_unwind exception used by NPTL cancellation will terminate the process. It should allow exceptions to pass through, so that a thread can be cleanly cancelled when waiting on a condition variable. The new behaviour is exported as a new version of the symbol, to avoid an ABI break for existing code linked to the non-throwing definition of the function. Code linked against older releases will have a reference to the @GLIBCXX_3.4.11 version, andcode compiled against the new libstdc++ will get a reference to the @@GLIBCXX_3.4.30 version. libstdc++-v3/ChangeLog: PR libstdc++/103382 * config/abi/pre/gnu.ver (GLIBCXX_3.4.11): Do not export old symbol if .symver renaming is supported. (GLIBCXX_3.4.30): Export new symbol if .symver renaming is supported. * doc/xml/manual/evolution.xml: Document change. * doc/html/manual/api.html: Regenerate. * include/bits/std_mutex.h (__condvar::wait, __condvar::wait_until): Remove noexcept. * include/std/condition_variable (condition_variable::wait): Likewise. * src/c++11/condition_variable.cc (condition_variable::wait): Likewise. * src/c++11/compatibility-condvar.cc (__nothrow_wait_cv::wait): Define nothrow wrapper around std::condition_variable::wait and export the old symbol as an alias to it. * testsuite/30_threads/condition_variable/members/103382.cc: New test.
2021-12-02libstdc++: Allow exception classes to move fully-dynamic stringsJonathan Wakely1-20/+0
The move constructor for the fully-dynamic std::basic_string was not noexcept until recently, so the std::logic_error and std::runtime_error move constructors were defined to make non-throwing copies of their string members, instead of potentially-throwing moves. Now that move construction is always noexecpt, the exception classes can always move the string. The fully-dynamic string move assignment was always noexcept, so I don't know why I special-cased the move assignment operators of the exception classes. That can be changed too. libstdc++-v3/ChangeLog: * src/c++11/cow-stdexcept.cc [_GLIBCXX_FULY_DYNAMIC_STRING] (logic_error, runtime_error): Remove custom definitions.
2021-12-01libstdc++: Avoid unwanted allocations in filesystem::pathJonathan Wakely2-19/+17
When using COW strings, accessing _M_pathname[0] and similar non-const accessors can cause the string to "leak", meaning it reallocates itself if it shares ownership with another string object. This causes test failures for --enable-fully-dynamic-string builds: /home/jwakely/src/gcc/libstdc++-v3/testsuite/experimental/filesystem/path/construct/90634.cc:62: void test01(): Assertion 'bytes_allocated == 0' failed. FAIL: experimental/filesystem/path/construct/90634.cc execution test This FAIL happens because the fully-dynamic move constructor results in shared ownership, so for path(std::move(std::string("foo"))) the _M_pathname member shares ownership with the temporary, and the non-const accesses in _M_split_cmpts() cause a new copy of the string to be allocated. This un-sharing is wasteful, and entirely unnecessary when sharing ownership with an rvalue that is about to release its ownership anyway. Even for lvalues, sharing ownership is not a problem and reallocating a unique copy of the string is wasteful. This removes non-const accesses of _M_pathname in the path::_M_split_cmpts() members. libstdc++-v3/ChangeLog: * src/c++17/fs_path.cc (path::_M_split_cmpts()): Remove micro-optimization for "/" path. * src/filesystem/path.cc (path::_M_split_cmpts()): Only access the contents of _M_pathname using const member functions.
2021-11-30libstdc++: Ensure C++20 std::stringstream definitions use correct ABIJonathan Wakely1-1/+3
The definitions of the new C++20 members of std::stringstream etc are missing when --with-default-libstdcxx-abi=gcc4-compatible is used, because all the explicit instantiations in src/c++20/sstream-inst.cc are skipped. This ensures the contents of that file are compiled with the new ABI, so the same set of symbols are exported regardless of which ABI is active by default. libstdc++-v3/ChangeLog: * src/c++20/sstream-inst.cc (_GLIBCXX_USE_CXX11_ABI): Define to select new ABI.
2021-11-19libstdc++: Use __is_single_threaded in locale initializationJonathan Wakely1-2/+9
This replaces a __gthread_active_p() check with __is_single_threaded() so that std::locale initialization doesn't use __gthread_once if it happens before the first thread is created. This means that _S_initialize_once() might now be called twice instead of only once, because if __is_single_threaded() changes to false then we will do the __gthread_once call even if _S_initialize_once() was already called. Add a check to _S_initialize_once() and return immediately if it is the second call. Also use __builtin_expect to _S_initialize, as the branch will be taken at most once in the lifetime of the program. libstdc++-v3/ChangeLog: * src/c++98/locale_init.cc (_S_initialize_once): Check if initialization has already been done. (_S_initialize): Replace __gthread_active_p with __is_single_threaded. Use __builtin_expect.
2021-11-16libstdc++: Merge latest Ryu sourcesPatrick Palka2-6/+5
libstdc++-v3/ChangeLog: * src/c++17/ryu/MERGE: Update the commit hash. * src/c++17/ryu/d2s_intrinsics.h: Merge from Ryu's master branch. Signed-off-by: Patrick Palka <ppalka@redhat.com>
2021-11-15c++: check constexpr constructor bodyJason Merrill1-1/+1
The implicit constexpr patch revealed that our checks for constexpr constructors that could possibly produce a constant value (which otherwise are IFNDR) was failing to look at most of the function body. Fixing that required some library tweaks. gcc/cp/ChangeLog: * constexpr.c (maybe_save_constexpr_fundef): Also check whether the body of a constructor is potentially constant. libstdc++-v3/ChangeLog: * src/c++17/memory_resource.cc: Add missing constexpr. * include/experimental/internet: Only mark copy constructor as constexpr with __cpp_constexpr_dynamic_alloc. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-89285-2.C: Expect error. * g++.dg/cpp1y/constexpr-89285.C: Adjust error.
2021-11-12libstdc++: Print assertion messages to stderr [PR59675]Jonathan Wakely1-1/+17
This replaces the printf used by failed debug assertions with fprintf, so we can write to stderr. To avoid including <stdio.h> the assert function is moved into the library. To avoid programs using a vague linkage definition of the old inline function, the function is renamed. Code compiled with old versions of GCC might still call the old function, but code compiled with the newer GCC will call the new function and write to stderr. libstdc++-v3/ChangeLog: PR libstdc++/59675 * acinclude.m4 (libtool_VERSION): Bump version. * config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Add version and export new symbol. * configure: Regenerate. * include/bits/c++config (__replacement_assert): Remove, declare __glibcxx_assert_fail instead. * src/c++11/debug.cc (__glibcxx_assert_fail): New function to replace __replacement_assert, writing to stderr instead of stdout. * testsuite/util/testsuite_abi.cc: Update latest version.
2021-11-09libstdc++: Do not use 64-bit DARN on 32-bit powerpc [PR103146]Jonathan Wakely1-1/+1
We need to use the 64-bit DARN to detect failure without bias, but it's not available in 32-bit mode. libstdc++-v3/ChangeLog: PR libstdc++/103146 * src/c++11/random.cc: Check __powerpc64__ not __powerpc__.
2021-11-09libstdc++: Support getentropy and arc4random in std::random_deviceJonathan Wakely1-2/+67
This adds additional "getentropy" and "arc4random" tokens to std::random_device. The former is supported on Glibc and OpenBSD (and apparently wasm), and the latter is supported on various BSDs. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM): Define. * configure.ac (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM): Use them. * config.h.in: Regenerate. * configure: Regenerate. * src/c++11/random.cc (random_device): Add getentropy and arc4random as sources. * testsuite/26_numerics/random/random_device/cons/token.cc: Check new tokens. * testsuite/26_numerics/random/random_device/entropy.cc: Likewise.
2021-11-05libstdc++: Add [[unlikely]] attributes to std::random_device routinesJonathan Wakely1-2/+2
libstdc++-v3/ChangeLog: * src/c++11/random.cc (__x86_rdrand, __x86_rdseed): Add [[unlikely]] attribute.
2021-11-05libstdc++: Add support for POWER9 DARN instruction to std::random_deviceJonathan Wakely1-3/+53
The ISA-3.0 instruction set includes DARN ("deliver a random number") which can be used similarly to the existing support for RDRAND and RDSEED. libstdc++-v3/ChangeLog: * src/c++11/random.cc [__powerpc__] (USE_DARN): Define. (__ppc_darn): New function to use POWER9 DARN instruction. (Which): Add 'darn' enumerator. (which_source): Check for __ppc_darn. (random_device::_M_init): Support "darn" and "hw" tokens. (random_device::_M_getentropy): Add darn to switch. * testsuite/26_numerics/random/random_device/cons/token.cc: Check "darn" token. * testsuite/26_numerics/random/random_device/entropy.cc: Likewise.
2021-10-19libstdc++: Implement std::random_device::entropy() for other sourcesJonathan Wakely1-7/+63
Currently this function only returns a non-zero value for /dev/random and /dev/urandom. When a hardware instruction such as RDRAND is in use it should (in theory) be perfectly random and produce 32 bits of entropy in each 32-bit result. Add a helper function to identify the source of randomness from the _M_func and _M_file data members, and return a suitable value when RDRAND or RDSEED is being used. libstdc++-v3/ChangeLog: * src/c++11/random.cc (which_source): New helper function. (random_device::_M_getentropy()): Use which_source and return suitable values for sources other than device files. * testsuite/26_numerics/random/random_device/entropy.cc: New test.
2021-10-08libstdc++: Detect miscompilation of src/c++11/limits.ccJonathan Wakely1-0/+4
Add a #error directive to ensure that the definitions are not compiled as C++17, which would prevent them being emitted. libstdc++-v3/ChangeLog: PR libstdc++/98725 * src/c++11/limits.cc: Fail if __cpp_inline_variables is defined.
2021-10-02libstdc++: Fix typos in std::filesystem codeJonathan Wakely2-3/+3
There were a couple of typos in r12-4070 and r12-4071 which don't show up when building for POSIX targets. libstdc++-v3/ChangeLog: * src/c++17/fs_ops.cc (create_directory): Fix typo in enum name. * src/filesystem/ops-common.h (__last_system_error): Add explicit cast to avoid narrowing conversion. (do_space): Fix type in function name.
2021-10-01libstdc++: Allow stateful allocators in std::list::sort [PR 66742]Jonathan Wakely1-0/+2
The temporary lists used by std::list::sort are default constructed, which means they use default constructed allocators. The sort operation is defined in terms of merge and splice operations, which have undefined behaviour (and abort) if the allocators do not compare equal. This means it is not possible to sort a list that uses an allocator that compares unequal to an default constructed allocator. The solution is to avoid using temporary std::list objects at all. We do not need to be able to allocate memory because no nodes are allocated, only spliced from one list to another. That means the temporary lists don't need an allocator at all, so whether it would compare equal doesn't matter. Instead of temporary std::list objects, we can just use a collection of _List_node_base objects that nodes can be spliced onto as needed. Those objects are wrapped in a _Scratch_list type that implements the splicing and merging operations used by list::sort. We also don't need to update the list size during the sort, because sorting doesn't alter the number of nodes. Although we move nodes in and out of the scratch lists, at the end of the function all nodes are back in the original std::list and the scratch lists are empty. So for the cxx11 ABI we can avoid the _M_size modifications usually done when splicing nodes. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/66742 * include/bits/list.tcc (list::sort()): Use _Scratch_list objects for splicing and merging. (list::sort(StrictWeakOrdering)): Likewise. * include/bits/stl_list.h (__detail::_Scratch_list): New type. * src/c++98/list.cc (_List_node_base::_M_transfer): Add assertion for --enable-libstdcxx-debug library. * testsuite/23_containers/list/operations/66742.cc: New test.
2021-10-01libstdc++: Simplify __throw_out_of_range_fmt for freestandingJonathan Wakely2-12/+7
There is no point expanding the format string if we're just going to abort instead of throw an exception. And for freestanding or non-verbose builds we shouldn't do it either, to reduce the binary size. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * src/c++11/functexcept.cc (__throw_out_of_range_fmt): Do not expand the format string for freestanding, or non-vebose, or if we're just going to abort anyway. * src/c++11/snprintf_lite.cc: Remove unused header and declaration.
2021-10-01libstdc++: Avoid unconditional use of errc::not_supported [PR 99327]Jonathan Wakely3-55/+78
The errc::not_supported constant is only defined if ENOTSUP is defined, which is not true for all targets. Many uses of errc::not_supported in the filesystem library do not actually match the intended meaning of ENOTSUP described by POSIX. They should be using ENOSYS instead (i.e. errc::function_not_supported). This change ensures that appropriate error codes are used by the filesystem library. The remaining uses of errc::not_supported are replaced with a call to a new helper function so that an alternative value will be used on targets that don't support errc::not_supported. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/99327 * src/filesystem/ops-common.h (__unsupported): New function to return a suitable error code for missing functionality. (posix::off_t): New typedef. (posix::*): Set errno to ENOSYS instead of ENOTSUP for no-op fallback implementations. (do_copy_file): Replace uses of errc::not_supported. * src/c++17/fs_ops.cc (fs::copy, fs::copy_file, create_dir) (fs::create_directory, fs::create_directory_symlink) (fs::create_hard_link, fs::create_symlink, fs::current_path) (fs::equivalent, do_stat, fs::file_size, fs::hard_link_count) (fs::last_write_time, fs::permissions, fs::read_symlink): Replace uses of errc::not_supported. (fs::resize_file): Qualify off_t. * src/filesystem/ops.cc (fs::copy, fs::copy_file, create_dir) (fs::create_directory, fs::create_directory_symlink) (fs::create_hard_link, fs::create_symlink, fs::current_path) (fs::equivalent, do_stat, fs::file_size, fs::last_write_time) (fs::permissions, fs::read_symlink, fs::system_complete): Replace uses of errc::not_supported. (fs::resize_file): Qualify off_t and enable unconditionally. * testsuite/19_diagnostics/system_error/cons-1.cc: Likewise.
2021-10-01libstdc++: Add utility for creating std::error_code from OS errorsJonathan Wakely3-9/+21
This adds a helper function to encapsulate obtaining an error code for errors from OS calls. For Windows we want to use GetLastError() and the system error category, but otherwise just use errno and the generic error category. This should not be used to replace existing uses of ec.assign(errno, generic_category()) because in those cases we really do want to get the value of errno, not a system-specific error. Only the cases that currently use GetLastError() are replace by this new function. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * src/filesystem/ops-common.h (last_error): New helper function. (filesystem::do_space): Use last_error(). * src/c++17/fs_ops.cc (fs::absolute, fs::create_hard_link) (fs::equivalent, fs::remove, fs::temp_directory_path): Use last_error(). * src/filesystem/ops.cc (fs::create_hard_link) (fs::remove, fs::temp_directory_path): Likewise.