Commit Graph

643 Commits

Author SHA1 Message Date
Jonathan Wakely 74d14778e7 libstdc++: Define std::__is_constant_evaluated() for internal use
This adds std::__is_constant_evaluated() as a C++11 wrapper for
__builtin_is_constant_evaluated, but just returning false if the
built-in isn't supported by the compiler. This allows us to use it
throughout the library without checking __has_builtin every time.

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

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

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in (PREDEFINED): Change macro name.
	* include/bits/allocator.h (allocate, deallocate): Use
	std::__is_constant_evaluated() unconditionally, instead of
	checking whether std::is_constant_evaluated() (or the built-in)
	can be used.
	* include/bits/basic_string.h: Check new macro. call
	std::is_constant_evaluated() directly in C++20-only code that is
	guarded by a suitable macro.
	* include/bits/basic_string.tcc: Likewise.
	* include/bits/c++config (__is_constant_evaluated): Define.
	(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Replace with ...
	(_GLIBCXX_HAVE_IS_CONSTANT_EVALUATED): New macro.
	* include/bits/char_traits.h (char_traits): Replace conditional
	calls to std::is_constant_evaluated with unconditional calls to
	std::__is_constant_evaluated.
	* include/bits/cow_string.h: Use new macro.
	* include/bits/ranges_algobase.h (__copy_or_move): Replace
	conditional calls to std::is_constant_evaluated with unconditional
	calls to std::__is_constant_evaluated.
	(__copy_or_move_backward, __fill_n_fn): Likewise.
	* include/bits/ranges_cmp.h (ranges::less): Likewise.
	* include/bits/stl_algobase.h (lexicographical_compare_three_way):
	Likewise.
	* include/bits/stl_bvector.h: Call std::is_constant_evaluated
	directly in C++20-only code that is guarded by a suitable macro.
	* include/bits/stl_construct.h (_Construct, _Destroy, _Destroy_n):
	Replace is_constant_evaluated with __is_constant_evaluated.
	* include/bits/stl_function.h (greater, less, greater_equal)
	(less_equal): Replace __builtin_is_constant_evaluated and
	__builtin_constant_p with __is_constant_evaluated.
	* include/bits/stl_vector.h: Call std::is_constant_evaluated()
	in C++20-only code.
	* include/debug/helper_functions.h (__check_singular): Use
	__is_constant_evaluated instead of built-in, or remove check
	entirely.
	* include/std/array (operator<=>): Use __is_constant_evaluated
	unconditionally.
	* include/std/bit (__bit_ceil): Likewise.
	* include/std/type_traits (is_constant_evaluated): Define using
	'if consteval' if possible.
	* include/std/version: Use new macro.
	* libsupc++/compare: Use __is_constant_evaluated instead of
	__builtin_is_constant_evaluated.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error lines.
2021-12-01 15:00:33 +00:00
Jonathan Wakely 054bf99841 libstdc++: Fix std::type_info::before for ARM [PR103240]
The r179236 fix for std::type_info::operator== should also have been
applied to std::type_info::before. Otherwise two distinct types can
compare equivalent due to using a string comparison, when they should do
a pointer comparison.

libstdc++-v3/ChangeLog:

	PR libstdc++/103240
	* libsupc++/tinfo2.cc (type_info::before): Use unadjusted name
	to check for the '*' prefix.
	* testsuite/util/testsuite_shared.cc: Add type_info object for
	use in new test.
	* testsuite/18_support/type_info/103240.cc: New test.
2021-11-17 17:21:24 +00:00
Jonathan Wakely f4130a3eb5 libstdc++: Deprecate std::unexpected and handler functions
These functions have been deprecated since C++11, and were removed in
C++17. The proposal P0323 wants to reuse the name std::unexpected for a
class template, so we will need to stop defining the current function
for C++23 anyway.

This marks them as deprecated for C++11 and up, to warn users they won't
continue to be available. It disables them for C++17 and up, unless the
_GLIBCXX_USE_DEPRECATED macro is defined.

The <unwind-cxx.h> header uses std::unexpected_handler in the public
API, but since that type is the same as std::terminate_handler we can
just use that instead, to avoid warnings about it being deprecated.

libstdc++-v3/ChangeLog:

	* doc/xml/manual/evolution.xml: Document deprecations.
	* doc/html/*: Regenerate.
	* libsupc++/exception (unexpected_handler, unexpected)
	(get_unexpected, set_unexpected): Add deprecated attribute.
	Do not define without _GLIBCXX_USE_DEPRECATED for C++17 and up.
	* libsupc++/eh_personality.cc (PERSONALITY_FUNCTION): Disable
	deprecated warnings.
	* libsupc++/eh_ptr.cc (std::rethrow_exception): Likewise.
	* libsupc++/eh_terminate.cc: Likewise.
	* libsupc++/eh_throw.cc (__cxa_init_primary_exception):
	Likewise.
	* libsupc++/unwind-cxx.h (struct __cxa_exception): Use
	terminate_handler instead of unexpected_handler.
	(struct __cxa_dependent_exception): Likewise.
	(__unexpected): Likewise.
	* testsuite/18_support/headers/exception/synopsis.cc: Add
	dg-warning for deprecated warning.
	* testsuite/18_support/exception_ptr/60612-unexpected.cc:
	Disable deprecated warnings.
	* testsuite/18_support/set_unexpected.cc: Likewise.
	* testsuite/18_support/unexpected_handler.cc: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/lambda/lambda-eh2.C: Add dg-warning for new
	deprecation warnings.
	* g++.dg/cpp0x/noexcept06.C: Likewise.
	* g++.dg/cpp0x/noexcept07.C: Likewise.
	* g++.dg/eh/forced3.C: Likewise.
	* g++.dg/eh/unexpected1.C: Likewise.
	* g++.old-deja/g++.eh/spec1.C: Likewise.
	* g++.old-deja/g++.eh/spec2.C: Likewise.
	* g++.old-deja/g++.eh/spec3.C: Likewise.
	* g++.old-deja/g++.eh/spec4.C: Likewise.
	* g++.old-deja/g++.mike/eh33.C: Likewise.
	* g++.old-deja/g++.mike/eh34.C: Likewise.
	* g++.old-deja/g++.mike/eh50.C: Likewise.
	* g++.old-deja/g++.mike/eh51.C: Likewise.
2021-11-04 20:53:29 +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
Jason Merrill 76b75018b3 c++: implement C++17 hardware interference size
The last missing piece of the C++17 standard library is the hardware
intereference size constants.  Much of the delay in implementing these has
been due to uncertainty about what the right values are, and even whether
there is a single constant value that is suitable; the destructive
interference size is intended to be used in structure layout, so program
ABIs will depend on it.

In principle, both of these values should be the same as the target's L1
cache line size.  When compiling for a generic target that is intended to
support a range of target CPUs with different cache line sizes, the
constructive size should probably be the minimum size, and the destructive
size the maximum, unless you are constrained by ABI compatibility with
previous code.

From discussion on gcc-patches, I've come to the conclusion that the
solution to the difficulty of choosing stable values is to give up on it,
and instead encourage only uses where ABI stability is unimportant: in
particular, uses where the ABI is shared at most between translation units
built at the same time with the same flags.

To that end, I've added a warning for any use of the constant value of
std::hardware_destructive_interference_size in a header or module export.
Appropriate uses within a project can disable the warning.

A previous iteration of this patch included an -finterference-tune flag to
make the value vary with -mtune; this iteration makes that the default
behavior, which should be appropriate for all reasonable uses of the
variable.  The previous default of "stable-ish" seems to me likely to have
been more of an attractive nuisance; since we can't promise actual
stability, we should instead make proper uses more convenient.

JF Bastien's implementation proposal is summarized at
https://github.com/itanium-cxx-abi/cxx-abi/issues/74

I implement this by adding new --params for the two sizes.  Targets can
override these values in targetm.target_option.override() to support a range
of values for the generic target; otherwise, both will default to the L1
cache line size.

64 bytes still seems correct for all x86.

I'm not sure why he proposed 64/64 for generic 32-bit ARM, since the Cortex
A9 has a 32-byte cache line, so I'd think 32/64 would make more sense.

He proposed 64/128 for generic AArch64, but since the A64FX now has a 256B
cache line, I've changed that to 64/256.

Other arch maintainers are invited to set ranges for their generic targets
if that seems better than using the default cache line size for both values.

With the above choice to reject stability as a goal, getting these values
"right" is now just a matter of what we want the default optimization to be,
and we can feel free to adjust them as CPUs with different cache lines
become more and less common.

gcc/ChangeLog:

	* params.opt: Add destructive-interference-size and
	constructive-interference-size.
	* doc/invoke.texi: Document them.
	* config/aarch64/aarch64.c (aarch64_override_options_internal):
	Set them.
	* config/arm/arm.c (arm_option_override): Set them.
	* config/i386/i386-options.c (ix86_option_override_internal):
	Set them.

gcc/c-family/ChangeLog:

	* c.opt: Add -Winterference-size.
	* c-cppbuiltin.c (cpp_atomic_builtins): Add __GCC_DESTRUCTIVE_SIZE
	and __GCC_CONSTRUCTIVE_SIZE.

gcc/cp/ChangeLog:

	* constexpr.c (maybe_warn_about_constant_value):
	Complain about std::hardware_destructive_interference_size.
	(cxx_eval_constant_expression): Call it.
	* decl.c (cxx_init_decl_processing): Check
	--param *-interference-size values.

libstdc++-v3/ChangeLog:

	* include/std/version: Define __cpp_lib_hardware_interference_size.
	* libsupc++/new: Define hardware interference size variables.

gcc/testsuite/ChangeLog:

	* g++.dg/warn/Winterference.H: New file.
	* g++.dg/warn/Winterference.C: New test.
	* g++.target/aarch64/interference.C: New test.
	* g++.target/arm/interference.C: New test.
	* g++.target/i386/interference.C: New test.
2021-09-13 12:28:06 -04:00
Jonathan Wakely da6ce35106 libstdc++: Use __builtin_expect in __dynamic_cast
The null pointer check is never needed for correct code, only to
gracefully handle undefined cases. Add __builtin_expect to be sure that
we don't pessimize the valid uses.

libstdc++-v3/ChangeLog:

	* libsupc++/dyncast.cc (__dynamic_cast): Add __builtin_expect to
	precondition check.
2021-08-23 14:45:00 +01:00
Jonathan Wakely c2a984a357 libstdc++: Also move the [[nodiscard]] attributes in <compare>
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* libsupc++/compare (compare_three_way, strong_order)
	(weak_order, partial_order, compare_strong_order_fallback)
	(compare_weak_order_fallback, compare_partial_order_fallback):
	Move nodiscard attributes to correct location.
2021-08-06 13:43:26 +01:00
Jonathan Wakely 8dec72aeb5 libstdc++: Add [[nodiscard]] to <compare>
This adds the [[nodiscard]] attribute to all conversion operators,
comparison operators, call operators and non-member functions in
<compare>. Nothing in this header except constructors has side effects.

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

libstdc++-v3/ChangeLog:

	* libsupc++/compare (partial_ordering, weak_ordering)
	(strong_ordering, is_eq, is_neq, is_lt, is_lteq, is_gt, is_gteq)
	(compare_three_way, strong_order, weak_order, partial_order)
	(compare_strong_order_fallback, compare_weak_order_fallback)
	(compare_partial_order_fallback, __detail::__synth3way): Add
	nodiscard attribute.
	* testsuite/18_support/comparisons/categories/zero_neg.cc: Add
	-Wno-unused-result to options.
2021-08-05 15:16:58 +01:00
Jonathan Wakely f2ce64b53f libstdc++: Improvements to Doxygen markup
This attempst to improve the doxygen output to work around what seems to
be some bugs in doxygen (issues 8635 and 8638).

The @addtogroup command doesn't work for entities inside a nested
namespace (see 8635) so we need to close and reopen groups on entering
and elaving nested namespaces. This fixes the problem that
chrono::duration and chrono::time_point were not documented in the
"Time" documentation group. I am unable to make the path classes appear
as part of their relevant groups (File System and Filesystem TS), nor
the contents of <exception> or <system_error>. I have made some minor
improvements to the docs for those types, including starting to address
PR 97001 by adding @since to the doxygen comments.

This change also excludes the <experimental/bits/net.h> header from
Doxygen processing, so we don't get an unwanted "Networking-ts" group
in the documentation.

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

libstdc++-v3/ChangeLog:

	* doc/doxygen/doxygroups.cc: Fix docs for std::literals.
	* doc/doxygen/user.cfg.in: Exclude the Networking TS header.
	Add some more predefined macros.
	* include/bits/fs_fwd.h: Move @addtogroup commands inside
	namespaces. Add better documentation.
	* include/bits/fs_path.h: Likewise.
	* include/experimental/bits/fs_fwd.h: Likewise.
	* include/experimental/bits/fs_path.h: Likewise.
	* include/ext/throw_allocator.h: Fix typo and improve docs.
	* include/std/chrono: Move @addtogroup commands.
	* include/std/system_error: Move @addtogroup commands.
	* libsupc++/exception: Improve documentation.
	* libsupc++/exception.h: Add @since documentation.
2021-07-01 18:45:48 +01:00
Jonathan Wakely b76a529c09 libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056]
libstdc++-v3/ChangeLog:

	PR libstdc++/101056
	* libsupc++/compare (compare_partial_order_fallback): Add
	constraint using reversed parameter order, as per LWG 3465.
	* testsuite/18_support/comparisons/algorithms/fallback.cc:
	Adjust expected result.
2021-06-14 14:04:45 +01:00
Jonathan Wakely e2c79b968f libstdc++: Change [cmp.alg] assertions to constraints
This moves the same_as<decay_t<_Tp>, decay_t<_Up>> checks from the
[cmp.alg] function bodies into their constraints.

Also add a test for the compare_xxx_order_fallback algorithms.

libstdc++-v3/ChangeLog:

	* libsupc++/compare (__decayed_same_as): New helper concept.
	(strong_order, weak_order, partial_order): Constrain with new
	concept instead of using static_assert.
	(compare_strong_order_fallback, compare_weak_order_fallback)
	(compare_partial_order_fallback): Likewise. Do not deduce return
	types. Remove redundant if-constexpr checks.
	* testsuite/18_support/comparisons/algorithms/fallback.cc: New test.
2021-06-14 14:04:45 +01:00
Jonathan Wakely 6c0c7fc623 libstdc++: Move atomic functions to libsupc++ [PR 96657]
The changes for PR libstdc++/64735 mean that libsupc++ function might
now depend on the __exchange_and_add and __atomic_add functions defined
in config/cpu/*/atomicity.h which is not compiled into libsupc++. This
causes a link failure for some targets when trying to use libsupc++
without the rest of libstdc++.

This patch simply moves the definitions of those functions into
libsupc++ so that they are available there.

libstdc++-v3/ChangeLog:

	PR libstdc++/96657
	* libsupc++/Makefile.am: Add atomicity.cc here.
	* src/c++98/Makefile.am: Remove it from here.
	* libsupc++/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* testsuite/18_support/exception_ptr/96657.cc: New test.
2021-04-15 16:56:44 +01:00
Jonathan Wakely f0b883464c libstdc++: Fix doxygen markup for group close commands
A change in Doxygen 1.8.16 means that "// @}" is no longer recognized by
Doxygen, so doesn't close a @{ group. A "///" comment needs to be used.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h: Fix doxygen group close.
	* include/bits/basic_ios.h: Likewise.
	* include/bits/forward_list.h: Likewise.
	* include/bits/fs_dir.h: Likewise.
	* include/bits/fs_ops.h: Likewise.
	* include/bits/fs_path.h: Likewise.
	* include/bits/functional_hash.h: Likewise.
	* include/bits/gslice.h: Likewise.
	* include/bits/gslice_array.h: Likewise.
	* include/bits/hashtable_policy.h: Likewise.
	* include/bits/indirect_array.h: Likewise.
	* include/bits/locale_classes.h: Likewise.
	* include/bits/locale_facets.h: Likewise.
	* include/bits/locale_facets_nonio.h: Likewise.
	* include/bits/mask_array.h: Likewise.
	* include/bits/refwrap.h: Likewise.
	* include/bits/regex.h: Likewise.
	* include/bits/regex_automaton.h: Likewise.
	* include/bits/regex_compiler.h: Likewise.
	* include/bits/regex_constants.h: Likewise.
	* include/bits/regex_error.h: Likewise.
	* include/bits/regex_executor.h: Likewise.
	* include/bits/regex_scanner.h: Likewise.
	* include/bits/shared_ptr.h: Likewise.
	* include/bits/shared_ptr_atomic.h: Likewise.
	* include/bits/shared_ptr_base.h: Likewise.
	* include/bits/slice_array.h: Likewise.
	* include/bits/specfun.h: Likewise.
	* include/bits/std_function.h: Likewise.
	* include/bits/std_mutex.h: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_iterator.h: Likewise.
	* include/bits/stl_iterator_base_types.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_numeric.h: Likewise.
	* include/bits/stl_pair.h: Likewise.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_uninitialized.h: Likewise.
	* include/bits/stream_iterator.h: Likewise.
	* include/bits/streambuf_iterator.h: Likewise.
	* include/bits/unique_ptr.h: Likewise.
	* include/bits/unordered_map.h: Likewise.
	* include/bits/unordered_set.h: Likewise.
	* include/decimal/decimal: Likewise.
	* include/experimental/any: Likewise.
	* include/experimental/array: Likewise.
	* include/experimental/bits/fs_dir.h: Likewise.
	* include/experimental/bits/fs_fwd.h: Likewise.
	* include/experimental/bits/fs_ops.h: Likewise.
	* include/experimental/bits/fs_path.h: Likewise.
	* include/experimental/buffer: Likewise.
	* include/experimental/internet: Likewise.
	* include/experimental/optional: Likewise.
	* include/experimental/propagate_const: Likewise.
	* include/experimental/socket: Likewise.
	* include/ext/pb_ds/assoc_container.hpp: Likewise.
	* include/ext/pb_ds/detail/priority_queue_base_dispatch.hpp:
	Likewise.
	* include/ext/pb_ds/detail/tree_policy/node_metadata_selector.hpp: Likewise.
	* include/ext/pb_ds/detail/trie_policy/node_metadata_selector.hpp: Likewise.
	* include/ext/pb_ds/detail/types_traits.hpp: Likewise.
	* include/ext/pb_ds/exception.hpp: Likewise.
	* include/ext/pb_ds/priority_queue.hpp: Likewise.
	* include/ext/pb_ds/tag_and_trait.hpp: Likewise.
	* include/ext/random: Likewise.
	* include/std/any: Likewise.
	* include/std/atomic: Likewise.
	* include/std/bitset: Likewise.
	* include/std/chrono: Likewise.
	* include/std/complex: Likewise.
	* include/std/condition_variable: Likewise.
	* include/std/fstream: Likewise.
	* include/std/future: Likewise.
	* include/std/iostream: Likewise.
	* include/std/istream: Likewise.
	* include/std/mutex: Likewise.
	* include/std/numeric: Likewise.
	* include/std/ostream: Likewise.
	* include/std/ratio: Likewise.
	* include/std/shared_mutex: Likewise.
	* include/std/stdexcept: Likewise.
	* include/std/streambuf: Likewise.
	* include/std/system_error: Likewise.
	* include/std/thread: Likewise.
	* include/std/valarray: Likewise.
	* include/std/variant: Likewise.
	* include/tr1/cmath: Likewise.
	* include/tr1/regex: Likewise.
	* include/tr2/dynamic_bitset: Likewise.
	* libsupc++/atomic_lockfree_defines.h: Likewise.
	* libsupc++/exception: Likewise.
	* libsupc++/exception.h: Likewise.
	* libsupc++/exception_ptr.h: Likewise.
	* libsupc++/nested_exception.h: Likewise.

libstdc++-v3/ChangeLog:

	* include/tr1/regex:
2021-04-06 16:43:24 +01:00
Jonathan Wakely 15d649f79d libstdc++: Declare malloc for freestanding
For a target with none of aligned_alloc, memalign etc. we defined our
own aligned_alloc using malloc, so we need a declaration of malloc. As
in libsupc++/new_op.cc we need to declare it ourselves for freestanding
environments.

libstdc++-v3/ChangeLog:

	* libsupc++/new_opa.cc [!_GLIBCXX_HOSTED]: Declare malloc.
2021-03-25 18:25:40 +00:00
Jonathan Wakely dddd011113 libstdc++: Implement LWG 3530 for concept-constrained comparisons
The proposed resolution for this library issue simplifies the
constraints for compare_three_way, ranges::equal_to, ranges::less etc.
so that they do not work with types which are convertible to pointers
but which fail to meet the usual syntactic requirements for the
comparisons.

This affects the example in PR libstdc++/93628 but doesn't fix the
problem described in that report.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_cmp.h (__eq_builtin_ptr_cmp): Remove.
	(ranges::equal_to, ranges::not_equal_to): Do not constrain
	with __eq_builtin_ptr_cmp.
	(ranges::less, ranges::greater, ranges::less_equal)
	(ranges::greater_equal): Do not constrain with
	__less_builtin_ptr_cmp.
	* libsupc++/compare (compare_three_way): Do not constrain with
	__3way_builtin_ptr_cmp.
	* testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc: Moved to...
	* testsuite/18_support/comparisons/object/lwg3530.cc: ...here.
	* testsuite/20_util/function_objects/range.cmp/lwg3530.cc: New test.
2021-03-10 15:27:06 +00:00
Martin Sebor 6d134ca4b9 PR c++/99074 - crash in dynamic_cast<>() on null pointer
libstdc++-v3/ChangeLog:

	PR c++/99074
	* libsupc++/dyncast.cc (__dynamic_cast): Return null when
	first argument is null.

gcc/testsuite/ChangeLog:

	PR c++/99074
	* g++.dg/warn/Wnonnull11.C: New test.
2021-02-23 14:14:20 -07:00
Jonathan Wakely bc0f7db7eb libstdc++: Fix versioned namespace build
The recent changes to define various std::exception_ptr functions inline
included a change so that the definitions of those functions would be
omitted for the ABI unstable gnu-versioned-namespace configuration. That
change was incorrect, because the existing functions that are gated by
the _GLIBCXX_EH_PTR_COMPAT macro are always needed even for the
versioned namespace.

This change introduces a new macro to control whether operator== is
defined as deleted or not, distinct from the existing macro. The new
macro is not defined for versioned namespace builds, but the old macro
still is.

libstdc++-v3/ChangeLog:

	* libsupc++/eh_ptr.cc (_GLIBCXX_EH_PTR_RELOPS_COMPAT): Define
	new macro.
	* libsupc++/exception_ptr.h (_GLIBCXX_EH_PTR_USED): Check new
	macro instead of _GLIBCXX_EH_PTR_COMPAT.
	(operator==): Likewise.
2021-02-11 17:28:16 +00:00
Jakub Jelinek 99dee82307 Update copyright years. 2021-01-04 10:26:59 +01:00
Jonathan Wakely 7c1e7eed89 libstdc++: Add C++ runtime support for new 128-bit long double format
This adds support for the new __ieee128 long double format on
powerpc64le targets.

Most of the complexity comes from wanting a single libstdc++.so library
that contains the symbols needed by code compiled with both
-mabi=ibmlongdouble and -mabi=ieeelongdouble (and not forgetting
-mlong-double-64 as well!)

In a few places this just requires an extra overload, for example
std::from_chars has to be overloaded for both forms of long double.
That can be done in a single translation unit that defines overloads
for 'long double' and also '__ieee128', so that user code including
<charconv> will be able to link to a definition for either type of long
double. Those are the easy cases.

The difficult parts are (as for the std::string ABI transition) the I/O
and locale facets. In order to be able to write either form of long
double to an ostream such as std::cout we need the locale to contain a
std::num_put facet that can handle both forms. The same approach is
taken as was already done for supporting 64-bit long double and 128-bit
long double: adding extra overloads of do_put to the facet class. On
targets where the new long double code is enabled, the facets that are
registered in the locale at program startup have additional overloads so
that they can work with any long double type. Where this fails to work
is if user code installs its own facet, which will probably not have the
additional overloads and so will only be able to output one or the other
type. In practice the number of users expecting to be able to use their
own locale facets in code using a mix of -mabi=ibmlongdouble and
-mabi=ieeelongdouble is probably close to zero.

libstdc++-v3/ChangeLog:

	* Makefile.in: Regenerate.
	* config.h.in: Regenerate.
	* config/abi/pre/gnu.ver: Make patterns less greedy.
	* config/os/gnu-linux/ldbl-ieee128-extra.ver: New file with patterns
	for IEEE128 long double symbols.
	* configure: Regenerate.
	* configure.ac: Enable alternative 128-bit long double format on
	powerpc64*-*-linux*.
	* doc/Makefile.in: Regenerate.
	* fragment.am: Regenerate.
	* include/Makefile.am: Set _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT.
	* include/Makefile.in: Regenerate.
	* include/bits/c++config: Define inline namespace for new long
	double symbols. Don't define _GLIBCXX_USE_FLOAT128 when it's the
	same type as long double.
	* include/bits/locale_classes.h [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT]
	(locale::_Impl::_M_init_extra_ldbl128): Declare new member function.
	* include/bits/locale_facets.h (_GLIBCXX_NUM_FACETS): Simplify by
	only counting narrow character facets.
	(_GLIBCXX_NUM_CXX11_FACETS): Likewise.
	(_GLIBCXX_NUM_LBDL_ALT128_FACETS): New.
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT] (num_get::__do_get): Define
	vtable placeholder for __ibm128 long double type.
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(num_get::__do_get): Declare vtable placeholder for __ibm128 long
	double type.
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(num_put::__do_put): Likewise.
	* include/bits/locale_facets.tcc
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(num_get::__do_get, num_put::__do_put): Define.
	* include/bits/locale_facets_nonio.h
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(money_get::__do_get): Declare vtable placeholder for __ibm128 long
	double type.
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(money_put::__do_put): Likewise.
	* include/bits/locale_facets_nonio.tcc
	[_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__]
	(money_get::__do_get, money_put::__do_put): Define.
	* include/ext/numeric_traits.h [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT]
	(__numeric_traits<__ibm128>, __numeric_traits<__ieee128>): Define.
	* libsupc++/Makefile.in: Regenerate.
	* po/Makefile.in: Regenerate.
	* python/Makefile.in: Regenerate.
	* src/Makefile.am: Add compatibility-ldbl-alt128.cc and
	compatibility-ldbl-alt128-cxx11.cc sources and recipes for objects.
	* src/Makefile.in: Regenerate.
	* src/c++11/Makefile.in: Regenerate.
	* src/c++11/compatibility-ldbl-alt128-cxx11.cc: New file defining
	symbols using the old 128-bit long double format, for the cxx11 ABI.
	* src/c++11/compatibility-ldbl-alt128.cc: Likewise, for the
	gcc4-compatible ABI.
	* src/c++11/compatibility-ldbl-facets-aliases.h: New header for long
	double compat aliases.
	* src/c++11/cow-locale_init.cc: Add comment.
	* src/c++11/cxx11-locale-inst.cc: Define C and C_is_char
	unconditionally.
	* src/c++11/cxx11-wlocale-inst.cc: Add sanity check. Include
	locale-inst.cc directly, not via cxx11-locale-inst.cc.
	* src/c++11/locale-inst-monetary.h: New header for monetary
	category instantiations.
	* src/c++11/locale-inst-numeric.h: New header for numeric category
	instantiations.
	* src/c++11/locale-inst.cc: Include new headers for monetary,
	numeric, and long double definitions.
	* src/c++11/wlocale-inst.cc: Remove long double compat aliases that
	are defined in new header now.
	* src/c++17/Makefile.am: Use -mabi=ibmlongdouble for
	floating_from_chars.cc.
	* src/c++17/Makefile.in: Regenerate.
	* src/c++17/floating_from_chars.cc (from_chars_impl): Add
	if-constexpr branch for __ieee128.
	(from_chars): Overload for __ieee128.
	* src/c++20/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* src/c++98/locale_init.cc (num_facets): Adjust calculation.
	(locale::_Impl::_Impl(size_t)): Call _M_init_extra_ldbl128.
	* src/c++98/localename.cc (num_facets): Adjust calculation.
	(locale::_Impl::_Impl(const char*, size_t)): Call
	_M_init_extra_ldbl128.
	* src/filesystem/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/util/testsuite_abi.cc: Add new symbol versions.
	Allow new symbols to be added to GLIBCXX_IEEE128_3.4.29 and
	CXXABI_IEEE128_1.3.13 too.
	* testsuite/26_numerics/complex/abi_tag.cc: Add u9__ieee128 to
	regex matching expected symbols.
2020-12-16 23:25:01 +00:00
Jonathan Wakely 0af3930a49 libstdc++: Use 'inline' consistently in std::exception_ptr [PR 97729]
With PR c++/67453 fixed we can rely on the 'used' attribute to emit
inline constructors and destructors in libsupc++/eh_ptr.cc. This means
we don't need to suppress the 'inline' keyword on them in that file, and
don't need to force 'always_inline' on them in other files.

libstdc++-v3/ChangeLog:

	PR libstdc++/97729
	* libsupc++/exception_ptr.h (exception_ptr::exception_ptr())
	(exception_ptr::exception_ptr(const exception_ptr&))
	(exception_ptr::~exception_ptr()): Remove 'always_inline'
	attributes. Use 'inline' unconditionally.
2020-11-09 14:28:38 +00:00
Liu Hao 7fc0f78c3f libsupc++: Make the destructor parameter to `__cxa_thread_atexit()` use the `__thiscall` calling convention for i686-w64-mingw32
The mingw-w64 implementations of `__cxa_thread_atexit()` and `__cxa_atexit()` have been
using `__thiscall` since two years ago. Using the default calling convention (which is
`__cdecl`) causes crashes as explained in PR83562.

Calling conventions have no effect on x86_64-w64-mingw32.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83562
Reference: https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/crt/cxa_thread_atexit.c
Reference: f3e0fbb40c/
Reference: https://github.com/msys2/MINGW-packages/issues/7071
Signed-off-by: Liu Hao <lh_mouse@126.com>

    2020-10-08  Liu Hao  <lh_mouse@126.com>

	libstdc++-v3:
	* libsupc++/cxxabi.h: (__cxa_atexit): mark with _GLIBCXX_CDTOR_CALLABI
	(__cxa_thread_atexit): ditto
	* libsupc++/atexit_thread.cc: (__cxa_atexit): mark with
	_GLIBCXX_CDTOR_CALLABI
	(__cxa_thread_atexit): ditto
	(elt): ditto
2020-11-07 02:50:43 +00:00
Jonathan Wakely 710508c7b1 libstdc++: Fix multiple definitions of std::exception_ptr functions [PR 97729]
This fixes some multiple definition errors caused by the changes for
PR libstdc++/90295. The previous solution for inlining the members of
std::exception_ptr but still exporting them from the library was to
suppress the 'inline' keyword on those functions when compiling
libsupc++/eh_ptr.cc, so they get defined in that file. That produces ODR
violations though, because there are now both inline and non-inline
definitions in the library, due to the use of std::exception_ptr in
other files sucg as src/c++11/future.cc.

The new solution is to define all the relevant members as 'inline'
unconditionally, but use __attribute__((used)) to cause definitions to
be emitted in libsupc++/eh_ptr.cc as before. This doesn't quite work
however, because PR c++/67453 means the attribute is ignored on
constructors and destructors. As a workaround, the old solution
(conditionally inline) is still used for those members, but they are
given the always_inline attribute so that they aren't emitted in
src/c++11/future.o as inline definitions.

libstdc++-v3/ChangeLog:

	PR libstdc++/97729
	* include/std/future (__basic_future::_M_get_result): Use
	nullptr for null pointer constant.
	* libsupc++/eh_ptr.cc (operator==, operator!=): Remove
	definitions.
	* libsupc++/exception_ptr.h (_GLIBCXX_EH_PTR_USED): Define
	macro to conditionally add __attribute__((__used__)).
	(operator==, operator!=, exception_ptr::exception_ptr())
	(exception_ptr::exception_ptr(const exception_ptr&))
	(exception_ptr::~exception_ptr())
	(exception_ptr::operator=(const exception_ptr&))
	(exception_ptr::swap(exception_ptr&)): Always define as
	inline. Add macro to be conditionally "used".
2020-11-05 18:01:25 +00:00
Jonathan Wakely c227d96feb libstdc++: Add comment to nothrow new explaining catch (...)
The decision to not rethrow a __forced_unwind exception is deliberate,
so add a comment explaining it.

libstdc++-v3/ChangeLog:

	* libsupc++/new_opnt.cc (new): Add comment about forced unwind
	exceptions.
2020-10-28 13:19:21 +00:00
Jonathan Wakely 93e9a7bcd5 libstdc++: Fix declarations of memalign etc. for freestanding [PR 97570]
libstdc++-v3/ChangeLog:

	PR libstdc++/97570
	* libsupc++/new_opa.cc: Declare size_t in global namespace.
	Remove unused header.
2020-10-26 12:02:50 +00:00
Martin Sebor 1be51a3a9a PR c++/97201 - ICE in -Warray-bounds writing to result of operator new(0)
gcc/cp/ChangeLog:

	PR c++/97201
	* error.c (dump_type_suffix): Handle both the C and C++ forms of
	zero-length arrays.

libstdc++-v3/ChangeLog:

	PR c++/97201
	* libsupc++/new (operator new): Add attribute alloc_size and malloc.

gcc/testsuite/ChangeLog:

	PR c++/97201
	* g++.dg/warn/Wplacement-new-size-8.C: Adjust expected message.
	* g++.dg/warn/Warray-bounds-10.C: New test.
	* g++.dg/warn/Warray-bounds-11.C: New test.
	* g++.dg/warn/Warray-bounds-12.C: New test.
	* g++.dg/warn/Warray-bounds-13.C: New test.
2020-10-12 09:36:26 -06:00
Jonathan Wakely 23f75da95f libstdc++: Fix non-reserved names in headers
My recent changes to std::exception_ptr moved some members to be inline
in the header but didn't replace the variable names with reserved names.

The "tmp" variable must be fixed. The "other" parameter is actually a
reserved name because of std::allocator<T>::rebind<U>::other but should
be fixed anyway.

There are also some bad uses of "ForwardIterator" in <ranges>.

There's also a "il" parameter in a std::seed_seq constructor in <random>
which is only reserved since C++14.

libstdc++-v3/ChangeLog:

	* include/bits/random.h (seed_seq(initializer_list<T>)): Rename
	parameter to use reserved name.
	* include/bits/ranges_algo.h (shift_left, shift_right): Rename
	template parameters to use reserved name.
	* libsupc++/exception_ptr.h (exception_ptr): Likewise for
	parameters and local variables.
	* testsuite/17_intro/names.cc: Check "il". Do not check "d" and
	"y" in C++20 mode.
2020-10-08 00:05:53 +01:00
Jonathan Wakely 1352ea1925 libstdc++: Inline std::exception_ptr members [PR 90295]
This inlines most members of std::exception_ptr so that all operations
on a null exception_ptr can be optimized away. This benefits code like
std::future and coroutines where an exception_ptr object is present to
cope with exceptional cases, but is usually not used and remains null.

Since those functions were previously non-inline we have to continue to
export them from the library, for objects that were compiled against the
old headers and expect to find definitions in the library.

In order to inline the copy constructor and destructor we need to export
the _M_addref() and _M_release() members that increment/decrement the
reference count when copying/destroying a non-null exception_ptr. The
copy ctor and dtor check for null and don't call _M_addref and
_M_release unless they need to. The checks for null pointers in
_M_addref and _M_release are still needed because old code might call
them without checking for null first. But we can use __builtin_expect to
predict that they are usually called for the non-null case.

libstdc++-v3/ChangeLog:

	PR libstdc++/90295
	* config/abi/pre/gnu.ver (CXXABI_1.3.13): New symbol version.
	(exception_ptr::_M_addref(), exception_ptr::_M_release()):
	Export symbols.
	* libsupc++/eh_ptr.cc (exception_ptr::exception_ptr()):
	Remove out-of-line definition.
	(exception_ptr::exception_ptr(const exception_ptr&)):
	Likewise.
	(exception_ptr::~exception_ptr()): Likewise.
	(exception_ptr::operator=(const exception_ptr&)):
	Likewise.
	(exception_ptr::swap(exception_ptr&)): Likewise.
	(exception_ptr::_M_addref()): Add branch prediction.
	* libsupc++/exception_ptr.h (exception_ptr::operator bool):
	Add noexcept.
	[!_GLIBCXX_EH_PTR_COMPAT] (operator==, operator!=): Define
	inline as hidden friends. Remove declarations at namespace
	scope.
	(exception_ptr::exception_ptr()): Define inline.
	(exception_ptr::exception_ptr(const exception_ptr&)):
	Likewise.
	(exception_ptr::~exception_ptr()): Likewise.
	(exception_ptr::operator=(const exception_ptr&)):
	Likewise.
	(exception_ptr::swap(exception_ptr&)): Likewise.
	* testsuite/util/testsuite_abi.cc: Add CXXABI_1.3.13.
	* testsuite/18_support/exception_ptr/90295.cc: New test.
2020-10-06 17:24:16 +01:00
Jonathan Wakely e6923541fa libstdc++: Use __libc_single_threaded to optimise atomics [PR 96817]
Glibc 2.32 adds a global variable that says whether the process is
single-threaded. We can use this to decide whether to elide atomic
operations, as a more precise and reliable indicator than
__gthread_active_p.

This means that guard variables for statics and reference counting in
shared_ptr can use less expensive, non-atomic ops even in processes that
are linked to libpthread, as long as no threads have been created yet.
It also means that we switch to using atomics if libpthread gets loaded
later via dlopen (this still isn't supported in general, for other
reasons).

We can't use __libc_single_threaded to replace __gthread_active_p
everywhere. If we replaced the uses of __gthread_active_p in std::mutex
then we would elide the pthread_mutex_lock in the code below, but not
the pthread_mutex_unlock:

  std::mutex m;
  m.lock();            // pthread_mutex_lock
  std::thread t([]{}); // __libc_single_threaded = false
  t.join();
  m.unlock();          // pthread_mutex_unlock

We need the lock and unlock to use the same "is threading enabled"
predicate, and similarly for init/destroy pairs for mutexes and
condition variables, so that we don't try to release resources that were
never acquired.

There are other places that could use __libc_single_threaded, such as
_Sp_locker in src/c++11/shared_ptr.cc and locale init functions, but
they can be changed later.

libstdc++-v3/ChangeLog:

	PR libstdc++/96817
	* include/ext/atomicity.h (__gnu_cxx::__is_single_threaded()):
	New function wrapping __libc_single_threaded if available.
	(__exchange_and_add_dispatch, __atomic_add_dispatch): Use it.
	* libsupc++/guard.cc (__cxa_guard_acquire, __cxa_guard_abort)
	(__cxa_guard_release): Likewise.
	* testsuite/18_support/96817.cc: New test.
2020-09-26 20:32:36 +01:00
Jonathan Wakely 473da7e22c libstdc++: Remove redundant -std=gnu++1z flags from makefile
Now that G++ defaults to gnu++17 we don't need special rules for
compiling the C++17 allocation and deallocation functions.

libstdc++-v3/ChangeLog:

	* libsupc++/Makefile.am: Remove redundant -std=gnu++1z flags.
	* libsupc++/Makefile.in: Regenerate.
2020-09-25 12:50:17 +01:00
Christophe Lyon 55bdee9af3 libstdc++-v3/libsupc++/eh_call.cc: Avoid "set but not used" warning
When building with -fno-exceptions, bad_exception_allowed is set but
not used, causing a warning during the build.

This patch adds __attribute__((unused)) to avoid it.

2020-09-11  Torbjörn SVENSSON  <torbjorn.svensson@st.com>
	    Christophe Lyon  <christophe.lyon@linaro.org>

	libstdc++-v3/
	* libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.
2020-09-11 13:00:29 +00:00
Christophe Lyon fb00a9fc39 libstdc++-v3/libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.
When building with -fno-exceptions, __throw_exception_again expands to
nothing, causing a "suggest braces around empty body in an 'if'
statement" warning.

This patch adds braces, like what was done in eh_personality.cc in svn
r193295 (git g:54ba39f599fc2f3d59fd3cd828a301ce9b731a20)

2020-09-11  Torbjörn SVENSSON  <torbjorn.svensson@st.com>
	    Christophe Lyon  <christophe.lyon@linaro.org>

	libstdc++-v3/
	* libsupc++/eh_call.cc: Avoid warning with -fno-exceptions.
2020-09-11 13:00:23 +00:00
Jonathan Wakely 6bdbf0f37b libstdc++: Break header cycle between <new> and <exception>
The <new> and <exception> headers each include each other, which makes
building them as header-units "exciting". The <new> header only needs
the definition of std::exception (in order to derive from it) which is
already in its own header, so just include that.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h: Include <bits/exception_defines.h>
	for definitions of __try, __catch and __throw_exception_again.
	(counted_iterator::operator++(int)): Use __throw_exception_again
	instead of throw.
	* libsupc++/new: Include <bits/exception.h> not <exception>.
	* libsupc++/new_opvnt.cc: Include <bits/exception_defines.h>.
	* testsuite/18_support/destroying_delete.cc: Include
	<type_traits> for std::is_same_v definition.
	* testsuite/20_util/variant/index_type.cc: Qualify size_t.
2020-09-02 13:56:32 +01:00
Jonathan Wakely a2c5150e40 libstdc++: Regenerate makefiles
libstdc++-v3/ChangeLog:

	* doc/Makefile.in: Regenerate.
	* include/Makefile.in: Regenerate.
	* libsupc++/Makefile.in: Regenerate.
	* po/Makefile.in: Regenerate.
	* python/Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
	* src/c++11/Makefile.in: Regenerate.
	* src/c++17/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* src/filesystem/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.
2020-06-23 07:59:40 +01:00
Fangrui Song 1405ed4334 libstdc++: Fix the return type of __cxa_finalize
This should return void according to the Itanium C++ ABI.

2020-05-04  Fangrui Song  <maskray@google.com>

	* libsupc++/cxxabi.h (__cxa_finalize): Fix return type.
2020-05-04 23:07:19 +01:00
Nathan Sidwell e6b31fc717 libstdc++: Avoid negating a size_t [pr 94747]
Although the code here is well formed, it doesn't show intent well.
The reason checkers trigger on this is that it is a cause of real
bugs.  So, negate a ptrdiff_t instead.

	* libsupc++/dyncast.cc (__dynamic_cast): Cast offsetof to
	ptrdiff_t before negation, to show intent more clearly.
2020-05-04 10:08:13 -07:00
Jonathan Wakely 73a0a21d22 libstdc++: Update __cpp_lib_three_way_comparison macro
With P1614R2 fully implemented (except for the <chrono> types which we
don't support at all) we can define the feature test macro to the new
value.

	* include/std/version (__cpp_lib_three_way_comparison): Update value.
	* libsupc++/compare (__cpp_lib_three_way_comparison): Likewise.
2020-04-20 17:50:10 +01:00
Jonathan Wakely e1e9e8d7aa libstdc++: Fix constraints on std::compare_three_way
My "simplification" of std::compare_three_way's constraints in commit
f214ffb336 was incorrect, because
std::three_way_comparable_with imposes additional restrictions beyond
the <=> expression being valid.

	* libsupc++/compare (compare_three_way): Fix constraint so that
	BUILTIN-PTR-THREE-WAY does not require three_way_comparable_with.
	* testsuite/18_support/comparisons/object/builtin-ptr-three-way.cc:
	New test.
2020-04-14 21:59:15 +01:00
Jonathan Wakely 597601aa7a libstdc++: Make comparison category comparisons noexcept (PR 94565)
PR libstdc++/94565
	* libsupc++/compare (__unspec): Add noexcept-specifier to constructor.
	* testsuite/18_support/comparisons/categories/94565.cc: New test.
2020-04-14 11:42:04 +01:00
Jonathan Wakely 3fd1c229ad libstdc++: Implement LWG 3324 for [cmp.alg] function objects (LWG 3324)
LWG 3324 changed the [cmp.alg] types to use std::compare_three_way
instead of the <=> operator, but we were still using the old
specification. In order to make the existing tests pass the N::X type
needs to be equality comparable, so that three_way_comparable is
satisfied and compare_three_way can be used.

As part of this change I noticed that the compare_three_way call
operator was unconditionally noexcept, which is incorrect.

	* libsupc++/compare (compare_three_way): Fix noexcept-specifier.
	(strong_order, weak_order, partial_order): Replace uses of <=> with
	compare_three_way function object (LWG 3324).
	* testsuite/18_support/comparisons/algorithms/partial_order.cc: Add
	equality operator so that X satisfies three_way_comparable.
	* testsuite/18_support/comparisons/algorithms/strong_order.cc:
	Likewise.
	* testsuite/18_support/comparisons/algorithms/weak_order.cc: Likewise.
2020-04-09 22:24:57 +01:00
Jonathan Wakely 20fa41e61f libstdc++: Remove std::type_info::operator!= for C++20
This function can be synthesized by the compiler now.

	* libsupc++/typeinfo (type_info::operator!=): Remove for C++20.
2020-02-20 11:30:19 +00:00
Jonathan Wakely 256f67aa07 libstdc++: Simplify std::three_way_comparable_with (LWG 3360)
This also removes a useless condition that was supposed to be removed by
the P1959R0 changes, but left in when that was implemented.

	* libsupc++/compare (three_way_comparable): Remove always-false check
	that should have been removed with weak_equality (P1959R0).
	(three_way_comparable_with): Likewise. Reorder requirements (LWG 3360).
2020-02-19 21:49:24 +00:00
Jonathan Wakely 0294dc5f4e libstdc++: Simplify std::totally_ordered (LWG 3331)
* include/std/concepts (__detail::__partially_ordered_with): Move here
	from <compare>.
	(totally_ordered, totally_ordered_with): Use __partially_ordered_with
	to simplify definition (LWG 3331).
	* libsupc++/compare (__detail::__partially_ordered_with): Move to
	<concepts>.
2020-02-19 21:40:03 +00:00
Jonathan Wakely c5e1c1d3ab libstdc++: P1964R2 Wording for boolean-testable
This removes the complicated std::boolean concept, as agreed in Prague.

	* include/bits/ranges_algo.h (__find_fn, __find_first_of_fn)
	(__adjacent_find_fn): Cast result of predicate to bool.
	* include/std/concepts (__boolean): Remove.
	(__detail::__boolean_testable_impl, __detail::__boolean_testable): Add
	new helper concepts.
	(__detail::__weakly_eq_cmp_with, totally_ordered, totally_ordered_with)
	(predicate): Use __boolean_testable instead of boolean.
	* libsupc++/compare (__detail::__partially_ordered, _Synth3way):
	Likewise.
2020-02-17 18:22:05 +00:00
Jonathan Wakely 9866abe31e libstdc++ P1956R1 On the names of low-level bit manipulation functions
Implement this change for C++20 that was just approved in Prague.

	P1956R1 On the names of low-level bit manipulation functions
	* include/bits/hashtable_policy.h: Update comment.
	* include/std/bit (__ispow2, __ceil2, __floor2, __log2p1): Rename.
	(ispow2, ceil2, floor2, log2p1): Likewise.
	(__cpp_lib_int_pow2): Add feature test macro.
	* include/std/charconv (__to_chars_len_2): Adjust use of __log2p1.
	* include/std/memory (assume_aligned): Adjust use of ispow2.
	* include/std/version (__cpp_lib_int_pow2): Add.
	* libsupc++/new_opa.cc: Adjust use of __ispow2.
	* src/c++17/memory_resource.cc: Likewise, and for __ceil2 and __log2p1.
	* testsuite/17_intro/freestanding.cc: Adjust use of ispow2.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/ceil2_neg.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil_neg.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/floor2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_floor.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/bit_width.cc: ... here.
	* testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: Rename to ...
	* testsuite/26_numerics/bit/bit.pow.two/has_single_bit.cc: ... here.
2020-02-17 17:09:18 +00:00
Jonathan Wakely 0d57370c9c libstdc++: Optimize C++20 comparison category types
This reduces the size and alignment of all three comparison category
types to a single byte. The partial_ordering::_M_is_ordered flag is
replaced by the value 0x02 in the _M_value member.

This also optimizes conversion and comparison operators to avoid
conditional branches where possible, by comparing _M_value to constants
or using bitwise operations to correctly handle the unordered state.

	* libsupc++/compare (__cmp_cat::type): Define typedef for underlying
	type of enumerations and comparison category types.
	(__cmp_cat::_Ord, __cmp_cat::_Ncmp): Add underlying type.
	(__cmp_cat::_Ncmp::unordered): Change value to 2.
	(partial_ordering::_M_value, weak_ordering::_M_value)
	(strong_ordering::_M_value): Change type to __cmp_cat::type.
	(partial_ordering::_M_is_ordered): Remove data member.
	(partial_ordering): Use second bit of _M_value for unordered. Adjust
	comparison operators.
	(weak_ordering::operator partial_ordering): Simplify to remove
	branches.
	(operator<=>(unspecified, weak_ordering)): Likewise.
	(strong_ordering::operator partial_ordering): Likewise.
	(strong_ordering::operator weak_ordering): Likewise.
	(operator<=>(unspecified, strong_ordering)): Likewise.
	* testsuite/18_support/comparisons/categories/partialord.cc: New test.
	* testsuite/18_support/comparisons/categories/strongord.cc: New test.
	* testsuite/18_support/comparisons/categories/weakord.cc: New test.
2020-02-07 14:09:03 +00:00
Jonathan Wakely f214ffb336 libstdc++: Simplify constraints on std::compare_three_way
The __3way_builtin_ptr_cmp concept can use three_way_comparable_with to
check whether <=> is valid. Doing that makes it obvious that the
disjunction on compare_three_way::operator() is redundant, because
the second constraint subsumes the first.

The workaround for PR c++/91073 can also be removed as that bug is fixed
now.

	* libsupc++/compare (__detail::__3way_builtin_ptr_cmp): Use
	three_way_comparable_with.
	(__detail::__3way_cmp_with): Remove workaround for fixed bug.
	(compare_three_way::operator()): Remove redundant constraint from
	requires-clause.
	(__detail::_Synth3way::operator()): Use three_way_comparable_with
	instead of workaround.
	* testsuite/18_support/comparisons/object/93479.cc: Prune extra
	output due to simplified constraints on compare_three_way::operator().
2020-01-29 13:56:49 +00:00
Jonathan Wakely 83b0201035 libstdc++: Make std::compare_three_way check if <=> is valid (PR 93479)
Currently types that cannot be compared using <=> but which are
convertible to pointers will be compared by converting to pointers
first. They should not be comparable.

	PR libstdc++/93479
	* libsupc++/compare (__3way_builtin_ptr_cmp): Require <=> to be valid.
	* testsuite/18_support/comparisons/object/93479.cc: New test.
2020-01-29 13:36:15 +00:00
Jonathan Wakely 482eeff5f1 libstdc++: Simplify construction of comparison category types
The _Eq and _Ord enumerations can be combined into one, reducing the
number of constructors needed for the comparison category types. The
redundant equal enumerator can be removed and equivalent used in its
place. The _Less and _Greater enumerators can be renamed because 'less'
and 'greater' are already reserved names anyway.

	* libsupc++/compare (__cmp_cat::_Eq): Remove enumeration type.
	(__cmp_cat::_Ord::equivalent): Add enumerator.
	(__cmp_cat::_Ord::_Less, __cmp_cat::_Ord::_Greater): Rename to less
	and greater.
	(partial_ordering, weak_ordering, strong_ordering): Remove
	constructors taking __cmp_cat::_Eq parameters. Use renamed
	enumerators.
2020-01-24 17:17:16 +00:00
Maciej W. Rozycki e8e66971cd Add `--with-toolexeclibdir=' configuration option
Provide means, in the form of a `--with-toolexeclibdir=' configuration
option, to override the default installation directory for target
libraries, otherwise known as $toolexeclibdir.  This is so that it is
possible to get newly-built libraries, particularly the shared ones,
installed in a common place, so that they can be readily used by the
target system as their host libraries, possibly over NFS, without a need
to manually copy them over from the currently hardcoded location they
would otherwise be installed in.

In the presence of the `--enable-version-specific-runtime-libs' option
and for configurations building native GCC the option is ignored.

	config/
	* toolexeclibdir.m4: New file.

	gcc/
	* doc/install.texi (Cross-Compiler-Specific Options): Document
	`--with-toolexeclibdir' option.

	libada/
	* Makefile.in (configure_deps): Add `toolexeclibdir.m4'.
	* configure.ac: Handle `--with-toolexeclibdir='.
	* configure: Regenerate.

	libatomic/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	libffi/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* include/Makefile.in: Regenerate.
	* man/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	libgcc/
	* Makefile.in (configure_deps): Add `toolexeclibdir.m4'.
	* configure.ac: Handle `--with-toolexeclibdir='.
	* configure: Regenerate.

	libgfortran/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libgomp/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	libhsail-rt/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libitm/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	libobjc/
	* Makefile.in (aclocal_deps): Add `toolexeclibdir.m4'.
	* aclocal.m4: Include `toolexeclibdir.m4'.
	* configure.ac: Handle `--with-toolexeclibdir='.
	* configure: Regenerate.

	liboffloadmic/
	* plugin/configure.ac: Handle `--with-toolexeclibdir='.
	* plugin/Makefile.in: Regenerate.
	* plugin/aclocal.m4: Regenerate.
	* plugin/configure: Regenerate.
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libphobos/
	* m4/druntime.m4: Handle `--with-toolexeclibdir='.
	* m4/Makefile.in: Regenerate.
	* libdruntime/Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libquadmath/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libsanitizer/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* asan/Makefile.in: Regenerate.
	* interception/Makefile.in: Regenerate.
	* libbacktrace/Makefile.in: Regenerate.
	* lsan/Makefile.in: Regenerate.
	* sanitizer_common/Makefile.in: Regenerate.
	* tsan/Makefile.in: Regenerate.
	* ubsan/Makefile.in: Regenerate.

	libssp/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	libstdc++-v3/
	* acinclude.m4: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* doc/Makefile.in: Regenerate.
	* include/Makefile.in: Regenerate.
	* libsupc++/Makefile.in: Regenerate.
	* po/Makefile.in: Regenerate.
	* python/Makefile.in: Regenerate.
	* src/Makefile.in: Regenerate.
	* src/c++11/Makefile.in: Regenerate.
	* src/c++17/Makefile.in: Regenerate.
	* src/c++98/Makefile.in: Regenerate.
	* src/filesystem/Makefile.in: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	libvtv/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.in: Regenerate.

	zlib/
	* configure.ac: Handle `--with-toolexeclibdir='.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
2020-01-24 11:24:25 +00:00
Jonathan Wakely 0ba6a850b5 libstdc++: Fix freestanding build PR 92376)
In a freestanding library we don't install the <pstl/pstl_config.h>
header, so don't try to include it unless it exists.

Explicitly declare aligned alloc functions for freestanding, because
<cstdlib> doesn't declare them.

	PR libstdc++/92376
	* include/bits/c++config: Only do PSTL config when the header is
	present, to fix freestanding.
	* libsupc++/new_opa.cc [!_GLIBCXX_HOSTED]: Declare allocation
	functions if they were detected by configure.
2020-01-17 17:03:46 +00:00