Commit Graph

13476 Commits

Author SHA1 Message Date
Jonathan Wakely d3a757af21 libstdc++: Ensure __glibcxx_assert_fail has default visibility
This ensures there's no linker error if libstdc++ headers are included
following a pragma that sets hidden visibility.

Similarly for std::__terminate, which is always-inline so shouldn't
matter, but it's not wrong to do this anyway.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (__glibcxx_assert_fail): Add visibility
	attribute.
	(__terminate): Likewise.
2022-03-05 20:33:36 +00:00
GCC Administrator 8d96e14c1d Daily bump. 2022-03-05 00:16:31 +00:00
Jonathan Wakely 289f65d643 libstdc++: Fix -Wunused-local-typedefs warning in <compare>
libstdc++-v3/ChangeLog:

	* libsupc++/compare (strong_order::_S_fp_cmp): Move typedef
	inside #if condition.
2022-03-04 10:43:29 +00:00
GCC Administrator fc03ebdcea Daily bump. 2022-03-04 00:16:21 +00:00
Jonathan Wakely 5706a5db88 libstdc++: Use non-debug vector in constexpr test [PR104748]
The std::__debug::vector isn't usable in constant expressions, so this
test fails in debug mode. Until the debug vector is fixed we can just
make the test use the non-debug one.

libstdc++-v3/ChangeLog:

	PR libstdc++/104748
	* testsuite/std/ranges/adaptors/all.cc: Use non-debug vector for
	constexpr test.
2022-03-03 22:28:48 +00:00
Jonathan Wakely 64cdf49962 libstdc++: Fix test failure on AIX
This fixes a test failure due to a non-reserved name in an AIX system
header (included via <pthread.h>). That name clashes with one of the
names we check our own headers for, so skip checking that name on AIX.

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/names.cc (func): Undef on AIX.
2022-03-03 22:25:44 +00:00
Jonathan Wakely 9805965e35 libstdc++: Implement std::strong_order for floating-point types [PR96526]
This removes a FIXME in <compare>, defining the total order for
floating-point types. I originally opened PR96526 to request a new
compiler built-in to implement this, but now that we have std::bit_cast
it can be done entirely in the library.

The implementation is based on the glibc definitions of totalorder,
totalorderf, totalorderl etc.

I think this works for all the types that satisfy std::floating_point
today, and should also work for the types expected to be added by P1467
except for std::bfloat16_t. It also supports some additional types that
don't currently satisfy std::floating_point, such as __float80, but we
probably do want that to satisfy the concept for non-strict modes.

libstdc++-v3/ChangeLog:

	PR libstdc++/96526
	* libsupc++/compare (strong_order): Add missing support for
	floating-point types.
	* testsuite/18_support/comparisons/algorithms/strong_order_floats.cc:
	New test.
2022-03-03 22:24:45 +00:00
GCC Administrator 12d4552e5e Daily bump. 2022-03-02 00:16:32 +00:00
Jonathan Wakely ad66b03b3c libstdc++: Fix -Wmaybe-uninitialized false positive [PR103984]
This fixes a false positive warning seen with LTO:

12/bits/regex_compiler.tcc:443:32: error: '__last_char._M_char' may be used uninitialized [-Werror=maybe-uninitialized]

Given that the std::regex code is not very efficient anyway, the
overhead of initializing this byte should be minimal.

libstdc++-v3/ChangeLog:

	PR middle-end/103984
	* include/bits/regex_compiler.h (_BracketMatcher::_M_char): Use
	default member initializer.
2022-03-01 15:25:39 +00:00
GCC Administrator 756a61851c Daily bump. 2022-02-25 00:16:20 +00:00
Jonathan Wakely 41cbcf53dc libstdc++: Fix cast in source_location::current() [PR104602]
This fixes a problem for Clang, which is going to return a non-void
pointer from __builtin_source_location(). The current definition of
std::source_location::current() converts that to void* and then has to
cast it back again in the body (which makes it invalid in a constant
expression). By using the actual type of the returned pointer, we avoid
the problematic cast for Clang.

libstdc++-v3/ChangeLog:

	PR libstdc++/104602
	* include/std/source_location (source_location::current): Use
	deduced type of __builtin_source_location().
2022-02-24 23:42:41 +00:00
GCC Administrator 2cfb33fc1e Daily bump. 2022-02-23 00:16:24 +00:00
Patrick Palka 5e1b17f038 libstdc++: Implement P2415R2 changes to viewable_range / views::all
This implements the wording changes in P2415R2 "What is a view?", which
is a DR for C++20.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__detail::__is_initializer_list):
	Define.
	(viewable_range): Adjust as per P2415R2.
	* include/bits/ranges_cmp.h (__cpp_lib_ranges): Adjust value.
	* include/std/ranges (owning_view): Define as per P2415R2.
	(enable_borrowed_range<owning_view>): Likewise.
	(views::__detail::__can_subrange): Replace with ...
	(views::__detail::__can_owning_view): ... this.
	(views::_All::_S_noexcept): Sync with operator().
	(views::_All::operator()): Use owning_view instead of subrange
	as per P2415R2.
	* include/std/version (__cpp_lib_ranges): Adjust value.
	* testsuite/std/ranges/adaptors/all.cc (test06): Adjust now that
	views::all uses owning_view instead of subrange.
	(test08): New test.
	* testsuite/std/ranges/adaptors/lazy_split.cc (test09): Adjust
	now that rvalue non-view non-borrowed ranges are viewable.
	* testsuite/std/ranges/adaptors/split.cc (test06): Likewise.
2022-02-22 09:37:58 -05:00
GCC Administrator 0bdb049877 Daily bump. 2022-02-18 00:16:39 +00:00
Jonathan Wakely 12a88e6e20 libstdc++: Deprecate non-standard std::vector<bool>::insert(pos) [PR104559]
The SGI STL and pre-1998 drafts of the C++ standard had a default
argument for vector<bool>::insert(iterator, const bool&) which was
remove by N1051. The default argument is still present in libstdc++ for
some reason. There are no tests verifying it as an extension, so I don't
think it has been kept intentionally.

This removes the default argument but adds an overload without the
second parameter, and adds the deprecated attribute to it. This allows
any code using it to keep working (for now) but with a warning.

libstdc++-v3/ChangeLog:

	PR libstdc++/104559
	* doc/xml/manual/evolution.xml: Document deprecation.
	* doc/html/manual/api.html: Regenerate.
	* include/bits/stl_bvector.h (insert(const_iterator, const bool&)):
	Remove default argument.
	(insert(const_iterator)): New overload with deprecated attribute.
	* testsuite/23_containers/vector/bool/modifiers/insert/104559.cc:
	New test.
2022-02-17 23:44:25 +00:00
Jonathan Wakely 36100e0e95 libstdc++: Make std::error_code printer more robust
This attempts to implement a partial workaround for the GDB bug
https://sourceware.org/bugzilla/show_bug.cgi?id=28856 which causes GDB
to crash when printing a frame with a std::error_code argument.

By recognising the known error categories defined in the library and
hardcoding their names we do not need to call cat->name() on the
category.  This has the additional benefit of also working when
debugging a core file rather than a running process. For those known
categories we can also cast the int value to the corresponding error
code enum (e.g. future_errc) so that we show an enumerator instead of
just an integer.

For program-defined categories we just use the name of the dynamic type
to identify the category, and print the value as an integer. Once the
GDB bug is fixed and the virtual name() function can be called safely,
that would be preferable. For now it's better to have an imperfect
printer that doesn't crash GDB.

This rewritten StdErrorCodePrinter needs gdb.Value.dynamic_type, so is
only registered if that is supported, which means GDB 7.7 and later.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Replace
	code that call cat->name() on std::error_category objects.
	Identify known categories by symbol name and use a hardcoded
	name. Print error code values as enumerators where appopriate.
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Adjust expected
	name of custom category. Check io_errc and future_errc errors.
2022-02-17 22:22:14 +00:00
GCC Administrator 875e493bf5 Daily bump. 2022-02-16 00:16:26 +00:00
Jonathan Wakely 6cfb7ffb65 libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542]
libstdc++-v3/ChangeLog:

	PR libstdc++/104542
	* include/bits/uses_allocator_args.h (make_obj_using_allocator)
	(uninitialized_construct_using_allocator): Add constexpr.
	* testsuite/20_util/uses_allocator/make_obj.cc: Check constexpr.
	* testsuite/20_util/uses_allocator/uninitialized_construct.cc: New test.
2022-02-15 12:49:34 +00:00
GCC Administrator 1f8a09d2f3 Daily bump. 2022-02-15 00:16:41 +00:00
Jonathan Wakely 3d50dede07 libstdc++: Fix stream extraction of IEEE128 long double [PR100912]
The std::__convert_from_v helper that formats double and long double
values into a char buffer was not being duplicated for the two long
double ABIs. This resulted in an ODR violation inside the library, where
some callers needed it to use snprintf to format __ibm128 values and
other callers needed it to use __snprintfieee128 to format __ieee128
values. The linker discarded one of the definitions, leaving one set of
callers using the wrong code.

This puts __convert_from_v in the __gnu_cxx_ieee128 inline namespace
when long double is __ieee128, so that there are two different
definitions of the function.

The std::money_put::__do_put overload for __ibm128 values needs a
different fix, because that is defined when long double is __ieee128 and
so would call the one in the inline namespace. That can be fixed by just
inlining the code directly into the function and using an asm alias to
call the right version of snprintf for the __ibm128 format. The code to
do that can be simpler than __convert_from_v because if we're defining
the ALT128_COMPAT symbols we know that we have a recent glibc and so we
can assume that uselocale and snprintf are supported.

libstdc++-v3/ChangeLog:

	PR libstdc++/100912
	* config/locale/gnu/c_locale.h (__convert_from_v): Use inline
	namespace for IEEE128 long double mode.
	* config/os/gnu-linux/ldbl-ieee128-extra.ver: Add new symbol
	version and export __gnu_cxx_ieee128::__convert_from_v.
	* include/bits/locale_facets_nonio.tcc (money_put::__do_put):
	Make __ibm128 overload use snprintf directly
	* testsuite/util/testsuite_abi.cc: Add new symbol version.
	Remove stable IEEE128/LDBL versions.
2022-02-14 17:19:08 +00:00
Jonathan Wakely 164a761a9f libstdc++: Use __cpp_concepts instead of custom macro [PR103891]
With the new value of __cpp_concepts required by P2493, we can test
whether the compiler supports conditionally trivial special members.
This allows us to remove the workaround that disables fully-constexpr
std::variant for Clang. Now it should work for non-GCC compilers (such
as future releases of Clang) that support conditionally trivial
destructors and define the new value of __cpp_concepts.

libstdc++-v3/ChangeLog:

	PR libstdc++/103891
	* include/bits/c++config (_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
	Remove.
	* include/std/variant: Check feature test macros instead.
	* include/std/version: Likewise.
2022-02-14 13:03:31 +00:00
Jonathan Wakely 220d85fdf0 libstdc++: Fix typo in pragma
libstdc++-v3/ChangeLog:

	* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
	Fix typo.
2022-02-14 12:46:04 +00:00
Jonathan Wakely 8134156502 libstdc++: Fix std::to_chars for IEEE128 long double
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-14 12:34:21 +00:00
GCC Administrator e8d68f0a45 Daily bump. 2022-02-12 00:16:23 +00:00
Jonathan Wakely 9a56779dbc libstdc++: Fix FAIL: 20_util/temporary_buffer.cc for C++14
The std::get_temporary_buffer function is deprecated since C++17, but
the test was expecting a warning for C++14 as well.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/temporary_buffer.cc: Fix dg-warning target
	selector.
2022-02-11 21:42:22 +00:00
Jonathan Wakely b02247346e libstdc++: Fix test failures at -O0
libstdc++-v3/ChangeLog:

	* testsuite/20_util/monotonic_buffer_resource/allocate.cc:
	Ignore -Walloc-larger-than warning.
	* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
	Likewise.
	* testsuite/29_atomics/atomic/cons/user_pod.cc: Compile with -O1
	to avoid linker error for __atomic_is_lock_free.
2022-02-11 21:41:43 +00:00
GCC Administrator a645583d4d Daily bump. 2022-02-11 00:16:25 +00:00
Thomas Rodgers b25a7c05f1 libstdc++: Strengthen memory order for atomic<T>::wait/notify
This changes the memory order used in the spin wait code to match
that of libc++.

libstdc++-v3/ChangeLog:
	* include/bits/atomic_wait.h (__waiter_base::_S_do_spin,
	__waiter_base::_S_do_spin_v): Change memory order from relaxed
	to acquire.
2022-02-10 10:14:36 -08:00
Jonathan Wakely 3e539985cc libstdc++: Add atomic_fetch_xor to <stdatomic.h>
This function (and the explicit memory over version) are present in both
C++ <atomic> and C <stdatomic.h>, so should be in C++ <stdatomic.h> too.
There is a library issue incoming for this, but the resolution is
obvious.

libstdc++-v3/ChangeLog:

	* include/c_compatibility/stdatomic.h (atomic_fetch_xor): Add
	using-declaration.
	(atomic_fetch_xor_explicit): Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: Check
	arithmetic and logical operations for atomic_int.
2022-02-10 13:01:10 +00:00
Jonathan Wakely 3d5f4f76e6 libstdc++: Fix directory iterator build for newlib
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-10 13:01:10 +00:00
GCC Administrator 3adf509fe6 Daily bump. 2022-02-10 00:16:27 +00:00
Thomas Rodgers 4cf3c33981 libstdc++: Fix deadlock in atomic wait [PR104442]
This issue was observed as a deadlock in
29_atomics/atomic/wait_notify/100334.cc on vxworks. When a wait is
"laundered" (e.g. type T* does not suffice as a waitable address for the
platform's native waiting primitive), the address waited is that of the
_M_ver member of __waiter_pool_base, so several threads may wait on the
same address for unrelated atomic<T> objects. As noted in the PR, the
implementation correctly exits the wait for the thread whose data
changed, but not for any other threads waiting on the same address.

As noted in the PR the __waiter::_M_do_wait_v member was correctly exiting
but the other waiters were not reloading the value of _M_ver before
re-entering the wait.

Moving the spin call inside the loop accomplishes this, and is
consistent with the predicate accepting version of __waiter::_M_do_wait.

libstdc++-v3/ChangeLog:

	PR libstdc++/104442
	* include/bits/atomic_wait.h (__waiter::_M_do_wait_v): Move spin
	 loop inside do loop so that threads failing the wait, reload
	 _M_ver.
2022-02-09 12:30:51 -08:00
GCC Administrator 2a2fda2d9b Daily bump. 2022-02-09 00:16:24 +00:00
Jonathan Wakely 1ef6085f09 libstdc++: Simplify resource management in directory iterators
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-08 21:04:14 +00:00
Jonathan Wakely 8dbb60b8df libstdc++: Add comment to acinclude.m4
libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add comment about
	checking for CAS on correct word size.
2022-02-08 14:15:38 +00:00
Jonathan Wakely 61b783995f libstdc++: Adjust Filesystem TS test for Windows
The Filesystem TS isn't really supported for Windows, but the FAIL for
this test is just because it doesn't match what happens on Windows.

libstdc++-v3/ChangeLog:

	* testsuite/experimental/filesystem/operations/create_directories.cc:
	Adjust expected results for Windows.
2022-02-08 13:31:09 +00:00
Jonathan Wakely 5750952bec libstdc++: Fix filesystem::remove_all for Windows [PR104161]
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-08 13:31:05 +00:00
GCC Administrator 3c1cbde16e Daily bump. 2022-02-05 00:16:31 +00:00
Jonathan Wakely 6e3419529d libstdc++: Fix std::filesystem build failure for Windows
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-04 23:56:29 +00:00
Jonathan Wakely 0d1aabb60e libstdc++: Allow Clang to use <stdatomic.h> before C++23
There is code that only expects to be compiled with clang++ and uses its
<stdatomic.h>, which works because Clang supports the _Atomic specifier
in C++. The addition  of <stdatomic.h> to libstdc++ broke this code, as
now it finds the C++ header instead, which is empty for any standard
mode before C++23.

This change allows that code to keep working as before, by forwarding to
clang's <stdatomic.h>.

libstdc++-v3/ChangeLog:

	* include/c_compatibility/stdatomic.h [__clang__]: Use
	#include_next <stdatomic.h>.
2022-02-04 19:51:26 +00:00
Jonathan Wakely da72e0fd20 libstdc++: Remove un-implementable noexcept from Filesystem TS operations
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-04 19:51:26 +00:00
Jonathan Wakely ebf6175464 libstdc++: Fix filesystem::remove_all races [PR104161]
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-04 19:51:26 +00:00
Jonathan Wakely 27ba40559c libstdc++: Add suggestion to std::uncaught_exception() warning
We should use the SUGGEST macro for std::uncaught_exception()
deprecation warnings.

libstdc++-v3/ChangeLog:

	* include/bits/allocator.h: Qualify std::allocator_traits in
	deprecated warnings.
	* libsupc++/exception (uncaught_exception): Add suggestion to
	deprecated warning.
2022-02-04 15:26:59 +00:00
GCC Administrator 88944e1314 Daily bump. 2022-02-03 00:16:22 +00:00
Jonathan Wakely 2905e1af94 libstdc++: Fix -Wunused-variable warning for -fno-exceptions build
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-02 17:55:16 +00:00
Jonathan Wakely c123096cf1 libstdc++: Fix invalid instantiations in tests
These tests instantiate std::multiset and std::set with a type that has
no operator< so they should use a custom comparison function.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/multiset/operators/cmp_c++20.cc: Use
	custom comparison function for multiset.
	* testsuite/23_containers/set/operators/cmp_c++20.cc: Use custom
	comparison function for set.
2022-02-02 17:08:54 +00:00
Jonathan Wakely b229c51860 libstdc++: Fix link failure in _OutputIteratorConcept
The C++98-style concept check for output iterators causes a link
failure on mingw-w64, because the __val() member function isn't defined.
Change it to use a function pointer instead. That pointer is never set
to anything meaningful, but it doesn't matter as the __constraints()
function only has to be instantiated, it's never called.

We could refactor all of these to use unevaluated contexts (e.g. sizeof
of __decltype) so that we only check the expressions are well-formed,
without any codegen at all. Any improvements to these are very low
priority though.

libstdc++-v3/ChangeLog:

	* include/bits/boost_concept_check.h (_OutputIteratorConcept):
	Change member function to data member of function pointer type.
2022-02-02 16:30:51 +00:00
Martin Sebor 756eabacfc Declare std::array members with attribute const [PR101831].
Resolves:
PR libstdc++/101831 - Spurious maybe-uninitialized warning on std::array::size

libstdc++-v3/ChangeLog:

	PR libstdc++/101831
	* include/std/array (begin): Declare const member function attribute
	const.
	(end, rbegin, rend, size, max_size, empty, data): Same.
	* testsuite/23_containers/array/capacity/empty.cc: Add test cases.
	* testsuite/23_containers/array/capacity/max_size.cc: Same.
	* testsuite/23_containers/array/capacity/size.cc: Same.
	* testsuite/23_containers/array/iterators/begin_end.cc: New test.
2022-02-01 17:21:49 -07:00
GCC Administrator ae7e4af964 Daily bump. 2022-02-02 00:17:16 +00:00
Jonathan Wakely d98668eb06 libstdc++: Do not use dirent::d_type unconditionally
These new tests should not use the d_type member unless it's actually
present on the OS.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/iterators/error_reporting.cc: Use
	autoconf macro to check whether d_type is present.
	* testsuite/experimental/filesystem/iterators/error_reporting.cc:
	Likewise.
2022-02-02 00:01:43 +00:00
Jonathan Wakely 2dc2f41728 libstdc++: Add more tests for filesystem directory iterators
The PR 97731 test was added to verify a fix to the Filesystem TS code,
but we should also have the same test to avoid similar regressions in
the C++17 std::filesystem code.

Also add tests for directory_options::follow_directory_symlink

libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/iterators/97731.cc: New test.
	* testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc:
	Check follow_directory_symlink option.
	* testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc:
	Likewise.
2022-02-01 21:56:35 +00:00
Jonathan Wakely ec09a5335f libstdc++: Reset filesystem::recursive_directory_iterator on error
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-02-01 21:56:16 +00:00
Jonathan Wakely 90263a4830 libstdc++: Fix doxygen comment for filesystem::perms operators
libstdc++-v3/ChangeLog:

	* include/bits/fs_fwd.h (filesystem::perms): Fix comment.
2022-02-01 21:53:15 +00:00
Jonathan Wakely 19b8946dbd libstdc++: Improve config output for --enable-cstdio [PR104301]
Currently we just print "checking for underlying I/O to use... stdio"
unconditionally, whether configured to use stdio_pure or stdio_posix. We
should make it clear that the user's configure option chose the right
thing.

libstdc++-v3/ChangeLog:

	PR libstdc++/104301
	* acinclude.m4 (GLIBCXX_ENABLE_CSTDIO): Print different messages
	for stdio_pure and stdio_posix options.
	* configure: Regenerate.
2022-02-01 21:53:14 +00:00
Thomas Rodgers 07a971b28c Strengthen memory order for atomic<T>::wait/notify
This matches the memory order in libc++.

libstdc++-v3/ChangeLog:
	* include/bits/atomic_wait.h: Change memory order from
	Acquire/Release with relaxed loads to SeqCst+Release for
	accesses to the waiter's count.
2022-02-01 09:04:10 -08:00
GCC Administrator 1bb5266257 Daily bump. 2022-02-01 00:16:29 +00:00
Martin Liska c99a6eb015 Add mold detection for libs.
libatomic/ChangeLog:

	* acinclude.m4: Detect *_ld_is_mold and use it.
	* configure: Regenerate.

libgomp/ChangeLog:

	* acinclude.m4: Detect *_ld_is_mold and use it.
	* configure: Regenerate.

libitm/ChangeLog:

	* acinclude.m4: Detect *_ld_is_mold and use it.
	* configure: Regenerate.

libstdc++-v3/ChangeLog:

	* acinclude.m4: Detect *_ld_is_mold and use it.
	* configure: Regenerate.
2022-01-31 09:46:44 +01:00
GCC Administrator c67ffc256d Daily bump. 2022-01-31 00:16:28 +00:00
Hans-Peter Nilsson baf98320ac libstdc++ testsuite: Don't run lwg3464.cc tests on simulators
These tests have always been failing for my autotester running a
cris-elf simulator; when unrestrained they take about 20 minutes each,
compared to the (doubled) timeout of 720 seconds, of a total 2h40min
for the whole of the libstdc++-v3 testsuite.  The tests cover counter
overflow and are already disabled for LP64 targets.

	* testsuite/27_io/basic_istream/get/char/lwg3464.cc: Don't run on
	simulator targets.
	* testsuite/27_io/basic_istream/get/wchar_t/lwg3464.cc: Likewise.
2022-01-30 17:51:02 +01:00
GCC Administrator 99f17e996f Daily bump. 2022-01-28 00:16:32 +00:00
Jonathan Wakely eae41b4d2c libstdc++: Prevent -Wstringop-overread warning in std::deque [PR100516]
The compiler warns about the loop in deque::_M_range_initialize because
it doesn't know that the number of nodes has already been correctly
sized to match the size of the input. Use __builtin_unreachable to tell
it that the loop will never be entered if the number of elements is
smaller than a single node.

libstdc++-v3/ChangeLog:

	PR libstdc++/100516
	* include/bits/deque.tcc (_M_range_initialize<ForwardIterator>):
	Add __builtin_unreachable to loop.
	* testsuite/23_containers/deque/100516.cc: New test.
2022-01-27 23:31:03 +00:00
Jonathan Wakely f21f22d1ba libstdc++: Avoid overflow in ranges::advance(i, n, bound)
When (bound - i) or n is the most negative value of its type, the
negative of the value will overflow. Instead of abs(n) >= abs(bound - i)
use n >= (bound - i) when positive and n <= (bound - i) when negative.
The function has a precondition that they must have the same sign, so
this works correctly. The precondition check can be moved into the else
branch, and simplified.

The standard requires calling ranges::advance(i, bound) even if i==bound
is already true, which is technically observable, but that's pointless.
We can just return n in that case. Similarly, for i!=bound but n==0 we
are supposed to call ranges::advance(i, n), but that's pointless. An LWG
issue to allow omitting the pointless calls is expected to be filed.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (ranges::advance): Avoid signed
	overflow. Do nothing if already equal to desired result.
	* testsuite/24_iterators/range_operations/advance_overflow.cc:
	New test.
2022-01-27 22:24:29 +00:00
Martin Liska 14f339894d libstdc++: fix typo in acinclude.m4.
PR libstdc++/104259

libstdc++-v3/ChangeLog:

	* acinclude.m4: Fix typo.
	* configure: Regenerate.
2022-01-27 15:34:06 +01:00
GCC Administrator e0b8716f53 Daily bump. 2022-01-26 00:16:38 +00:00
Jonathan Wakely 5c1f274e3e libstdc++: Avoid some more warnings [PR104019]
With -fno-exceptions we get a -Wmisleading-indentation warning for:

  if (cond)
    __try {}
    __catch (...) {}

This is because the __catch(...) expands to if (false), but is indented
as though it is controlled by the preceding 'if'. Surround it in braces.

The new make_shared<T[]> code triggers a bogus warning due to PR 61596,
which can be disabled with a pragma.

libstdc++-v3/ChangeLog:

	PR libstdc++/104019
	* include/bits/istream.tcc (basic_istream::sentry): Add braces
	around try-block.
	* include/bits/shared_ptr_base.h (_Sp_counted_array_base::_M_init):
	Add pragmas to disable bogus warnings from PR 61596.
2022-01-25 21:05:16 +00:00
Jonathan Wakely e20486d508 libstdc++: Define _GNU_SOURCE for secure_getenv on Cygwin [PR104217]
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-25 21:05:16 +00:00
Jonathan Wakely c8bd4dc821 libstdc++: Avoid symlink race in filesystem::remove_all [PR104161]
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-25 21:05:15 +00:00
GCC Administrator 0c940703f0 Daily bump. 2022-01-24 00:16:28 +00:00
Jonathan Wakely 51631875a2 libstdc++: Fix std::spanstream move assignment [PR104032]
libstdc++-v3/ChangeLog:

	PR libstdc++/104032
	* include/std/spanstream (basic_spanbuf(basic_spanbuf&&)): Use
	mem-initializer for _M_buf.
	(basic_spanbuf::Operator=(basic_spanbuf&&)): Fix ill-formed
	member access.
	* testsuite/27_io/spanstream/2.cc: New test.
2022-01-23 22:48:33 +00:00
Jonathan Wakely 416b6fc748 libstdc++: Use fast_float for long double if it uses binary64 format
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-23 22:47:00 +00:00
Jonathan Wakely 084680db9a libstdc++: Restore support for unordered_map<const T, ...> [PR104174]
I broke this unintentionally in r12-4259.

libstdc++-v3/ChangeLog:

	PR libstdc++/104174
	* include/bits/hashtable_policy.h (_Map_base): Add partial
	specialization for maps with const key types.
	* testsuite/23_containers/unordered_map/104174.cc: New test.
2022-01-23 22:47:00 +00:00
Jonathan Wakely 2d8a9ad4a9 libstdc++: Fix aliasing violation in std::shared_ptr [PR104019]
The non-atomic store that sets both reference counts to zero uses a
type-punned pointer, which has undefined behaviour. We could use memset
to write 8 bytes, but we don't actually need it to be a single store
anyway. No other thread can observe the values, that's why it's safe to
use non-atomic stores in the first place. So we can just set each count
to zero.

With -fstore-merging (which is enabled by default at -O2) GCC produces
the same code for this as for memset or the type punned store. Clang
does that store merging even at -O1.

libstdc++-v3/ChangeLog:

	PR libstdc++/104019
	* include/bits/shared_ptr_base.h (_Sp_counted_base<>::_M_release):
	Set members to zero without type punning.
2022-01-23 22:47:00 +00:00
GCC Administrator 9dd443578f Daily bump. 2022-01-22 00:16:26 +00:00
Jonathan Wakely 45cae5b639 libstdc++: Fix typo in comment
libstdc++-v3/ChangeLog:

	* testsuite/20_util/shared_ptr/cons/array.cc: Fix comment.
2022-01-21 16:07:34 +00:00
Jonathan Wakely b8806796ec libstdc++: Ensure all feature test macros have type long [PR87193]
This defines all the __cpp_lib_xxx macros as type long, as required by
the standard. We had an inconsistent mix of int and long, sometimes even
for the same macro name.

The __cpp_lib_experimental_xxx macros are left as type int, because
that's what it says in the relevant TS specs.

libstdc++-v3/ChangeLog:

	PR libstdc++/87193
	PR libstdc++/104019
	* include/bits/alloc_traits.h (__cpp_lib_allocator_traits_is_always_equal):
	Define as type long.
	* include/bits/allocator.h (__cpp_lib_incomplete_container_elements):
	Likewise.
	* include/bits/basic_string.h (__cpp_lib_string_udls): Likewise.
	* include/bits/chrono.h (__cpp_lib_chrono): Likewise.
	(__cpp_lib_chrono_udls): Likewise.
	* include/bits/move.h (__cpp_lib_addressof_constexpr): Likewise.
	* include/bits/node_handle.h (__cpp_lib_node_extract): Likewise.
	* include/bits/range_access.h (__cpp_lib_nonmember_container_access):
	Likewise.
	* include/bits/shared_ptr.h (__cpp_lib_enable_shared_from_this):
	Likewise.
	* include/bits/stl_algo.h (__cpp_lib_clamp): Likewise.
	(__cpp_lib_sample): Likewise.
	* include/bits/stl_algobase.h (__cpp_lib_robust_nonmodifying_seq_ops):
	Likewise.
	* include/bits/stl_function.h (__cpp_lib_transparent_operators):
	Likewise.
	* include/bits/stl_iterator.h (__cpp_lib_make_reverse_iterator):
	Likewise.
	* include/bits/stl_map.h (__cpp_lib_map_try_emplace):
	Likewise.
	* include/bits/stl_tree.h (__cpp_lib_generic_associative_lookup):
	Likewise.
	* include/bits/unique_ptr.h (__cpp_lib_make_unique):
	Likewise.
	* include/bits/unordered_map.h (__cpp_lib_unordered_map_try_emplace):
	Likewise.
	* include/c_global/cmath (__cpp_lib_hypot): Likewise.
	* include/c_global/cstddef (__cpp_lib_byte): Likewise.
	* include/std/atomic (__cpp_lib_atomic_is_always_lock_free):
	Likewise.
	* include/std/complex (__cpp_lib_complex_udls): Likewise.
	* include/std/filesystem (__cpp_lib_filesystem): Likewise.
	* include/std/functional (__cpp_lib_not_fn): Likewise.
	(__cpp_lib_boyer_moore_searcher): Likewise.
	* include/std/iomanip (__cpp_lib_quoted_string_io): Likewise.
	* include/std/mutex (__cpp_lib_scoped_lock): Likewise.
	* include/std/numeric (__cpp_lib_gcd_lcm): Likewise.
	(__cpp_lib_gcd, __cpp_lib_lcm): Likewise.
	* include/std/tuple (__cpp_lib_apply): Likewise.
	(__cpp_lib_make_from_tuple): Likewise.
	* include/std/type_traits (__cpp_lib_integral_constant_callable)
	(__cpp_lib_bool_constant, __cpp_lib_logical_traits)
	(__cpp_lib_is_null_pointer, __cpp_lib_transformation_trait_aliases)
	(__cpp_lib_result_of_sfinae, __cpp_lib_void_t)
	(__cpp_lib_is_swappable, __cpp_lib_is_invocable)
	(__cpp_lib_has_unique_object_representations)
	(__cpp_lib_is_aggregate): Likewise.
	* include/std/version: Likewise.
	* libsupc++/new (__cpp_lib_launder): Likewise.
2022-01-21 16:07:34 +00:00
Jonathan Wakely 2da1ef06ff libstdc++: Fix condition for __cpp_lib_shared_ptr_arrays
I changed the preprocessor condition from <= to < in r12-6574 which
meant the macro was not defined by <version> for C++17.

libstdc++-v3/ChangeLog:

	* include/std/version (__cpp_lib_shared_ptr_arrays): Fix
	condition for C++17 definition.
2022-01-21 16:07:33 +00:00
Jonathan Wakely 7d47aae7cd libstdc++: Fix constexpr constructor for atomic<shared_ptr<T>>
libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count):
	Add constexpr.
	(_Sp_atomic::_M_ptr): Add default member-initializer.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc:
	Check constant initialization.
	* testsuite/20_util/weak_ptr/atomic_weak_ptr.cc: Likewise.
2022-01-21 13:21:27 +00:00
GCC Administrator 5fa55d55ab Daily bump. 2022-01-21 00:16:28 +00:00
Jonathan Wakely 109f8af3d3 libstdc++: Use Clang attribute instead of __constinit
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-20 12:29:29 +00:00
Jonathan Wakely 5929f253fc libstdc++: Only add valid -L paths to testsuite linker options
The MacOS linker warns about -L arguments that don't exist, which causes
all tests to fail for the defauly configuration (because libbacktrace
isn't built).

libstdc++-v3/ChangeLog:

	* scripts/testsuite_flags.in: Only add src/filesystem/.libs and
	src/libbacktrace/.libs to LDFLAGS if those directories exist.
2022-01-20 12:29:29 +00:00
GCC Administrator fe1ad14165 Daily bump. 2022-01-20 00:16:54 +00:00
Jonathan Wakely fe3e978027 libstdc++: Remove -gdwarf-4 from flags for debug library
The default is -gdwarf-5 now, so this is hurting rather than improving
things.

libstdc++-v3/ChangeLog:

	* configure.ac (GLIBCXX_ENABLE_DEBUG_FLAGS): Remove -gdwarf-4
	from default flags.
	* configure: Regenerate.
2022-01-19 19:31:00 +00:00
Jonathan Wakely f5c50748f3 libstdc++: Include <stddef.h> for size_t and ptrdiff_t [PR104123]
libstdc++-v3/ChangeLog:

	PR libstdc++/104123
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: Include
	<stddef.h>.
2022-01-19 17:40:37 +00:00
Jonathan Wakely 6a26ad6736 libstdc++: Fix libbacktrace build files
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-19 14:23:13 +00:00
Matthias Kretz 39f581028c libstdc++: Fix for non-constexpr math_errhandling
Use SFINAE magic to support: "It is unspecified whether math_errhandling
is a macro or an identifier with external linkage." [C Standard]

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

	* include/experimental/bits/simd.h (__floating_point_flags): Do
	not rely on math_errhandling to expand to a constant expression.
2022-01-19 13:45:58 +01:00
Jonathan Wakely 9c186493a7 libstdc++: Update documentation for C++17 deprecations
libstdc++-v3/ChangeLog:

	* doc/xml/manual/evolution.xml: Document deprecations.
	* doc/xml/manual/status_cxx2017.xml: Update status.
	* doc/html/*: Regenerate.
2022-01-19 00:58:26 +00:00
Jonathan Wakely a68080a121 libstdc++: Fix deprecated attribute for std::get_temporary_buffer
This was deprecated in C++17, not C++14.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tempbuf.h (get_temporary_buffer): Change
	_GLIBCXX14_DEPRECATED to _GLIBCXX17_DEPRECATED.
2022-01-19 00:58:25 +00:00
Jonathan Wakely 72ce3fd2c7 libstdc++: Remove unused std::pair helper function
This function is no longer used since r12-6691 and can be removed.

libstdc++-v3/ChangeLog:

	* include/bits/stl_pair.h (_PCC::_DeprConsPair): Remove unused
	function.
2022-01-19 00:58:25 +00:00
Jonathan Wakely c3861f7985 libstdc++: Fix std::atomic<std::shared_ptr<T>> for AIX [PR104101]
This fixes an on AIX.

The lock function currently just spins, which should be changed to use
back-off, and maybe then _M_val.wait(__current) when supported.

libstdc++-v3/ChangeLog:

	PR libstdc++/104101
	* include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count::lock):
	Only use __thread_relax if __cpp_lib_atomic_wait is defined.
2022-01-19 00:58:21 +00:00
GCC Administrator 7a761ae658 Daily bump. 2022-01-19 00:16:32 +00:00
Jonathan Wakely fe3ed885cd libstdc++: Limit new basic_string(nullptr_t) constructor to C++23 [PR104099]
The new deleted constructors added by P2166R1 are a breaking change,
making previously valid code ill-formed in C++23. As a result, they
should only be defined for C++23 and not for C++11 and up.

libstdc++-v3/ChangeLog:

	PR libstdc++/104099
	* include/bits/basic_string.h (basic_string(nullptr_t)): Only
	define for C++23.
	(operator=(nullptr_t)): Likewise.
	* include/bits/cow_string.h: Likewise.
	* include/std/string_view (basic_string_view(nullptr_t)):
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/nullptr.cc: Adjust
	expected error. Add examples that become ill-formed in C++23.
	* testsuite/21_strings/basic_string_view/cons/char/nonnull.cc:
	Adjust expected errors.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc:
	Likewise.
2022-01-18 20:41:46 +00:00
Jonathan Wakely e13e95bd27 libstdc++: Use __cpp_lib_concepts in std::reverse_iterator [PR104098]
We should not assume that std::iter_value_t etc. are defined
unconditionally for C++20 mode.

libstdc++-v3/ChangeLog:

	PR libstdc++/104098
	* include/bits/stl_iterator.h (reverse_iterator): Check
	__cpp_lib_concepts instead of __cplusplus.
2022-01-18 16:31:03 +00:00
Jonathan Wakely 302343d8dd libstdc++: Fix ambiguous std::pair constructors [PR101124]
The deprecated non-standard std::pair constructors that allow
constructing std::pair<move-only-type, pointer-type> from an rvalue and
a literal zero where not sufficiently constrained. They were viable when
constructing std::pair<copyable-type, pointer-type>, and that case
should work fine using the standard constructors.

Replace the constraints on the non-standard constructors so they are
only viable in cases that should actually be ill-formed according to the
standard.

Also rename __null_ptr_constant to __zero_as_null_pointer_constant so it
matches the name of the -Wzero-as-null-pointer-constant warning. Also
make the text of the deprecated warning describe the problem in more
detail.

libstdc++-v3/ChangeLog:

	PR libstdc++/101124
	* include/bits/stl_pair.h (pair): Adjust constraints on
	deprecated constructors accepting literal zero as null pointer
	constant. Improve wording of deprecated attribute.
	* testsuite/20_util/pair/cons/99957.cc: Check that deprecated
	constructors do not cause ambiguities for copyable types.
2022-01-18 16:31:03 +00:00
Jonathan Wakely 50bc6e463b libstdc++: Fix suggested alternative to std::ptr_fun
libstdc++-v3/ChangeLog:

	* include/bits/stl_function.h (ptr_fun): Fix suggestion for
	non-deprecated alternative.
2022-01-18 16:31:02 +00:00
Tom Honermann 0e4e4b37d9 libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library
This patch completes implementation of the C++20 proposal P0482R6 [1] by
adding declarations of std::c8rtomb() and std::mbrtoc8() in <cuchar> if
provided by the C library in <uchar.h>.

This patch addresses feedback provided in response to a previous patch
submission [2].

Autoconf changes determine if the C library declares c8rtomb and mbrtoc8
at global scope when uchar.h is included and compiled with either
-fchar8_t or -std=c++20. New _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T
and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros
reflect the probe results. The <cuchar> header declares these functions
in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T
configuration macro is defined (by default it is defined if the C++20
__cpp_char8_t feature test macro is defined)

Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [3].

New tests validate the presence of these declarations. The tests pass
trivially if the C library does not provide these functions. Otherwise
they ensure that the functions are declared when <cuchar> is included
and either -fchar8_t or -std=c++20 is enabled.

1]: WG21 P0482R6
      "char8_t: A type for UTF-8 characters and strings (Revision 6)"
      https://wg21.link/p0482r6

[2]: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8
if provided by the C library
      https://gcc.gnu.org/pipermail/libstdc++/2021-June/052685.html

[3]: "C++20 P0482R6 and C2X N2653"
      [Patch 0/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135061.html
      [Patch 1/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135062.html
      [Patch 2/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135063.html
      [Patch 3/3]:
https://sourceware.org/pipermail/libc-alpha/2022-January/135064.html

libstdc++-v3/ChangeLog:

	* acinclude.m4: Define config macros if uchar.h provides
	c8rtomb() and mbrtoc8().
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* include/c_compatibility/uchar.h (c8rtomb, mbrtoc8): Define.
	* include/c_global/cuchar (c8rtomb, mbrtoc8): Likewise.
	* include/c_std/cuchar (c8rtomb, mbrtoc8): Likewise.
	* testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc:
	New test.
	* testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc:
	New test.
2022-01-18 16:31:02 +00:00
Jonathan Wakely d7f2a09e98 libstdc++: Define <stdatomic.h> for C++23
This adds the C++23 <stdatomic.h> header, as proposed by P0943R6, for
compatibility with C code.

There are still some ABI differences between atomic_xxx in C and C++
std::atomic_xxx in C++, so this only provides source compatibility, not
binary compatibility.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Install new header.
	* include/Makefile.in: Regenerate.
	* include/c_compatibility/stdatomic.h: New file.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: New test.
2022-01-18 16:31:02 +00:00
Jonathan Wakely 8f6b62e0f0 libstdc++: Use GCC's predefined macro for endianness [PR104080]
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-18 10:03:16 +00:00
Jonathan Wakely 97b9236976 libstdc++: Fix deduction failure for std::min call [PR104080]
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-18 09:53:30 +00:00
Jonathan Wakely ac358eef7a libstdc++: Update status tables in manual
libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2017.xml: Update C++17 status.
	* doc/xml/manual/status_cxx2020.xml: Use 12.1 instead of 12 for
	upcoming release.
	* doc/html/manual/status.html: Regenerate.
2022-01-18 09:51:02 +00:00
Jonathan Wakely 5f3c0ee908 libstdc++: Improve comments describing --enable-fully-dynamic-string
libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING): Improve
	comments.
	* configure: Regenerate.
2022-01-18 09:51:02 +00:00
GCC Administrator fc82978278 Daily bump. 2022-01-18 00:16:54 +00:00
Patrick Palka 490e23032b libstdc++: Use fast_float in std::from_chars for binary32/64
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-17 14:33:12 -05:00
Patrick Palka 40b0d4472a libstdc++: Adjust fast_float's over/underflow behavior for conformance
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-17 14:32:30 -05:00
Patrick Palka f5c8b82512 libstdc++: Apply modifications to our local copy of fast_float
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-17 14:32:27 -05:00
Patrick Palka 2800bc08e4 libstdc++: Import the fast_float library
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-17 14:32:16 -05:00
Patrick Palka cc3bf3404e libstdc++: Directly implement hexfloat std::from_chars for binary32/64
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-17 14:32:13 -05:00
Jonathan Wakely 3acb929cc0 libstdc++: Define <stacktrace> header for C++23
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-17 12:13:02 +00:00
Jonathan Wakely 5a3dc58a1d libstdc++: Document final option names for enabling C++20
libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2020.xml: Use final C++20 option
	names.
	* doc/html/manual/status.html: Regenerate.
2022-01-17 12:08:37 +00:00
Jonathan Wakely fa092570fb libstdc++: Rename non-reserved macros in config header [PR103650]
libstdc++-v3/ChangeLog:

	PR libstdc++/103650
	* include/Makefile.am: Rename LT_OBJDIR and STDC_HEADERS.
	* include/Makefile.in: Regenerate.
	* testsuite/17_intro/headers/c++1998/103650.cc: New test.
2022-01-17 12:08:26 +00:00
Matthias Kretz 84eb13b9d6 libstdc++: Don't fail if math_errhandling is not defined
Older glibc does not define math_errhandling with -ffast-math, in which
case floating-point exceptions are not used.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

	* include/experimental/bits/simd.h (__floating_point_flags): Do
	not rely on the presence of the math_errhandling macro.
2022-01-17 11:27:32 +01:00
Jonathan Wakely a923345c72 libstdc++: Add 'typename' to dependent types in atomic<shared_ptr<T>>
libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (_Sp_atomic): Add typename
	to qualified-id for dependent type.
2022-01-17 09:48:09 +00:00
GCC Administrator 1e942d7c05 Daily bump. 2022-01-17 00:16:24 +00:00
Jonathan Wakely a326934886 libstdc++: Update C++20 status table
libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2020.xml: Update.
	* doc/html/manual/status.html: Regenerate.
2022-01-17 00:06:28 +00:00
Jonathan Wakely 2ac0649d7b libstdc++: Implement C++20 atomic<shared_ptr> and atomic<weak_ptr>
This adds another piece of C++20, the std::atomic specializations for
std::shared_ptr and std::weak_ptr.

The new _Sp_atomic type mimics the structure of shared_ptr<T> and
weak_ptr<T>, holding a T* pointer (the one returned by get() on a
shared_ptr/weak ptr) and a _Sp_counted_base<>* pointer to the
ref-counted control block. For _Sp_atomic the low bit of the control
block pointer is used as a lock bit, to ensure only one thread will
access the object at a time.  The pointer is actually stored as a
uintptr_t to avoid accidental dereferences of the pointer when unlocked
(which would be a race) or when locked (which would dereference the
wrong pointer value due to the low bit being set). To get a raw pointer
to the control block, the lock must be acquired. Converting between a
_Sp_atomic and a shared_ptr or weak_ptr requires manually adjusting the
T* and _Sp_counted_base<>* members of the shared/weak ptr, instead of
going through the public API. This must be done carefully to ensure that
any change in the number of owners is reflected in a ref-count update.

Co-authored-by: Thomas Rodgers <trodgers@redhat.com>
Signed-off-by: Thomas Rodgers <trodgers@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (__cpp_lib_atomic_shared_ptr):
	New macro.
	(_Sp_atomic): New class template.
	(atomic<shared_ptr<T>>, atomic<weak_ptr<T>>): New partial
	specializations.
	* include/bits/shared_ptr_base.h (__shared_count, __weak_count)
	(__shared_ptr, __weak_ptr): Declare _Sp_atomic as a friend.
	* include/std/version (__cpp_lib_atomic_shared_ptr): New macro.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc: New
	test.
	* testsuite/20_util/weak_ptr/atomic_weak_ptr.cc: New test.
2022-01-17 00:06:28 +00:00
GCC Administrator 9248ee4147 Daily bump. 2022-01-16 00:16:26 +00:00
Matthias Kretz 52d2821038 libstdc++: Fix ODR issues with different -m flags
Explicitly support use of the stdx::simd implementation in situations
where the user links TUs that were compiled with different -m flags. In
general, this is always a (quasi) ODR violation for inline functions
because at least codegen may differ in important ways. However, in the
resulting executable only one (unspecified which one) of them might be
used. For simd we want to support users to compile code multiple times,
with different -m flags and have a runtime dispatch to the TU matching
the target CPU. But if internal functions are not inlined this may lead
to unexpected performance loss or execution of illegal instructions.
Therefore, inline functions that are not marked as always_inline must
use an additional template parameter somewhere in their name, to
disambiguate between the different -m translations.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

	* include/experimental/bits/simd.h: Move feature detection bools
	and add __have_avx512bitalg, __have_avx512vbmi2,
	__have_avx512vbmi, __have_avx512ifma, __have_avx512cd,
	__have_avx512vnni, __have_avx512vpopcntdq.
	(__detail::__machine_flags): New function which returns a unique
	uint64 depending on relevant -m and -f flags.
	(__detail::__odr_helper): New type alias for either an anonymous
	type or a type specialized with the __machine_flags number.
	(_SimdIntOperators): Change template parameters from _Impl to
	_Tp, _Abi because _Impl now has an __odr_helper parameter which
	may be _OdrEnforcer from the anonymous namespace, which makes
	for a bad base class.
	(many): Either add __odr_helper template parameter or mark as
	always_inline.
	* include/experimental/bits/simd_detail.h: Add defines for
	AVX512BITALG, AVX512VBMI2, AVX512VBMI, AVX512IFMA, AVX512CD,
	AVX512VNNI, AVX512VPOPCNTDQ, and AVX512VP2INTERSECT.
	* include/experimental/bits/simd_builtin.h: Add __odr_helper
	template parameter or mark as always_inline.
	* include/experimental/bits/simd_fixed_size.h: Ditto.
	* include/experimental/bits/simd_math.h: Ditto.
	* include/experimental/bits/simd_scalar.h: Ditto.
	* include/experimental/bits/simd_neon.h: Add __odr_helper
	template parameter.
	* include/experimental/bits/simd_ppc.h: Ditto.
	* include/experimental/bits/simd_x86.h: Ditto.
2022-01-15 21:05:17 +01:00
GCC Administrator 617db51d7e Daily bump. 2022-01-15 00:16:27 +00:00
Uros Bizjak 6795e6ae66 libstdc++: Fix 22_locale/numpunct/members/char/3.cc execution test
The test fails on Fedora 33+ because nl_NL locale got thousands
separator defined.  Use one of ar_SA, bg_BG, bs_BA, pt_PT
or plain C locale instead.

2022-01-14  Uroš Bizjak  <ubizjak@gmail.com>

libstdc++-v3/ChangeLog:

	* testsuite/22_locale/numpunct/members/char/3.cc:
	Require pt_PT locale instead of nl_NL.
	(test02): Use pt_PT locale instead of nl_NL.
2022-01-14 16:21:57 +01:00
Jonathan Wakely de196e5dd8 libstdc++: Add attribute to features deprecated in C++17 [PR91260]
There are a lot of things in the C++ standard library which were
deprecated in C++11, and more in C++17.  Some of them were removed after
deprecation and are no longer present in the standard at all. We have
not removed these from libstdc++ because keeping them as non-standard
extensions is conforming, and avoids gratuitously breaking user code,
and in some cases we need to keep using them to avoid ABI changes. But
we should at least give a warning for using them. That has not been done
previously because of the library's own uses of them (e.g. the
std::iterator class template used as a base class).

This adds deprecated attributes to the relevant components, and then
goes through the whole library to add diagnostic pragmas where needed to
suppress warnings about our internal uses of them. The tests are updated
to either expect the additional warnings, or to suppress them where we
aren't interested in them.

libstdc++-v3/ChangeLog:

	PR libstdc++/91260
	PR libstdc++/91383
	PR libstdc++/95065
	* include/backward/binders.h (bind1st, bind2nd): Add deprecated
	attribute.
	* include/bits/refwrap.h (_Maybe_unary_or_binary_function):
	Disable deprecated warnings for base classes.
	(_Reference_wrapper_base): Likewise.
	* include/bits/shared_ptr_base.h (_Sp_owner_less): Likewise.
	* include/bits/stl_bvector.h (_Bit_iterator_base): Likewise.
	* include/bits/stl_function.h (unary_function, binary_function):
	Add deprecated attribute.
	(unary_negate, not1, binary_negate, not2, ptr_fun)
	(pointer_to_unary_function, pointer_to_binary_function)
	(mem_fun_t, const_mem_fun_t, mem_fun_ref_t, const_mem_fun_ref_t)
	(mem_fun1_t, const_mem_fun1_t, mem_fun_ref1_t)
	(const_mem_fun1_ref_t, mem_fun, mem_fun_ref): Add deprecated
	attributes.
	* include/bits/stl_iterator.h: Disable deprecated warnings for
	std::iterator base classes.
	* include/bits/stl_iterator_base_types.h (iterator): Add
	deprecated attribute.
	* include/bits/stl_map.h (map::value_compare): Disable
	deprecated warnings for base class.
	* include/bits/stl_multimap.h (multimap::value_compare):
	Likewise.
	* include/bits/stl_raw_storage_iter.h (raw_storage_iterator):
	Add deprecated attribute.
	* include/bits/stl_tempbuf.h (get_temporary_buffer): Likewise.
	* include/bits/stream_iterator.h: Disable deprecated warnings.
	* include/bits/streambuf_iterator.h: Likewise.
	* include/ext/bitmap_allocator.h: Remove unary_function base
	classes.
	* include/ext/functional: Disable deprecated warnings.
	* include/ext/rope: Likewise.
	* include/ext/throw_allocator.h: Likewise.
	* include/std/type_traits (result_of): Add deprecated attribute.
	* include/tr1/functional: Disable deprecated warnings.
	* include/tr1/functional_hash.h: Likewise.
	* testsuite/20_util/function_objects/binders/1.cc: Add
	-Wno-disable-deprecations.
	* testsuite/20_util/function_objects/binders/3113.cc: Likewise.
	* testsuite/20_util/function_objects/constexpr.cc: Add
	dg-warning.
	* testsuite/20_util/raw_storage_iterator/base.cc: Likewise.
	* testsuite/20_util/raw_storage_iterator/dr2127.cc: Likewise.
	* testsuite/20_util/raw_storage_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/20_util/raw_storage_iterator/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/20_util/raw_storage_iterator/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/reference_wrapper/24803.cc:
	Likewise.
	* testsuite/20_util/reference_wrapper/typedefs.cc: Enable for
	C++20 and check for absence of nested types.
	* testsuite/20_util/shared_ptr/comparison/less.cc: Remove
	std::binary_function base class.
	* testsuite/20_util/temporary_buffer.cc: Add dg-warning.
	* testsuite/21_strings/basic_string/cons/char/69092.cc: Remove
	std::iterator base class.
	* testsuite/24_iterators/back_insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/front_insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/istream_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/92285.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/ostream_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/ostreambuf_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/reverse_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/25_algorithms/copy/34595.cc:
	Likewise.
	* testsuite/25_algorithms/minmax/3.cc: Remove std::binary_function
	base class.
	* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/2.cc:
	Disable deprecated warnings.
	* testsuite/25_algorithms/all_of/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/any_of/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/copy_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/count_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/find_end/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/find_first_of/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/find_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/find_if_not/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/for_each/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/is_partitioned/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/is_permutation/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/none_of/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/partition/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/partition/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/partition_copy/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/partition_point/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/remove_copy_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/remove_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/replace_copy_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/replace_if/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/search/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/search/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/search_n/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/transform/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/transform/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc: Add
	dg-warning.
	* testsuite/ext/pb_ds/example/priority_queue_erase_if.cc:
	Likewise.
	* testsuite/ext/pb_ds/example/priority_queue_split_join.cc:
	Likewise.
	* testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc:
	Disable deprecated warnings.
	* testsuite/tr1/6_containers/hash/requirements/base_classes.cc:
	Likewise.
	* testsuite/util/regression/trait/erase_if_fn.hpp: Remove
	std::unary_function base classes.
	* testsuite/util/testsuite_iterators.h (output_iterator_wrapper):
	Remove std::iterator base classes.
2022-01-14 11:27:50 +00:00
Jonathan Wakely 9a0b518a82 libstdc++: Add C++20 std::make_shared enhancements (P0674R1)
This adds the overloads of std::make_shared and std::allocate_shared for
creating arrays, added to C++20 by P0674R1.

It also adds std::make_shared_for_overwrite, added to C++20 by P1020R1
(and renamed by P1973R1). The std::make_unique_for_overwite overloads
are already supported.

The original std::make_shared overload is changed to construct a
shared_ptr directly instead of calling std::allocate_shared. This
removes a function call at runtime, and avoids having to do overload
resolution for std::allocate_shared, now that there are five overloads
of it.

Allocating a shared array is done by a new __shared_count constructor.
An array is allocated with space for additional elements at the end and
an instance of new _Sp_counted_array class template is constructed in
that unused capacity.

The non-array form of std::make_shared_for_overwrite uses the same
__shared_count constructor as the original std::make_shared overload,
but a new partial specialization of _Sp_counted_ptr_inplace is selected
when the allocator's value_type is the new _Sp_overwrite_tag type. That
new partial specialization default-initializes its contained object and
destroys it with a destructor call rather than using the allocator.

Despite being C++20 features, this implementation only uses concepts
conditionally, with workarounds when they are not supported. This allows
it to work with older non-GCC compilers (Clang 9 and icc 2021). At some
point we can simplify the code by removing the workarounds.

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr.h (__cpp_lib_shared_ptr_weak_type):
	Correct type of macro value.
	(shared_ptr): Add additional friend declarations.
	(make_shared, allocate_shared): Constrain existing overloads and
	remove static_assert.
	* include/bits/shared_ptr_base.h (__cpp_lib_smart_ptr_for_overwrite):
	New macro.
	(_Sp_counted_ptr_inplace<T, Alloc, Lp>): New partial
	specialization for use with make_shared_for_overwrite.
	(__cpp_lib_shared_ptr_arrays): Update value for C++20.
	(_Sp_counted_array_base): New class template.
	(_Sp_counted_array): New class template.
	(__shared_count(_Tp*&, const _Sp_counted_array_base&, _Init)):
	New constructor for allocating shared arrays.
	(__shared_ptr(const _Sp_counted_array_base&, _Init)): Likewise.
	* include/std/version (__cpp_lib_shared_ptr_weak_type): Correct
	type.
	(__cpp_lib_shared_ptr_arrays): Update value for C++20.
	(__cpp_lib_smart_ptr_for_overwrite): New macro.
	* testsuite/20_util/shared_ptr/creation/99006.cc: Adjust
	expected errors.
	* testsuite/20_util/shared_ptr/creation/array.cc: New test.
	* testsuite/20_util/shared_ptr/creation/overwrite.cc: New test.
	* testsuite/20_util/shared_ptr/creation/version.cc: New test.
	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc: Check
	feature test macro. Test non-trivial default-initialization.
2022-01-14 10:14:25 +00:00
Jonathan Wakely fc6f1128ae libstdc++: Ignore cv-quals when std::allocator<void> constructs
When I added the std::allocator_traits<std::allocator<void>>
specialization it broke code like this:

  std::allocate_shared<const int>(std::allocator<void>());

The problem is that allocator_traits<allocator<void>>::construct(a, p)
now uses std::_Construct(p), which only does a static_cast<void*>(p) and
so fails if the pointer has cv-quals.

This changes std::_Construct (and the related std::_Construct_novalue)
to use a C-style cast to (void*) which matches the effects of the
"voidify" helper in the C++20 standard.

libstdc++-v3/ChangeLog:

	* include/bits/stl_construct.h (_Construct, _Construct_novalue):
	Also cast away cv-qualifiers when converting pointer to void.
	* testsuite/20_util/allocator/void.cc: Test construct function
	with cv-qualified types.
2022-01-14 10:14:25 +00:00
Jonathan Wakely d67ba1dce9 libstdc++: Use std::construct_at in std::common_iterator [PR103992]
This should have been done as part of the LWG 3574 changes.

libstdc++-v3/ChangeLog:

	PR libstdc++/103992
	* include/bits/stl_iterator.h (common_iterator): Use
	std::construct_at instead of placement new.
	* testsuite/24_iterators/common_iterator/1.cc: Check copy
	construction is usable in constant expressions.
2022-01-14 10:14:24 +00:00
Jonathan Wakely 7f390f11b4 libstdc++: Document new std::random_device tokens
libstdc++-v3/ChangeLog:

	* doc/xml/manual/status_cxx2011.xml: Document new tokens
	accepted by std::random_device constructor.
	* doc/html/manual/status.html: Regenerate.
2022-01-14 10:14:24 +00:00
GCC Administrator 02a8a01bf3 Daily bump. 2022-01-13 00:16:21 +00:00
Patrick Palka acc38526f6 libstdc++: Add explicit dg-do directive to .../103955.cc
libstdc++-v3/ChangeLog:

	* testsuite/20_util/to_chars/103955.cc: Add explicit dg-do
	directive.
2022-01-12 11:39:48 -05:00
Patrick Palka c0e355c779 libstdc++: Avoid overflow in bounds checks [PR103955]
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-12 09:10:24 -05:00
GCC Administrator 01a254e3e5 Daily bump. 2022-01-12 00:16:39 +00:00
Jonathan Wakely 8b35f02ed5 libstdc++: Install <source_location> header for freestanding [PR103726]
This C++20 header is also supposed to be present for freestanding.

libstdc++-v3/ChangeLog:

	PR libstdc++/103726
	* include/Makefile.am: Install <source_location> for
	freestanding.
	* include/Makefile.in: Regenerate.
	* include/std/version (__cpp_lib_source_location): Define for
	freestanding.
2022-01-11 18:36:36 +00:00
Jonathan Wakely 46de918f98 libstdc++: Add missing noexcept to lazy_split_view iterator (LWG 3593)
This was approved at the October 2021 plenary. We already have noexcept
in the other places the issue adds it in the spec.

libstdc++-v3/ChangeLog:

	* include/std/ranges (ranges::lazy_split_view::_InnerIter::end()):
	Add neoxcept (LWG 3593).
2022-01-11 15:17:27 +00:00
Jonathan Wakely d2dc5305d8 libstdc++: Make copyable-box completely constexpr (LWG 3572)
This LWG issue was approved at the October 2021 plenary and can be
implemented now that std::optional is fully constexpr.

libstdc++-v3/ChangeLog:

	* include/std/ranges (ranges::__detail::__box): Add constexpr to
	assignment operators (LWG 3572).
	* testsuite/std/ranges/adaptors/filter.cc: Check assignment of a
	view that uses copyable-box.
2022-01-11 15:17:26 +00:00
Jonathan Wakely 265d3e1a4e libstdc++: Install <coroutine> header for freestanding [PR103726]
The standard says that <coroutine> should be present for freestanding.
That was intentionally left out of the initial implementation, but can
be done without much trouble. The header should be moved to libsupc++ at
some point in stage 1.

The standard also says that <coroutine> defines a std::hash
specialization, which was missing from our implementation. That's a
problem for freestanding (see LWG 3653) so only do that for hosted.

We can use concepts to constrain the __coroutine_traits_impl base class
when compiled with concepts enabled. In a pure C++20 implementation we
would not need that base class at all and could just use a constrained
partial specialization of coroutine_traits. But the absence of the
__coroutine_traits_impl<R, void> base would create an ABI difference
between the non-standard C++14/C++17 support for coroutines and the same
code compiled as C++20. If we drop support for <coroutine> pre-C++20 we
should revisit this.

libstdc++-v3/ChangeLog:

	PR libstdc++/103726
	* include/Makefile.am: Install <coroutine> for freestanding.
	* include/Makefile.in: Regenerate.
	* include/std/coroutine: Adjust headers and preprocessor
	conditions.
	(__coroutine_traits_impl): Use concepts when available.
	[_GLIBCXX_HOSTED] (hash<coroutine_handle>): Define.
2022-01-11 13:28:46 +00:00
Jonathan Wakely e4fe6dba90 libstdc++: Optimize std::ostream inserters for single characters
On the libsdc++ mailing list Lewis Hyatt pointed out the performance
overhead of using sputn in stream inserters, rather than writing
directly to the streambuf's put area:
https://gcc.gnu.org/pipermail/libstdc++/2021-July/052877.html

As Lewis noted, the standard explicitly requires a call to sputn for
inserting a std::basic_string_view or std::basic_string.  But for
inserting single characters or null-terminated strings it is more vague,
and so we can improve performance by not using the __ostream_insert
function.

This is a minimal change that avoids __ostream_insert for single
characters. We can use the unformatted basic_ostream::put(charT)
function when we don't need the additional effects of a formatted output
function (i.e. padding and resetting the width). The put function will
insert into the buffer if possible, and only make a virtual call (to
overflow) if the buffer is full.

We could also avoid sputn when inserting null-terminated character
strings, but that would require using a new function for inserting
null-terminated strings, so the existing code using sputn is still used
for basic_string and basic_string_view. My preference is to leave that
for now, and try to improve the standard. We could either remove the
requirement to call sputn, or allow sputn to write directly to the
buffer instead of calling xsputn.

libstdc++-v3/ChangeLog:

	* include/std/ostream (operator<<(basic_ostream&, charT)):
	Use unformatted input if no padding is needed.
	(operator<<(basic_ostream<char>&, char)): Likewise.
2022-01-11 13:28:46 +00:00
Jonathan Wakely 5b417b3582 libstdc++: Make std::variant work with Clang in C++20 mode [PR103891]
Clang has some bugs with destructors that use constraints to be
conditionally trivial, so disable the P2231R1 constexpr changes to
std::variant unless the compiler is GCC 12 or later.

If/when P2493R0 gets accepted and implemented by G++ we can remove the
__GNUC__ check and use __cpp_concepts >= 202002 instead.

libstdc++-v3/ChangeLog:

	PR libstdc++/103891
	* include/bits/c++config (_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
	Define.
	* include/std/variant (__cpp_lib_variant): Only define C++20
	value when the compiler is known to support conditionally
	trivial destructors.
	* include/std/version (__cpp_lib_variant): Likewise.
2022-01-11 13:22:35 +00:00
Jonathan Wakely 11d3e8f436 libstdc++: Make std::common_iterator completely constexpr-able (LWG 3574)
This library issue was approved in the October 2021 plenary.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (common_iterator): Add constexpr
	to all member functions (LWG 3574).
	* testsuite/24_iterators/common_iterator/1.cc: Evaluate some
	tests as constant expressions.
	* testsuite/24_iterators/common_iterator/2.cc: Likewise.
2022-01-11 13:22:34 +00:00
GCC Administrator d9450aa0e8 Daily bump. 2022-01-11 00:16:36 +00:00
Jakub Jelinek a8d3c98746 libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760]
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-10 15:38:47 +01:00
Jonathan Wakely 68c2e9e923 libstdc++: Fix and simplify freestanding configuration [PR103866]
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-10 12:18:14 +00:00
Jonathan Wakely e54dda45f9 libstdc++: Add dg-timeout-factor to some more regex tests
I'm seeing these fail with tool_timeout=30 on a busy machine.

libstdc++-v3/ChangeLog:

	* testsuite/28_regex/algorithms/regex_replace/char/103664.cc:
	Add dg-timeout-factor directive.
	* testsuite/28_regex/basic_regex/84110.cc: Likewise.
	* testsuite/28_regex/basic_regex/ctors/char/other.cc: Likewise.
	* testsuite/28_regex/match_results/102667.cc: Likewise.
2022-01-10 12:18:14 +00:00
Jonathan Wakely e1b8a91e47 libstdc++: Update default -std option in manual
libstdc++-v3/ChangeLog:

	* doc/xml/manual/using.xml: Update documentation around default
	-std option.
	* doc/html/*: Regenerate.
2022-01-10 12:18:14 +00:00
Jonathan Wakely 4fde88e5dd libstdc++: Add -nostdinc++ for c++17 sources [PR100017]
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-10 12:18:13 +00:00
GCC Administrator 3a5702df3f Daily bump. 2022-01-10 00:16:20 +00:00
Sandra Loosemore 57fe1f6ad3 Testsuite: Make dependence on -fdelete-null-pointer-checks explicit
nios2-elf target defaults to -fno-delete-null-pointer-checks, breaking
tests that implicitly depend on that optimization.  Add the option
explicitly on these tests.

2022-01-08  Sandra Loosemore  <sandra@codesourcery.com>

	gcc/testsuite/
	* g++.dg/cpp0x/constexpr-compare1.C: Add explicit
	-fdelete-null-pointer-checks option.
	* g++.dg/cpp0x/constexpr-compare2.C: Likewise.
	* g++.dg/cpp0x/constexpr-typeid2.C: Likewise.
	* g++.dg/cpp1y/constexpr-94716.C: Likewise.
	* g++.dg/cpp1z/constexpr-compare1.C: Likewise.
	* g++.dg/cpp1z/constexpr-if36.C: Likewise.
	* gcc.dg/init-compare-1.c: Likewise.

	libstdc++-v3/
	* testsuite/18_support/type_info/constexpr.cc: Add explicit
	-fdelete-null-pointer-checks option.
2022-01-08 22:17:18 -08:00
GCC Administrator 11ce8d04f2 Daily bump. 2022-01-07 00:16:24 +00:00
Pavel I. Kryukov 52ebc2be09 libstdc++: Add self-merge check to std::forward_list::merge [PR103853]
This implements the proposed resolution of LWG 3088, so that x.merge(x)
is a no-op, consistent with std::list::merge.

Signed-off-by: Pavel I. Kryukov <pavel.kryukov@phystech.edu>

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/103853
	* include/bits/forward_list.tcc (forward_list::merge): Check for
	self-merge.
	* testsuite/23_containers/forward_list/operations/merge.cc: New test.
2022-01-06 14:56:48 +00:00
Jonathan Wakely ec12ddd1e7 libstdc++: Adjust friend declarations to work with Clang
I think this code is valid but it fails with Clang, possibly due to
https://llvm.org/PR38882

Qualifying the names makes it work for all compilers.

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (basic_regex, match_results): Qualify
	name in friend declaration, to work around Clang bug.
2022-01-06 14:56:48 +00:00
Jonathan Wakely e19e2989c3 libstdc++: Increase timeout for pthread7-rope.cc test
This test spawns thousands of threads and so times out if the tests are
run with a low timeout value and the machine is busy.

libstdc++-v3/ChangeLog:

	* testsuite/ext/rope/pthread7-rope.cc: Add dg-timeout-factor.
2022-01-06 14:56:33 +00:00
Jonathan Wakely c83ecfbe74 libstdc++: Do not use std::isdigit in <charconv> [PR103911]
This avoids a potential race condition if std::setlocale is used
concurrently with std::from_chars.

libstdc++-v3/ChangeLog:

	PR libstdc++/103911
	* include/std/charconv (__from_chars_alpha_to_num): Return
	char instead of unsigned char. Change invalid return value to
	127 instead of using numeric trait.
	(__from_chars_alnum): Fix comment. Do not use std::isdigit.
	Change type of variable to char.
2022-01-06 14:56:12 +00:00
GCC Administrator 0fbefa25b3 Daily bump. 2022-01-06 00:16:32 +00:00
François Dumont e3ef832a9e libstdc++: Optimize operations on small size hashtable [PR 68303]
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-05 21:46:52 +01:00
Jonathan Wakely 6aa0859afa libstdc++: Fix overconstrained std::string constructor [PR103919]
The C++17 basic_string(const T&, size_t, size_t) constructor is
overconstrained, so it can't be used for a NTBS and a temporary string
gets constructed (potentially allocating memory). There is no
corresponding constructor taking an NTBS, so no need to disambiguate
from it. Accepting an NTBS avoids the temporary (and potential
allocation) and is what the standard requires.

libstdc++-v3/ChangeLog:

	PR libstdc++/103919
	* include/bits/basic_string.h (basic_string(const T&, size_t, size_t)):
	Relax constraints on string_view parameter.
	* include/bits/cow_string.h (basic_string(const T&, size_t, size_t)):
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/103919.cc: New test.
2022-01-05 15:31:04 +00:00
Jonathan Wakely 3633cc5428 libstdc++: Implement P1328 "Making std::type_info::operator== constexpr"
This feature is present in the C++23 draft.

With Jakub's recent front-end changes we can implement constexpr
equality by comparing the addresses of std::type_info objects. We do not
need string comparisons, because for constant evaluation cases we know
we aren't dealing with std::type_info objects defined in other
translation units.

The ARM EABI requires that the type_info::operator== function can be
defined out-of-line (and suggests that should be the default), but to be
a constexpr function it must be defined inline (at least for C++23
mode). To meet these conflicting requirements we make the inline version
of operator== call a new __equal function when called at runtime. That
is an alias for the non-inline definition of operator== defined in
libsupc++.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export new symbol for
	ARM EABI.
	* include/bits/c++config (_GLIBCXX23_CONSTEXPR): Define.
	* include/std/version (__cpp_lib_constexpr_typeinfo): Define.
	* libsupc++/tinfo.cc: Add #error to ensure non-inline definition
	is emitted.
	(type_info::__equal): Define alias symbol.
	* libsupc++/typeinfo (type_info::before): Combine different
	implementations into one.
	(type_info::operator==): Likewise. Use address equality for
	constant evaluation. Call __equal for targets that require the
	definition to be non-inline.
	* testsuite/18_support/type_info/constexpr.cc: New test.
2022-01-05 14:43:01 +00:00
Jonathan Wakely 096228d84e libstdc++: Improvements to standard error category objects (part deux)
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-05 14:17:51 +00:00
Jonathan Wakely 1918067e2d libstdc++: Fix std::error_code pretty printer for versioned namespace
libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Strip
	versioned namespace from the type name that is printed.
2022-01-05 14:17:50 +00:00
Jonathan Wakely 7a2f2d91aa libstdc++: Add pretty printer for std::regex internals
This helps visualize the NFA states in a std::regex.  It probably isn't
very useful for users, but helps when working on the implementation.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdRegexStatePrinter): New
	printer for std::regex NFA states.
2022-01-05 13:47:02 +00:00
Jonathan Wakely 749ee73406 libstdc++: Fix comments in std::forward_list tests
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/forward_list/operations/1.cc: Fill in
	placeholders in comments.
	* testsuite/23_containers/forward_list/operations/2.cc:
	Likewise.
	* testsuite/23_containers/forward_list/operations/3.cc:
	Likewise.
	* testsuite/23_containers/forward_list/operations/4.cc:
	Likewise.
	* testsuite/23_containers/forward_list/operations/5.cc:
	Likewise.
	* testsuite/23_containers/forward_list/operations/6.cc:
	Likewise.
	* testsuite/23_containers/forward_list/operations/7.cc:
	Likewise.
2022-01-05 13:47:02 +00:00
Jonathan Wakely 76a45931ab libstdc++: Avoid -Wzero-as-null-pointer-constant warning [PR103848]
libstdc++-v3/ChangeLog:

	PR libstdc++/103848
	* include/bits/stl_deque.h (operator-): Do not use 0 as null
	pointer constant.
2022-01-05 13:47:02 +00:00
Jonathan Wakely 917c7b136e libstdc++: Simplify std::allocator_traits<allocator<void>>::construct
We don't need a preprocessor condition to decide whether to use
placement new or std::construct_at, because std::_Construct already does
that.

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (allocator_traits<allocator<void>>):
	Use std::_Construct for construct.
2022-01-05 13:47:01 +00:00
Jonathan Wakely cebe875f6f libstdc++: Fix example preprocessor command in FAQ [PR103877]
libstdc++-v3/ChangeLog:

	PR libstdc++/103877
	* doc/xml/faq.xml: Add '-x c++' to preprocessor command.
	* doc/html/faq.html: Regenerate.
2022-01-05 13:47:01 +00:00
Jonathan Wakely e09366718a libstdc++: Reduce template instantiations in <regex>
This moves the last two template parameters of __regex_algo_impl to be
runtime function parameters instead, so that we don't need four
different instantiations for the possible ways to call it. Most of the
function (and what it instantiates) is the same in all cases, so making
them compile-time choices doesn't really have much benefit.

Use  'if constexpr' for conditions that check template parameters, so
that when we do depend on a compile-time condition we only instantiate
what we need to.

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (__regex_algo_impl): Change __policy and
	__match_mode template parameters to be function parameters.
	(regex_match, regex_search): Pass policy and match mode as
	function arguments.
	* include/bits/regex.tcc (__regex_algo_impl): Change template
	parameters to function parameters.
	* include/bits/regex_compiler.h (_RegexTranslatorBase): Use
	'if constexpr' for conditions using template parameters.
	(_RegexTranslator): Likewise.
	* include/bits/regex_executor.tcc (_Executor::_M_handle_accept):
	Likewise.
	* testsuite/util/testsuite_regex.h (regex_match_debug)
	(regex_search_debug): Move template arguments to function
	arguments.
2022-01-05 13:47:01 +00:00
Jonathan Wakely 9a2451c101 libstdc++: Compare match_results for failed regex_match
The regex_match_debug testsuite helper doesn't compare the
std::match_results objects after a failed match, but it should do. The
standard says that the effects of a failed match on the match-results
are unspecified, except that [conditions testable by operator==]. So we
can check that the two sets of results compare equal even if the match
failed.

libstdc++-v3/ChangeLog:

	* testsuite/util/testsuite_regex.h (regex_match_debug): Compare
	results even if the match failed.
2022-01-05 13:47:00 +00:00
Jonathan Wakely 260a5334ee libstdc++: Improve std::regex_error::what() strings
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-05 13:47:00 +00:00
Jakub Jelinek 7adcbafe45 Update copyright years. 2022-01-03 10:42:10 +01:00
Jakub Jelinek 6123f29a18 Rotate ChangeLog files - step 2 - remove 2021 entries from ChangeLog files.
Can't be committed together with the previous one due to the ChangeLog vs.
other files restrictions.
2022-01-03 10:23:34 +01:00
Jakub Jelinek d04ae83244 Rotate ChangeLog files - part 1 - add ChangeLog-2021.
2022-01-03  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
gcc/ada/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
gcc/cp/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
gcc/d/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
gcc/fortran/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
gcc/testsuite/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
libgfortran/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
libstdc++-v3/
	* ChangeLog-2021: Rotate ChangeLog.  New file.
2022-01-03 10:18:16 +01:00
GCC Administrator 8a89c39be0 Daily bump. 2021-12-16 00:16:28 +00:00
François Dumont 807ad4bc85 libstdc++: Overload std::__to_address for __gnu_cxx::__normal_iterator.
Prefer to overload __to_address to partially specialize std::pointer_traits because
std::pointer_traits would be mostly useless. Moreover partial specialization of
pointer_traits<__normal_iterator<P, C>> fails to rebind C, so you get incorrect types
like __normal_iterator<long*, vector<int>>. In the case of __gnu_debug::_Safe_iterator
the to_pointer method is impossible to implement correctly because we are missing
the parent container to associate the iterator to.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h
	(std::pointer_traits<__gnu_cxx::__normal_iterator<>>): Remove.
	(std::__to_address(const __gnu_cxx::__normal_iterator<>&)): New for C++11 to C++17.
	* include/debug/safe_iterator.h
	(std::__to_address(const __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<>,
	_Sequence>&)): New for C++11 to C++17.
	* testsuite/24_iterators/normal_iterator/to_address.cc: Add check on std::vector::iterator
	to validate both __gnu_cxx::__normal_iterator<> __to_address overload in normal mode and
	__gnu_debug::_Safe_iterator in _GLIBCXX_DEBUG mode.
2021-12-15 22:28:05 +01:00
Jakub Jelinek a5b4ebc217 libstdc++: Poor man's case insensitive comparisons in time_get [PR71557]
This patch uses the same not completely correct case insensitive comparisons
as used elsewhere in the same header.  Proper comparisons that would handle
even multi-byte characters would be harder, but I don't see them implemented
in __ctype's methods.

2021-12-15  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/71557
	* include/bits/locale_facets_nonio.tcc (_M_extract_via_format):
	Compare characters other than format specifiers and whitespace
	case insensitively.
	(_M_extract_name): Compare characters case insensitively.
	* testsuite/22_locale/time_get/get/char/71557.cc: New test.
	* testsuite/22_locale/time_get/get/wchar_t/71557.cc: New test.
2021-12-15 10:25:53 +01:00
GCC Administrator 9c6586bc20 Daily bump. 2021-12-15 00:16:28 +00:00
Jonathan Wakely 9a4b4514bd libstdc++: Support old and new T_FMT for en_HK locale [PR103687]
This checks whether the locale data for en_HK includes %p and adjusts
the string being tested accordingly. To account for Jakub's fix to make
%I parse "12" as 0 instead of 12, we need to change the expected value
for the case where the locale format doesn't include %p. Also change the
time from 12:00:00 to 12:02:01 so we can tell if the minutes and seconds
get mixed up.

libstdc++-v3/ChangeLog:

	PR libstdc++/103687
	* testsuite/22_locale/time_get/get_date/wchar_t/4.cc: Restore
	original locale before returning.
	* testsuite/22_locale/time_get/get_time/char/2.cc: Check for %p
	in locale's T_FMT and adjust accordingly.
	* testsuite/22_locale/time_get/get_time/wchar_t/2.cc: Likewise.
2021-12-14 23:37:14 +00:00
Jonathan Wakely 7ce3c230ed libstdc++: Fix handling of invalid ranges in std::regex [PR102447]
std::regex currently allows invalid bracket ranges such as [\w-a] which
are only allowed by ECMAScript when in web browser compatibility mode.
It should be an error, because the start of the range is a character
class, not a single character. The current implementation of
_Compiler::_M_expression_term does not provide a way to reject this,
because we only remember a previous character, not whether we just
processed a character class (or collating symbol etc.)

This patch replaces the pair<bool, CharT> used to emulate
optional<CharT> with a custom class closer to pair<tribool,CharT>. That
allows us to track three states, so that we can tell when we've just
seen a character class.

With this additional state the code in _M_expression_term for processing
the _S_token_bracket_dash can be improved to correctly reject the [\w-a]
case, without regressing for valid cases such as [\w-] and [----].

libstdc++-v3/ChangeLog:

	PR libstdc++/102447
	* include/bits/regex_compiler.h (_Compiler::_BracketState): New
	class.
	(_Compiler::_BrackeyMatcher): New alias template.
	(_Compiler::_M_expression_term): Change pair<bool, CharT>
	parameter to _BracketState. Process first character for
	ECMAScript syntax as well as POSIX.
	* include/bits/regex_compiler.tcc
	(_Compiler::_M_insert_bracket_matcher): Pass _BracketState.
	(_Compiler::_M_expression_term): Use _BracketState to store
	state between calls. Improve handling of dashes in ranges.
	* testsuite/28_regex/algorithms/regex_match/cstring_bracket_01.cc:
	Add more tests for ranges containing dashes. Check invalid
	ranges with character class at the beginning.
2021-12-14 21:45:46 +00:00
Jonathan Wakely fda2872270 libstdc++: Simplify typedefs by using __UINTPTR_TYPE__
libstdc++-v3/ChangeLog:

	* include/ext/pointer.h (_Relative_pointer_impl::_UIntPtrType):
	Rename to uintptr_t and define as __UINTPTR_TYPE__.
2021-12-14 21:45:46 +00:00
Jonathan Wakely 63bb98e1c1 libstdc++: Simplify definition of std::regex_constants variables
This removes the __syntax_option and __match_flag enumeration types,
which are only used to define enumerators with successive values that
are then used to initialize the std::regex_constants global variables.

By defining enumerators in the syntax_option_type and match_flag_type
enumeration types with the correct values for the globals we get rid of
two useless enumeration types that just count from 0 to N, and we
improve the debugging experience. Because the enumeration types now have
enumerators defined, GDB will print values in terms of those enumerators
e.g.

$6 = (std::regex_constants::_S_ECMAScript | std::regex_constants::_S_multiline)

Previously this would have been shown as simply 0x810 because there were
no enumerators of that type.

This changes the type and value of enumerators such as _S_grep, but
users should never be referring to them directly anyway.

libstdc++-v3/ChangeLog:

	* include/bits/regex_constants.h (__syntax_option, __match_flag):
	Remove.
	(syntax_option_type, match_flag_type): Define enumerators.
	Use to initialize globals. Add constexpr to compound assignment
	operators.
	* include/bits/regex_error.h (error_type): Add comment.
	* testsuite/28_regex/constants/constexpr.cc: Remove comment.
	* testsuite/28_regex/constants/error_type.cc: Improve comment.
	* testsuite/28_regex/constants/match_flag_type.cc: Check bitmask
	requirements.
	* testsuite/28_regex/constants/syntax_option_type.cc: Likewise.
2021-12-14 21:45:45 +00:00
Jonathan Wakely b0e6a257f1 libstdc++: Fix non-reserved name in <regex> header
libstdc++-v3/ChangeLog:

	* include/bits/regex_compiler.tcc (_Compiler::_M_match_token):
	Use reserved name for parameter.
	* testsuite/17_intro/names.cc: Check "token".
2021-12-14 14:23:55 +00:00
GCC Administrator 7f1239cb43 Daily bump. 2021-12-14 00:16:25 +00:00
Jonathan Wakely 7bf710b511 libstdc++: Add support for '?' in linker script globs
The scripts/make_exports.pl script used for darwin only replaces '*'
wildcards in globs, it doesn't handle '?'. This means the recent changes
to std::__timepunct exports broke darwin.

Rather than use mangled names in the linker script, this adds support
for '?' to the perl script.

This also removes some unnecessary escaping of the replacement strings
in s// substitutions.

libstdc++-v3/ChangeLog:

	* scripts/make_exports.pl: Replace '?' with '.' when turning
	a glob into a regex.
2021-12-13 13:14:51 +00:00
Jonathan Wakely 55823c5a0b libstdc++: Make ranges::size and ranges::empty check for unbounded arrays
Passing IncompleteType(&)[] to ranges::begin produces an error outside
the immediate context, which is fine for ranges::begin, but it means
that we fail to enforce the SFINAE-able constraints for ranges::size and
ranges::size. They should not be callable for any array of unknown
bound, whether the type is complete or not. Because we don't enforce
that in their constraints, we get a hard error when they try to use
ranges::begin.

This simply adds explicit checks for arrays of unknown bound to the
constraints for ranges::size and ranges::empty. We only need to check it
for the __sentinel_size and __eq_iter_empty concepts, because those are
the ones that are relevant to arrays, and which try to use
ranges::begin.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (ranges::size, ranges::empty): Add
	explicit check for unbounded arrays before using ranges::begin.
	* testsuite/std/ranges/access/empty.cc: Check handling of unbounded
	arrays.
	* testsuite/std/ranges/access/size.cc: Likewise.
2021-12-13 11:15:41 +00:00
Jonathan Wakely ef5d671cd8 libstdc++: Fix std::regex_replace for strings with embedded null [PR103664]
The overload of std::regex_replace that takes a std::basic_string as the
fmt argument (for the replacement string) is implemented in terms of the
one taking a const C*, which uses std::char_traits to find the length.
That means it stops at a null character, even though the basic_string
might have additional characters beyond that.

Rather than duplicate the implementation of the const C* one for the
std::basic_string case, this moves that implementation to a new
__regex_replace function which takes a const C* and a length. Then both
the std::basic_string and const C* overloads can call that (with the
latter using char_traits to find the length to pass to the new
function).

libstdc++-v3/ChangeLog:

	PR libstdc++/103664
	* include/bits/regex.h (__regex_replace): Declare.
	(regex_replace): Use it.
	* include/bits/regex.tcc (__regex_replace): Replace regex_replace
	definition with __regex_replace.
	* testsuite/28_regex/algorithms/regex_replace/char/103664.cc: New test.
2021-12-13 11:11:30 +00:00
GCC Administrator e8decbe783 Daily bump. 2021-12-12 00:16:45 +00:00
Jason Merrill 2e8067041d libstdc++: check length in string append [PR103534]
In the testcase for 103534 we get a warning about append leading to memcpy
of a very large number of bytes overflowing the buffer.  This turns out to
be because we weren't calling _M_check_length for string append.  Rather
than do that directly, let's go through the public pointer append that calls
it.

	PR c++/103534

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (append (basic_string)): Call pointer
	append instead of _M_append directly.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Wstringop-overflow-8.C: New test.
2021-12-10 23:58:13 -05:00
GCC Administrator 0bceef1671 Daily bump. 2021-12-11 00:16:30 +00:00
Jakub Jelinek 982a2c9b78 libstdc++: Add std::time_get %r support [PR71367]
This incremental patch adds std::time_get %r support (%p was added already
in the previous patch).  The _M_am_fm_format method previously in the header
unfortunately had wrong arguments and so was useless, so the largest
complication in this patch is exporting a new symbol in the right symbol
version.

2021-12-10  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/71367
	* config/locale/dragonfly/time_members.cc (_M_initialize_timepunct):
	Initialize "C" _M_am_pm_format to %I:%M:%S %p rather than empty
	string.
	* config/locale/gnu/time_members.cc (_M_initialize_timepunct):
	Likewise.
	* config/locale/generic/time_members.cc (_M_initialize_timepunct):
	Likewise.
	* include/bits/locale_facets_nonio.h (_M_am_pm_format): New method.
	* include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Handle
	%r.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export _M_am_pm_format
	with const _CharT** argument, ensure it isn't exported in GLIBCXX_3.4.
	* testsuite/22_locale/time_get/get/char/71367.cc: New test.
	* testsuite/22_locale/time_get/get/wchar_t/71367.cc: New test.
2021-12-10 17:05:04 +01:00
Jakub Jelinek c82e492616 libstdc++: Some time_get fixes [PR78714]
The following patch is an attempt to fix various time_get related issues.
Sorry, it is long...

One of them is PR78714.  It seems _M_extract_via_format has been written
with how strftime behaves in mind rather than how strptime behaves.
There is a significant difference between the two, for strftime %a and %A
behave differently etc., one emits an abbreviated name, the other full name.
For strptime both should behave the same and accept both the full or
abbreviated names.  This needed large changes in _M_extract_name, which
was assuming the names are unique and names aren't prefixes of other names.
The _M_extract_name changes allow to deal with those cases.  As can be
seen in the new testcase, e.g. for %b and english locales we need to
accept both Apr and April.  If we see Apr in the input, the code looks
at whether there is end right after those 3 chars or if the next
character doesn't match characters in the longer names; in that case
it accepts the abbreviated name.  Otherwise, if the input has Apri, it
commits to a longer name and fails if it isn't April.  This behavior is
different from strptime, which for %bix and Aprix accepts it, but for
an input iterator I'm afraid we can't do better, we can't go back (peek
more than the current character).

Another case is that %d and %e in strptime should work the same, while
previously the code was hardcoding that %d would be 01 to 31 and %e
 1 to 31 (with leading 0 replaced by space).
strptime POSIX 2009 documentation seems to suggest for numbers it should
accept up to the specified number of digits rather than exactly that number
of digits:
The pattern "[x,y]" indicates that the value shall fall within the range
given (both bounds being inclusive), and the maximum number of characters scanned
shall be the maximum required to represent any value in the range without leading
zeros.
so by my reading "1:" is valid for "%H:".
The glibc strptime implementation actually skips any amount of whitespace
in all the cases where a number is read, my current patch skips a single
space at the start of %d/%e but not the others, but doesn't subtract the
space length from the len characters.
One option would be to do the leading whitespace skipping in _M_extract_num
but take it into account how many digits can be read.
This matters for " 12:" and "%H:", but not for " 12:" and " %H:"
as in the latter case the space in the format string results in all the
whitespace at the start to be consumed.
Note, the allowing of a single digit rather than 2 changes a behavior in
other ways, e.g. when seeing 40 in a number for range [1, 31] we reject
it as before, but previously we'd keep *ret == '4' because it was assuming
it has to be 2 digits and 40 isn't valid, so we know error already on the
4, but now we accept the 4 as value and fail iff the next format string
doesn't match the 0.
Also, previously it wasn't really checking the number was in the right
range, it would accept 00 for [1, 31] numbers, or would accept 39.

Another thing is that %I was parsing 12 as tm_hour 12 rather than as tm_hour 0
like e.g. glibc does.

Another thing is that %t was matching a single tab and %n a single newline,
while strptime docs say it skips over whitespace (again, zero or more).

Another thing is that %p wasn't handled at all, I think this was the main
cause of
FAIL: 22_locale/time_get/get_time/char/2.cc execution test
FAIL: 22_locale/time_get/get_time/char/wrapped_env.cc execution test
FAIL: 22_locale/time_get/get_time/char/wrapped_locale.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/2.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/wrapped_env.cc execution test
FAIL: 22_locale/time_get/get_time/wchar_t/wrapped_locale.cc execution test
before this patch, because en_HK* locales do use %I and %p in it.
The patch handles %p only if it follows %I (i.e. when the hour is parsed
first), which is the more usual case (in glibc):
grep '%I' localedata/locales/* | grep '%I.*%p' | wc -l
282
grep '%I' localedata/locales/* | grep -v '%I.*%p' | wc -l
44
grep '%I' localedata/locales/* | grep -v '%p' | wc -l
17
The last case use %P instead of %p in t_fmt_ampm, not sure if that one
is never used by strptime because %P isn't handled by strptime.
Anyway, the right thing to handle even %p%I would be to pass some state
around through all the _M_extract_via_format calls like glibc passes
  struct __strptime_state
  {
    unsigned int have_I : 1;
    unsigned int have_wday : 1;
    unsigned int have_yday : 1;
    unsigned int have_mon : 1;
    unsigned int have_mday : 1;
    unsigned int have_uweek : 1;
    unsigned int have_wweek : 1;
    unsigned int is_pm : 1;
    unsigned int want_century : 1;
    unsigned int want_era : 1;
    unsigned int want_xday : 1;
    enum ptime_locale_status decided : 2;
    signed char week_no;
    signed char century;
    int era_cnt;
  } s;
around.  That is for the %p case used like:
  if (s.have_I && s.is_pm)
    tm->tm_hour += 12;
during finalization, but handles tons of other cases which it is unclear
if libstdc++ needs or doesn't need to handle, e.g. strptime if one
specifies year and yday computes wday/mon/day from it, etc. basically for
the redundant fields computes them from other fields if those have been
parsed and are sufficient to determine it.
To do this we'd need to change ABI for the _M_extract_via_format,
though sure, we could add a wrapper around the new one with the old
arguments that would just use a dummy state.  And we'd need a new
_M_whatever finalizer that would do those post parsing tweaks.

Also, %% wasn't handled.

For a whitespace in the strings there was inconsistent behavior,
_M_extract_via_format would require exactly that whitespace char (say
matching space, or matching tab), while the caller follows what
https://eel.is/c++draft/locale.time.get#members-8.5 says, that
when encountering whitespace it skips whitespace in the format and
then whitespace in the input if any.  I've changed _M_extract_via_format
to skip whitespace in the input (looping over format isn't IMHO necessary,
because next iteration of the loop will handle that too).

Tested on x86_64-linux by make check-target-libstdc++-v3, ok for trunk
if it passes full bootstrap/regtest?

For the new 3.cc testcases, I have included hopefully correctly
corresponding C testcase using strptime in an attachment, and to the
extent where it can be compared (e.g. strptime on failure just
returns NULL, doesn't tell where it exactly stopped) I think the
only difference is that
  str = "Novembur";
  format = "%bembur";
  ret = strptime (str, format, &time);
case where strptime accepts it but there is no way to do it with input
operator.

I admit I don't have libc++ or other STL libraries around to be able to
check how much the new 3.cc matches or disagrees with other implementations.

Now, the things not handled by this patch but which should be fixed (I
probably need to go back to compiler work) or at least looked at:

1) seems %j, %r, %U, %w and %W aren't handled (not sure if all of them
   are already in POSIX 2009 or some are later)
2) I haven't touched the %y/%Y/%C and year handling stuff, that is
   definitely not matching what POSIX 2009 says:
       C       All  but the last two digits of the year {2}; leading zeros shall be permitted but shall not be required. A leading '+' or '−' character shall be permitted before
               any leading zeros but shall not be required.
       y       The  last  two  digits of the year. When format contains neither a C conversion specifier nor a Y conversion specifier, values in the range [69,99] shall refer to
               years 1969 to 1999 inclusive and values in the range [00,68] shall refer to years 2000 to 2068 inclusive; leading zeros shall be permitted but shall  not  be  re‐
               quired. A leading '+' or '−' character shall be permitted before any leading zeros but shall not be required.

               Note:     It is expected that in a future version of this standard the default century inferred from a 2-digit year will change. (This would apply to all commands
                         accepting a 2-digit year as input.)
       Y       The full year {4}; leading zeros shall be permitted but shall not be required. A leading '+' or '−' character shall be permitted  before  any  leading  zeros  but
               shall not be required.
   I've tried to avoid making changes to _M_extract_num for these as well
   to keep current status quo (the __len == 4 cases).  One thing is what
   to do for things with %C %y and/or %Y in the formats, another thing
   is what to do in the methods that directly perform _M_extract_num
   for year
3) the above question what to do for leading whitespace of any numbers
   being parsed
4) the %p%I issue mentioned above and generally what to do if we
   pass state and have finalizers at the end of parsing
5) _M_extract_via_format is also inconsistent with its callers on handling
   the non-whitespace characters in between format specifiers, the caller
   follows https://eel.is/c++draft/locale.time.get#members-8.6 and does
   case insensitive comparison:
          // TODO real case-insensitive comparison
          else if (__ctype.tolower(*__s) == __ctype.tolower(*__fmt) ||
                   __ctype.toupper(*__s) == __ctype.toupper(*__fmt))
   while _M_extract_via_format only compares exact characters:
              // Verify format and input match, extract and discard.
              if (__format[__i] == *__beg)
                ++__beg;
   (another question is if there is a better way how to do real
   case-insensitive comparison of 2 characters and whether we e.g. need
   to handle the Turkish i/İ and ı/I which have different number of bytes
   in UTF-8)
6) _M_extract_name does something weird for case-sensitivity,
      // NB: Some of the locale data is in the form of all lowercase
      // names, and some is in the form of initially-capitalized
      // names. Look for both.
      if (__beg != __end)
   and
            if (__c == __names[__i1][0]
                || __c == __ctype.toupper(__names[__i1][0]))
   for the first letter while just
        __name[__pos] == *__beg
   on all the following letters.  strptime says:
   In case a text string (such as the name of a day of the week or a month
   name) is to be matched, the comparison is case insensitive.
   so supposedly all the _M_extract_name comparisons should be case
   insensitive.

2021-12-10  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/78714
	* include/bits/locale_facets_nonio.tcc (_M_extract_via_format):
	Mention in function comment it interprets strptime format string
	rather than strftime.  Handle %a and %A the same by accepting both
	full and abbreviated names.  Similarly handle %h, %b and %B the same.
	Handle %d and %e the same by accepting possibly optional single space
	and 1 or 2 digits.  For %I store tm_hour 0 instead of tm_hour 12.  For
	%t and %n skip any whitespace.  Handle %p and %%.  For whitespace in
	the string skip any whitespace.
	(_M_extract_num): For __len == 2 accept 1 or 2 digits rather than
	always 2.  Don't punt early if __value * __mult is larget than __max
	or smaller than __min - __mult, instead punt if __value > __max.
	At the end verify __value is in between __min and __max and punt
	otherwise.
	(_M_extract_name): Allow non-unique names or names which are prefixes
	of other names.  Don't recompute lengths of names for every character.
	* testsuite/22_locale/time_get/get/char/3.cc: New test.
	* testsuite/22_locale/time_get/get/wchar_t/3.cc: New test.
	* testsuite/22_locale/time_get/get_date/char/12791.cc (test01): Use
	62 instead 60 and expect 6 to be accepted and thus *ret01 == '2'.
	* testsuite/22_locale/time_get/get_date/wchar_t/12791.cc (test01):
	Similarly.
	* testsuite/22_locale/time_get/get_time/char/2.cc (test02): Add " PM"
	to the string.
	* testsuite/22_locale/time_get/get_time/char/5.cc (test01): Expect
	tm_hour 1 rather than 0.
	* testsuite/22_locale/time_get/get_time/wchar_t/2.cc (test02): Add
	" PM" to the string.
	* testsuite/22_locale/time_get/get_time/wchar_t/5.cc (test01): Expect
	tm_hour 1 rather than 0.
2021-12-10 17:03:58 +01:00
Jonathan Wakely ffb632517f libstdc++: Guard mutex and condvar with gthreads macro [PR103638]
A mutex and condition variable is used for timed waits on atomics if
there is no "platform wait" (e.g. futex) supported. But the use of those
types wasn't guarded by the _GLIBCXX_HAS_GTHREADS macro, causing errors
for --disable-threads builds. This fix allows <atomic> to work on
targets with futexes but no gthreads.

libstdc++-v3/ChangeLog:

	PR libstdc++/103638
	* include/bits/atomic_timed_wait.h: Check _GLIBCXX_HAS_GTHREADS
	before using std::mutex and std::__condvar.
2021-12-10 14:05:46 +00:00
Jonathan Wakely ca1c7065e9 libstdc++: Fix definition of _GLIBCXX_NO_SLEEP config macro
If no OS function to sleep (e.g. nanosleep, usleep, Win32 Sleep etc.) is
available then configure defines the macro NO_SLEEP. But this will not
get prefixed with "_GLIBCXX_" because include/Makefile.am only does that
for macros beginning with "HAVE_". The configure script should define
_GLIBCXX_NO_SLEEP instead (which is what the code actually checks for).

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Add _GLIBCXX_
	prefix to NO_SLEEP macro.
	* config.h.in: Regenerate.
	* configure: Regenerate.
2021-12-10 14:05:46 +00:00
Jonathan Wakely db184a3453 libstdc++: Fix diagnostic pragma push that should be pop
libstdc++-v3/ChangeLog:

	* include/bits/char_traits.h: Change pragma push to pop.
2021-12-10 09:06:37 +00:00
Thomas Rodgers 38c60e5075 libstdc++: Make atomic<T*>::wait() const [PR102994]
This was an oversight in the original commit adding wait/notify
to atomic<T>.

libstdc++-v3/ChangeLog:

	PR libstdc++/102994
	* include/bits/atomic_base.h (__atomic_base<_PTp*>::wait()):
	Add const qualifier.
	* include/std/atomic (atomic<_Tp*>::wait(), atomic_wait()):
	Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc:
	New test.
2021-12-09 17:57:03 -08:00
GCC Administrator 4b4839e325 Daily bump. 2021-12-10 00:16:29 +00:00
Jonathan Wakely 2c7fb16b52 libstdc++: Fix ambiguous comparisons for iterators in C++20
Since r11-1571 (c++: Refinements to "more constrained") was changed in
the front end, the following comment from stl_iterator.h stopped being
true:

  // These extra overloads are not needed in C++20, because the ones above
  // are constrained with a requires-clause and so overload resolution will
  // prefer them to greedy unconstrained function templates.

The requires-clause is no longer considered when comparing unrelated
function templates. That means that the constrained operator== specified
in the standard is no longer more constrained than the pathological
comparison operators defined in the testsuite_greedy_ops.h header. This
was causing several tests to FAIL in C++20 mode:

FAIL: 23_containers/deque/types/1.cc (test for excess errors)
FAIL: 23_containers/vector/types/1.cc (test for excess errors)
FAIL: 24_iterators/move_iterator/greedy_ops.cc (test for excess errors)
FAIL: 24_iterators/normal_iterator/greedy_ops.cc (test for excess errors)
FAIL: 24_iterators/reverse_iterator/greedy_ops.cc (test for excess errors)

The solution is to restore some of the non-standard comparison operators
that are more specialized than the greedy operators in the testsuite.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (operator==, operator<=>): Define
	overloads for homogeneous specializations of reverse_iterator,
	__normal_iterator and move_iterator.
2021-12-09 23:19:03 +00:00
Jonathan Wakely 9042302ef0 libstdc++: Remove bogus dg-error for effective-target c++20
This test no longer has additional errors for C++20 mode, so remove the
dg-error that is now failing, and the unnecessary dg-prune-output.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/scoped_allocator/69293_neg.cc: Remove
	dg-error for c++20.
2021-12-09 23:18:24 +00:00
Jonathan Wakely a8e02a00a0 libstdc++: Make std::make_exception_ptr work with -fno-exceptions [PR85813]
This allows std::make_exception_ptr to be used in a translation unit
compiled with -fno-exceptions. This works because the new implementation
added for PR 68297 doesn't need to throw or catch anything. The catch is
there to handle exceptions from the constructor of the exception object,
which we can assume won't happen in a -fno-exceptions TU and so use the
__catch macro instead. If the constructor does throw (because it's
defined in a different TU which was compiled with exceptions enabled)
then that exception will propagate to the make_exception_ptr caller.
That seems acceptable for a program that is trying to mix & match TUs
compiled with and without exceptions, and using types that throw when
constructed. That should be rare, and can't reasonably be expected to
have sensible behaviour.

This also enables the new implementation for targets that use a
non-standard calling convention for the exceptionDestructor callback
(specifically, mingw, which uses __thiscall). All we need to do is mark
the __dest_thunk function template with the right calling convention.

Finally, the useless no-op definition of make_exception_ptr (which is
only used if both RTTI and exceptions are disabled) is marked
always_inline, to ensure that the linker won't keep that definition and
discard the functional ones when both definitions of the function are
present in the link. An alternative would be to add the abi_tag
attribute to the useless definition, but making it always_inline should
work, and it's small enough to always be inlined reliably.

libstdc++-v3/ChangeLog:

	PR libstdc++/85813
	* libsupc++/exception_ptr.h (__dest_thunk): Add macro for
	destructor calling convention.
	(make_exception_ptr): Enable non-throwing implementation for
	-fno-exceptions and for non-standard calling conventions. Use
	always_inline attribute on the useless no-rtti no-exceptions
	definition.
	* testsuite/18_support/exception_ptr/64241.cc: Add -fno-rtti so
	the no-op implementation is still used.
2021-12-09 23:12:20 +00:00
Jonathan Wakely a1ca039fc0 libstdc++: Fix std::exception_ptr regressions [PR103630]
This restores support for std::make_exception_ptr<E&> and for using
std::exception_ptr in C++98.

Because the new non-throwing implementation needs to use std::decay to
handle references the original throwing implementation is used for
C++98.

We also need to change the typeid expression so it doesn't yield the
dynamic type when the function parameter is a reference to a polymorphic
type. Otherwise the new exception object could be caught by any handler
matching the dynamic type, even though the actual exception object is
only a copy of the base class, sliced to the static type.

libstdc++-v3/ChangeLog:

	PR libstdc++/103630
	* libsupc++/exception_ptr.h (exception_ptr): Fix exception
	specifications on inline definitions.
	(make_exception_ptr): Decay the template parameter. Use typeid
	of the static type.
	* testsuite/18_support/exception_ptr/103630.cc: New test.
2021-12-09 23:02:37 +00:00
Jonathan Wakely a219139e98 libstdc++: Implement std::ios_base::noreplace for C++23 [PR59769]
This implements my P2467R0 proposal to support opening an fstream in
exclusive mode. The new constant is also supported pre-C++23 as
std::ios_base::__noreplace.

This proposal hasn't been approved for C++23 yet, but I am confident it
will be, as this is restoring a feture found in pre-ISO C++ iostreams
implementations (and still present in the MSVC library as _Noreplace).
If the proposal fails for C++23 we can remove the ios::noreplace
name and just keep ios::__noreplace as an extension.

libstdc++-v3/ChangeLog:

	PR libstdc++/59769
	* config/io/basic_file_stdio.cc (fopen_mode): Add support for
	exclusive mode.
	* include/bits/ios_base.h (_S_noreplace): Define new enumerator.
	(ios_base::__noreplace): Define.
	(ios_base::noreplace): Define for C++23.
	* include/std/version (__cpp_lib_ios_noreplace): Define.
	* testsuite/27_io/basic_ofstream/open/char/noreplace.cc: New test.
	* testsuite/27_io/basic_ofstream/open/wchar_t/noreplace.cc: New test.
2021-12-09 22:59:48 +00:00
Jonathan Wakely 9e18a25331 libstdc++: Allow std::condition_variable waits to be cancelled [PR103382]
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-09 22:58:19 +00:00
Jonathan Wakely db5fa0837e libstdc++: Avoid unnecessary allocations in std::map insertions [PR92300]
Inserting a pair<Key, Value> into a map<Key, Value> will allocate a new
node and construct a pair<const Key, Value> in the node, then check if
the Key is already present in the map. That is because pair<Key, Value>
is not the same type as the map's value_type. But it only differs in the
const-qualification on the Key, and so we should be able to do the
lookup directly, without allocating a new node. This avoids allocating
and then deallocating a node for the case where the key is already found
and nothing gets inserted.

We can take this optimization further and lookup the key directly for a
pair<Key, X>, pair<const Key, X>, pair<Key&, X> etc. for any X. A strict
reading of the standard says we can only do this when we know the
allocator won't do anything funky with the value when constructing a
pair<const Key, Value> from a slightly different type. Inserting that
type only requires the value_type to be Cpp17EmplaceInsertable into the
container, and that doesn't have any requirement that the value is
unchanged (unlike Cpp17CopyInsertable and Cpp17MoveInsertable). For that
reason, the optimization is only done for maps using std::allocator.

A similar optimization can be done for map.emplace(key, value) where the
first argument is similar to the key_type and so can be looked up
without allocating a new node and constructing a key_type.

Finally, both of the insert and emplace cases can use the same
optimization when key_type is a scalar type and some other scalar is
being passed as the insert/emplace argument. Converting from one scalar
type to another won't have surprising value-altering behaviour, and has
no side effects (unlike e.g. constructing a std::string from a const
char* argument, which might allocate).

We don't need to do this for std::multimap, because we always insert the
new node even if the key is already present. So there's no benefit to
doing the lookup before allocating the new node.

libstdc++-v3/ChangeLog:

	PR libstdc++/92300
	* include/bits/stl_map.h (insert(Pair&&), emplace(Args&&...)):
	Check whether the arguments can be looked up directly without
	constructing a temporary node first.
	* include/bits/stl_pair.h (__is_pair): Move to here, from ...
	* include/bits/uses_allocator_args.h (__is_pair): ... here.
	* testsuite/23_containers/map/modifiers/emplace/92300.cc: New test.
	* testsuite/23_containers/map/modifiers/insert/92300.cc: New test.
2021-12-09 22:56:57 +00:00
Jonathan Wakely fb9875ebf1 libstdc++: Do not leak empty COW strings
When non-const references, pointers or iterators are obtained to the
contents of a COW std::basic_string, the implementation has to assume it
could result in a write to the contents. If the string was previously
shared, it does the "copy-on-write" step of creating a new copy of the
data that is not shared by another object.  It also marks the string as
"leaked", so that no future copies of it will share ownership either.

However, if the string is empty then the only character in the sequence
is the terminating null, and modifying that is undefined behaviour. This
means that non-const references/pointers/iterators to an empty string
are effectively const. Since no direct modification is possible, there
is no need to "leak" the string, it can be safely shared with other
objects. This avoids unnecessary allocations to create new copies of
empty strings that can't be modified anyway.

We already did this optimization for strings that share ownership of the
static _S_empty_rep() object, but not for strings that have non-zero
capacity, and not for fully-dynamic-strings (where the _S_empty_rep()
object is never used).

With this change we avoid two allocations in the return statement:

  std::string s;
  s.reserve(1);       // allocate
  std::string s2 = s;
  std::string s3 = s;
  return s[0] + s2[0] + s3[0]; // leak+allocate twice

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_leak_hard): Do not
	reallocate an empty string.
2021-12-09 22:51:06 +00:00
Jonathan Wakely f8463b0e3e libstdc++: Disable over-zealous warnings about std::string copies [PR103332]
These warnings are triggered by perfectly valid code using std::string.
They're particularly bad when --enable-fully-dynamic-string is used,
because even std::string().begin() will give a warning.

Use pragmas to stop the troublesome warnings for copies done by
std::char_traits.

libstdc++-v3/ChangeLog:

	PR libstdc++/103332
	PR libstdc++/102958
	PR libstdc++/103483
	* include/bits/char_traits.h: Suppress stringop and array-bounds
	warnings.
2021-12-09 22:51:06 +00:00
Jonathan Wakely fe9571a35d libstdc++: Fix non-reserved name in std::allocator base class [PR64135]
The possible base classes of std::allocator are new_allocator and
malloc_allocator, which both cause a non-reserved name to be declared in
every program that includes the definition of std::allocator. This is
non-conforming.

This change replaces __gnu_cxx::new_allocator with std::__new_allocator
which is identical except for using a reserved name. The non-standard
extension __gnu_cxx::new_allocator is preserved as a thin wrapper over
std::__new_allocator. There is no problem with the extension using a
non-reserved name now that it's not included by default in other
headers.

The same change could be done to __gnu_cxx::malloc_allocator but as it's
not the default configuration it can wait.

libstdc++-v3/ChangeLog:

	PR libstdc++/64135
	* config/allocator/new_allocator_base.h: Include
	<bits/new_allocator.h> instead of <ext/new_allocator.h>.
	(__allocator_base): Use std::__new_allocator instead of
	__gnu_cxx::new_allocator.
	* doc/xml/manual/allocator.xml: Document new default base class
	for std::allocator.
	* doc/xml/manual/evolution.xml: Likewise.
	* doc/html/*: Regenerate.
	* include/Makefile.am: Add bits/new_allocator.h.
	* include/Makefile.in: Regenerate.
	* include/experimental/memory_resource (new_delete_resource):
	Use std::__new_allocator instead of __gnu_cxx::new_allocator.
	* include/ext/new_allocator.h (new_allocator): Derive from
	std::__new_allocator. Move implementation to ...
	* include/bits/new_allocator.h: New file.
	* testsuite/20_util/allocator/64135.cc: New test.
2021-12-09 22:50:10 +00:00
GCC Administrator 641ff2196f Daily bump. 2021-12-09 00:16:31 +00:00
Jonathan Wakely c15aa46cca libstdc++: Fix undefined shift when _Atomic_word is 64-bit
The check for _Atomic_word being 32-bit is just a normal runtime
condition for C++11 and C++14, because it doesn't use if-constexpr. That
means the 1LL << (CHAR_BIT * sizeof(_Atomic_word)) expression expands to
1LL << 64 on Solaris, which is ill-formed.

This adds another indirection so that the shift width is zero if the
code is unreachable.

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_base.h (_Sp_counted_base::_M_release()):
	Make shift width conditional on __double_word condition.
2021-12-08 23:41:03 +00:00
François Dumont e7fac1e1a5 libstdc++: [_GLIBCXX_DEBUG] Enhance std::erase_if for vector/deque
libstdc++-v3/ChangeLog:

	* include/std/deque (erase_if): Use _GLIBCXX_STD_C container reference and
	__niter_wrap to limit _GLIBCXX_DEBUG mode impact.
	* include/std/vector (erase_if): Likewise.
2021-12-08 19:09:47 +01:00
Maged Michael dbf8bd3c2f libstdc++: Skip atomic instructions in shared_ptr when both counts are 1
This rewrites _Sp_counted_base::_M_release to skip the two atomic
instructions that decrement each of the use count and the weak count
when both are 1.

Benefits: Save the cost of the last atomic decrements of each of the use
count and the weak count in _Sp_counted_base. Atomic instructions are
significantly slower than regular loads and stores across major
architectures.

How current code works: _M_release() atomically decrements the use
count, checks if it was 1, if so calls _M_dispose(), atomically
decrements the weak count, checks if it was 1, and if so calls
_M_destroy().

How the proposed algorithm works: _M_release() loads both use count and
weak count together atomically (assuming suitable alignment, discussed
later), checks if the value corresponds to a 0x1 value in the individual
count members, and if so calls _M_dispose() and _M_destroy().
Otherwise, it follows the original algorithm.

Why it works: When the current thread executing _M_release() finds each
of the counts is equal to 1, then no other threads could possibly hold
use or weak references to this control block. That is, no other threads
could possibly access the counts or the protected object.

There are two crucial high-level issues that I'd like to point out first:
- Atomicity of access to the counts together
- Proper alignment of the counts together

The patch is intended to apply the proposed algorithm only to the case of
64-bit mode, 4-byte counts, and 8-byte aligned _Sp_counted_base.

** Atomicity **
- The proposed algorithm depends on the mutual atomicity among 8-byte
atomic operations and 4-byte atomic operations on each of the 4-byte halves
of the 8-byte aligned 8-byte block.
- The standard does not guarantee atomicity of 8-byte operations on a pair
of 8-byte aligned 4-byte objects.
- To my knowledge this works in practice on systems that guarantee native
implementation of 4-byte and 8-byte atomic operations.
- __atomic_always_lock_free is used to check for native atomic operations.

** Alignment **
- _Sp_counted_base is an internal base class, with a virtual destructor,
so it has a vptr at the beginning of the class, and will be aligned to
alignof(void*) i.e. 8 bytes.
- The first members of the class are the 4-byte use count and 4-byte
weak count, which will occupy 8 contiguous bytes immediately after the
vptr, i.e. they form an 8-byte aligned 8 byte range.

Other points:
- The proposed algorithm can interact correctly with the current algorithm.
That is, multiple threads using different versions of the code with and
without the patch operating on the same objects should always interact
correctly. The intent for the patch is to be ABI compatible with the
current implementation.
- The proposed patch involves a performance trade-off between saving the
costs of atomic instructions when the counts are both 1 vs adding the cost
of loading the 8-byte combined counts and comparison with {0x1, 0x1}.
- I noticed a big difference between the code generated by GCC vs LLVM. GCC
seems to generate noticeably more code and what seems to be redundant null
checks and branches.
- The patch has been in use (built using LLVM) in a large environment for
many months. The performance gains outweigh the losses (roughly 10 to 1)
across a large variety of workloads.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_TSAN): Define macro
	indicating that TSan is in use.
	* include/bits/shared_ptr_base.h (_Sp_counted_base::_M_release):
	Replace definition in primary template with explicit
	specializations for _S_mutex and _S_atomic policies.
	(_Sp_counted_base<_S_mutex>::_M_release): New specialization.
	(_Sp_counted_base<_S_atomic>::_M_release): New specialization,
	using a single atomic load to access both reference counts at
	once.
	(_Sp_counted_base::_M_release_last_use): New member function.
2021-12-08 11:39:34 +00:00
GCC Administrator 1f6b0003b6 Daily bump. 2021-12-08 00:16:23 +00:00
Tamar Christina ba6bb287f0 Revert "libstdc++: Fix ctype changed after newlib update."
Newlib has reverted the commit that caused us to require a
workaround.  As such we can now revert the workaround.

This reverts commit 0e510ab534.

libstdc++-v3/ChangeLog:

	PR libstdc++/103305
	* config/os/newlib/ctype_base.h (upper, lower, alpha, digit, xdigit,
	space, print, graph, cntrl, punct, alnum, blank): Revert.
2021-12-07 10:37:30 +00:00
GCC Administrator 70e4cb66c1 Daily bump. 2021-12-05 00:16:28 +00:00
Jonathan Wakely 87710ec7b2 libstdc++: Initialize member in std::match_results [PR103549]
This fixes a -Wuninitialized warning for std::cmatch m1, m2; m1=m2;

Also name the template parameters in the forward declaration, to get rid
of the <template-parameter-1-1> noise in diagnostics.

libstdc++-v3/ChangeLog:

	PR libstdc++/103549
	* include/bits/regex.h (match_results): Give names to template
	parameters in first declaration.
	(match_results::_M_begin): Add default member-initializer.
2021-12-04 15:55:01 +00:00
GCC Administrator 03a9bd059b Daily bump. 2021-12-04 00:16:46 +00:00
Jonathan Wakely bf548ce3e6 libstdc++: Simplify emplace member functions in _Rb_tree
This introduces a new RAII type to simplify the emplace members which
currently use try-catch blocks to deallocate a node if an exception is
thrown by the comparisons done during insertion. The new type is created
on the stack and manages the allocation of a new node and deallocates it
in the destructor if it wasn't inserted into the tree. It also provides
helper functions for doing the insertion, releasing ownership of the
node to the tree.

Also, we don't need to use long qualified names if we put the return
type after the nested-name-specifier.

libstdc++-v3/ChangeLog:

	* include/bits/stl_tree.h (_Rb_tree::_Auto_node): Define new
	RAII helper for creating and inserting new nodes.
	(_Rb_tree::_M_insert_node): Use trailing-return-type to simplify
	out-of-line definition.
	(_Rb_tree::_M_insert_lower_node): Likewise.
	(_Rb_tree::_M_insert_equal_lower_node): Likewise.
	(_Rb_tree::_M_emplace_unique): Likewise. Use _Auto_node.
	(_Rb_tree::_M_emplace_equal): Likewise.
	(_Rb_tree::_M_emplace_hint_unique): Likewise.
	(_Rb_tree::_M_emplace_hint_equal): Likewise.
2021-12-03 22:52:27 +00:00
Jonathan Wakely 7bfe82e5a8 Fix typos in libstdc++-v3/ChangeLog 2021-12-03 21:34:18 +00:00
GCC Administrator ea6ef320b0 Daily bump. 2021-12-03 00:17:04 +00:00
Jonathan Wakely acf4fe96f1 libstdc++: Allow exception classes to move fully-dynamic strings
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-02 16:53:13 +00:00
Jonathan Wakely e2e98f524f libstdc++: Remove broken std::allocator base classes [PR103340]
The bitmap_allocator, __mt_alloc and __pool_alloc extensions are no
longer suitable for use as the base class of std::allocator, because
they have not been updated to meet the C++20 requirements.  There is a
patch attached to PR 103340 which addresses that, but more work would be
needed to solve the linking errors that occur when the library is
configured to use them.

Using --enable-libstdcxx-allocator=bitmap wouldn't even bootstrap for
the past few years, and I can't find any gcc-testresults reports using
any of these allocators. This patch removes the configure option to use
these as the std::allocator base class. The allocators are still in the
tree and can be used directly, you just can't configure the library to
use one of them as the base class of std::allocator.

libstdc++-v3/ChangeLog:

	PR libstdc++/103340
	PR libstdc++/103400
	PR libstdc++/103381
	* acinclude.m4 (GLIBCXX_ENABLE_ALLOCATOR): Remove mt, bitmap
	and pool options.
	* configure: Regenerate.
	* config/allocator/bitmap_allocator_base.h: Removed.
	* config/allocator/mt_allocator_base.h: Removed.
	* config/allocator/pool_allocator_base.h: Removed.
	* doc/xml/manual/allocator.xml: Update.
	* doc/xml/manual/configure.xml: Update.
	* doc/xml/manual/evolution.xml: Document removal.
	* doc/xml/manual/mt_allocator.xml: Editorial tweaks.
	* doc/html/manual/*: Regenerate.
2021-12-02 16:46:28 +00:00
Jonathan Wakely b5a568683f libstdc++: Restore unconditional atomic load in COW std::string
The relaxed load is already optimal, checking the __single_threaded
global before doing a non-atomic load isn't an optimization.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_is_leaked()):
	Revert change to check __is_single_threaded() before using
	atomic load.
2021-12-02 16:46:28 +00:00
GCC Administrator 40fa651e60 Daily bump. 2021-12-02 00:16:33 +00:00
Jonathan Wakely 056551414a libstdc++: Clear RB tree after moving elements [PR103501]
If the allocator-extended move constructor move-constructs each element
into the new container, the contents of the old container are left in
moved-from states. We cannot know if those states preserve the
container's ordering and uniqueness guarantees, so just erase all
moved-from elements.

libstdc++-v3/ChangeLog:

	PR libstdc++/103501
	* include/bits/stl_tree.h (_Rb_tree(_Rb_tree&&, false_type)):
	Clear container if elements have been moved-from.
	* testsuite/23_containers/map/allocator/move_cons.cc: Expect
	moved-from container to be empty.
	* testsuite/23_containers/multimap/allocator/move_cons.cc:
	Likewise.
	* testsuite/23_containers/multiset/allocator/103501.cc: New test.
	* testsuite/23_containers/set/allocator/103501.cc: New test.
2021-12-01 15:00:33 +00:00
Jonathan Wakely 74d14778e7 libstdc++: Define std::__is_constant_evaluated() for internal use
This adds std::__is_constant_evaluated() as a C++11 wrapper for
__builtin_is_constant_evaluated, but just returning false if the
built-in isn't supported by the compiler. This allows us to use it
throughout the library without checking __has_builtin every time.

Some uses in std::vector and std::string can only be constexpr when the
std::is_constant_evaluated() function actually works, so we might as
well guard them with a relevant macro and call that function directly,
rather than the built-in or std::__is_constant_evaluated().

The remaining checks of the __cpp_lib_is_constant_evaluated macro could
now be replaced by checking __cplusplus >= 202002 instead, but there's
no practical difference. We still need some kind of preprocessor check
there anyway.

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in (PREDEFINED): Change macro name.
	* include/bits/allocator.h (allocate, deallocate): Use
	std::__is_constant_evaluated() unconditionally, instead of
	checking whether std::is_constant_evaluated() (or the built-in)
	can be used.
	* include/bits/basic_string.h: Check new macro. call
	std::is_constant_evaluated() directly in C++20-only code that is
	guarded by a suitable macro.
	* include/bits/basic_string.tcc: Likewise.
	* include/bits/c++config (__is_constant_evaluated): Define.
	(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Replace with ...
	(_GLIBCXX_HAVE_IS_CONSTANT_EVALUATED): New macro.
	* include/bits/char_traits.h (char_traits): Replace conditional
	calls to std::is_constant_evaluated with unconditional calls to
	std::__is_constant_evaluated.
	* include/bits/cow_string.h: Use new macro.
	* include/bits/ranges_algobase.h (__copy_or_move): Replace
	conditional calls to std::is_constant_evaluated with unconditional
	calls to std::__is_constant_evaluated.
	(__copy_or_move_backward, __fill_n_fn): Likewise.
	* include/bits/ranges_cmp.h (ranges::less): Likewise.
	* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Likewise.
	* include/bits/stl_bvector.h: Call std::is_constant_evaluated
	directly in C++20-only code that is guarded by a suitable macro.
	* include/bits/stl_construct.h (_Construct, _Destroy, _Destroy_n):
	Replace is_constant_evaluated with __is_constant_evaluated.
	* include/bits/stl_function.h (greater, less, greater_equal)
	(less_equal): Replace __builtin_is_constant_evaluated and
	__builtin_constant_p with __is_constant_evaluated.
	* include/bits/stl_vector.h: Call std::is_constant_evaluated()
	in C++20-only code.
	* include/debug/helper_functions.h (__check_singular): Use
	__is_constant_evaluated instead of built-in, or remove check
	entirely.
	* include/std/array (operator<=>): Use __is_constant_evaluated
	unconditionally.
	* include/std/bit (__bit_ceil): Likewise.
	* include/std/type_traits (is_constant_evaluated): Define using
	'if consteval' if possible.
	* include/std/version: Use new macro.
	* libsupc++/compare: Use __is_constant_evaluated instead of
	__builtin_is_constant_evaluated.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error lines.
2021-12-01 15:00:33 +00:00
Jonathan Wakely 2b83bc6097 libstdc++: Optimize ref-count updates in COW std::string
Most ref-count updates in the COW string are done via the functions in
<ext/atomicity.h>, which will use non-atomic ops when the program is
known to be single-threaded. The _M_is_leaked() and _M_is_shared()
functions use __atomic_load_n directly, because <ext/atomicity.h>
doesn't provide a load operation. Those functions can check the
__is_single_threaded() predicate to avoid using __atomic_load_n when not
needed.

The move constructor for the fully-dynamic-string increments the
ref-count by either 2 or 1, for leaked or non-leaked strings
respectively. That can be changed to use a non-atomic store of 1 for all
non-shared strings. It can be non-atomic because even if the program is
multi-threaded, conflicting access to the rvalue object while it's being
moved from would be data race anyway. It can store 1 directly for all
non-shared strings because it doesn't matter whether the initial
refcount was -1 or 0, it should be 1 after the move constructor creates
a second owner.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string::_M_is_leaked): Use
	non-atomic load when __is_single_threaded() is true.
	(basic_string::_M_is_shared): Likewise.
	(basic_string::(basic_string&&)) [_GLIBCXX_FULLY_DYNAMIC_STRING]:
	Use non-atomic store when rvalue is not shared.
2021-12-01 15:00:33 +00:00
Jonathan Wakely e9089e4fa9 libstdc++: Avoid unwanted allocations in filesystem::path
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-12-01 15:00:32 +00:00
GCC Administrator c177e80609 Daily bump. 2021-12-01 00:17:04 +00:00
Jonathan Wakely be30fc4ce0 libstdc++: Fix tests that fail with fully-dynamic-string
Fix some tests that assume that a moved-from string is empty, or that
default constructing a string doesn't allocate.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/cons/char/moveable.cc: Allow
	moved-from string to be non-empty.
	* testsuite/21_strings/basic_string/cons/char/moveable2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/moveable2_c++17.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/moveable2_c++17.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/assign/char/87749.cc:
	Construct empty string before setting oom flag.
	* testsuite/21_strings/basic_string/modifiers/assign/wchar_t/87749.cc:
	Likewise.
2021-11-30 23:10:04 +00:00
Jonathan Wakely 675afa2124 libstdc++: Fix fully-dynamic-string build
My last change to the fully-dynamic-string actually broke it. This fixes
the move constructor so it builds, and simplifies it slightly so that
more code is common between the fully-dynamic enabled/disabled cases.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h (basic_string(basic_string&&)): Fix
	mem-initializer for _GLIBCXX_FULLY_DYNAMIC_STRING==0 case.
	* testsuite/21_strings/basic_string/cons/char/noexcept_move_construct.cc:
	Remove outdated comment.
	* testsuite/21_strings/basic_string/cons/wchar_t/noexcept_move_construct.cc:
	Likewise.
2021-11-30 23:10:03 +00:00
Jonathan Wakely 56b07badf0 libstdc++: Ensure C++20 std::stringstream definitions use correct ABI
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-30 23:10:03 +00:00
Jonathan Wakely 91c2600403 libstdc++: Skip tag dispatching for _S_relocate in C++17
In C++17 mode all callers of _S_relocate have already done:

  if constexpr (_S_use_relocate())

so we don't need to repeat that check and use tag dispatching to avoid
ill-formed instantiations.

libstdc++-v3/ChangeLog:

	* include/bits/stl_vector.h (vector::_S_do_relocate): Remove
	C++20 constexpr specifier.
	(vector::_S_relocate) [__cpp_if_constexpr]: Call __relocate_a
	directly without tag dispatching.
2021-11-30 20:10:19 +00:00
Jonathan Wakely cca6090b13 libstdc++: Make Asan detection work for Clang [PR103453]
Clang doesn't define __SANITIZE_ADDRESS__ so use its __has_feature check
to detect Asan instead.

libstdc++-v3/ChangeLog:

	PR libstdc++/103453
	* config/allocator/malloc_allocator_base.h
	(_GLIBCXX_SANITIZE_STD_ALLOCATOR): Define for Clang.
	* config/allocator/new_allocator_base.h
	(_GLIBCXX_SANITIZE_STD_ALLOCATOR): Likewise.
2021-11-30 20:10:19 +00:00
Jonathan Wakely 67013a2f71 libstdc++: Use gender-agnostic pronoun in docs
libstdc++-v3/ChangeLog:

	* doc/xml/manual/debug_mode.xml: Replace "his or her" with "they".
	* doc/html/manual/debug_mode_design.html: Regenerate.
2021-11-30 13:08:50 +00:00
Jakub Jelinek 92084a6dcd libstdc++: Add [[nodiscard]] to std::byteswap
This patch adds [[nodiscard]] to std::byteswap, because the function
template doesn't do anything useful if the result isn't used.

2021-11-30  Jakub Jelinek  <jakub@redhat.com>

	* include/std/bit (byteswap): Add [[nodiscard]].
2021-11-30 13:30:27 +01:00
GCC Administrator 2f0dd172bc Daily bump. 2021-11-29 00:16:16 +00:00
Jakub Jelinek 7393fa8b1d libstdc++: Implement std::byteswap for C++23
This patch attempts to implement P1272R4 (except for the std::bit_cast
changes in there which seem quite unrelated to this and will need to be
fixed on the compiler side).
While at least for GCC __builtin_bswap{16,32,64,128} should work fine
in constant expressions, I wonder about other compilers, so I'm using
a fallback implementation for constexpr evaluation always.
If you think that is unnecessary, I can drop the
__cpp_if_consteval >= 202106L &&
if !consteval
  {
and
  }
and reformat.
The fallback implementation is an attempt to make it work even for integral
types that don't have number of bytes divisible by 2 or when __CHAR_BIT__
is e.g. 16.

2021-11-28  Jakub Jelinek  <jakub@redhat.com>

	* include/std/bit (__cpp_lib_byteswap, byteswap): Define.
	* include/std/version (__cpp_lib_byteswap): Define.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: New test.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: New test.
2021-11-28 16:33:33 +01:00
GCC Administrator f4ed2e3ae7 Daily bump. 2021-11-27 00:16:19 +00:00
Jonathan Wakely 52b769437a libstdc++: Fix test that fails in C++20 mode
This test was written to verify that the LWG 3265 changes work. But
those changes were superseded by LWG 3435, and the test is now incorrect
according to the current draft. The assignment operator is now
constrained to also require convertibility, which makes the test fail.

Change the Iter type to be convertible from int*, but make it throw an
exception if that conversion is used. Change the test from compile-only
to run, so we verify that the exception isn't thrown.

libstdc++-v3/ChangeLog:

	* testsuite/24_iterators/move_iterator/dr3265.cc: Fix test to
	account for LWG 3435 resolution.
2021-11-26 22:56:51 +00:00
Jonathan Wakely 33adfd0d42 libstdc++: Fix trivial relocation for constexpr std::vector
When implementing constexpr std::vector I added a check for constant
evaluation in vector::_S_use_relocate(), so that we would not try to relocate
trivial objects by using memmove. But I put it in the constexpr function
that decides whether to relocate or not, and calls to that function are
always constant evaluated. This had the effect of disabling relocation
entirely, even in non-constexpr vectors.

This removes the check in _S_use_relocate() and modifies the actual
relocation algorithm, __relocate_a_1, to use the non-trivial
implementation instead of memmove when called during constant
evaluation.

libstdc++-v3/ChangeLog:

	* include/bits/stl_uninitialized.h (__relocate_a_1): Do not use
	memmove during constant evaluation.
	* include/bits/stl_vector.h (vector::_S_use_relocate()): Do not
	check is_constant_evaluated in always-constexpr function.
2021-11-26 22:28:48 +00:00
Jonathan Wakely 76c6be48b7 libstdc++: Remove workaround for FE bug in std::tuple [PR96592]
The FE bug was fixed, so we don't need this workaround now.

libstdc++-v3/ChangeLog:

	PR libstdc++/96592
	* include/std/tuple (tuple::is_constructible): Remove.
2021-11-26 22:26:08 +00:00
Jonathan Wakely 665f726b8a libstdc++: Ensure dg-add-options comes after dg-options
This is what the docs say is required.

libstdc++-v3/ChangeLog:

	* testsuite/29_atomics/atomic_float/1.cc: Reorder directives.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 0a12bd92d1 libstdc++: Fix dg-do directive for tests supposed to be run
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/unordered_map/modifiers/move_assign.cc:
	Change dg-do compile to run.
	* testsuite/27_io/basic_istream/extractors_character/wchar_t/lwg2499.cc:
	Likewise.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 1ecc9ba578 libstdc++: Remove redundant xfail selectors in dg-do compile tests
An 'xfail' selector means the test is expected to fail at runtime, so is
ignored for a compile-only test. The way to mark a compile-only test as
failing is with dg-error (which these already do).

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
	Remove xfail selector.
	* testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc:
	Likewise.
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc:
	Likewise.
	* testsuite/23_containers/span/101411.cc: Likewise.
	* testsuite/25_algorithms/copy/debug/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/copy_backward/debug/constexpr_neg.cc:
	Likewise.
	* testsuite/25_algorithms/equal/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/equal/debug/constexpr_neg.cc: Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_partitioned_pred_neg.cc:
	Likewise.
	* testsuite/25_algorithms/lower_bound/debug/constexpr_valid_range_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_partitioned_pred_neg.cc:
	Likewise.
	* testsuite/25_algorithms/upper_bound/debug/constexpr_valid_range_neg.cc:
	Likewise.
2021-11-26 15:11:58 +00:00
Jonathan Wakely 0178b73a02 libstdc++: Move std::to_address tests to more appropriate place
Some of the checks in 20_util/pointer_traits/lwg3545.cc really belong in
20_util/to_address/lwg3545 instead.

This also fixes the ordering of the dg-options and dg-do directives.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/pointer_traits/lwg3545.cc: Move to_address
	tests to ...
	* testsuite/20_util/to_address/lwg3545.cc: ... here. Add -std
	option before checking effective target.
2021-11-26 12:38:35 +00:00
GCC Administrator 091ccc066d Daily bump. 2021-11-26 00:16:26 +00:00
Jonathan Wakely 9664c46545 libstdc++: Remove dg-error that no longer happens
There was a c++11_only dg-error in this testcase, for a "body of
constexpr function is not a return statement" diagnostic that was bogus,
but happened because the return statement was ill-formed. A change to
G++ earlier this month means that diagnostic is no longer emitted, so
remove the dg-error.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/tuple/comparison_operators/overloaded2.cc:
	Remove dg-error for C++11_only error.
2021-11-25 23:12:15 +00:00
Jonathan Wakely b8018e5c5e libstdc++: Make std::pointer_traits SFINAE-friendly [PR96416]
This implements the resolution I'm proposing for LWG 3545, to avoid hard
errors when using std::to_address for types that make pointer_traits
ill-formed.

Consistent with std::iterator_traits, instantiating std::pointer_traits
for a non-pointer type will be well-formed, but give an empty type with
no member types. This avoids the problematic cases for std::to_address.
Additionally, the pointer_to member is now only declared when the
element type is not cv void (and for C++20, when the function body would
be well-formed). The rebind member was already SFINAE-friendly in our
implementation.

libstdc++-v3/ChangeLog:

	PR libstdc++/96416
	* include/bits/ptr_traits.h (pointer_traits): Reimplement to be
	SFINAE-friendly (LWG 3545).
	* testsuite/20_util/pointer_traits/lwg3545.cc: New test.
	* testsuite/20_util/to_address/1_neg.cc: Adjust dg-error line.
	* testsuite/20_util/to_address/lwg3545.cc: New test.
2021-11-25 23:12:14 +00:00
Jonathan Wakely 82c3657dd7 libstdc++: Do not use memset in constexpr calls to ranges::fill_n [PR101608]
libstdc++-v3/ChangeLog:

	PR libstdc++/101608
	* include/bits/ranges_algobase.h (__fill_n_fn): Check for
	constant evaluation before using memset.
	* testsuite/25_algorithms/fill_n/constrained.cc: Check
	byte-sized values as well.
2021-11-25 20:03:13 +00:00
GCC Administrator d9ca4b45bd Daily bump. 2021-11-25 00:16:29 +00:00
Jonathan Wakely 3b2337831a libstdc++: Add xfail to some printer tests for debug mode
The type printers are not substituting std::string for
std::basic_string<char> in debug mode, mark some tests as xfail.

libstdc++-v3/ChangeLog:

	* testsuite/libstdc++-prettyprinters/80276.cc: Add xfail for
	debug mode.
	* testsuite/libstdc++-prettyprinters/libfundts.cc: Likewise.
2021-11-24 13:20:26 +00:00
Jonathan Wakely a04b73e15b libstdc++: Replace hyphens in effective target keywords
An effective target like foo-bar-baz will match a target selector of
*-*-* and cause problems in the testsuite. Several libstdc++ et keywords
are of the form foo-bar, which could still be a problem for *-*
selectors.

Replace hyphens with underscores in the et keywords "debug-mode",
"cxx11-abi", etc.

libstdc++-v3/ChangeLog:

	* testsuite/lib/libstdc++.exp: Rename effective target keywords
	to avoid dashes in the name.
	* testsuite/*: Update effective targe keywords.
2021-11-24 13:20:26 +00:00
GCC Administrator e1d4359264 Daily bump. 2021-11-24 00:16:29 +00:00
Jonathan Wakely c59ec55c34 libstdc++: Add another testcase for std::unique_ptr printer [PR103086]
libstdc++-v3/ChangeLog:

	PR libstdc++/103086
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Check unique_ptr
	with non-empty pointer and non-empty deleter.
2021-11-23 21:39:46 +00:00
Jonathan Wakely 39de0e5411 libstdc++: Add effective-target for std::allocator implementation
This allows tests to be skipped if the std::allocator implementation is
not __gnu_cxx::new_allocator.

The 20_util/allocator/overaligned.cc test requires either C++17 or
new_allocator, otherwise we can't guarantee to return overaligned
memory.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/50594.cc: Check effective target.
	* testsuite/20_util/allocator/1.cc: Likewise.
	* testsuite/20_util/allocator/overaligned.cc: Likewise.
	* testsuite/23_containers/unordered_map/96088.cc: Likewise.
	* testsuite/23_containers/unordered_multimap/96088.cc: Likewise.
	* testsuite/23_containers/unordered_multiset/96088.cc: Likewise.
	* testsuite/23_containers/unordered_set/96088.cc: Likewise.
	* testsuite/ext/throw_allocator/check_delete.cc: Likewise.
	* testsuite/ext/throw_allocator/check_new.cc: Likewise.
	* testsuite/lib/libstdc++.exp (check_effective_target_std_allocator_new):
	Define new proc.
2021-11-23 21:23:24 +00:00
Jonathan Wakely 5459fa132a libstdc++: Fix circular dependency for bitmap_allocator [PR103381]
<ext/bitmap_allocator.h> includes <function>, and since C++17 that
includes <unordered_map>. If std::allocator is defined in terms of
__gnu_cxx::bitmap_allocator then you get a circular reference and
bootstrap fails when compiling src/c++17/*.cc.

libstdc++-v3/ChangeLog:

	PR libstdc++/103381
	* include/ext/bitmap_allocator.h: Include <bits/stl_function.h>
	instead of <functional>.
2021-11-23 12:30:57 +00:00
GCC Administrator 06be28f64a Daily bump. 2021-11-23 00:16:27 +00:00
Jonathan Wakely d7376862b6 libstdc++: Fix condition for definition of _GLIBCXX14_DEPRECATED
The check for C++14 was using the wrong date.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX14_DEPRECATED): Fix condition
	checking for C++14.
2021-11-22 14:57:17 +00:00
GCC Administrator f658f1d7a2 Daily bump. 2021-11-21 00:16:32 +00:00
François Dumont 5f40d34b6d libstdc++: [_GLIBCXX_DEBUG] Reduce performance impact on std::erase_if
Bypass the _GLIBCXX_DEBUG additional checks in std::__detail::__erase_node_if used
by all implementations of std::erase_if for node based containers.

libstdc++-v3/ChangeLog:

	* include/bits/erase_if.h (__erase_nodes_if): Add _UnsafeContainer template
	parameter. Use it to get iterators to work with.
	* include/debug/macros.h (__glibcxx_check_erase2): New.
	* include/debug/map.h (map<>::erase(_Base_const_iterator)): New.
	(map<>::erase(const_iterator)): Use latter.
	* include/debug/multimap.h (multimap<>::erase(_Base_const_iterator)): New.
	(multimap<>::erase(const_iterator)): Use latter.
	* include/debug/multiset.h (multiset<>::erase(_Base_const_iterator)): New.
	(multiset<>::erase(const_iterator)): Use latter.
	* include/debug/set.h (set<>::erase(_Base_const_iterator)): New.
	(set<>::erase(const_iterator)): Use latter.
	* include/debug/unordered_map (unordered_map<>::erase(_Base_const_iterator)): New.
	(unordered_multimap<>::erase(const_iterator)): New.
	* include/debug/unordered_set (unordered_set<>::erase(_Base_const_iterator)): New.
	(unordered_multiset<>::erase(const_iterator)): New.
	* include/experimental/map (erase_if): Adapt.
	* include/experimental/set (erase_if): Adapt.
	* include/experimental/unordered_map (erase_if): Adapt.
	* include/experimental/unordered_set (erase_if): Adapt.
	* include/std/map (erase_if): Adapt.
	* include/std/set (erase_if): Adapt.
	* include/std/unordered_map (erase_if): Adapt.
	* include/std/unordered_set (erase_if): Adapt.
2021-11-20 16:11:22 +01:00
GCC Administrator 9c0773984c Daily bump. 2021-11-20 00:16:35 +00:00
Jonathan Wakely be08d57317 libstdc++: Improve tests for stringstream constructors in C++20
This ensures all constructors are checked.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_istringstream/cons/char/1.cc: Check all
	constructors.
	* testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc:
	Likewise.
2021-11-19 20:23:50 +00:00
Jonathan Wakely 5faf1c8c7a libstdc++: Use __is_single_threaded in locale initialization
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-19 20:22:52 +00:00
Jonathan Wakely 1f8d01eb14 libstdc++: One more change for Clang to support constexpr std::string [PR103295]
All writes into the allocated buffer need to be via traits_type::assign
to begin lifetimes.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.tcc (_M_construct): Use the
	traits assign member to write into allcoated memory.
2021-11-19 20:17:52 +00:00
Iain Sandoe c7b782d847 libstdc++, testsuite: Add a prune expression for external tool bug.
Depending on the permutation of CPU, OS version and shared/non-
shared library inclusion, we get can get warnings from the external
tools (ld64, dsymutil) which are not actually libstdc++ issues but
relate to the external tools themselves.  This is already pruned
in the main testsuite, this adds it to the library.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libstdc++-v3/ChangeLog:

	* testsuite/lib/prune.exp: Prune dsymutil (ld64) warning.
2021-11-19 19:52:03 +00:00
Jonathan Wakely b8f2efaed0 libstdc++: Suppress -Wstringop warnings [PR103332]
libstdc++-v3/ChangeLog:

	PR libstdc++/103332
	PR libstdc++/102958
	* testsuite/21_strings/basic_string/capacity/char/1.cc: Add
	-Wno-stringop-overflow.
	* testsuite/21_strings/basic_string/operators/char/1.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/factory/u8path-char8_t.cc:
	Add -Wno-stringop-overread.
2021-11-19 18:15:52 +00:00
Jonathan Wakely 2d76292bd6 libstdc++: Begin lifetime of chars in constexpr std::string [PR103295]
Clang gives errors for constexpr std::string because the memory returned
by std::allocator<T>::allocate does not contain any objects yet, and
attempting to set them using char_traits::assign or char_traits::copy
fails with:

assignment to object outside its lifetime is not allowed in a constant expression
              *__result = *__first;
                        ^
This adds code to std::char_traits to use std::construct_at to begin
lifetimes when called during constant evaluation. To support
specializations of std::basic_string that don't use std::char_traits
there is now another layer of wrapper around the allocator_traits, so
that the lifetime of characters is begun as soon as the memory is
allocated. By doing it in the char traits and allocator traits, the rest
of basic_string can ignore the problem.

While modifying char_traits::copy and char_traits::assign to begin
lifetimes for the constexpr cases, I also replaced their uses of
std::copy and std::fill_n respectively. That means we don't need
<bits/stl_algobase.h> for char_traits.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.h (_Alloc_traits): Replace typedef
	with struct for C++20 mode.
	* include/bits/basic_string.tcc (_M_replace): Use _Alloc_traits
	for allocation.
	* include/bits/char_traits.h (__gnu_cxx::char_traits::assign):
	Use std::_Construct during constant evaluation.
	(__gnu_cxx::char_traits::assign(CharT*, const CharT*, size_t)):
	Likewise. Replace std::fill_n with memset or manual loop.
	(__gnu_cxx::char_traits::copy): Likewise, replacing std::copy
	with memcpy.
	* include/ext/vstring.h: Include <bits/stl_algobase.h> for
	std::min.
	* include/std/string_view: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
	Add constexpr test.
2021-11-19 18:15:15 +00:00
Tamar Christina 0e510ab534 libstdc++: Fix ctype changed after newlib update.
Newlib changed ctype.h recently[1] by moving the short labels from ctype.h intro
the private namespace in ctype_.h.  This broke embedded builds due to them no
longer being found.  Instead they now expose the long names to match glibc.

This patch now uses the short or long names depending on is the short ones are
defined or not.

[1] 3ba1bd0d9d

libstdc++-v3/ChangeLog:

	PR libstdc++/103305
	* config/os/newlib/ctype_base.h (upper, lower, alpha, digit, xdigit,
	space, print, graph, cntrl, punct, alnum, blank): Use short or long
	names depending on if short ones are defined.
2021-11-19 08:48:11 +00:00
GCC Administrator 483092d3d9 Daily bump. 2021-11-19 00:16:34 +00:00
Jonathan Wakely ca243ada71 libstdc++: Fix std::char_traits<C>::move for constexpr
The constexpr branch in __gnu_cxx::char_traits::move compares the string
arguments to see if they overlap, but relational comparisons between
unrelated pointers are not core constant expressions.

I want to replace the comparisons with a loop using pointer equality to
determine whether the end of the source string is in the destination
string. However, that doesn't work with GCC, due to PR c++/89074 so
allocate a temporary buffer instead and copy out into that first, so
that overlapping source and destination don't matter. The allocation
isn't supported by the current Intel icc so use the loop as a fallback.

libstdc++-v3/ChangeLog:

	* include/bits/char_traits.h (__gnu_cxx::char_traits::move):
	Do not compare unrelated pointers during constant evaluation.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
	Improve tests for char_traits::move.
2021-11-18 16:14:15 +00:00
Jonathan Wakely 9646a3229b libstdc++: Replace AC_CACHE_VAL with AC_CACHE_CHECK
This replaces most uses of AC_CACHE_VAL with AC_CACHE_CHECK, which means
we don't need separate AC_MSG_CHECKING and AC_MSG_RESULT macros.

There are a few trivial bugs fixed as a side effect, where an
AC_MSG_RESULT was printed out even if the actual checks hadn't been
done. That didn't affect the results, only the content of config.log.

libstdc++-v3/ChangeLog:

	* acinclude.m4: Replace AC_CACHE_VAL with AC_CACHE_CHECK.
	* configure: Regenerate.
2021-11-18 13:56:33 +00:00
GCC Administrator 280d2838c1 Daily bump. 2021-11-18 00:16:34 +00:00
Jonathan Wakely 0e4a8656e8 libstdc++: Fix author name in ChangeLog
The constexpr std::string commit was my own work, but the commit still
had the author name from an earlier cherry-pick that eventually got
entirely reverted. This fixes the name in the ChangeLog file.
2021-11-17 22:41:49 +00:00
Jonathan Wakely 5ea8803e65 libstdc++: Use std::construct_at in net::ip::address
Using placement-new isn't valid in constant expressions, so this
replaces it with std::construct_at (via the std::_Construct function
that is usable before C++20).

libstdc++-v3/ChangeLog:

	* include/experimental/internet (address): Use std::_Construct
	to initialize union members.
2021-11-17 17:28:52 +00:00
Jonathan Wakely 5a9572e486 libstdc++: Simplify std::string constructors
Several std::basic_string constructors dispatch to one of the
two-argument overloads of _M_construct, which then dispatches again to
_M_construct_aux to detect whether the arguments are iterators or not.
That then dispatches to one of _M_construct(size_type, char_type) or
_M_construct(Iter, Iter, iterator_traits<Iter>::iterator_category{}).

For most of those constructors this is a waste of time, because we know
the arguments are already iterators. For basic_string(const CharT*) and
basic_string(initializer_list<C>) we know that we call _M_construct with
two pointers, and for basic_string(const basic_string&) we call it with
two const_iterators.  Those constructors can call the three-argument
overload of _M_construct with the iterator category tag right away,
without the intermediate dispatching.

The case where this doesn't apply is basic_string(InputIter, InputIter),
but for C++11 and later this is constrained so we know it's an iterator
here as well. We can restrict the dispatching in this constructor to
only be done for C++98 and to call _M_construct_aux directly, which
allows us to remove the two-argument _M_construct(InputIter, InputIter)
overload entirely.

N.B. When calling the three-arg _M_construct with pointers or string
iterators, we pass forward_iterator_tag not random_access_iterator_tag.
This is because it makes no difference which overload gets called, and
simplifies overload resolution to not have to do a base-to-derived
check. If we ever add a new overload of M_construct for random access
iterators we would have to revisit this, but that seems unlikely.

This patch also moves the __is_null_pointer checks from the three-arg
_M_construct into the constructors where a null pointer argument is
actually possible. This avoids redundant checks where we know we have a
non-null pointer, or don't have a pointer at all.

Finally, this patch replaces some try-blocks with an RAII type, so that
memory is deallocated during unwinding. This avoids the overhead of
catching and rethrowing an exception.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (_M_construct_aux): Only define
	for C++98. Remove constexpr.
	(_M_construct_aux_2): Likewise.
	(_M_construct(InputIter, InputIter)): Remove.
	(basic_string(const basic_string&)): Call _M_construct with
	iterator category argument.
	(basic_string(const basic_string&, size_type, const Alloc&)):
	Likewise.
	(basic_string(const basic_string&, size_type, size_type)):
	Likewise.
	(basic_string(const charT*, size_type, const Alloc&)): Likewise.
	Check for null pointer.
	(basic_string(const charT*, const Alloc&)): Likewise.
	(basic_string(initializer_list<charT>, const Alloc&)): Call
	_M_construct with iterator category argument.
	(basic_string(const basic_string&, const Alloc&)): Likewise.
	(basic_string(basic_string&&, const Alloc&)): Likewise.
	(basic_string(_InputIter, _InputIter, const Alloc&)): Likewise
	for C++11 and later, call _M_construct_aux for C++98.
	* include/bits/basic_string.tcc
	(_M_construct(I, I, input_iterator_tag)): Replace try-block with
	RAII type.
	(_M_construct(I, I, forward_iterator_tag)): Likewise. Remove
	__is_null_pointer check.
2021-11-17 17:28:44 +00:00
Jonathan Wakely 6afa1083c6 libstdc++: Set active member of union in std::string [PR103295]
Clang diagnoses that the new constexpr std::string constructors are not
usable in constant expressions, because they start to write to members
of the union without setting an active member.

This adds a new helper function which returns the address of the local
buffer after making it the active member.

This doesn't fix all problems with Clang, because it still refuses to
write to memory returned by the allocator.

libstdc++-v3/ChangeLog:

	PR libstdc++/103295
	* include/bits/basic_string.h (_M_use_local_data()): New
	member function to make local buffer the active member.
	(assign(const basic_string&)): Use it.
	* include/bits/basic_string.tcc (_M_construct, reserve()):
	Likewise.
2021-11-17 17:21:25 +00:00
Jonathan Wakely 054bf99841 libstdc++: Fix std::type_info::before for ARM [PR103240]
The r179236 fix for std::type_info::operator== should also have been
applied to std::type_info::before. Otherwise two distinct types can
compare equivalent due to using a string comparison, when they should do
a pointer comparison.

libstdc++-v3/ChangeLog:

	PR libstdc++/103240
	* libsupc++/tinfo2.cc (type_info::before): Use unadjusted name
	to check for the '*' prefix.
	* testsuite/util/testsuite_shared.cc: Add type_info object for
	use in new test.
	* testsuite/18_support/type_info/103240.cc: New test.
2021-11-17 17:21:24 +00:00
GCC Administrator 6b1695f4a0 Daily bump. 2021-11-17 00:16:29 +00:00
Jonathan Wakely 73e4d9f175 libstdc++: Fix tests for constexpr std::string
Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (operator<=>): Use constexpr
	unconditionally.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc:
	Require cxx11-abit effective target.
	* testsuite/21_strings/headers/string/synopsis.cc: Add
	conditional constexpr to declarations, and adjust relational
	operators for C++20.
2021-11-16 22:48:15 +00:00
Patrick Palka 7461b58131 libstdc++: Merge latest Ryu sources
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-16 12:23:27 -05:00
Michael de Lang b96e2ff9d8 libstdc++: Implement constexpr std::basic_string for C++20
This is only supported for the cxx11 ABI, not for COW strings.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string, operator""s): Add
	constexpr for C++20.
	(basic_string::basic_string(basic_string&&)): Only copy
	initialized portion of the buffer.
	(basic_string::basic_string(basic_string&&, const Alloc&)):
	Likewise.
	* include/bits/basic_string.tcc (basic_string): Add constexpr
	for C++20.
	(basic_string::swap(basic_string&)): Only copy initialized
	portions of the buffers.
	(basic_string::_M_replace): Add constexpr implementation that
	doesn't depend on pointer comparisons.
	* include/bits/cow_string.h: Adjust comment.
	* include/ext/type_traits.h (__is_null_pointer): Add constexpr.
	* include/std/string (erase, erase_if): Add constexpr.
	* include/std/version (__cpp_lib_constexpr_string): Update
	value.
	* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/literals/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/constexpr.cc: New test.
	* testsuite/21_strings/basic_string/modifiers/swap/char/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/modifiers/swap/wchar_t/constexpr.cc:
	New test.
	* testsuite/21_strings/basic_string/version.cc: New test.
2021-11-16 16:43:20 +00:00
Jonathan Wakely 59434931fb libstdc++: Use hidden friends for vector<bool>::reference swap overloads
These swap overloads are non-standard, but are needed to make swap work
for vector<bool>::reference rvalues. They don't need to be called
explicitly, only via ADL, so hide them from normal lookup. This is what
I've proposed as the resolution to LWG 3638.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (swap(_Bit_reference, _Bit_reference))
	(swap(_Bit_reference, bool&), swap(bool&, _Bit_reference)):
	Define as hidden friends of _Bit_reference.
2021-11-16 16:42:59 +00:00
Jonathan Wakely 8d8e8f3ad5 libstdc++: Fix out-of-bound array accesses in testsuite
I fixed some undefined behaviour in string tests in r238609, but I only
fixed the narrow char versions. This applies the same fixes to the
wchar_t ones. These problems were found when testing a patch to make
std::basic_string usable in constexpr.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc:
	Fix reads past the end of strings.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
	Likewise.
	* testsuite/experimental/string_view/operations/compare/wchar_t/1.cc:
	Likewise.
2021-11-16 14:09:00 +00:00
Jonathan Wakely 9719769471 libstdc++: Fix typos in tests
libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/allocator/71964.cc: Fix
	typo.
	* testsuite/23_containers/set/allocator/71964.cc: Likewise.
2021-11-16 14:08:42 +00:00
GCC Administrator e2b57363fc Daily bump. 2021-11-16 00:16:31 +00:00
Jason Merrill 87c2080b05 c++: Add -fimplicit-constexpr
With each successive C++ standard the restrictions on the use of the
constexpr keyword for functions get weaker and weaker; it recently occurred
to me that it is heading toward the same fate as the C register keyword,
which was once useful for optimization but became obsolete.  Similarly, it
seems to me that we should be able to just treat inlines as constexpr
functions and not make people add the extra keyword everywhere.

There were a lot of testcase changes needed; many disabling errors about
non-constexpr functions that are now constexpr, and many disabling implicit
constexpr so that the tests can check the same thing as before, whether
that's mangling or whatever.

gcc/c-family/ChangeLog:

	* c.opt: Add -fimplicit-constexpr.
	* c-cppbuiltin.c: Define __cpp_implicit_constexpr.
	* c-opts.c (c_common_post_options): Disable below C++14.

gcc/cp/ChangeLog:

	* cp-tree.h (struct lang_decl_fn): Add implicit_constexpr.
	(decl_implicit_constexpr_p): New.
	* class.c (type_maybe_constexpr_destructor): Use
	TYPE_HAS_TRIVIAL_DESTRUCTOR and maybe_constexpr_fn.
	(finalize_literal_type_property): Simplify.
	* constexpr.c (is_valid_constexpr_fn): Check for dtor.
	(maybe_save_constexpr_fundef): Try to set DECL_DECLARED_CONSTEXPR_P
	on inlines.
	(cxx_eval_call_expression): Use maybe_constexpr_fn.
	(maybe_constexpr_fn): Handle flag_implicit_constexpr.
	(var_in_maybe_constexpr_fn): Use maybe_constexpr_fn.
	(potential_constant_expression_1): Likewise.
	(decl_implicit_constexpr_p): New.
	* decl.c (validate_constexpr_redeclaration): Allow change with
	-fimplicit-constexpr.
	(grok_special_member_properties): Use maybe_constexpr_fn.
	* error.c (dump_function_decl): Don't print 'constexpr'
	if it's implicit.
	* Make-lang.in (check-c++-all): Update.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/to_address/1_neg.cc: Adjust error.
	* testsuite/26_numerics/random/concept.cc: Adjust asserts.

gcc/testsuite/ChangeLog:

	* lib/g++-dg.exp: Handle "impcx".
	* lib/target-supports.exp
	(check_effective_target_implicit_constexpr): New.
	* g++.dg/abi/abi-tag16.C:
	* g++.dg/abi/abi-tag18a.C:
	* g++.dg/abi/guard4.C:
	* g++.dg/abi/lambda-defarg1.C:
	* g++.dg/abi/mangle26.C:
	* g++.dg/cpp0x/constexpr-diag3.C:
	* g++.dg/cpp0x/constexpr-ex1.C:
	* g++.dg/cpp0x/constexpr-ice5.C:
	* g++.dg/cpp0x/constexpr-incomplete2.C:
	* g++.dg/cpp0x/constexpr-memfn1.C:
	* g++.dg/cpp0x/constexpr-neg3.C:
	* g++.dg/cpp0x/constexpr-specialization.C:
	* g++.dg/cpp0x/inh-ctor19.C:
	* g++.dg/cpp0x/inh-ctor30.C:
	* g++.dg/cpp0x/lambda/lambda-mangle3.C:
	* g++.dg/cpp0x/lambda/lambda-mangle5.C:
	* g++.dg/cpp1y/auto-fn12.C:
	* g++.dg/cpp1y/constexpr-loop5.C:
	* g++.dg/cpp1z/constexpr-lambda7.C:
	* g++.dg/cpp2a/constexpr-dtor3.C:
	* g++.dg/cpp2a/constexpr-new13.C:
	* g++.dg/cpp2a/constinit11.C:
	* g++.dg/cpp2a/constinit12.C:
	* g++.dg/cpp2a/constinit14.C:
	* g++.dg/cpp2a/constinit15.C:
	* g++.dg/cpp2a/spaceship-constexpr1.C:
	* g++.dg/cpp2a/spaceship-eq3.C:
	* g++.dg/cpp2a/udlit-class-nttp-neg2.C:
	* g++.dg/debug/dwarf2/auto1.C:
	* g++.dg/debug/dwarf2/cdtor-1.C:
	* g++.dg/debug/dwarf2/lambda1.C:
	* g++.dg/debug/dwarf2/pr54508.C:
	* g++.dg/debug/dwarf2/pubnames-2.C:
	* g++.dg/debug/dwarf2/pubnames-3.C:
	* g++.dg/ext/is_literal_type3.C:
	* g++.dg/ext/visibility/template7.C:
	* g++.dg/gcov/gcov-12.C:
	* g++.dg/gcov/gcov-2.C:
	* g++.dg/ipa/devirt-35.C:
	* g++.dg/ipa/devirt-36.C:
	* g++.dg/ipa/devirt-37.C:
	* g++.dg/ipa/devirt-44.C:
	* g++.dg/ipa/imm-devirt-1.C:
	* g++.dg/lookup/builtin5.C:
	* g++.dg/lto/inline-crossmodule-1_0.C:
	* g++.dg/modules/enum-1_a.C:
	* g++.dg/modules/fn-inline-1_c.C:
	* g++.dg/modules/pmf-1_b.C:
	* g++.dg/modules/used-1_c.C:
	* g++.dg/tls/thread_local11.C:
	* g++.dg/tls/thread_local11a.C:
	* g++.dg/tm/pr46653.C:
	* g++.dg/ubsan/pr70035.C:
	* g++.old-deja/g++.other/delete6.C:
	* g++.dg/modules/pmf-1_a.H:
	Adjust for implicit constexpr.
2021-11-15 18:50:07 -05:00
François Dumont d10b863fa3 libstdc++: Unordered containers merge re-use hash code
When merging 2 unordered containers with same hasher we can re-use the hash code from
the cache if any.

Also in the context of the merge operation on multi-container use previous insert iterator as a hint
for the next insert.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h:
	(_Hash_code_base<>::_M_hash_code(const _Hash&, const _Hash_node_value<_Value, true>&)): New.
	(_Hash_code_base<>::_M_hash_code<_H2>(const _H2&, const _Hash_node_value<>&)): New.
	* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Use latter.
	(_Hashtable<>::_M_merge_multi): Likewise.
	* testsuite/23_containers/unordered_multiset/modifiers/merge.cc (test05): New test.
	* testsuite/23_containers/unordered_set/modifiers/merge.cc (test04): New test.
2021-11-15 18:52:07 +01:00
Jason Merrill 37326651b4 c++: check constexpr constructor body
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-15 02:50:45 -05:00
GCC Administrator b85a03ae11 Daily bump. 2021-11-15 00:16:20 +00:00
François Dumont e9a53a4f76 libstdc++: [_GLIBCXX_DEBUG] Remove _Safe_container<>::_M_safe()
_GLIBCXX_DEBUG container code cleanup to get rid of _Safe_container<>::_M_safe() and just
use _Safe:: calls which use normal inheritance. Also remove several usages of _M_base()
which can be most of the time ommitted and sometimes replace with explicit _Base::
calls.

libstdc++-v3/ChangeLog:

	* include/debug/safe_container.h (_Safe_container<>::_M_safe): Remove.
	* include/debug/deque (deque::operator=(initializer_list<>)): Replace
	_M_base() call with _Base:: call.
	(deque::operator[](size_type)): Likewise.
	* include/debug/forward_list (forward_list(forward_list&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(forward_list::operator=(initializer_list<>)): Remove _M_base() calls.
	(forward_list::splice_after, forward_list::merge): Likewise.
	* include/debug/list (list(list&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(list::operator=(initializer_list<>)): Remove _M_base() calls.
	(list::splice, list::merge): Likewise.
	* include/debug/map.h (map(map&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(map::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/multimap.h (multimap(multimap&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(multimap::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/set.h (set(set&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(set::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/multiset.h (multiset(multiset&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(multiset::operator=(initializer_list<>)): Remove _M_base() calls.
	* include/debug/string (basic_string(basic_string&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(basic_string::operator=(initializer_list<>)): Remove _M_base() call.
	(basic_string::operator=(const _CharT*), basic_string::operator=(_CharT)): Likewise.
	(basic_string::operator[](size_type), basic_string::operator+=(const basic_string&)):
	Likewise.
	(basic_string::operator+=(const _Char*), basic_string::operator+=(_CharT)): Likewise.
	* include/debug/unordered_map (unordered_map(unordered_map&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_map::operator=(initializer_list<>), unordered_map::merge):
	Remove _M_base() calls.
	(unordered_multimap(unordered_multimap&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_multimap::operator=(initializer_list<>), unordered_multimap::merge):
	Remove _M_base() calls.
	* include/debug/unordered_set (unordered_set(unordered_set&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_set::operator=(initializer_list<>), unordered_set::merge):
	Remove _M_base() calls.
	(unordered_multiset(unordered_multiset&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(unordered_multiset::operator=(initializer_list<>), unordered_multiset::merge):
	Remove _M_base() calls.
	* include/debug/vector (vector(vector&&, const allocator_type&)):
	Remove _M_safe() and _M_base() calls.
	(vector::operator=(initializer_list<>)): Remove _M_base() calls.
	(vector::operator[](size_type)): Likewise.
2021-11-14 21:55:01 +01:00
GCC Administrator a8029add30 Daily bump. 2021-11-14 00:16:23 +00:00
Jonathan Wakely a30a2e43e4 libstdc++: Implement std::spanstream for C++23
This implements the <spanstream> header, as proposed for C++23 by P0448R4.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add spanstream header.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Add spanstream header.
	* include/std/version (__cpp_lib_spanstream): Define.
	* include/std/spanstream: New file.
	* testsuite/27_io/spanstream/1.cc: New test.
	* testsuite/27_io/spanstream/version.cc: New test.
2021-11-13 11:45:31 +00:00
Hans-Peter Nilsson 60f761c7e5 libstdc++: Use GCC_TRY_COMPILE_OR_LINK for getentropy, arc4random
Since r12-5056-g3439657b0286, there has been a regression in
test results; an additional 100 FAILs running the g++ and
libstdc++ testsuite on cris-elf, a newlib target.  The
failures are linker errors, not finding a definition for
getentropy.  It appears newlib has since 2017-12-03
declarations of getentropy and arc4random, and provides an
implementation of arc4random using getentropy, but provides no
definition of getentropy, not even a stub yielding ENOSYS.
This is similar to what it does for many other functions too.

While fixing newlib (like adding said stub) would likely help,
it still leaves older newlib releases hanging.  Thankfully,
the libstdc++ configury test can be improved to try linking
where possible; using the bespoke GCC_TRY_COMPILE_OR_LINK
instead of AC_TRY_COMPILE.  BTW, I see a lack of consistency;
some tests use AC_TRY_COMPILE and some GCC_TRY_COMPILE_OR_LINK
for no apparent reason, but this commit just amends
r12-5056-g3439657b0286.

libstdc++-v3:
	PR libstdc++/103166
	* acinclude.m4 (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM):
	Use GCC_TRY_COMPILE_OR_LINK instead of AC_TRY_COMPILE.
	* configure: Regenerate.
2021-11-13 01:45:06 +01:00
GCC Administrator af2852b9dc Daily bump. 2021-11-13 00:16:39 +00:00
Jonathan Wakely a54ce8865a libstdc++: Print assertion messages to stderr [PR59675]
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-12 12:23:10 +00:00
Jonathan Wakely 1ae8edf5f7 libstdc++: Implement constexpr std::vector for C++20
This implements P1004R2 ("Making std::vector constexpr") for C++20.

For now, debug mode vectors are not supported in constant expressions.
To make that work we might need to disable all attaching/detaching of
safe iterators. That can be fixed later.

Co-authored-by: Josh Marshall <joshua.r.marshall.1991@gmail.com>

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (_Destroy): Make constexpr for
	C++20 mode.
	* include/bits/allocator.h (__shrink_to_fit::_S_do_it):
	Likewise.
	* include/bits/stl_algobase.h (__fill_a1): Declare _Bit_iterator
	overload constexpr for C++20.
	* include/bits/stl_bvector.h (_Bit_type, _S_word_bit): Move out
	of inline namespace.
	(_Bit_reference, _Bit_iterator_base, _Bit_iterator)
	(_Bit_const_iterator, _Bvector_impl_data, _Bvector_base)
	(vector<bool, A>>): Add constexpr to every member function.
	(_Bvector_base::_M_allocate): Initialize storage during constant
	evaluation.
	(vector<bool, A>::_M_initialize_value): Use __fill_bvector_n
	instead of memset.
	(__fill_bvector_n): New helper function to replace memset during
	constant evaluation.
	* include/bits/stl_uninitialized.h (__uninitialized_copy<false>):
	Move logic to ...
	(__do_uninit_copy): New function.
	(__uninitialized_fill<false>): Move logic to ...
	(__do_uninit_fill): New function.
	(__uninitialized_fill_n<false>): Move logic to ...
	(__do_uninit_fill_n): New function.
	(__uninitialized_copy_a): Add constexpr. Use __do_uninit_copy.
	(__uninitialized_move_a, __uninitialized_move_if_noexcept_a):
	Add constexpr.
	(__uninitialized_fill_a): Add constexpr. Use __do_uninit_fill.
	(__uninitialized_fill_n_a): Add constexpr. Use
	__do_uninit_fill_n.
	(__uninitialized_default_n, __uninitialized_default_n_a)
	(__relocate_a_1, __relocate_a): Add constexpr.
	* include/bits/stl_vector.h (_Vector_impl_data, _Vector_impl)
	(_Vector_base, vector): Add constexpr to every member function.
	(_Vector_impl::_S_adjust): Disable ASan annotation during
	constant evaluation.
	(_Vector_base::_S_use_relocate): Disable bitwise-relocation
	during constant evaluation.
	(vector::_Temporary_value): Use a union for storage.
	* include/bits/vector.tcc (vector, vector<bool>): Add constexpr
	to every member function.
	* include/std/vector (erase_if, erase): Add constexpr.
	* testsuite/23_containers/headers/vector/synopsis.cc: Add
	constexpr for C++20 mode.
	* testsuite/23_containers/vector/bool/cmp_c++20.cc: Change to
	compile-only test using constant expressions.
	* testsuite/23_containers/vector/bool/capacity/29134.cc: Adjust
	namespace for _S_word_bit.
	* testsuite/23_containers/vector/bool/modifiers/insert/31370.cc:
	Likewise.
	* testsuite/23_containers/vector/cmp_c++20.cc: Likewise.
	* testsuite/23_containers/vector/cons/89164.cc: Adjust errors
	for C++20 and move C++17 test to ...
	* testsuite/23_containers/vector/cons/89164_c++17.cc: ... here.
	* testsuite/23_containers/vector/bool/capacity/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/cons/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/element_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/constexpr.cc: New test.
	* testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc: New test.
	* testsuite/23_containers/vector/capacity/constexpr.cc: New test.
	* testsuite/23_containers/vector/cons/constexpr.cc: New test.
	* testsuite/23_containers/vector/data_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/element_access/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/assign/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/constexpr.cc: New test.
	* testsuite/23_containers/vector/modifiers/swap/constexpr.cc: New test.
2021-11-12 00:42:39 +00:00
GCC Administrator b39265d4fe Daily bump. 2021-11-12 00:16:32 +00:00
Jonathan Wakely 4a407d358e libstdc++: Fix debug containers for C++98 mode
Since r12-5072 made _Safe_container::operator=(const _Safe_container&)
protected, the debug containers no longer compile in C++98 mode. They
have user-provided copy assignment operators in C++98 mode, and they
assign each base class in turn. The 'this->_M_safe() = __x' expressions
fail, because calling a protected member function is only allowed via
'this'. They could be fixed by using this->_Safe::operator=(__x) but a
simpler solution is to just remove the user-provided assignment
operators and let the compiler define them (as we do for C++11 and
later, by defining them as defaulted).

The only change needed for that to work is to define the _Safe_vector
copy assignment operator in C++98 mode, so that the implicit
__gnu_debug::vector::operator= definition will call it, instead of
needing to call _M_update_guaranteed_capacity() manually.

libstdc++-v3/ChangeLog:

	* include/debug/deque (deque::operator=(const deque&)): Remove
	definition.
	* include/debug/list (list::operator=(const list&)): Likewise.
	* include/debug/map.h (map::operator=(const map&)): Likewise.
	* include/debug/multimap.h (multimap::operator=(const multimap&)):
	Likewise.
	* include/debug/multiset.h (multiset::operator=(const multiset&)):
	Likewise.
	* include/debug/set.h (set::operator=(const set&)): Likewise.
	* include/debug/string (basic_string::operator=(const basic_string&)):
	Likewise.
	* include/debug/vector (vector::operator=(const vector&)):
	Likewise.
	(_Safe_vector::operator=(const _Safe_vector&)): Define for
	C++98 as well.
2021-11-11 21:55:11 +00:00
Jonathan Wakely 083fd73202 libstdc++: Make pmr::memory_resource::allocate implicitly create objects
Calling the placement version of ::operator new "implicitly creates
objects in the returned region of storage" as per [intro.object]. This
allows the returned memory to be used as storage for implicit-lifetime
types (including arrays) without additional action by the caller. This
is required by the proposed resolution of LWG 3147.

libstdc++-v3/ChangeLog:

	* include/std/memory_resource (memory_resource::allocate):
	Implicitly create objects in the returned storage.
2021-11-11 18:16:17 +00:00
Jonathan Wakely ef0e100f58 libstdc++: Remove public std::vector<bool>::data() member
This function only exists to avoid an error in the debug mode vector, so
doesn't need to be public.

libstdc++-v3/ChangeLog:

	* include/bits/stl_bvector.h (vector<bool>::data()): Give
	protected access, and delete for C++11 and later.
2021-11-11 18:16:17 +00:00
GCC Administrator 8d36a0d288 Daily bump. 2021-11-11 00:16:28 +00:00
Jonathan Wakely 77963796ae libstdc++: Fix test for libstdc++ not including <unistd.h> [PR100117]
The <cxxx> headers for the C library are not under our control, so we
can't prevent them from including <unistd.h>. Change the PR 49745 test
to only include the C++ library headers, not the <cxxx> ones.

To ensure <bits/stdc++.h> isn't included automatically we need to use
no_pch to disable PCH.

libstdc++-v3/ChangeLog:

	PR libstdc++/100117
	* testsuite/17_intro/headers/c++1998/49745.cc: Explicitly list
	all C++ headers instead of including <bits/stdc++.h>
2021-11-10 12:03:29 +00:00
Jonathan Wakely 80fe172ba9 libstdc++: Disable gthreads weak symbols for glibc 2.34 [PR103133]
Since Glibc 2.34 all pthreads symbols are defined directly in libc not
libpthread, and since Glibc 2.32 we have used __libc_single_threaded to
avoid unnecessary locking in single-threaded programs. This means there
is no reason to avoid linking to libpthread now, and so no reason to use
weak symbols defined in gthr-posix.h for all the pthread_xxx functions.

libstdc++-v3/ChangeLog:

	PR libstdc++/100748
	PR libstdc++/103133
	* config/os/gnu-linux/os_defines.h (_GLIBCXX_GTHREAD_USE_WEAK):
	Define for glibc 2.34 and later.
2021-11-10 12:01:27 +00:00
GCC Administrator c9b1334eec Daily bump. 2021-11-10 00:16:28 +00:00
François Dumont f4b4ce152a libstdc++: [_GLIBCXX_DEBUG] Implement unordered container merge
The _GLIBCXX_DEBUG unordered containers need a dedicated merge implementation
so that any existing iterator on the transfered nodes is properly invalidated.

Add typedef/using declarations for everything used as-is from normal implementation.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (__distance_fw): Replace class keyword with
	typename.
	* include/bits/hashtable.h (_Hashtable<>::_M_merge_unique): Remove noexcept
	qualification. Use const_iterator for node extraction/reinsert.
	(_Hashtable<>::_M_merge_multi): Likewise. Compute new hash code before extract.
	* include/debug/safe_container.h (_Safe_container<>): Make all methods
	protected.
	* include/debug/safe_unordered_container.h
	(_Safe_unordered_container<>::_UContInvalidatePred<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_UMContInvalidatePred<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_UContMergeGuard<_Source, _InvalidatePred>): New.
	(_Safe_unordered_container<>::_S_uc_guard<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_S_umc_guard<_ExtractKey, _Source>): New.
	(_Safe_unordered_container<>::_M_invalide_all): Make public.
	(_Safe_unordered_container<>::_M_invalide_if): Likewise.
	(_Safe_unordered_container<>::_M_invalide_local_if): Likewise.
	* include/debug/unordered_map
	(unordered_map<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_map<>::reference, const_reference, difference_type): New typedef.
	(unordered_map<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_map<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_map<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_map<>::operator[], at, rehash, reserve): Add usings.
	(unordered_map<>::merge): New.
	(unordered_multimap<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_multimap<>::reference, const_reference, difference_type): New typedef.
	(unordered_multimap<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_multimap<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_multimap<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_multimap<>::rehash, reserve): Add usings.
	(unordered_multimap<>::merge): New.
	* include/debug/unordered_set
	(unordered_set<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_set<>::reference, const_reference, difference_type): New typedef.
	(unordered_set<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_set<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_set<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_set<>::rehash, reserve): Add usings.
	(unordered_set<>::merge): New.
	(unordered_multiset<>::mapped_type, pointer, const_pointer): New typedef.
	(unordered_multiset<>::reference, const_reference, difference_type): New typedef.
	(unordered_multiset<>::get_allocator, empty, size, max_size): Add usings.
	(unordered_multiset<>::bucket_count, max_bucket_count, bucket): Add usings.
	(unordered_multiset<>::hash_function, key_equal, count, contains): Add usings.
	(unordered_multiset<>::rehash, reserve): Add usings.
	(unordered_multiset<>::merge): New.
	* testsuite/23_containers/unordered_map/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_map/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_multimap/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_multiset/debug/merge4_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge1_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge2_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge3_neg.cc: New test.
	* testsuite/23_containers/unordered_set/debug/merge4_neg.cc: New test.
	* testsuite/util/testsuite_abi.h: [_GLIBCXX_DEBUG] Use normal unordered
	container implementation.
2021-11-09 21:50:17 +01:00
Jonathan Wakely 95e8fcd3d5 libstdc++: Make test print which random_device tokens work
libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/random_device/cons/token.cc:
	Print results of random_device_available checks.
2021-11-09 15:12:29 +00:00
Jonathan Wakely d9ebf0ce08 libstdc++: Do not use 64-bit DARN on 32-bit powerpc [PR103146]
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-09 14:40:33 +00:00
Jonathan Wakely 3439657b02 libstdc++: Support getentropy and arc4random in std::random_device
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-09 14:40:33 +00:00
Jonathan Wakely 8d2d0a6c43 libstdc++: Make spurious std::random_device FAIL less likely
It's possible that independent reads from /dev/random and /dev/urandom
could produce the same value by chance. Retry if that happens. The
chances of it happening twice are miniscule.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/random_device/cons/token.cc:
	Retry if random devices produce the same value.
2021-11-09 14:40:33 +00:00
Rasmus Villemoes cc6b8cd9a2 libstdc++: only define _GLIBCXX_HAVE_TLS for VxWorks >= 6.6
According to
https://gcc.gnu.org/legacy-ml/gcc-patches/2008-03/msg01698.html, the
TLS support, including the __tls_lookup function, was added to VxWorks
in 6.6.

It certainly doesn't exist on our VxWorks 5 platform, but the fallback
code in eh_globals.cc using __gthread_key_create() etc. used to work
just fine.

libstdc++-v3/ChangeLog:

	* config/os/vxworks/os_defines.h (_GLIBCXX_HAVE_TLS): Only
	define for VxWorks >= 6.6.
2021-11-09 09:51:08 +01:00