Commit graph

13660 commits

Author SHA1 Message Date
Jonathan Wakely
f1b51f68f8 libstdc++: Make _GLIBCXX_HOSTED respect -ffreestanding [PR103626]
This allows the library to switch to freestanding mode when compiling
with the -ffreestanding flag. This means you don't need a separate
libstdc++ build configured with --disable-hosted-libstdcxx in order to
compile for a freestanding environment.

The testsuite support files cannot be compiled for freestanding, so add
-fno-freestanding to override any -ffreestanding in the test flags.

libstdc++-v3/ChangeLog:

	PR libstdc++/103626
	* acinclude.m4 (GLIBCXX_ENABLE_HOSTED): Define _GLIBCXX_HOSTED
	to __STDC_HOSTED__ for non-freestanding installations.
	* configure: Regenerate.
	* include/Makefile.am (${host_builddir}/c++config.h): Adjust
	grep pattern.
	* include/Makefile.in: Regenerate.
	* testsuite/lib/libstdc++.exp (v3-build_support): Use
	-fno-freestanding.
	* testsuite/libstdc++-abi/abi.exp: Likewise.
2022-10-03 15:43:48 +01:00
Jonathan Wakely
866263a5fe libstdc++: Fix tests broken by C++23 P2266R3 "Simpler implicit move"
In C++23 mode these tests started to FAIL because an rvalue reference
parameter can no longer be bound to an lvalue reference return type. As
confirmed by Ville (who added these tests) the problem overloads are not
intended to be called, and only exist to verify that they don't
interfere with the intended behaviour. This changes the function bodies
to just throw, so that the tests will fail if the function is called.

libstdc++-v3/ChangeLog:

	* testsuite/27_io/basic_ostream/inserters_other/char/6.cc:
	Change body of unused operator<< overload to throw if called.
	* testsuite/27_io/basic_ostream/inserters_other/wchar_t/6.cc:
	Likewise.
2022-10-03 12:45:05 +01:00
François Dumont
4347fea9c2 libstdc++: Fix gdb pretty printers when dealing with std::string
Since revision 33b43b0d8c std::string and other
similar typedef are ambiguous from a gdb point of view because it matches both
std::basic_string<char> and std::__cxx11::basic_string<char> symbols. For those
typedef add a workaround to accept the substitution as long as the same regardless
of __cxx11 namespace.

Also avoid to register printers for types in std::__cxx11::__8:: namespace, there is
no such symbols.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (Printer.add_version): Do not add version
	namespace for __cxx11 symbols.
	(add_one_template_type_printer): Likewise.
	(add_one_type_printer): Likewise.
	(FilteringTypePrinter._recognizer.recognize): Add a workaround for std::string & al
	ambiguous typedef matching both std:: and std::__cxx11:: symbols.
	* testsuite/libstdc++-prettyprinters/cxx17.cc: Remove obsolete
	\#define _GLIBCXX_USE_CXX11_ABI 0.
	* testsuite/libstdc++-prettyprinters/simple.cc: Likewise. Adapt test to accept
	std::__cxx11::list.
	* testsuite/libstdc++-prettyprinters/simple11.cc: Likewise.
	* testsuite/libstdc++-prettyprinters/whatis.cc: Likewise.
	* testsuite/libstdc++-prettyprinters/80276.cc: Likewise and remove xfail for c++20
	and debug mode.
	* testsuite/libstdc++-prettyprinters/libfundts.cc: Likewise.
2022-10-03 07:01:10 +02:00
GCC Administrator
3a221b73d0 Daily bump. 2022-10-01 00:18:00 +00:00
Jonathan Wakely
789ddef1cf libstdc++: Remove <sstream> dependency from std::bitset::to_ulong() test
There's no need to use a stringstream to test the to_ulong() member.
This will allow the test to be used in freestanding mode.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/bitset/access/to_ulong.cc: Construct bitset
	from binary literal instead of using stringstream.
2022-09-30 21:52:02 +01:00
Jonathan Wakely
1c12a3cfdf libstdc++: Optimize operator>> for std::bitset
We can improve performance by using a char buffer instead of
basic_string. The loop bound already means we can't overflow the buffer,
and we don't need to keep writing a null character after every character
written to the buffer.

We could just use basic_string::resize(N) to zero-init the whole string,
then overwrite those chars. But that zero-init of all N chars would be
wasted in the case where we are writing to a bitset<N> with large N, but
only end up extracting one or two chars from the stream.

With this change we just use buffer of uninitialized chars.  For a
small-ish bitset (currently <= 256) we can improve performance further
by using alloca instead of the heap.

libstdc++-v3/ChangeLog:

	* include/std/bitset (operator>>): Use a simple buffer instead
	of std::basic_string.
2022-09-30 21:52:02 +01:00
Jonathan Wakely
4eb46f453c libstdc++: Remove non-standard public members in std::bitset
This makes _M_copy_from_ptr, _M_copy_from_string and _M_copy_to_string
private, and declares operator<< and operator>> as friends.

Also remove the historical _M_copy_from_string and _M_copy_to_string
overloads. Those were used before DR 396 was implemented but are
not needed now. There are no tests or docs describing them, so I don't
think we intend to support them as extensions.

libstdc++-v3/ChangeLog:

	* include/std/bitset (_M_copy_from_ptr, _M_copy_from_string)
	(_M_copy_to_string): Change access to private.
	(_M_copy_from_string(const basic_string&, size_t, size_t)):
	Remove.
	(_M_copy_to_string(const basic_string&)): Remove.
2022-09-30 21:52:02 +01:00
Jonathan Wakely
7069d03ba4 libstdc++: Fix broken dg-prune-output
The new pattern in the dg-prune-output directive doesn't work. Instead
of a messy regex full of leaning toothpicks, just match on the
diagnostic text instead of the header paths.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/bind/ref_neg.cc: Fix dg-prune-output
	directive.
2022-09-30 21:28:34 +01:00
Torbjörn SVENSSON
fe8264bb9b testsuite: Windows paths use \ and not /
libstdc++-v3/ChangeLog:

	* testsuite/20_util/bind/ref_neg.cc: Prune Windows paths too.

Co-Authored-By: Yvan ROUX  <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON  <torbjorn.svensson@foss.st.com>
2022-09-30 18:33:06 +02:00
Arsen Arsenović
57707f38f2 libstdc++: Add missing <bits/stl_algobase.h> include to <bitset>
libstdc++-v3/ChangeLog:

	* include/std/bitset: Include <bits/stl_algobase.h>.
2022-09-30 14:43:19 +01:00
GCC Administrator
bbdcdf5cc7 Daily bump. 2022-09-30 00:17:47 +00:00
François Dumont
13337ea9a1 libstdc++: [_GLIBCXX_INLINE_VERSION] Add gdb pretty print for _GLIBCXX_DEBUG
In _GLIBCXX_DEBUG mode containers are in std::__debug namespace but not template
parameters. In _GLIBCXX_INLINE_VERSION mode most types are in std::__8 namespace but
not std::__debug containers. We need to register specific type printers for this
combination.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (add_one_template_type_printer): Register
	printer for types in std::__debug namespace with template parameters in std::__8
	namespace.
2022-09-29 20:41:37 +02:00
Patrick Palka
9ca1471540 c++: implement __remove_cv, __remove_reference and __remove_cvref
This implements builtins for std::remove_cv, std::remove_reference and
std::remove_cvref using TRAIT_TYPE from the previous patch.

gcc/c-family/ChangeLog:

	* c-common.cc (c_common_reswords): Add __remove_cv,
	__remove_reference and __remove_cvref.
	* c-common.h (enum rid): Add RID_REMOVE_CV, RID_REMOVE_REFERENCE
	and RID_REMOVE_CVREF.

gcc/cp/ChangeLog:

	* constraint.cc (diagnose_trait_expr): Handle CPTK_REMOVE_CV,
	CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF.
	* cp-objcp-common.cc (names_builtin_p): Likewise.
	* cp-tree.h (enum cp_trait_kind): Add CPTK_REMOVE_CV,
	CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF.
	* cxx-pretty-print.cc (pp_cxx_trait): Handle CPTK_REMOVE_CV,
	CPTK_REMOVE_REFERENCE and CPTK_REMOVE_CVREF.
	* parser.cc (cp_keyword_starts_decl_specifier_p): Return true
	for RID_REMOVE_CV, RID_REMOVE_REFERENCE and RID_REMOVE_CVREF.
	(cp_parser_trait): Handle RID_REMOVE_CV, RID_REMOVE_REFERENCE
	and RID_REMOVE_CVREF.
	(cp_parser_simple_type_specifier): Likewise.
	* semantics.cc (finish_trait_type): Likewise.

libstdc++-v3/ChangeLog:

	* include/bits/unique_ptr.h (unique_ptr<_Tp[], _Dp>): Remove
	__remove_cv and use __remove_cv_t instead.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/has-builtin-1.C: Test existence of __remove_cv,
	__remove_reference and __remove_cvref.
	* g++.dg/ext/remove_cv.C: New test.
	* g++.dg/ext/remove_reference.C: New test.
	* g++.dg/ext/remove_cvref.C: New test.
2022-09-29 09:18:40 -04:00
Jonathan Wakely
df7f273650 libstdc++: Guard use of new built-in with __has_builtin
I forgot that non-GCC compilers don't have this built-in yet.

For Clang we could do something like the check below (as described in
P2255), but for now I'm just fixing the regression.

 #if __has_builtin((__reference_binds_to_temporary)
  bool _Dangle = __reference_binds_to_temporary(_Tp, _Res_t)
                 && __and_<is_reference<_Tp>,
                           __not_<is_reference<_Res_t>>,
                           is_convertible<__remove_cvref_t<_Res_t>*,
                                          __remove_cvref_t<_Tp>*>>::value
 #endif

libstdc++-v3/ChangeLog:

	* include/std/type_traits (__is_invocable_impl): Check
	__has_builtin(__reference_converts_from_temporary) before using
	built-in.
2022-09-29 12:47:37 +01:00
GCC Administrator
9e79a25b66 Daily bump. 2022-09-29 00:16:38 +00:00
Jonathan Wakely
d01f112de4 libstdc++: Disable volatile-qualified std::bind for C++20
LWG 2487 added a precondition to std::bind for C++17, making
volatile-qualified uses undefined. We still support it, but with a
deprecated warning.

P1065R2 made it explicitly ill-formed for C++20, so we should no longer
accept it as deprecated. This implements that change.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/evolution.xml: Document std::bind API
	changes.
	* doc/xml/manual/intro.xml: Document LWG 2487 status.
	* doc/xml/manual/using.xml: Clarify default value of
	_GLIBCXX_USE_DEPRECATED.
	* doc/html/*: Regenerate.
	* include/std/functional (_Bind::operator()(Args&&...) volatile)
	(_Bind::operator()(Args&&...) const volatile)
	(_Bind_result::operator()(Args&&...) volatile)
	(_Bind_result::operator()(Args&&...) const volatile): Replace
	with deleted overload for C++20 and later.
	* testsuite/20_util/bind/cv_quals.cc: Check for deprecated
	warnings in C++17.
	* testsuite/20_util/bind/cv_quals_2.cc: Likewise, and check for
	ill-formed in C++20.
2022-09-29 00:33:46 +01:00
Jonathan Wakely
fa9bda3ea4 libstdc++: Make INVOKE<R> refuse to create dangling references [PR70692]
This is the next part of the library changes from P2255R2. This makes
INVOKE<R> ill-formed if converting the INVOKE expression to R would bind
a reference to a temporary object.

The is_invocable_r trait is now false if the invocation would create a
dangling reference. This is done by adding the dangling check to the
__is_invocable_impl partial specialization used for INVOKE<R>
expressions. This change also slightly simplifies the nothrow checking
recently added to that partial specialization.

This change also removes the is_invocable_r checks from the pre-C++17
implementation of std::__invoke_r, because there is no need for it to be
SFINAE-friendly. None of our C++11 and C++14 uses of INVOKE<R> require
those constraints. The std::function constructor needs to check
is_invocable_r, but that's already done explicitly, so we don't need to
recheck when calling __is_invoke_r in std::function::operator(). The
other uses of std::__is_invoke_r do not need to be constrained and can
just be ill-formed if the INVOKE<R> expression is ill-formed.

libstdc++-v3/ChangeLog:

	PR libstdc++/70692
	* include/bits/invoke.h [__cplusplus < 201703] (__invoke_r):
	Remove is_invocable and is_convertible constraints.
	* include/std/type_traits (__is_invocable_impl::_S_conv): Use
	non-deduced context for parameter.
	(__is_invocable_impl::_S_test): Remove _Check_noex template
	parameter and use deduced noexcept value in its place. Add bool
	parameter to detect dangling references.
	(__is_invocable_impl::type): Adjust call to _S_test to avoid
	deducing unnecessary noexcept property..
	(__is_invocable_impl::__nothrow_type): Rename to ...
	(__is_invocable_impl::__nothrow_conv): ... this. Adjust call
	to _S_test to deduce noexcept property.
	* testsuite/20_util/bind/dangling_ref.cc: New test.
	* testsuite/20_util/function/cons/70692.cc: New test.
	* testsuite/20_util/function_objects/invoke/dangling_ref.cc:
	New test.
	* testsuite/20_util/is_invocable/dangling_ref.cc: New test.
	* testsuite/30_threads/packaged_task/cons/dangling_ref.cc:
	New test.
2022-09-29 00:33:36 +01:00
GCC Administrator
1f16a020ac Daily bump. 2022-09-28 00:17:27 +00:00
Jonathan Wakely
3f7eea4411 c++: Make __is_{,nothrow_}convertible SFINAE on access [PR107049]
The is_convertible built-ins should return false if the conversion fails
an access check, not report an error.

	PR c++/107049

gcc/cp/ChangeLog:

	* method.cc (is_convertible_helper): Use access check sentinel.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/is_convertible4.C: New test.
	* g++.dg/ext/is_nothrow_convertible4.C: New test.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/is_convertible/requirements/access.cc: New
	test.
2022-09-27 11:59:53 +01:00
Jonathan Wakely
614e5696d7 libstdc++: Adjust deduction guides for static operator() [PR106651]
Adjust the deduction guides for std::function and std::packaged_task to
work with static call operators. This finishes the implementation of
P1169R4 for C++23.

libstdc++-v3/ChangeLog:

	PR c++/106651
	* include/bits/std_function.h (__function_guide_t): New alias
	template.
	[__cpp_static_call_operator] (__function_guide_static_helper):
	New class template.
	(function): Use __function_guide_t in deduction guide.
	* include/std/future (packaged_task): Use __function_guide_t in
	deduction guide.
	* testsuite/20_util/function/cons/deduction_c++23.cc: New test.
	* testsuite/30_threads/packaged_task/cons/deduction_c++23.cc:
	New test.
2022-09-27 11:59:53 +01:00
GCC Administrator
220c4d8e44 Daily bump. 2022-09-27 00:17:52 +00:00
Jonathan Wakely
03cb9ed8dd libstdc++: Update std::pointer_traits to match new LWG 3545 wording
It was pointed out in recent LWG 3545 discussion that having a
constrained partial specialization of std::pointer_traits can cause
ambiguities with program-defined specializations. For example, the
addition to the testcase has:

template<typename P> requires std::derived_from<P, base_type
struct std::pointer_traits<P>;

This would be ambiguous with the library's own constrained partial
specialization:

template<typename Ptr> requires requires { typename Ptr::element_type; }
struct std::pointer_traits<Ptr>;

Neither specialization is more specialized than the other for a type
that is derived from base_type and also has an element_type member.

The solution is to remove the library's partial specialization, and do
the check for Ptr::element_type in the __ptr_traits_elem helper (which
is what we already do for !__cpp_concepts anyway).

libstdc++-v3/ChangeLog:

	* include/bits/ptr_traits.h (__ptr_traits_elem) [__cpp_concepts]:
	Also define the __ptr_traits_elem class template for the
	concepts case.
	(pointer_traits<Ptr>): Remove constrained partial
	specialization.
	* testsuite/20_util/pointer_traits/lwg3545.cc: Check for
	ambiguitiy with program-defined partial specialization.
2022-09-26 23:47:37 +01:00
Jonathan Wakely
af85ad8917 libstdc++: Use new built-ins for std::is_convertible traits
libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_convertible, is_convertible_v):
	Define using new built-in.
	(is_nothrow_convertible is_nothrow_convertible_v): Likewise.
2022-09-26 23:47:37 +01:00
Jonathan Wakely
6904ed80a2 libstdc++: Add #if around non-C++03 code in std::bitset [PR107037]
libstdc++-v3/ChangeLog:

	PR libstdc++/107037
	* include/std/bitset (_Base_bitset::_M_do_reset): Use
	preprocessor conditional around non-C++03 code.
	* testsuite/20_util/bitset/107037.cc: New test.
2022-09-26 12:00:07 +01:00
GCC Administrator
28a61ecdc1 Daily bump. 2022-09-25 00:18:01 +00:00
Jonathan Wakely
2b667beba6 libstdc++: Simplify detection idiom using concepts
Add a simpler definition of std::__detected_or using concepts.  This
also replaces the __detector::value_t member which should have been using
a reserved name.

Use __detected_or in pointer_traits.

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (allocator_traits::is_always_equal):
	Only instantiate is_empty if needed.
	* include/bits/ptr_traits.h (__ptr_traits_impl::difference_type)
	(__ptr_traits_impl::rebind): Use __detected_or.
	* include/experimental/type_traits (is_same_v): Add a partial
	specialization instead of instantiating the std::is_same class
	template.
	(detected_t): Redefine in terms of detected_or_t.
	(is_detected, is_detected_v): Redefine in terms of detected_t.
	* include/std/type_traits [__cpp_concepts] (__detected_or): Add
	new definition using concepts.
	(__detector::value_t): Rename to __is_detected.
	* testsuite/17_intro/names.cc: Check value_t isn't used.
2022-09-24 15:18:11 +01:00
GCC Administrator
4afaeaab52 Daily bump. 2022-09-24 00:16:37 +00:00
Jonathan Wakely
5924c7d584 libstdc++: Add test for type traits not having friend access
This ensures that the std::is_assignable and std::is_assignable_v
traits are evaluated "in a context unrelated" to the argument types.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/is_assignable/requirements/access.cc:
	New test.
2022-09-23 23:22:37 +01:00
Jonathan Wakely
71c828f845 libstdc++: Fix std::is_nothrow_invocable_r for uncopyable prvalues [PR91456]
This is the last missing piece of PR 91456.

This also removes the only use of the C++11 version of
std::is_nothrow_invocable, which was just renamed to
__is_nothrow_invocable_lib. We can remove that now.

libstdc++-v3/ChangeLog:

	PR libstdc++/91456
	* include/std/type_traits (__is_nothrow_invocable_lib): Remove.
	(__is_invocable_impl::__nothrow_type): New member type which
	checks if the conversion can throw.
	(__is_nt_invocable_impl): Replace class template with alias
	template to __is_nt_invocable_impl::__nothrow_type.
	* testsuite/20_util/is_nothrow_invocable/91456.cc: New test.
	* testsuite/20_util/is_nothrow_convertible/value.cc: Remove
	macro used by value_ext.cc test.
	* testsuite/20_util/is_nothrow_convertible/value_ext.cc: Remove
	test for non-standard __is_nothrow_invocable_lib trait.
2022-09-23 23:22:37 +01:00
Marek Polacek
8a7bcf95a8 c++: Implement __is_{nothrow_,}convertible [PR106784]
To improve compile times, the C++ library could use compiler built-ins
rather than implementing std::is_convertible (and _nothrow) as class
templates.  This patch adds the built-ins.  We already have
__is_constructible and __is_assignable, and the nothrow forms of those.

Microsoft (and clang, for compatibility) also provide an alias called
__is_convertible_to.  I did not add it, but it would be trivial to do
so.

I noticed that our __is_assignable doesn't implement the "Access checks
are performed as if from a context unrelated to either type" requirement,
therefore std::is_assignable / __is_assignable give two different results
here:

  class S {
    operator int();
    friend void g(); // #1
  };

  void
  g ()
  {
    // #1 doesn't matter
    static_assert(std::is_assignable<int&, S>::value, "");
    static_assert(__is_assignable(int&, S), "");
  }

This is not a problem if __is_assignable is not meant to be used by
the users.

This patch doesn't make libstdc++ use the new built-ins, but I had to
rename a class otherwise its name would clash with the new built-in.

	PR c++/106784

gcc/c-family/ChangeLog:

	* c-common.cc (c_common_reswords): Add __is_convertible and
	__is_nothrow_convertible.
	* c-common.h (enum rid): Add RID_IS_CONVERTIBLE and
	RID_IS_NOTHROW_CONVERTIBLE.

gcc/cp/ChangeLog:

	* constraint.cc (diagnose_trait_expr): Handle CPTK_IS_CONVERTIBLE
	and CPTK_IS_NOTHROW_CONVERTIBLE.
	* cp-objcp-common.cc (names_builtin_p): Handle RID_IS_CONVERTIBLE
	RID_IS_NOTHROW_CONVERTIBLE.
	* cp-tree.h (enum cp_trait_kind): Add CPTK_IS_CONVERTIBLE and
	CPTK_IS_NOTHROW_CONVERTIBLE.
	(is_convertible): Declare.
	(is_nothrow_convertible): Likewise.
	* cxx-pretty-print.cc (pp_cxx_trait_expression): Handle
	CPTK_IS_CONVERTIBLE and CPTK_IS_NOTHROW_CONVERTIBLE.
	* method.cc (is_convertible): New.
	(is_nothrow_convertible): Likewise.
	* parser.cc (cp_parser_primary_expression): Handle RID_IS_CONVERTIBLE
	and RID_IS_NOTHROW_CONVERTIBLE.
	(cp_parser_trait_expr): Likewise.
	* semantics.cc (trait_expr_value): Handle CPTK_IS_CONVERTIBLE and
	CPTK_IS_NOTHROW_CONVERTIBLE.
	(finish_trait_expr): Likewise.

libstdc++-v3/ChangeLog:

	* include/std/type_traits: Rename __is_nothrow_convertible to
	__is_nothrow_convertible_lib.
	* testsuite/20_util/is_nothrow_convertible/value_ext.cc: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/ext/has-builtin-1.C: Enhance to test __is_convertible and
	__is_nothrow_convertible.
	* g++.dg/ext/is_convertible1.C: New test.
	* g++.dg/ext/is_convertible2.C: New test.
	* g++.dg/ext/is_nothrow_convertible1.C: New test.
	* g++.dg/ext/is_nothrow_convertible2.C: New test.
2022-09-23 12:12:41 -04:00
Jonathan Wakely
ab98b4c072 libstdc++: Micro-optimizaion for std::bitset stream extraction
Don't bother trying to copy any characters for bitset<0>.

libstdc++-v3/ChangeLog:

	* include/std/bitset (operator>>): Do not copy for N==0.
	* testsuite/20_util/bitset/io/input.cc: Add comment.
2022-09-23 15:10:51 +01:00
Jonathan Wakely
4ceb5bc42d libstdc++: Enable constexpr std::bitset for debug mode
We already disable all debug mode checks for C++11 and later, so we can
easily make everything constexpr. This fixes the FAIL results for the
new tests when using -D_GLIBCXX_DEBUG.

Also fix some other tests failing with non-default test flags.

libstdc++-v3/ChangeLog:

	* include/debug/bitset (__debug::bitset): Add constexpr to all
	member functions.
	(operator&, operator|, operator^): Add inline and constexpr.
	(operator>>, operator<<): Add inline.
	* testsuite/20_util/bitset/access/constexpr.cc: Only check using
	constexpr std::string for the cxx11 ABI.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise.
	* testsuite/20_util/headers/bitset/synopsis.cc: Check constexpr
	for C++23.
2022-09-23 12:53:51 +01:00
Jonathan Wakely
ffb03fa128 libstdc++: Optimize std::bitset<N>::to_string
This makes to_string approximately twice as fast at any optimization
level. Instead of iterating through every bit, jump straight to the next
bit that is set, by using _Find_first and _Find_next.

libstdc++-v3/ChangeLog:

	* include/std/bitset (bitset::_M_copy_to_string): Find set bits
	instead of iterating over individual bits.
2022-09-23 12:53:51 +01:00
GCC Administrator
279c671509 Daily bump. 2022-09-23 00:18:01 +00:00
Jonathan Wakely
9194c13909 libstdc++: Implement constexpr std::bitset for C++23 (P2417R2)
Also add _GLIBCXX_HOSTED checks to simplify making <bitset>
freestanding in the near future.

libstdc++-v3/ChangeLog:

	* include/std/bitset (bitset): Add constexpr for C++23. Guard
	members using std::string with _GLIBCXX_HOSTED.
	* include/std/version (__cpp_lib_constexpr_bitset): Define.
	* testsuite/20_util/bitset/access/constexpr.cc: New test.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: New test.
	* testsuite/20_util/bitset/count/constexpr.cc: New test.
	* testsuite/20_util/bitset/ext/constexpr.cc: New test.
	* testsuite/20_util/bitset/operations/constexpr_c++23.cc: New test.
	* testsuite/20_util/bitset/version.cc: New test.
2022-09-22 15:18:00 +01:00
Jonathan Wakely
4b4b51445f libstdc++: Rearrange tests for <bitset>
In C++03 std::bitset was in the Container clause, but since C++11 it has
been in the Utilties clause. This moves the tests to the 20_util
directory, where most people probably expect to find them.

Also create 'access', 'observers', and 'io' subdirectories and group
some tests under there, rather than having one directory per function
name, and only a single test in that directory.

libstdc++-v3/ChangeLog:

	* testsuite/23_containers/bitset/18604.cc: Moved to...
	* testsuite/20_util/bitset/18604.cc: ...here.
	* testsuite/23_containers/bitset/45713.cc: Moved to...
	* testsuite/20_util/bitset/45713.cc: ...here.
	* testsuite/23_containers/bitset/to_string/dr396.cc: Moved to...
	* testsuite/20_util/bitset/access/dr396.cc: ...here.
	* testsuite/23_containers/bitset/to_string/1.cc: Moved to...
	* testsuite/20_util/bitset/access/to_string.cc: ...here.
	* testsuite/23_containers/bitset/to_ullong/1.cc: Moved to...
	* testsuite/20_util/bitset/access/to_ullong.cc: ...here.
	* testsuite/23_containers/bitset/to_ulong/1.cc: Moved to...
	* testsuite/20_util/bitset/access/to_ulong.cc: ...here.
	* testsuite/23_containers/bitset/cons/1.cc: Moved to...
	* testsuite/20_util/bitset/cons/1.cc: ...here.
	* testsuite/23_containers/bitset/cons/16020.cc: Moved to...
	* testsuite/20_util/bitset/cons/16020.cc: ...here.
	* testsuite/23_containers/bitset/cons/2.cc: Moved to...
	* testsuite/20_util/bitset/cons/2.cc: ...here.
	* testsuite/23_containers/bitset/cons/3.cc: Moved to...
	* testsuite/20_util/bitset/cons/3.cc: ...here.
	* testsuite/23_containers/bitset/cons/38244.cc: Moved to...
	* testsuite/20_util/bitset/cons/38244.cc: ...here.
	* testsuite/23_containers/bitset/cons/50268.cc: Moved to...
	* testsuite/20_util/bitset/cons/50268.cc: ...here.
	* testsuite/23_containers/bitset/cons/6282.cc: Moved to...
	* testsuite/20_util/bitset/cons/6282.cc: ...here.
	* testsuite/23_containers/bitset/cons/constexpr.cc: Moved to...
	* testsuite/20_util/bitset/cons/constexpr.cc: ...here.
	* testsuite/23_containers/bitset/cons/dr1325-1.cc: Moved to...
	* testsuite/20_util/bitset/cons/dr1325-1.cc: ...here.
	* testsuite/23_containers/bitset/cons/dr1325-2.cc: Moved to...
	* testsuite/20_util/bitset/cons/dr1325-2.cc: ...here.
	* testsuite/23_containers/bitset/cons/dr396.cc: Moved to...
	* testsuite/20_util/bitset/cons/dr396.cc: ...here.
	* testsuite/23_containers/bitset/debug/invalidation/1.cc: Moved to...
	* testsuite/20_util/bitset/debug/invalidation/1.cc: ...here.
	* testsuite/23_containers/bitset/ext/15361.cc: Moved to...
	* testsuite/20_util/bitset/ext/15361.cc: ...here.
	* testsuite/23_containers/bitset/hash/1.cc: Moved to...
	* testsuite/20_util/bitset/hash/1.cc: ...here.
	* testsuite/23_containers/bitset/input/1.cc: Moved to...
	* testsuite/20_util/bitset/io/input.cc: ...here.
	* testsuite/23_containers/bitset/count/6124.cc: Moved to...
	* testsuite/20_util/bitset/observers/6124.cc: ...here.
	* testsuite/23_containers/bitset/all/1.cc: Moved to...
	* testsuite/20_util/bitset/observers/all.cc: ...here.
	* testsuite/23_containers/bitset/test/1.cc: Moved to...
	* testsuite/20_util/bitset/observers/test.cc: ...here.
	* testsuite/23_containers/bitset/operations/1.cc: Moved to...
	* testsuite/20_util/bitset/operations/1.cc: ...here.
	* testsuite/23_containers/bitset/operations/13838.cc: Moved to...
	* testsuite/20_util/bitset/operations/13838.cc: ...here.
	* testsuite/23_containers/bitset/operations/2.cc: Moved to...
	* testsuite/20_util/bitset/operations/2.cc: ...here.
	* testsuite/23_containers/bitset/operations/96303.cc: Moved to...
	* testsuite/20_util/bitset/operations/96303.cc: ...here.
	* testsuite/23_containers/bitset/operations/constexpr-2.cc: Moved to...
	* testsuite/20_util/bitset/operations/constexpr-2.cc: ...here.
	* testsuite/23_containers/bitset/operations/constexpr.cc: Moved to...
	* testsuite/20_util/bitset/operations/constexpr.cc: ...here.
	* testsuite/23_containers/bitset/requirements/constexpr_functions.cc: Moved to...
	* testsuite/20_util/bitset/requirements/constexpr_functions.cc: ...here.
	* testsuite/23_containers/bitset/requirements/explicit_instantiation/1.cc: Moved to...
	* testsuite/20_util/bitset/requirements/explicit_instantiation/1.cc: ...here.
	* testsuite/23_containers/bitset/requirements/explicit_instantiation/1_c++0x.cc: Moved to...
	* testsuite/20_util/bitset/requirements/explicit_instantiation/1_c++0x.cc: ...here.
	* testsuite/23_containers/headers/bitset/synopsis.cc: Moved to...
	* testsuite/20_util/headers/bitset/synopsis.cc: ...here.
2022-09-22 14:49:51 +01:00
François Dumont
42630dc056 libstdc++: Remove useless gdb printer registrations
libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py: Remove ptinter registration for non-existing
	types std::__debug::unique_ptr, std::__debug::stack, std::__debug::queue,
	std::__debug::priority_queue.
2022-09-22 06:22:59 +02:00
GCC Administrator
f85847bd40 Daily bump. 2022-09-22 00:19:09 +00:00
Jonathan Wakely
5814816641 libstdc++: Fix accidental duplicate test [PR91456]
It looks like I committed the testcase for std::function twice, instead
of one for std::function and one for std::is_invocable_r. This replaces
the is_invocable_r one with the example from the PR.

libstdc++-v3/ChangeLog:

	PR libstdc++/91456
	* testsuite/20_util/function/91456.cc: Add comment with PR
	number.
	* testsuite/20_util/is_invocable/91456.cc: Likewise. Replace
	std::function checks with std::is_invocable_r checks.
2022-09-21 15:01:37 +01:00
Jonathan Wakely
16fe325a43 libstdc++: Remove main() from some compile-only tests
libstdc++-v3/ChangeLog:

	* testsuite/17_intro/headers/c++1998/all_attributes.cc: Remove
	unnecessary main function.
	* testsuite/17_intro/headers/c++2011/all_attributes.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2014/all_attributes.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2017/all_attributes.cc:
	Likewise.
	* testsuite/17_intro/headers/c++2020/all_attributes.cc:
	Likewise.
2022-09-21 15:01:28 +01:00
Jonathan Wakely
980aa91e9c libstdc++: Update <memory> synopsis test for C++11 and later
libstdc++-v3/ChangeLog:

	* testsuite/20_util/headers/memory/synopsis.cc: Add declarations
	from C++11 and later.
2022-09-21 15:01:28 +01:00
Jonathan Wakely
9c23fe08c1 libstdc++: Remove trailing whitespace in documentation sources
libstdc++-v3/ChangeLog:

	* doc/xml/manual/documentation_hacking.xml: Remove trailing
	whitespace.
	* doc/xml/manual/policy_data_structures.xml: Likewise.
2022-09-21 08:44:22 +01:00
Jonathan Wakely
cb29396e67 libstdc++: Add _Exit to <stdlib.h> for freestanding
When I added std::_Exit to the freestanding declarations in <cstdlib> I
should also have added it to <stdlib.h>.

libstdc++-v3/ChangeLog:

	* include/c_compatibility/stdlib.h [!_GLIBCXX_HOSTED]: Add
	using-declaration for _Exit.
2022-09-21 08:44:21 +01:00
Jonathan Wakely
d784c5cfe6 libstdc++: Qualify std::abort() in test
This test includes <cstdlib> so should use std::abort not ::abort.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/uncaught_exception/14026.cc: Qualify
	call to std::abort.
2022-09-21 08:44:21 +01:00
Jonathan Wakely
26cb69f8b4 libstdc++: Add <initializer_list> to ranges_base.h header
The header should be included explicitly to use std::initializer_list.
With the upcoming changes to make <ranges> available for freestanding
this becomes an error, because <initializer_list> is no longer provided
by any of the other headers involved here.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h: Include <initializer_list>.
2022-09-21 08:42:00 +01:00
GCC Administrator
5e4f5c25d6 Daily bump. 2022-09-21 00:19:14 +00:00
Jonathan Wakely
5ed0c11ec2 libstdc++: Fix typo in <cstdlib> for freestanding
libstdc++-v3/ChangeLog:

	* include/c_global/cstdlib [!_GLIBCXX_HOSTED] (quick_exit): Fix
	missing space.
2022-09-20 13:21:36 +01:00
GCC Administrator
7ee0fa100f Daily bump. 2022-09-17 00:17:20 +00:00
Jonathan Wakely
cf0fded5d8 libstdc++: Add preprocessor conditions for freestanding [PR106953]
This adds checks for _GLIBCXX_HOSTED to a number of headers which are
not currently installed for freestanding, but need to be for P1642R11
support. For example, <iterator> needs to be installed for C++23
freestanding mode, but without stream iterators and streambuf iterators.
Similarly, <memory> needs to be installed, but without std::allocator
and std::shared_ptr. This change disables the non-freestanding parts of
those headers.

libstdc++-v3/ChangeLog:

	PR libstdc++/106953
	* include/backward/auto_ptr.h [!_GLIBCXX_HOSTED]: Do not define
	shared_ptr members.
	* include/bits/alloc_traits.h [!_GLIBCXX_HOSTED]: Do not declare
	std::allocator_traits<std::allocator<T>> specializations for
	freestanding.
	* include/bits/memoryfwd.h [!_GLIBCXX_HOSTED] (allocator): Do
	not declare for freestanding.
	* include/bits/stl_algo.h [!_GLIBCXX_HOSTED] (stable_partition):
	Do not define for freestanding.
	[!_GLIBCXX_HOSTED] (merge, stable_sort): Do not use temporary
	buffers for freestanding.
	* include/bits/stl_algobase.h [!_GLIBCXX_HOSTED]: Do not declare
	streambuf iterators and overloaded algorithms using them.
	* include/bits/stl_uninitialized.h [!_GLIBCXX_HOSTED]: Do not
	define specialized overloads for std::allocator.
	* include/bits/unique_ptr.h [!_GLIBCXX_HOSTED] (make_unique)
	(make_unique_for_overwrite, operator<<): Do not define for
	freestanding.
	* include/c_global/cstdlib [!_GLIBCXX_HOSTED] (_Exit): Declare.
	Use _GLIBCXX_NOTHROW instead of throw().
	* include/debug/assertions.h [!_GLIBCXX_HOSTED]: Ignore
	_GLIBCXX_DEBUG for freestanding.
	* include/debug/debug.h [!_GLIBCXX_DEBUG]: Likewise.
	* include/std/bit [!_GLIBCXX_HOSTED]: Do not use the custom
	__int_traits if <ext/numeric_traits.h> is available.
	* include/std/functional [!_GLIBCXX_HOSTED]: Do not include
	headers that aren't valid for freestanding.
	(boyer_moore_searcher, boyer_moore_horspool_searcher): Do not
	define for freestanding.
	* include/std/iterator [!_GLIBCXX_HOSTED]: Do not include
	headers that aren't valid for freestanding.
	* include/std/memory [!_GLIBCXX_HOSTED]: Likewise.
	* include/std/ranges [!_GLIBCXX_HOSTED] (istream_view): Do not
	define for freestanding.
	(views::__detail::__is_basic_string_view) [!_GLIBCXX_HOSTED]:
	Do not define partial specialization for freestanding.
2022-09-16 21:47:19 +01:00
Jonathan Wakely
7f4c37099a libstdc++: Move allocator-related helpers to <bits/alloc_traits.h>
The __alloc_swap and __shrink_to_fit_aux helpers are not specific to
std::allocator, so don't belong in <bits/allocator.h>. This also
simplifies enabling <memory> for freestanding, as now we can just omit
the whole of <bits/allocator.h> for freestanding.

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (__alloc_swap)
	(__shrink_to_fit_aux): Move here, from ...
	* include/bits/allocator.h: ... here.
	* include/ext/alloc_traits.h: Do not include allocator.h.
2022-09-16 21:35:43 +01:00