Commit Graph

5402 Commits

Author SHA1 Message Date
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 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
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
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
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
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 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
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
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
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 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
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 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 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
Jakub Jelinek 7adcbafe45 Update copyright years. 2022-01-03 10:42:10 +01: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
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 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
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
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
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
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 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
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 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
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
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