Commit Graph

12956 Commits

Author SHA1 Message Date
Jonathan Wakely 09bc98098e libstdc++: Reorder constraints on std::span::span(Range&&) constructor.
In PR libstdc++/103013 Tim Song pointed out that we could reorder the
constraints of this constructor. That's worth doing just to reduce the
work the compiler has to do during overload resolution, even if it isn't
needed to make the code in the PR work.

libstdc++-v3/ChangeLog:

	* include/std/span (span(Range&&)): Reorder constraints.
2021-11-01 21:01:31 +00:00
Jonathan Wakely 91bac9fed5 libstdc++: Fix range access for empty std::valarray [PR103022]
The std::begin and std::end overloads for std::valarray are defined in
terms of std::addressof(v[0]) which is undefined for an empty valarray.

libstdc++-v3/ChangeLog:

	PR libstdc++/103022
	* include/std/valarray (begin, end): Do not dereference an empty
	valarray. Add noexcept and [[nodiscard]].
	* testsuite/26_numerics/valarray/range_access.cc: Check empty
	valarray. Check iterator properties. Run as well as compiling.
	* testsuite/26_numerics/valarray/range_access2.cc: Likewise.
	* testsuite/26_numerics/valarray/103022.cc: New test.
2021-11-01 13:26:29 +00:00
GCC Administrator 4c61300f2b Daily bump. 2021-10-30 00:16:25 +00:00
Jonathan Wakely d27febaf00 libstdc++: Fix typo in std::stack test
libstdc++-v3/ChangeLog:

	* testsuite/23_containers/stack/deduction.cc: Fix typo.
2021-10-29 21:34:54 +01:00
GCC Administrator 3ff5b4edbe Daily bump. 2021-10-27 00:16:33 +00:00
Martin Sebor 9a27acc30a Make full use of context-sensitive ranges in access warnings.
gcc/ChangeLog:

	* builtins.c (check_strncat_sizes): Pass access_data ctor additional
	arguments.
	(expand_builtin_memcmp): Move code to gimple-ssa-warn-access.cc.
	(expand_builtin_fork_or_exec): Same.
	* gimple-array-bounds.cc (array_bounds_checker::check_mem_ref): Pass
	compute_objsize additional arguments.
	(inbounds_memaccess_p): Same.
	(array_bounds_checker::check_array_bounds): Add an assert.  Stash
	statement in a member.
	(check_array_bounds_dom_walker::before_dom_children): Same.
	* gimple-array-bounds.h (array_bounds_checker::m_stmt): New member.
	* gimple-ssa-sprintf.c (get_destination_size): Add an argument.
	(handle_printf_call): Pass a new argument.
	* gimple-ssa-warn-access.cc (get_size_range): Add an argument.
	(check_access): Add an argument and pass it along to callees.
	(check_read_access): Make a member function.
	(pass_waccess::check_strcat): Pass access_data ctor additional
	arguments.
	(pass_waccess::check_strncat): Same.
	(pass_waccess::check_stxcpy): Same.
	(pass_waccess::check_stxncpy): Same.
	(pass_waccess::check_strncmp): Same.
	(pass_waccess::check_read_access): Same.
	(pass_waccess::check_builtin): Same.
	(pass_waccess::maybe_check_access_sizes): Same.
	(pass_waccess::maybe_check_dealloc_call): Same.
	* gimple-ssa-warn-access.h (check_read_access): Declare a new
	member function.
	* pointer-query.cc (compute_objsize_r): Add an argument.
	(gimple_call_return_array): Same.
	(gimple_call_alloc_size): Same.
	(access_ref::access_ref): Same.
	(access_ref::get_ref): Same.
	(pointer_query::get_ref): Same.
	(handle_min_max_size): Pass an arguments to callees.
	(handle_array_ref): Add an argument.
	(handle_mem_ref): Same.
	(compute_objsize): Same.
	* pointer-query.h (struct access_ref): Adjust signatures.
	(struct access_data): Same.
	(gimple_call_alloc_size): Add an argument.
	(gimple_parm_array_size): Same.
	(compute_objsize): Same.
	* tree-ssa-strlen.c (strlen_pass::adjust_last_stmt): Pass an additional
	argument to compute_objsize.
	(strlen_pass::maybe_warn_overflow): Same.
	(maybe_diag_stxncpy_trunc): Same.

gcc/testsuite/ChangeLog:

	* gcc.dg/Wstringop-overflow-22.c: Correct typos.
	* gcc.dg/Wstringop-overflow-81.c: New test.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string/capacity/1.cc: Also suppress
	-Wstringop-overread.
	* testsuite/27_io/filesystem/path/factory/u8path-char8_t.cc: Same.
2021-10-26 16:53:23 -06:00
Rainer Orth 931f1e377a libstdc++: Fix 28_regex/basic_regex/84110.cc on Solaris
28_regex/basic_regex/84110.cc currently FAILs on Solaris:

FAIL: 28_regex/basic_regex/84110.cc (test for excess errors)
UNRESOLVED: 28_regex/basic_regex/84110.cc compilation failed to produce executable

Excess errors:
/vol/gcc/src/hg/master/local/libstdc++-v3/testsuite/28_regex/basic_regex/84110.cc:14: error: reference to 'extended' is ambiguous

The issue is seen in the full output:

/vol/gcc/src/hg/master/local/libstdc++-v3/testsuite/28_regex/basic_regex/84110.cc: In function ‘void test01()’:
/vol/gcc/src/hg/master/local/libstdc++-v3/testsuite/28_regex/basic_regex/84110.cc:14: error: reference to ‘extended’ is ambiguous
In file included from /var/gcc/regression/master/11.4-gcc-gas/build/gcc/include-fixed/math.h:391,
                 from /var/gcc/regression/master/11.4-gcc-gas/build/i386-pc-solaris2.11/libstdc++-v3/include/cmath:45,
                 from /vol/gcc/src/hg/master/local/libstdc++-v3/include/precompiled/stdc++.h:41:
/usr/include/floatingpoint.h:73: note: candidates are: ‘typedef unsigned int extended [3]’

Fixed by disambiguating extended.  Tested on i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.


2021-10-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libstdc++-v3:
	* testsuite/28_regex/basic_regex/84110.cc (test01)
	[__cpp_exceptions]: Disambiguate extended.
2021-10-26 14:07:57 +02:00
Rainer Orth 88037d82d7 libstdc++: Fix 17_intro/names.cc on Solaris
17_intro/names.cc and experimental/names.cc currently FAIL on Solaris

FAIL: 17_intro/names.cc (test for excess errors)
FAIL: experimental/names.cc (test for excess errors)

Excess errors:
/usr/include/sys/timespec_util.h:22: error: expected ')' before ';' token
/usr/include/stdlib.h:157: error: expected unqualified-id before '[' token
/usr/include/stdlib.h:157: error: expected ')' before '[' token

<sys/timespec_util.h> has

extern int timespeccompare(const struct timespec *l, const struct timespec *r);

while <stdlib.h> has

typedef struct drand48_data {
        unsigned int _initialised;
        unsigned short int x[3];
        unsigned short int a[3];
        unsigned int c;
        unsigned short lastx[3];
} drand48_data;

both of which are broken by defining r resp. x to ( in the testcase.

Fixed by undoing the defines.  Tested on i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.


2021-10-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libstdc++-v3:
	* testsuite/17_intro/names.cc [__sun__] (r, x): Undef.
2021-10-26 14:00:18 +02:00
GCC Administrator c2bd5d8a30 Daily bump. 2021-10-23 00:16:26 +00:00
Jonathan Wakely 0c1f737a48 libstdc++: Constrain std::make_any [PR102894]
std::make_any should be constrained so it can only be called if the
construction of the return value would be valid.

libstdc++-v3/ChangeLog:

	PR libstdc++/102894
	* include/std/any (make_any): Add SFINAE constraint.
	* testsuite/20_util/any/102894.cc: New test.
2021-10-22 23:09:54 +01:00
GCC Administrator ae5c540662 Daily bump. 2021-10-22 00:16:31 +00:00
Jonathan Wakely 394f60e6ed libstdc++: Improve generated man pages for libstdc++
The man pages generated by Doxygen show internal header files, not the
standard headers that users actually care about. The run_doxygen script
uses the doc/doxygen/stdheader.cc program to address that, but it
doesn't work. It only tries to fix headers with underscores in the
names, which doesn't work for <bits/align.h> or <bits/fsteam.tcc>.  It
isn't prepared for the strings like "bits/stl_set\&.h" that are produced
by Doxygen. It doesn't know about many headers that have been added
since it was written. And the run_doxygen script fails to use its output
correctly to modify the man pages. Additionally, run_doxygen doesn't
know about new nested namespaces like std::filesystem and std::ranges.

This change rewrites the stdheader.cc program to do a better job of
finding the right header. The run_doxygen script now uses the just-built
compiler to build stdheader.cc and actually uses its output. And the
script now knows about other nested namespaces.

The stdheader.cc program might be unnecessary if we consistently used
@headername tags in the Doxygen comments, but we don't (and probably
never will).

A problem that remains after this change is that all the free function
defined in namespace std get dumped into a single man page for std(3),
without detailed descriptions. We don't even install that std(3) page,
but remove it before installation. That means only classes are
documented in man pages (including many internal ones that should not be
publicly documented such as _Deque_base and _Tuple_impl).

libstdc++-v3/ChangeLog:

	* doc/doxygen/stdheader.cc: Refactor. Use C++23. Add new
	headers.
	* scripts/run_doxygen: Fix post-processing of #include
	directives in man pages. Use new xg++ to compile helper program.
2021-10-21 22:24:57 +01:00
Jonathan Wakely 5a5d7c2c80 libstdc++: Add Doxygen comments to contents of <functional>
libstdc++-v3/ChangeLog:

	* include/bits/mofunc_impl.h: Add doxygen comments.
	* include/std/functional: Likewise.
2021-10-21 22:24:53 +01:00
Jonathan Wakely 6667d5feb9 libstdc++: Suppress Doxygen docs for more implementation details
libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h: Suppress doxygen documentation.
	* include/bits/allocated_ptr.h: Likewise.
	* include/bits/enable_special_members.h: Likewise.
	* include/bits/hashtable.h: Likewise.
	* include/bits/hashtable_policy.h: Likewise.
	* include/bits/uses_allocator.h: Likewise.
	* include/bits/node_handle.h: Document node handles and suppress
	documentation for protected members.
	* include/std/any: Suppress documentation for implementation
	details.
2021-10-21 22:23:00 +01:00
Patrick Palka 5f7976f65b libstdc++: missing constexpr for __[nm]iter_base [PR102358]
PR libstdc++/102358

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (__niter_base): Make constexpr
	for C++20.
	(__miter_base): Likewise.
	* testsuite/25_algorithms/move/constexpr.cc: New test.
2021-10-21 12:13:35 -04:00
Patrick Palka 48154969d4 libstdc++: Implement P2432R1 changes for views::istream
libstdc++-v3/ChangeLog:

	* include/std/ranges (istream_view): Replace this function
	template with an alias template as per P2432R1.
	(wistream_view): Define as per P2432R1.
	(views::_Istream, views::istream): Likewise.
	* testsuite/std/ranges/istream_view.cc (test07): New test.
2021-10-21 11:55:19 -04:00
Patrick Palka 9626e44713 libstdc++: Implement P1739R4 changes to views::take/drop/counted
This implements P1739R4 along with the resolution for LWG 3407 which
corrects the paper's wording.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_util.h (views::_Drop): Forward declare.
	(subrange): Befriend views::_Drop.
	(subrange::_S_store_size): Declare constexpr instead of just
	const, remove obsolete comment.
	* include/std/ranges (views::__detail::__is_empty_view): Define.
	(views::__detail::__is_basic_string_view): Likewise.
	(views::__detail::__is_subrange): Likewise.
	(views::__detail::__is_iota_view): Likewise.
	(views::__detail::__can_take_view): Rename template parm _Tp to _Dp.
	(views::_Take): Rename template parm _Tp to _Dp, make it non-deducible
	and fix it to range_difference_t<_Range>.  Implement P1739R4 and
	LWG 3407 changes.
	(views::__detail::__can_drop_view): Rename template parm _Tp to _Dp.
	(views::_Drop): As with views::_Take.
	(views::_Counted): Implement P1739R4 changes.
	* include/std/span (__detail::__is_std_span): Rename to ...
	(__detail::__is_span): ... this and turn it into a variable
	template.
	(__detail::__is_std_array): Turn it into a variable template.
	(span::span): Adjust uses of __is_std_span and __is_std_array
	accordingly.
	* testsuite/std/ranges/adaptors/p1739.cc: New test.
2021-10-21 11:55:16 -04:00
Patrick Palka 1556e447c0 libstdc++: Implement LWG 3595 changes to common_iterator
libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (common_iterator::__arrow_proxy):
	Make fully constexpr as per LWG 3595.
	(common_iterator::__postfix_proxy): Likewise.
2021-10-20 21:43:42 -04:00
Patrick Palka 2d3ac60390 libstdc++: Implement LWG 3590-3592 changes to split_view/lazy_split_view
libstdc++-v3/ChangeLog:

	* include/std/ranges (lazy_split_view::base): Add forward_range
	constraint as per LWG 3591.
	(lazy_split_view::begin, lazy_split_view::end): Also check
	simpleness of _Pattern as per LWG 3592.
	(split_view::base): Relax copyable constraint as per LWG 3590.
2021-10-20 21:34:23 -04:00
Patrick Palka 6667274b05 libstdc++: Implement LWG 3535 changes to ranges::join_view
libstdc++-v3/ChangeLog:

	* include/std/ranges (join_view::__iter_cat::_S_iter_cat): Adjust
	criteria for returning bidirectional_iterator_tag as per LWG 3535.
	(join_view::_Iterator::_S_iter_concept): Likewise.
2021-10-20 21:34:21 -04:00
Patrick Palka a2c2dcc6ca libstdc++: Implement LWG 3481 change to ranges::viewable_range
libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (viewable_range): Adjust as per
	LWG 3481.
	* testsuite/std/ranges/adaptors/all.cc (test07): New test.
2021-10-20 21:34:18 -04:00
Jonathan Wakely 0fac85a24f libstdc++: Remove constraints from std::optional monadic ops [PR102863]
The constraints on transform and and_then can cause errors when checking
satisfaction. The constraints that were present in R6 of the paper were
moved for he final F8 revision, and so should have been included in the
implementation.

libstdc++-v3/ChangeLog:

	PR libstdc++/102863
	* include/std/optional (optional::and_then, optional::transform):
	Remove requires-clause.
	* testsuite/20_util/optional/monadic/and_then.cc: Check
	overload resolution doesn't cause errors.
	* testsuite/20_util/optional/monadic/transform.cc: Likewise.
2021-10-21 01:23:22 +01:00
GCC Administrator 674dda6be0 Daily bump. 2021-10-21 00:16:29 +00:00
Jonathan Wakely 4ba4b05315 libstdc++: Add missing test for std::optional::transform(F&&)
The test_copy_elision() function was supposed to ensure that the result
is constructed directly in the std::optional, without early temporary
materialization. But I forgot to write the test.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/optional/monadic/transform.cc: Check that
	an rvalue result is not materialized too soon.
2021-10-20 20:20:18 +01:00
GCC Administrator 19472fc3fc Daily bump. 2021-10-20 00:16:43 +00:00
Patrick Palka 5566f3c6b4 libstdc++: Implement LWG 3580 change to ranges::iota_view
libstdc++-v3/ChangeLog:

	* include/std/ranges (iota_view::_Iterator::operator+): Adjust
	definition as per LWG 3580.
	(iota_view::_Iterator::operator-): Likewise.
2021-10-19 18:07:19 -04:00
Patrick Palka bed1892f5b libstdc++: Implement LWG 3568 change to ranges::basic_istream_view
libstdc++-v3/ChangeLog:

	* include/std/ranges (basic_istream_view::_M_object): Value
	initialize as per LWG 3568.
2021-10-19 18:07:16 -04:00
Patrick Palka 98af6b86bc libstdc++: Implement LWG 3470 change to ranges::subrange
libstdc++-v3/ChangeLog:

	* include/bits/ranges_util.h
	(__detail::__uses_nonqualification_pointer_conversion): Define
	and use it ...
	(__detail::__convertible_to_nonslicing): ... here, as per LWG 3470.
	* testsuite/std/ranges/subrange/1.cc: New test.
2021-10-19 18:07:05 -04:00
Patrick Palka 861440a77b libstdc++: Implement LWG 3523 changes to ranges::iota_view
libstdc++-v3/ChangeLog:

	* include/std/ranges (iota_view::_Iterator): Befriend iota_view.
	(iota_view::_Sentinel): Likewise.
	(iota_view::iota_view): Add three overloads, each taking an
	iterator/sentinel pair as per LWG 3523.
	* testsuite/std/ranges/iota/iota_view.cc (test06): New test.
2021-10-19 17:54:24 -04:00
Patrick Palka 53b1c382d5 libstdc++: Implement LWG 3549 changes to ranges::enable_view
This patch also reverts r11-3504 since that workaround is now obsolete
after this resolution.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (view_interface): Forward declare.
	(__detail::__is_derived_from_view_interface_fn): Declare.
	(__detail::__is_derived_from_view_interface): Define as per LWG 3549.
	(enable_view): Adjust as per LWG 3549.
	* include/bits/ranges_util.h (view_interface): Don't derive from
	view_base.
	* include/std/ranges (filter_view): Revert r11-3504 change.
	(transform_view): Likewise.
	(take_view): Likewise.
	(take_while_view): Likewise.
	(drop_view): Likewise.
	(drop_while_view): Likewise.
	(join_view): Likewise.
	(lazy_split_view): Likewise.
	(split_view): Likewise.
	(reverse_view): Likewise.
	* testsuite/std/ranges/adaptors/sizeof.cc: Update expected sizes.
	* testsuite/std/ranges/view.cc (test_view::test_view): Remove
	this default ctor since views no longer need to be default initable.
	(test01): New test.
2021-10-19 17:50:56 -04:00
Jonathan Wakely 58f339fc5e libstdc++: Implement std::random_device::entropy() for other sources
Currently this function only returns a non-zero value for /dev/random
and /dev/urandom. When a hardware instruction such as RDRAND is in use
it should (in theory) be perfectly random and produce 32 bits of entropy
in each 32-bit result. Add a helper function to identify the source of
randomness from the _M_func and _M_file data members, and return a
suitable value when RDRAND or RDSEED is being used.

libstdc++-v3/ChangeLog:

	* src/c++11/random.cc (which_source): New helper function.
	(random_device::_M_getentropy()): Use which_source and return
	suitable values for sources other than device files.
	* testsuite/26_numerics/random/random_device/entropy.cc: New test.
2021-10-19 17:27:06 +01:00
Jonathan Wakely 04d392e843 libstdc++: Fix doxygen generation to work with relative paths
In r12-826 I tried to remove some redundant steps from the doxygen
build, but they are needed when configure is run as a relative path. The
use of pwd is to resolve the relative path to an absolute one.

libstdc++-v3/ChangeLog:

	* doc/Makefile.am (stamp-html-doxygen, stamp-html-doxygen)
	(stamp-latex-doxygen, stamp-man-doxygen): Fix recipes for
	relative ${top_srcdir}.
	* doc/Makefile.in: Regenerate.
2021-10-19 16:07:41 +01:00
Jonathan Wakely 5a8832b165 libstdc++: Change std::variant union member to empty struct
This more clearly expresses the intent (a completely unused, trivial
type) than using char. It's also consistent with the unions in
std::optional.

libstdc++-v3/ChangeLog:

	* include/std/variant (_Uninitialized): Use an empty struct
	for the unused union member, instead of char.
2021-10-19 15:01:16 +01:00
Jonathan Wakely c4ecb11e4f libstdc++: Fix std::stack deduction guide
libstdc++-v3/ChangeLog:

	* include/bits/stl_stack.h (stack(Iterator, Iterator)): Remove
	non-deducible template parameter from deduction guide.
	* testsuite/23_containers/stack/deduction.cc: Check new C++23
	deduction guides.
2021-10-19 15:01:16 +01:00
Jonathan Wakely 82b2e4f8cf libstdc++: Implement monadic operations for std::optional (P0798R8)
Another new addition to the C++23 working draft.

The new member functions of std::optional are only defined for C++23,
but the new members of _Optional_payload_base are defined for C++20 so
that they can be used in non-propagating-cache in <ranges>. The
_Optional_payload_base::_M_construct member can also be used in
non-propagating-cache now, because it's constexpr since r12-4389.

There will be an LWG issue about the feature test macro, suggesting that
we should just bump the value of __cpp_lib_optional instead. I haven't
done that here, but it can be changed once consensus is reached on the
change.

libstdc++-v3/ChangeLog:

	* include/std/optional (_Optional_payload_base::_Storage): Add
	constructor taking a callable function to invoke.
	(_Optional_payload_base::_M_apply): New function.
	(__cpp_lib_monadic_optional): Define for C++23.
	(optional::and_then, optional::transform, optional::or_else):
	Define for C++23.
	* include/std/ranges (__detail::__cached): Remove.
	(__detail::__non_propagating_cache): Remove use of __cached for
	contained value. Use _Optional_payload_base::_M_construct and
	_Optional_payload_base::_M_apply to set the contained value.
	* include/std/version (__cpp_lib_monadic_optional): Define.
	* testsuite/20_util/optional/monadic/and_then.cc: New test.
	* testsuite/20_util/optional/monadic/or_else.cc: New test.
	* testsuite/20_util/optional/monadic/or_else_neg.cc: New test.
	* testsuite/20_util/optional/monadic/transform.cc: New test.
	* testsuite/20_util/optional/monadic/version.cc: New test.
2021-10-19 15:01:16 +01:00
Jonathan Wakely 9890b12c72 libstdc++: Fix mem-initializer in std::move_only_function [PR102825]
libstdc++-v3/ChangeLog:

	PR libstdc++/102825
	* include/bits/mofunc_impl.h (move_only_function): Remove
	invalid base initializer.
	* testsuite/20_util/move_only_function/cons.cc: Instantiate
	constructors to check bodies.
2021-10-19 11:50:46 +01:00
GCC Administrator 93d183a5ff Daily bump. 2021-10-16 00:16:27 +00:00
Jonathan Wakely e547d1341b libstdc++: Fix error in filesystem::path with Clang
THis fixes teh following error seen with Clang:

error: function '_S_convert<std::basic_string_view<char8_t>>' with deduced
return type cannot be used before it is defined
          return string_type(_S_convert(std::u8string_view(__str)));
                             ^

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (path::_S_convert(T)): Avoid recursive
	call to function with deduced return type.
2021-10-16 00:44:28 +01:00
Jonathan Wakely 929abc7fe3 libstdc++: Define std::basic_string::resize_and_overwrite for C++23 (P1072R10)
A recently approved change for the C++23 working draft.

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (__cpp_lib_string_resize_and_overwrite):
	Define for C++23.
	(basic_string::resize_and_overwrite): Declare.
	* include/bits/basic_string.tcc (basic_string::resize_and_overwrite):
	Define.
	* include/std/version (__cpp_lib_resize_and_overwrite): Define
	for C++23.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
	New test.
2021-10-16 00:44:16 +01:00
Jonathan Wakely 2c564e813c libstdc++: Make non-propagating-cache fully constexpr [PR101263]
libstdc++-v3/ChangeLog:

	PR libstdc++/101263
	* include/std/ranges (__cached): New wrapper struct.
	(__non_propagating_cache): Use __cached for contained value.
	(__non_propagating_cache::_M_emplace_deref): Add constexpr. Use
	std::construct_at instead of placement new.
	* testsuite/std/ranges/adaptors/join.cc: Check constexpr works.
2021-10-15 18:26:53 +01:00
Jonathan Wakely ad820b0bb5 libstdc++: Add missing constexpr to std::variant (P2231R1)
This implements the changes in P2231R1 which make std::variant fully
constexpr in C++20.

We need to replace placement new with std::construct_at, but that isn't
defined for C++17. Use std::_Construct instead, which forwards to
std::construct_at in C++20 mode (since the related changes to make
std::optional fully constexpr, in r12-4389).

We also need to replace the untyped char buffer in _Uninitialized with a
union, which can be accessed in constexpr functions. But the union needs
to have a non-trivial destructor if its variant type is non-trivial,
which means that the _Variadic_union also needs a non-trivial
destructor. This adds a constrained partial specialization of
_Variadic_union for the C++20-only case where a non-trivial destructor
is needed.

We can't use concepts to constrain the specialization (or the primary
template's destructor) in C++17, so retain the untyped char buffer
solution for C++17 mode.

libstdc++-v3/ChangeLog:

	* include/std/variant (__cpp_lib_variant): Update value for
	C++20.
	(__variant_cast, __variant_construct): Add constexpr for C++20.
	(__variant_construct_single, __construct_by_index) Likewise. Use
	std::_Construct instead of placement new.
	(_Uninitialized<T, false>) [__cplusplus >= 202002]: Replace
	buffer with a union and define a destructor.
	(_Variadic_union) [__cplusplus >= 202002]: Add a specialization
	for non-trivial destruction.
	(_Variant_storage::__index_of): New helper variable template.
	(_Variant_storage::~_Variant_storage()): Add constexpr.
	(_Variant_storage::_M_reset()): Likewise.
	(_Copy_ctor_base, _Move_ctor_base): Likewise.
	(_Copy_assign_base, _Move_assign_base): Likewise.
	(variant, swap): Likewise.
	* include/std/version (__cpp_lib_variant): Update value for
	C++20.
	* testsuite/20_util/optional/version.cc: Check for exact value
	in C++17.
	* testsuite/20_util/variant/87619.cc: Increase timeout for
	C++20 mode.
	* testsuite/20_util/variant/constexpr.cc: New test.
	* testsuite/20_util/variant/version.cc: New test.
2021-10-15 18:26:53 +01:00
Jonathan Wakely e27771e5dc libstdc++: Remove try/catch overhead in std::variant::emplace
The __variant_construct_by_index helper function sets the new index
before constructing the new object. This means that if the construction
throws then the exception needs to be caught, so the index can be reset
to variant_npos, and then the exception rethrown. This means callers are
responsible for restoring the variant's invariants and they need the
overhead of a catch handler and a rethrow.

If we don't set the index until after construction completes then the
invariant is never broken, and callers can ignore the exception and let
it propagate. The callers all call _M_reset() first, which sets index to
variant_npos as required while the variant is valueless.

We need to be slightly careful here, because changing the order of
operations in __variant_construct_by_index and removing the try-block
from variant::emplace<I> changes an implicit ABI contract between those
two functions. If the linker were to create an executable containing an
instantiation of the old __variant_construct_by_index and an
instantiation of the new variant::emplace<I> code then we would have a
combination that breaks the invariant and doesn't have the exception
handling to restore it. To avoid this problem, we can rename the
__variant_construct_by_index function so that the new emplace<I> code
calls a new symbol, and is unaffected by the behaviour of the old
symbol.

libstdc++-v3/ChangeLog:

	* include/std/variant (__detail::__variant::__get_storage):
	Remove unused function.
	(__variant_construct_by_index): Set index after construction is
	complete. Rename to ...
	(__detail::__variant::__construct_by_index): ... this.
	(variant): Use new name for __variant_construct_by_index friend
	declaration. Remove __get_storage friend declaration.
	(variant::emplace): Use new name and remove try-blocks.
2021-10-15 18:26:53 +01:00
Jonathan Wakely 1ba7adabf2 libstdc++: Remove unused functions in std::variant implementation
These functions aren't used, and accessing the storage as a void* isn't
compatible with C++20 constexpr requirements anyway, so we're unlikely
to ever start using them in future.

libstdc++-v3/ChangeLog:

	* include/std/variant (_Variant_storage::_M_storage()): Remove.
	(__detail::__variant::__get_storage): Remove.
	(variant): Remove friend declaration of __get_storage.
2021-10-15 18:26:52 +01:00
Jason Merrill 1595fe44e1 c++: instantiate less for constant folding
I've been experimenting with a change to make all inline functions
implicitly constexpr; this revealed that we are instantiating too
aggressively for speculative constant evaluation, leading to ordering
difficulties with e.g. is_a_helper<cgraph_node*>::test.  This patch tries to
avoid such instantiation until we actually need the function definition to
determine whether a call is constant, by limiting the initial instantiation
of all used functions to manifestly-constant-evaluated expressions, and
checking whether the function arguments are constant before instantiating
the function.

This change resulted in a change in the diagnostics for a few library tests
due to instantiating the function with the static_assert later (during
constant evaluation) than we did before (during instantiation of the
intermediate function).

gcc/cp/ChangeLog:

	* constexpr.c (cxx_bind_parameters_in_call): Replace
	new_call parameter with fun.
	(cxx_eval_call_expression): Call it before instantiation.
	(cxx_eval_outermost_constant_expr): Only instantiate fns
	when manifestly_const_eval.
	* typeck2.c (check_narrowing): This context is manifestly
	constant-evaluated.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/integer_comparisons/greater_equal_neg.cc:
	* testsuite/20_util/integer_comparisons/greater_neg.cc:
	* testsuite/20_util/integer_comparisons/less_equal_neg.cc:
	Adjust expected message.
	* testsuite/lib/prune.exp: Prune 'in constexpr expansion'.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/vla22.C: Don't expect a narrowing error.
	* g++.dg/cpp0x/constexpr-inst1.C: New test.
2021-10-14 21:40:11 -04:00
GCC Administrator 5d5885c99c Daily bump. 2021-10-15 00:17:02 +00:00
Jonathan Wakely 4f87d4c5ae libstdc++: Simplify variant access functions
libstdc++-v3/ChangeLog:

	* include/std/variant (__variant::__get(in_place_index_t<N>, U&&)):
	Rename to __get_n and remove first argument. Replace pair of
	overloads with a single function using 'if constexpr'.
	(__variant::__get(Variant&&)): Adjust to use __get_n.
2021-10-14 22:19:38 +01:00
Jonathan Wakely 373acac1c8 libstdc++: Make filesystem::path(path&&) always noexcept
Since r12-4065 std::basic_string is always nothrow-move-constructible,
so filesystem::path is too.

That also means that path::_S_convert(T) is noexcept when returning its
argument, because T is either a basci_string or basic_string_view, and
will be moved into the return value.

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (path(path&&)): Make unconditionally
	noexcept.
	(path::_S_convert(T)): Add condtional noexcept.
2021-10-14 22:19:38 +01:00
Jonathan Wakely 5e3f888389 libstdc++: Fix brainwrong in path::_S_convert(T) [PR102743]
This function was supposed to check whether the parameter's value type
is the same as path::value_type, and therefore needs no conversion.
Instead it checks whether the parameter is the same as its own value
type, which is never true. This means we incorrectly return a string
view for the case where T is path::string_type, instead of just
returning the string itself. The only place that happens is
path::_S_convert_loc for Windows, where we call _S_convert with a
std::wstring rvalue.

This fixes the condition in _S_convert(T).

libstdc++-v3/ChangeLog:

	PR libstdc++/102743
	* include/bits/fs_path.h (path::_S_convert(T)): Fix condition
	for returning the same string unchanged.
2021-10-14 15:12:34 +01:00
Jonathan Wakely 3d95867ce6 libstdc++: Use more descriptive feature test macro
The out-of-class definitions of the static constants are redundant if
the __cpp_inline_variables feature is supported, so use that macro to
decide whether to define them or not.

libstdc++-v3/ChangeLog:

	* include/bits/regex.h: Check __cpp_inline_variables instead of
	__cplusplus.
2021-10-14 15:12:33 +01:00
Jonathan Wakely 6e3bfd60e8 libstdc++: Fix test for feature test macro
libstdc++-v3/ChangeLog:

	* testsuite/20_util/is_layout_compatible/version.cc: Check
	correct macro.
2021-10-14 09:08:01 +01:00
Jonathan Wakely 476f305b6c libstdc++: Add missing constexpr to std::optional (P2231R1)
This implements the changes in P2231R1 which make std::optional fully
constexpr in C++20.

libstdc++-v3/ChangeLog:

	* include/bits/stl_construct.h (_Construct): Use
	std::construct_at when constant evaluated.
	* include/std/optional (_Storage, _Optional_payload, optional):
	Add constexpr as specified by P2231R1.
	* include/std/version (__cpp_lib_optional): Update value for
	C++20.
	* testsuite/20_util/optional/requirements.cc: Check feature test
	macro.
	* testsuite/20_util/optional/constexpr/assign.cc: New test.
	* testsuite/20_util/optional/constexpr/cons/conv.cc: New test.
	* testsuite/20_util/optional/constexpr/modifiers.cc: New test.
	* testsuite/20_util/optional/constexpr/swap.cc: New test.
	* testsuite/20_util/optional/version.cc: New test.
2021-10-14 09:08:01 +01:00
GCC Administrator 9eb28a0f19 Daily bump. 2021-10-14 00:16:31 +00:00
Jonathan Wakely f874a13ca3 libstdc++: Fix regression in memory use when constructing paths
The changes in r12-4381 were intended to reduce memory usage, but
replacing the __contiguous constant in __string_from_range with the new
__is_contiguous variable template caused a regression. The old code
checked is_pointer_v<decltype(std::__niter_base(__first))> but he new
code just checks is_pointer_v<_InputIterator>. This means that we no
longer recognise basic_string::iterator and vector::iterator as
contiguous, and so return a temporary basic_string instead of a
basic_string_view. This only affects C++17 mode, because the
std::contiguous_iterator concept is used in C++20 which gives the right
answer for __normal_iterator (and more types as well).

The fix is to specialize the new __is_contiguous variable template so it
is true for __normal_iterator<T*, C> specializations. The new partial
specializations are defined for C++20 too, because it should be cheaper
to match the partial specialization than to check whether the
std::contiguous_iterator concept is satisfied.

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (__detail::__is_contiguous): Add
	partial specializations for pointers and __normal_iterator.
2021-10-13 22:35:32 +01:00
Jonathan Wakely ce55693604 libstdc++: Rename files with the wrong extensions
libstdc++-v3/ChangeLog:

	* testsuite/27_io/filesystem/path/construct/102592.C: Moved to...
	* testsuite/27_io/filesystem/path/construct/102592.cc: ...here.
	* testsuite/28_regex/match_results/102667.C: Moved to...
	* testsuite/28_regex/match_results/102667.cc: ...here.
2021-10-13 22:35:14 +01:00
Jonathan Wakely b83b810ac4 libstdc++: Refactor filesystem::path encoding conversions
Adjust the __detail::__effective_range overloads so they always return a
string or string view using std::char_traits, because we don't care
about the traits of an incoming string.

Use std::contiguous_iterator in the __effective_range(const Source&)
overload, to allow returning a basic_string_view in more cases. For the
non-contiguous casecl in both __effective_range and __string_from_range,
return a std::string instead of std::u8string when the value type of the
range is char8_t.  These changes avoid unnecessary basic_string
temporaries.

Also simplify __string_from_range(Iter, Iter) to not need
std::__to_address for the contiguous case.

Combine the _S_convert(string_type) and _S_convert(const T&) overloads
into a single _S_convert(T) function which also avoids the dangling
view problem of PR 102592 (should that recur somehow).

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (__detail::__is_contiguous): New
	variable template to identify contiguous iterators.
	(__detail::__unified_char8_t): New alias template to decide when
	to treat char8_t as char without encoding conversion.
	(__detail::__effective_range(const basic_string<C,T>&)): Use
	std::char_traits<C> for returned string view.
	(__detail::__effective_range(const basic_string_view<C,T>&)):
	Likewise.
	(__detail::__effective_range(const Source&)): Use
	__is_contiguous to detect mode cases of contiguous iterators.
	Use __unified_char8_t to return a std::string instead of
	std::u8string.
2021-10-13 20:36:51 +01:00
Jonathan Wakely 85b24e32dc libstdc++: Fix dangling string_view in filesystem::path [PR102592]
When creating a path from a pair of non-contiguous iterators we pass the
iterators to _S_convert(Iter, Iter). That function passes the iterators
to __string_from_range to get a contiguous sequence of characters, and
then calls _S_convert(const C*, const C*) to perform the encoding
conversions. If the value type, C, is char8_t, then no conversion is
needed and the _S_convert<char8_t>(const char8_t*, const char8_t*)
specialization casts the pointer to const char* and returns a
std::string_view that refs to the char8_t sequence. However, that
sequence is owned by the std::u8string rvalue returned by
__string_from_range, which goes out of scope when _S_convert(Iter, Iter)
returns. That means the std::string_view is dangling and we get
undefined behaviour when parsing it as a path.

The same problem does not exist for the path members taking a "Source"
argument, because those functions all convert a non-contiguous range
into a basic_string<C> immediately, using __effective_range(__source).
That means that the rvalue string returned by that function is still in
scope for the full expression, so the string_view does not dangle.

The solution for the buggy functions is to do the same thing, and call
__string_from_range immediately, so that the returned rvalue is still in
scope for the lifetime of the string_view returned by _S_convert. To
avoid reintroducing the same problem, remove the _S_convert(Iter, Iter)
overload that calls __string_from_range and returns a dangling view.

libstdc++-v3/ChangeLog:

	PR libstdc++/102592
	* include/bits/fs_path.h (path::path(Iter, Iter, format))
	(path::append(Iter, Iter), path::concat(Iter, Iter)): Call
	__string_from_range directly, instead of two-argument overload
	of _S_convert.
	(path::_S_convert(Iter, Iter)): Remove.
	* testsuite/27_io/filesystem/path/construct/102592.C: New test.
2021-10-13 20:36:51 +01:00
Jonathan Wakely c1b6c360fc libstdc++: Ensure language linkage of std::__terminate()
This is needed because people still find it necessary to do:

  extern "C" {
  #include <stdlib.h>
  }

libstdc++-v3/ChangeLog:

	* include/bits/c++config (__terminate): Add extern "C++".
2021-10-13 10:42:45 +01:00
GCC Administrator 52055987fb Daily bump. 2021-10-13 00:16:22 +00:00
Jonathan Wakely 727137d6ca libstdc++: Fix test that fails for C++20
Also restore the test for 'a < a' that was removed by r12-2537 because
it is ill-formed. We still want to test operator< for tuple, we just
need to not use std::nullptr_t in that tuple type.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/tuple/comparison_operators/overloaded.cc:
	Restore test for operator<.
	* testsuite/20_util/tuple/comparison_operators/overloaded2.cc:
	Adjust expected errors for C++20.
2021-10-12 16:05:15 +01:00
Jonathan Wakely 7481021364 libstdc++: Fix move construction of std::tuple with array elements [PR101960]
The r12-3022 commit only fixed the case where an array is the last
element of the tuple. This fixes the other cases too. We can just define
the move constructor as defaulted, which does the right thing. Changing
the move constructor to be trivial would be an ABI break, but since the
last base class still has a non-trivial move constructor, defining the
derived ones as defaulted doesn't change anything.

libstdc++-v3/ChangeLog:

	PR libstdc++/101960
	* include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Define as
	defauled.
	* testsuite/20_util/tuple/cons/101960.cc: Check tuples with
	array elements before the last element.
2021-10-12 16:05:15 +01:00
Jonathan Wakely d9dfd7ad3e libstdc++: Improve diagnostics for misuses of output iterators
This adds deleted overloads so that the errors for invalid uses of
std::advance and std::distance are easier to understand (see for example
PR 102181).

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator_base_funcs.h (__advance): Add
	deleted overload to improve diagnostics.
	(__distance): Likewise.
2021-10-12 16:05:15 +01:00
GCC Administrator 732d763847 Daily bump. 2021-10-12 00:17:02 +00:00
Jonathan Wakely 250ddf4c0b libstdc++: Add wrapper for internal uses of std::terminate
This adds an inline wrapper for std::terminate that doesn't add the
declaration of std::terminate to namespace std. This allows the
library to terminate without including all of <exception>.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_timed_wait.h: Remove unused header.
	* include/bits/c++config (std:__terminate): Define.
	* include/bits/semaphore_base.h: Remove <exception> and use
	__terminate instead of terminate.
	* include/bits/std_thread.h: Likewise.
	* libsupc++/eh_terminate.cc (std::terminate): Use qualified-id
	to call __cxxabiv1::__terminate.
2021-10-11 20:35:51 +01:00
Jonathan Wakely 247bac507e libstdc++: Simplify std::basic_regex::assign
We know that if __is_contiguous_iterator is true then we have a pointer
or a __normal_iterator that wraps a pointer, so we don't need to use
std::__to_address.

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (basic_regex::assign(Iter, Iter)): Avoid
	std::__to_address by using poitner directly or using base()
	member of __normal_iterator.
2021-10-11 20:35:45 +01:00
Jonathan Wakely 45ba5426c1 libstdc++: Fix std::numeric_limits::lowest() test for strict modes
This test uses std::is_integral to decide whether we are testing an
integral or floating-point type. But that fails for __int128 because
is_integral<__int128> is false in strict modes. By using
numeric_limits::is_integer instead we get the right answer for all types
that have a numeric_limits specialization.

We can also simplify the test by removing the unnecessary tag
dispatching.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/numeric_limits/lowest.cc: Use
	numeric_limits<T>::is_integer instead of is_integral<T>::value.
2021-10-11 20:34:17 +01:00
Jonathan Wakely 6b6788f8c2 libstdc++: Add valid range assertions to std::basic_regex [PR89927]
This adds some debug assertions to basic_regex. They don't actually
diagnose the error in the PR yet, but I have another patch to make them
more effective.

Also change the __glibcxx_assert(false) consistency checks to include a
string literal that tells the user a bit more about why the process
aborted. We could consider adding a __glibcxx_bug or
__glibcxx_internal_error macro for this purpose, but ideally we'll never
hit such bugs anyway so it shouldn't be needed.

libstdc++-v3/ChangeLog:

	PR libstdc++/89927
	* include/bits/regex.h (basic_regex(const _Ch_type*, size_t)):
	Add __glibcxx_requires_string_len assertion.
	(basic_regex::assign(InputIterator, InputIterator)): Add
	__glibcxx_requires_valid_range assertion.
	* include/bits/regex_scanner.tcc (_Scanner::_M_advance())
	(_Scanner::_M_scan_normal()): Use string literal in assertions.
2021-10-11 20:34:16 +01:00
Jonathan Wakely 84088dc4bb libstdc++: Fix std::match_results::end() for failed matches [PR102667]
The end() function needs to consider whether the underlying vector is
empty, not whether the match_results object is empty. That's because the
underlying vector will always contain at least three elements for a
match_results object that is "ready". It contains three extra elements
which are stored in the vector but are not considered part of sequence,
and so should not be part of the [begin(),end()) range.

libstdc++-v3/ChangeLog:

	PR libstdc++/102667
	* include/bits/regex.h (match_result::empty()): Optimize by
	calling the base function directly.
	(match_results::end()): Check _Base_type::empty() not empty().
	* testsuite/28_regex/match_results/102667.C: New test.
2021-10-11 20:34:16 +01:00
Jonathan Wakely f858239830 ChangeLog: Remove incorrect PR reference 2021-10-11 16:19:01 +01:00
GCC Administrator ce6eec3926 Daily bump. 2021-10-09 00:16:26 +00:00
Jonathan Wakely fec283b63d libstdc++: Remove unnecessary uses of _GLIBCXX_USE_WCHAR_T in testsuite [PR98725]
Now that std::wstring and other specializations for wchar_t are defined
unconditionally, many checks for _GLIBCXX_USE_WCHAR_T in the testsuite
are unnecessary and can be removed. Tests for iostreams, locales, regex
and filesystem::path still need to be guarded by _GLIBCXX_USE_WCHAR_T
because those components depend on libc support in <wchar.h> and other
headers.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* testsuite/18_support/numeric_limits/lowest.cc: Remove use of
	_GLIBCXX_USE_WCHAR_T.
	* testsuite/18_support/numeric_limits/min_max.cc: Replace use of
	_GLIBCXX_USE_WCHAR_T with checks for WCHAR_MIN and WCHAR_MAX.
	* testsuite/20_util/from_chars/1_neg.cc: Remove use of
	_GLIBCXX_USE_WCHAR_T.
	* testsuite/20_util/function_objects/searchers.cc: Likewise. Use
	char_traits<wchar_t>::length instead of wcslen.
	* testsuite/20_util/hash/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_arithmetic/value.cc: Likewise.
	* testsuite/20_util/is_compound/value.cc: Likewise.
	* testsuite/20_util/is_floating_point/value.cc: Likewise.
	* testsuite/20_util/is_fundamental/value.cc: Likewise.
	* testsuite/20_util/is_integral/value.cc: Likewise.
	* testsuite/20_util/is_signed/value.cc: Likewise.
	* testsuite/20_util/is_unsigned/value.cc: Likewise.
	* testsuite/20_util/is_void/value.cc: Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-1.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-2.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-3.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-4.cc:
	Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs-1.cc:
	Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs-2.cc:
	Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs-3.cc:
	Likewise.
	* testsuite/20_util/to_chars/3.cc: Likewise.
	* testsuite/20_util/type_identity/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string/hash/debug.cc: Likewise.
	* testsuite/21_strings/basic_string/hash/hash.cc: Likewise.
	* testsuite/21_strings/basic_string/literals/types-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string/literals/types.cc: Likewise.
	* testsuite/21_strings/basic_string/literals/values-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string/literals/values.cc:
	Likewise.
	* testsuite/21_strings/basic_string/modifiers/64422.cc:
	Likewise.
	* testsuite/21_strings/basic_string/range_access/wchar_t/1.cc:
	Likewise.
	* testsuite/21_strings/basic_string/requirements/citerators.cc:
	Likewise.
	* testsuite/21_strings/basic_string/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string/types/pmr_typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/types.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values-char8_t.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/literals/values.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/typedefs.cc: Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc:
	Likewise.
	* testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc:
	Likewise.
	* testsuite/22_locale/ctype/is/string/89728_neg.cc: Likewise.
	* testsuite/25_algorithms/fill/4.cc: Likewise.
	* testsuite/25_algorithms/fill_n/1.cc: Likewise.
	* testsuite/experimental/functional/searchers.cc: Likewise. Use
	char_traits<wchar_t>::length instead of wcslen.
	* testsuite/experimental/polymorphic_allocator/pmr_typedefs_string.cc:
	Likewise.
	* testsuite/experimental/string_view/literals/types-char8_t.cc:
	Likewise.
	* testsuite/experimental/string_view/literals/types.cc:
	Likewise.
	* testsuite/experimental/string_view/literals/values-char8_t.cc:
	Likewise.
	* testsuite/experimental/string_view/literals/values.cc:
	Likewise.
	* testsuite/experimental/string_view/range_access/wchar_t/1.cc:
	Likewise.
	* testsuite/experimental/string_view/requirements/typedefs.cc:
	Likewise.
	* testsuite/experimental/string_view/typedefs.cc: Likewise.
	* testsuite/ext/vstring/range_access.cc: Likewise.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/integral.cc:
	Likewise.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/signed_integral.cc:
	Likewise.
	* testsuite/std/concepts/concepts.lang/concept.arithmetic/unsigned_integral.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_arithmetic/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_compound/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_floating_point/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_fundamental/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_integral/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_signed/value.cc: Likewise.
	* testsuite/tr1/4_metaprogramming/is_unsigned/value.cc:
	Likewise.
	* testsuite/tr1/4_metaprogramming/is_void/value.cc: Likewise.
	* testsuite/tr1/6_containers/hash/24799.cc: Likewise.
2021-10-09 00:57:50 +01:00
Jonathan Wakely 9a89281c40 libstdc++: Define deleted wchar_t overloads unconditionally [PR 98725]
We don't need to have <wchar.h> support in order to delete overloads
for inserting wide characters into narrow streams.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* include/std/ostream (operator<<(basic_ostream<char, Tr>&, wchar_t))
	(operator<<(basic_ostream<char, Tr>&, const wchar_t*)): Always
	define as deleted. Do not check _GLIBCXX_USE_WCHAR_T.
2021-10-09 00:57:50 +01:00
Jonathan Wakely 3c9fbc26af libstdc++: Define std::wstring_convert unconditionally [PR 98725]
The wchar_t type is defined unconditionally for C++, so there is no
reason for std::wstring_convert and std::wbuffer_convert to be disabled
when <wchar.h> is not usable. It should be possible to use those class
templates with char16_t and char32_t even if wchar_t conversions don't
work.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* include/bits/locale_conv.h (wstring_convert, wbuffer_convert):
	Define unconditionally. Do not check _GLIBCXX_USE_WCHAR_T.
2021-10-09 00:57:49 +01:00
Jonathan Wakely 4bdb9d618d libstdc++: Enable type traits for wchar_t unconditionally [PR98725]
None of these traits depend on libc support for wchar_t, so they should
be defined unconditionally. The wchar_t type is always defined in C++.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* include/c_global/cstddef [!_GLIBCXX_USE_WCHAR_T]
	(__byte_operand<wchar_t>): Define specialization.
	* include/std/type_traits (__make_signed<wchar_t>)
	(__make_unsigned<wchar_t>): Remove redundant check for
	__WCHAR_TYPE__ being defined.
	* include/tr1/type_traits [!_GLIBCXX_USE_WCHAR_T]
	(__is_integral_helper<wchar_t>): Likewise.
2021-10-09 00:57:49 +01:00
Jonathan Wakely 4997c8b30e libstdc++: Enable vstring for wchar_t unconditionally [PR98725]
None of these vstring specializations depend on libc support for
wchar_t, so can be enabled unconditionally now that char_traits<wchar_t>
is always available.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* include/ext/rc_string_base.h [!_GLIBCXX_USE_WCHAR_T]
	(__rc_string_base<wchar_t>): Define member function.
	* include/ext/vstring.h [!_GLIBCXX_USE_WCHAR_T]
	(hash<__gnu_cxx::__wvstring>): Define specialization.
	* include/ext/vstring_fwd.h [!_GLIBCXX_USE_WCHAR_T] (__wvstring)
	(__wsso_string, __wrc_string): Declare typedefs.
2021-10-09 00:57:49 +01:00
Jonathan Wakely 0afb9ebaab libstdc++: Always define typedefs and hash functions for wide strings [PR 98725]
The wstring and wstring_view typedefs should be enabled even if
<wchar.h> isn't supported, because char_traits<wchar_t> works
unconditionally. Similarly, the std::hash specializations for wide
strings do not depend on <wchar.h> support.

Although the primary template works OK for std::char_traits<wchar_t> in
the absence of <wchar.h> support, this patch still defines it as an
explicit specialization for compatibility with declarations that expect
it to be specialized. The explicit specialization just uses the same
__gnu_cxx::char_traits base class as the primary template.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* include/bits/char_traits.h (char_traits<wchar_t>): Define
	explicit specialization unconditionally.
	* include/bits/basic_string.h (hash<wstring>): Define
	unconditionally. Do not check _GLIBCXX_USE_WCHAR_T.
	* include/bits/stringfwd.h (wstring): Likewise.
	* include/debug/string (wstring): Likewise.
	* include/experimental/string_view (experimental::wstring_view)
	(hash<experimental::wstring_view>): Likewise.
	* include/std/string (pmr::wstring, hash<pmr::wstring>):
	Likewise.
	* include/std/string_view (wstring_view, hash<wstring_view>):
	Likewise.
2021-10-09 00:57:49 +01:00
Jonathan Wakely cfeff094e6 libstdc++: Move test that depends on wchar_t I/O to wchar_t sub-directory
This fixes a FAIL when --disable-wchar_t is used.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_filebuf/close/81256.cc: Moved to...
	* testsuite/27_io/basic_filebuf/close/wchar_t/81256.cc: ...here.
2021-10-09 00:57:48 +01:00
Jonathan Wakely 43e2a44182 libstdc++: Add missing _GLIBCXX_USE_WCHAR_T checks in testsuite
These tests fail for a --disable-wchar_t build.

libstdc++-v3/ChangeLog:

	* testsuite/22_locale/conversions/buffer/1.cc: Check
	_GLIBCXX_USE_WCHAR_T.
	* testsuite/22_locale/conversions/buffer/3.cc: Likewise. Add
	test using char16_t.
	* testsuite/22_locale/conversions/string/1.cc: Check
	_GLIBCXX_USE_WCHAR_T.
	* testsuite/27_io/filesystem/path/generic/generic_string.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/modifiers/make_preferred.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/native/alloc.cc: Likewise.
	* testsuite/27_io/filesystem/path/native/string-char8_t.cc:
	Likewise.
	* testsuite/27_io/filesystem/path/native/string.cc: Likewise.
	* testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/generic/generic_string.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/native/alloc.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/native/string-char8_t.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/native/string.cc:
	Likewise.
2021-10-09 00:57:48 +01:00
Jonathan Wakely 29a9de9b40 libstdc++: Replace uses of _GLIBCXX_USE_INT128 in testsuite
Since r12-435 the _GLIBCXX_USE_INT128 macro is never defined, so all
uses of it in the testsuite are wrong. The tests should be checking
__SIZEOF_INT128__ instead.

Also add some tests for an INT_3 type, which were missing.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/numeric_limits/40856.cc: Replace use of
	_GLIBCXX_USE_INT128.
	* testsuite/18_support/numeric_limits/dr559.cc: Likewise.
	* testsuite/18_support/numeric_limits/lowest.cc: Likewise.
	* testsuite/18_support/numeric_limits/max_digits10.cc: Likewise.
	* testsuite/20_util/is_floating_point/value.cc: Likewise.
	* testsuite/20_util/is_integral/value.cc: Likewise.
	* testsuite/20_util/is_signed/value.cc: Likewise.
	* testsuite/20_util/is_unsigned/value.cc: Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-1.cc:
	Likewise.
	* testsuite/20_util/make_signed/requirements/typedefs-2.cc:
	Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs-1.cc:
	Likewise.
	* testsuite/20_util/make_unsigned/requirements/typedefs-2.cc:
	Likewise.
	* testsuite/20_util/type_identity/requirements/typedefs.cc:
	Likewise.
	* testsuite/26_numerics/bit/bit.count/countl_one.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countl_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countr_one.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countr_zero.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/popcount.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/bit_width.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc:
	Likewise.
	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/bit/bit.rotate/rotr.cc:
	* testsuite/util/testsuite_common_types.h:
2021-10-09 00:57:48 +01:00
Jonathan Wakely d87105d697 libstdc++: Access std::pair members without tuple-like helpers
This avoids the tuple-like API for std::pair in the unordered
containers, removing some overly generic code.

The _Select1st projection can figure out the member types of a std::pair
without using decltype(std::get<0>(...)).

We don't need _Select2nd because it's only needed in
_NodeBuilder::_S_build, and that can just access the .second member of
the pair directly. The return type of that function doesn't need to be
deduced by decltype, we can just expose the __node_type typedef of the
node generator.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable_policy.h (_Select1st): Replace use of
	std::get.
	(_Select2nd): Remove.
	(_NodeBuilder::_S_build): Use _NodeGenerator::__node_type
	typedef instead of deducing it. Remove unnecessary piecewise
	construction.
	(_ReuseOrAllocNode): Make __node_type public.
	(_Map_base): Adjust partial specialization to be able to extract
	the mapped_type without using tuple_element.
	(_Map_base::at): Define inline
	* testsuite/23_containers/unordered_map/requirements/53339.cc:
	Remove XFAIL.
	* testsuite/23_containers/unordered_multimap/requirements/53339.cc:
	Likewise.
2021-10-09 00:57:47 +01:00
Jonathan Wakely 64acc43de1 libstdc++: Avoid instantiation of _Hash_node before it's needed
This is a step towards restoring support for incomplete types in
unordered containers (PR 53339).

We do not need to instantiate the node type to get its value_type
member, because we know that the value type is the first template
parameter. We can deduce that template argument using a custom trait and
a partial specialization for _Hash_node. If we wanted to support custom
hash node types we could still use typename _Tp::value_type in the
primary template of that trait, but that seems unnecessary.

The other change needed is to defer a static assert at class scope, so
that it is done when the types are complete. We must have a complete
type in the destructor, so we can do it there instead.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h: Move static assertion to destructor.
	* include/bits/hashtable_policy.h: Deduce value type from node
	type without instantiating it.
2021-10-09 00:57:47 +01:00
Jonathan Wakely e6f6972b5f libstdc++: Detect miscompilation of src/c++11/limits.cc
Add a #error directive to ensure that the definitions are not compiled
as C++17, which would prevent them being emitted.

libstdc++-v3/ChangeLog:

	PR libstdc++/98725
	* src/c++11/limits.cc: Fail if __cpp_inline_variables is
	defined.
2021-10-08 15:51:08 +01:00
Jonathan Wakely a1fc4075fc libstdc++: Reduce header dependencies of <algorithm> in C++20 [PR 92546]
The <bits/ranges_algobase.h> header doesn't need the stream and
streambuf iterators, so don't include the whole of <iterator>.

libstdc++-v3/ChangeLog:

	PR libstdc++/92546
	* include/bits/ranges_algobase.h: Replace <iterator> with a
	subset of the headers it includes.
2021-10-08 15:00:06 +01:00
Jonathan Wakely 82e3a82687 libstdc++: Restore debug checks in uniform container erasure functions
This partially reverts commit 561078480f.

If we avoid all debug mode checks when erasing elements then we fail to
invalidate safe iterators to the removed elements. This reverts the
recent changes in r12-4083 and r12-4233, restoring the debug checking.

libstdc++-v3/ChangeLog:

	* include/experimental/deque (erase, erase_if): Revert changes
	to avoid debug mode overhead.
	* include/experimental/map (erase, erase_if): Likewise.
	* include/experimental/set (erase, erase_if): Likewise.
	* include/experimental/unordered_map (erase, erase_if):
	Likewise.
	* include/experimental/unordered_set (erase, erase_if):
	Likewise.
	* include/experimental/vector (erase, erase_if): Likewise.
	* include/std/deque (erase, erase_if): Likewise.
	* include/std/map (erase, erase_if): Likewise.
	* include/std/set (erase, erase_if): Likewise.
	* include/std/unordered_map (erase, erase_if): Likewise.
	* include/std/unordered_set (erase, erase_if): Likewise.
	* include/std/vector (erase, erase_if): Likewise.
2021-10-08 12:20:25 +01:00
Jonathan Wakely fcc13d6fc3 libstdc++: Implement ostream insertion for chrono::duration
This is a missing piece of the C++20 <chrono> header.

It would be good to move the code into the compiled library, so that we
don't need <sstream> in <chrono>. It could also use spanstream in C++20,
to avoid memory allocations. That can be changed at a later date.

libstdc++-v3/ChangeLog:

	* include/std/chrono (__detail::__units_suffix_misc): New
	helper function.
	(__detail::__units_suffix): Likewise.
	(chrono::operator<<(basic_ostream&, const duration&)): Define.
	* testsuite/20_util/duration/io.cc: New test.
2021-10-08 12:19:19 +01:00
GCC Administrator 50e20ee6e4 Daily bump. 2021-10-08 00:16:28 +00:00
Jonathan Wakely 7f78718b79 libstdc++: Move C++14 <chrono> components to new <bits/chrono.h> header
This moves the "classic" contents of <chrono> to a new header, so that
<future>, <thread> etc. can get use durations and clocks without
calendar types, time zones, and chrono I/O.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/std/chrono (duration, time_point, system_clock)
	(steady_clock, high_resolution_clock, chrono_literals, sys_time)
	(file_clock, file_time): Move to ...
	* include/bits/chrono.h: New file.
	* include/bits/atomic_futex.h: Include new header instead of
	<chrono>.
	* include/bits/atomic_timed_wait.h: Likewise.
	* include/bits/fs_fwd.h: Likewise.
	* include/bits/semaphore_base.h: Likewise.
	* include/bits/this_thread_sleep.h: Likewise.
	* include/bits/unique_lock.h: Likewise.
	* include/experimental/bits/fs_fwd.h: Likewise.
	* include/experimental/chrono: Likewise.
	* include/experimental/io_context: Likewise.
	* include/experimental/netfwd: Likewise.
	* include/experimental/timer: Likewise.
	* include/std/condition_variable: Likewise.
	* include/std/mutex: Likewise.
	* include/std/shared_mutex: Likewise.
2021-10-07 21:12:32 +01:00
Jonathan Wakely 0e90799071 libstdc++: Avoid use of hardware interference non-constant [PR102377]
libstdc++-v3/ChangeLog:

	PR libstdc++/102377
	* include/bits/atomic_wait.h (__waiter_pool_base:_S_align):
	Hardcode to 64 instead of using non-constant constant.
2021-10-07 18:35:16 +01:00
Jonathan Wakely 561078480f libstdc++: Avoid debug checks in uniform container erasure functions
In commit r12-4083 I tried to make the std::erase and std::erase_if
function avoid the unnecessary overhead of safe iterators. It didn't
work, for two reasons. Firstly, for the RB tree containers the
__niter_base function is a no-op (because the iterators aren't
random access) so the safe iterators were still used. Secondly, for the
cases where __niter_base did remove the safe iterator layer, there was
still unnecessary overhead to create a new safe iterator and link it to
the container.

This solves the problem by simply binding a reference to the non-debug
version of the conainer. For normal mode this is a no-op, and for debug
mode it binds a reference to the debug container's base class. That
means the rest of the function operates directly on the non-debug
container, and avoids all checking.

For std::basic_string there's no need to unwrap anything, because we use
std::basic_string directly in debug mode anyway.

libstdc++-v3/ChangeLog:

	* include/bits/erase_if.h (__erase_nodes_if): Remove redundant
	__niter_base calls.
	* include/std/string (erase, erase_if): Likewise.
	* include/std/deque (erase, erase_if): Access non-debug
	container directly.
	* include/std/map (erase, erase_if): Likewise.
	* include/std/set (erase, erase_if): Likewise.
	* include/std/unordered_map (erase, erase_if): Likewise.
	* include/std/unordered_set (erase, erase_if): Likewise.
	* include/std/vector (erase, erase_if): Likewise.
	* include/experimental/deque (erase, erase_if): Likewise.
	* include/experimental/map (erase, erase_if): Likewise.
	* include/experimental/set (erase, erase_if): Likewise.
	* include/experimental/unordered_map (erase, erase_if):
	Likewise.
	* include/experimental/unordered_set (erase, erase_if):
	Likewise.
	* include/experimental/vector (erase, erase_if): Likewise.
2021-10-07 17:52:04 +01:00
GCC Administrator 57c7ec62ee Daily bump. 2021-10-07 00:16:24 +00:00
Jonathan Wakely 881d1689a4 libstdc++: Implement std::move_only_function for C++23 (P0288R9)
libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add new headers.
	* include/Makefile.in: Regenerate.
	* include/std/functional: Include <bits/move_only_function.h>.
	* include/std/version (__cpp_lib_move_only_function): Define.
	* include/bits/mofunc_impl.h: New file.
	* include/bits/move_only_function.h: New file.
	* testsuite/20_util/move_only_function/call.cc: New test.
	* testsuite/20_util/move_only_function/cons.cc: New test.
	* testsuite/20_util/move_only_function/move.cc: New test.
	* testsuite/20_util/move_only_function/version.cc: New test.
2021-10-06 20:12:01 +01:00
GCC Administrator bb6194e0b4 Daily bump. 2021-10-06 00:16:30 +00:00
Jonathan Wakely 1f51e9af7b libstdc++: Ensure std::span and std::string_view are trivially copyable (P2251R1)
The recently approved P2251R1 paper requires these types to be trivially
copyable. They always have been in libstdc++, but add tests to check it.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string_view/requirements/trivially_copyable.cc:
	New test.
	* testsuite/23_containers/span/trivially_copyable.cc: New test.
2021-10-05 16:47:30 +01:00
Jonathan Wakely 6da36b7d0e libstdc++: Simplify constraints for std::any construction
libstdc++-v3/ChangeLog:

	* include/bits/utility.h (__is_in_place_type_v): Define
	variable template to detect in_place_type_t specializations.
	(__is_in_place_type): Replace class template with alias
	template using __is_in_place_type_v.
	* include/std/any (any(T&&)): Check __is_in_place_type first and
	avoid instantiating is_copy_constructible unnecessarily.
2021-10-05 15:56:56 +01:00
Jonathan Wakely 824e085573 libstdc++: Add test for std::cmp_greater
This was omitted from the commit that added these comparisons.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/integer_comparisons/greater.cc: New test.
2021-10-05 15:56:55 +01:00
Jonathan Wakely 313193edfc libstdc++: Improve test for printing volatile pointers
libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc:
	Check result matches non-volatile pointer.
2021-10-05 15:56:55 +01:00
Jonathan Wakely 7646847df7 libstdc++: Fix testcase for newly-implemented C++20 semantics [PR102535]
libstdc++-v3/ChangeLog:

	PR c++/102535
	* testsuite/20_util/is_trivially_constructible/value.cc: Adjust
	expected value for C++20.
2021-10-05 09:35:47 +01:00
Jonathan Wakely 9665c2e768 libstdc++: Add noexcept to some std::function internals
libstdc++-v3/ChangeLog:

	* include/bits/std_function.h (_Any_data::_M_access): Add
	noexcept.
	(_Function_base::_Base_manager::_M_get_pointer): Likewise.
	(_Function_base::_Base_manager::_M_not_empty_function):
	Likewise.
2021-10-05 09:35:47 +01:00
Jonathan Wakely 96955a82f0 libstdc++: Support printing volatile pointers (P1147R1)
To avoid needing to export a new symbol from the library (for now) the
new member function uses __attribute__((always_inline)).

libstdc++-v3/ChangeLog:

	* include/std/ostream (operator<<(const volatile void*)):
	Add new overload, as per P1147R1.
	* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc:
	New test.
2021-10-05 09:35:47 +01:00
Jonathan Wakely 9e136807c5 libstdc++: Update __cpp_lib_adaptor_iterator_pair_constructor value
I started implementing this feature before it was voted into the C++ WP,
and forgot to update the feature test macro after it was approved.

This defines it to the correct value, as specified in the C++23 draft.

libstdc++-v3/ChangeLog:

	* include/bits/stl_queue.h
	(__cpp_lib_adaptor_iterator_pair_constructor): Set to correct
	value.
	* include/bits/stl_stack.h
	(__cpp_lib_adaptor_iterator_pair_constructor): Likewise.
	* include/std/version
	(__cpp_lib_adaptor_iterator_pair_constructor): Likewise.
	* testsuite/23_containers/queue/cons_from_iters.cc: Update
	expected value.
	* testsuite/23_containers/stack/cons_from_iters.cc: Likewise.
2021-10-05 09:35:46 +01:00
GCC Administrator da9c5f7856 Daily bump. 2021-10-05 00:16:29 +00:00