Commit graph

397 commits

Author SHA1 Message Date
Jonathan Wakely
07e03761a7 libstdc++: Fix infinite loop in std::binomial_distribution [PR114359]
The multiplication (4 * _M_t * __1p) can wraparound to zero if _M_t is
unsigned and 4 * _M_t wraps to zero. The third operand has type double,
so do the second multiplication first, so that we aren't multiplying
integers.

libstdc++-v3/ChangeLog:

	PR libstdc++/114359
	* include/bits/random.tcc (binomial_distribution::param_type):
	Ensure arithmetic is done as type double.
	* testsuite/26_numerics/random/binomial_distribution/114359.cc: New test.
2024-03-19 15:59:44 +00:00
Jonathan Wakely
c74131e77f libstdc++: Fix FAIL: 26_numerics/random/pr60037-neg.cc again [PR113961]
PR libstdc++/87744
	PR libstdc++/113961

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
2024-02-16 19:12:04 +00:00
Jonathan Wakely
7f3d900684 libstdc++: Fix FAIL: 26_numerics/random/pr60037-neg.cc [PR113931]
PR libstdc++/87744
	PR libstdc++/113931

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
2024-02-16 10:49:26 +00:00
Jonathan Wakely
b58f0e5216 libstdc++: Avoid aliasing violation in std::valarray [PR99117]
The call to __valarray_copy constructs an _Array object to refer to
this->_M_data but that means that accesses to this->_M_data are through
a restrict-qualified pointer. This leads to undefined behaviour when
copying from an _Expr object that actually aliases this->_M_data.

Replace the call to __valarray_copy with a plain loop. I think this
removes the only use of that overload of __valarray_copy, so it could
probably be removed. I haven't done that here.

libstdc++-v3/ChangeLog:

	PR libstdc++/99117
	* include/std/valarray (valarray::operator=(const _Expr&)):
	Use loop to copy instead of __valarray_copy with _Array.
	* testsuite/26_numerics/valarray/99117.cc: New test.
2024-02-15 11:43:21 +00:00
Jonathan Wakely
c9ce332b55 libstdc++: Use 128-bit arithmetic for std::linear_congruential_engine [PR87744]
For 32-bit targets without __int128 we need to implement the LCG
transition function by hand using 64-bit types.

We can also slightly simplify the __mod function by using if-constexpr
unconditionally, disabling -Wc++17-extensions warnings with diagnostic
pragmas.

libstdc++-v3/ChangeLog:

	PR libstdc++/87744
	* include/bits/random.h [!__SIZEOF_INT128__] (_Select_uint_least_t):
	Define specialization for 64-bit generators with
	non-power-of-two modulus and large constants.
	(__mod): Use if constexpr unconditionally.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
	* testsuite/26_numerics/random/linear_congruential_engine/87744.cc:
	New test.
2024-02-15 11:43:21 +00:00
Jonathan Wakely
c224dec0e7 libstdc++: Fix non-portable results from 64-bit std::subtract_with_carry_engine [PR107466]
I implemented the resolution of LWG 3809 in r13-4364-ga64775a0edd469 but
it was recently noted in the MSVC STL github repo that the change causes
possible truncation for 64-bit seeds. Whether the truncation occurs (and
to what value) depends on the width of uint_least32_t which is not
portable, so the output of the PRNG for 64-bit seed values is no longer
the same as in C++20, and no longer portable across platforms.

That new issue was filed as LWG 4014. I proposed a new change which
reduces the seed by the LCG's modulus before the conversion to
uint_least32_t. This ensures that 64-bit seed values are consistently
reduced by the modulus before any truncation. This removes the
platform-dependent behaviour and restores the old behaviour for
std::subtract_with_carry_engine specializations using a 64-bit result
type (such as std::ranlux48_base).

libstdc++-v3/ChangeLog:

	PR libstdc++/107466
	* include/bits/random.tcc (subtract_with_carry_engine::seed):
	Implement proposed resolution of LWG 4014.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	line number.
	* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
	Check for expected result of 64-bit engine with seed that
	doesn't fit in 32-bits.
2024-01-13 00:11:44 +00:00
Jakub Jelinek
a945c346f5 Update copyright years. 2024-01-03 12:19:35 +01:00
Jonathan Wakely
5e8a30d8b8 libstdc++: Redefine __glibcxx_assert to work in C++23 constexpr
The changes in r14-5979 to support unknown references in constant
expressions caused some test regressions. The way that __glibcxx_assert
is defined for constant evaluation no longer works when
_GLIBCXX_ASSERTIONS is defined.

This change simplifies __glibcxx_assert so that there is only one check,
rather than a constexpr one and a conditionally-enabled runtime one. The
constexpr one does not need to use __builtin_unreachable to cause a
compilation failure, because __glibcxx_assert_fail is not usable in
constant expressions, so that will cause a failure too.

As well as fixing the regressions, this makes the code for the
assertions shorter and simpler, so should be quicker to compile, and
might inline better too.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (__glibcxx_assert_fail): Declare even
	when assertions are not enabled.
	(__glibcxx_constexpr_assert): Remove macro.
	(__glibcxx_assert_impl): Remove macro.
	(_GLIBCXX_ASSERT_FAIL): New macro.
	(_GLIBCXX_DO_ASSERT): New macro.
	(__glibcxx_assert): Simplify to a single definition that works
	at runtime and during constant evaluation.
	* testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
	Adjust expected errors.
	* testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/debug.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/debug.cc:
	Likewise.
	* testsuite/23_containers/span/back_neg.cc: Likewise.
	* testsuite/23_containers/span/front_neg.cc: Likewise.
	* testsuite/23_containers/span/index_op_neg.cc: Likewise.
	* testsuite/26_numerics/lcm/105844.cc: Likewise.
2023-12-05 23:33:22 +00:00
Jonathan Wakely
568eb2d25c libstdc++: Define C++26 saturation arithmetic functions (P0543R3)
This was approved for C++26 last week at the WG21 meeting in Kona.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def (saturation_arithmetic): Define.
	* include/bits/version.h: Regenerate.
	* include/std/numeric: Include new header.
	* include/bits/sat_arith.h: New file.
	* testsuite/26_numerics/saturation/add.cc: New test.
	* testsuite/26_numerics/saturation/cast.cc: New test.
	* testsuite/26_numerics/saturation/div.cc: New test.
	* testsuite/26_numerics/saturation/mul.cc: New test.
	* testsuite/26_numerics/saturation/sub.cc: New test.
	* testsuite/26_numerics/saturation/version.cc: New test.
2023-11-17 15:28:30 +00:00
Jonathan Wakely
f4ab68469c libstdc++: Test for feature test macros more accurately
Tests which check for feature test macros should use the no_pch option,
so that we're really testing for the definition being in the intended
header, and not just testing that it's present in <bits/stdc++.h> (which
includes all the standard headers and so defines all the macros).

libstdc++-v3/ChangeLog:

	* testsuite/18_support/byte/requirements.cc: Disable PCH.
	* testsuite/18_support/destroying_delete.cc: Likewise.
	* testsuite/18_support/source_location/1.cc: Likewise.
	* testsuite/18_support/source_location/version.cc: Likewise.
	* testsuite/18_support/type_info/constexpr.cc: Likewise.
	* testsuite/18_support/uncaught_exceptions/uncaught_exceptions.cc:
	Likewise.
	* testsuite/19_diagnostics/stacktrace/output.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
	* testsuite/20_util/addressof/requirements/constexpr.cc:
	Likewise.
	* testsuite/20_util/allocator_traits/header-2.cc: Likewise.
	* testsuite/20_util/allocator_traits/header.cc: Likewise.
	* testsuite/20_util/as_const/1.cc: Likewise. Likewise.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise.
	* testsuite/20_util/bitset/version.cc: Likewise.
	* testsuite/20_util/duration/arithmetic/constexpr_c++17.cc:
	Likewise.
	* testsuite/20_util/duration_cast/rounding.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	Likewise.
	* testsuite/20_util/exchange/constexpr.cc: Likewise.
	* testsuite/20_util/expected/synopsis.cc: Likewise.
	* testsuite/20_util/expected/version.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/1.cc: Likewise.
	* testsuite/20_util/function_objects/bind_front/2.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/3.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/4.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/constexpr.cc:
	Likewise.
	* testsuite/20_util/function_objects/invoke/version.cc:
	Likewise.
	* testsuite/20_util/function_objects/searchers.cc: Likewise.
	* testsuite/20_util/integer_comparisons/1.cc: Likewise.
	* testsuite/20_util/integer_comparisons/2.cc: Likewise.
	* testsuite/20_util/is_bounded_array/value.cc: Likewise.
	* testsuite/20_util/is_layout_compatible/value.cc: Likewise.
	* testsuite/20_util/is_layout_compatible/version.cc: Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable/value.cc: Likewise.
	* testsuite/20_util/is_nothrow_swappable/value.h: Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_nothrow_swappable_with/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/is_nothrow_swappable_with/value.cc: Disable
	PCH.
	* testsuite/20_util/is_pointer_interconvertible/value.cc:
	Likewise.
	* testsuite/20_util/is_pointer_interconvertible/version.cc:
	Likewise.
	* testsuite/20_util/is_scoped_enum/value.cc: Likewise.
	* testsuite/20_util/is_scoped_enum/version.cc: Likewise.
	* testsuite/20_util/is_swappable/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable/requirements/typedefs.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable/value.cc: Disable PCH.
	* testsuite/20_util/is_swappable/value.h: Reorder headers.
	* testsuite/20_util/is_swappable_with/requirements/explicit_instantiation.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable_with/requirements/typedefs.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/20_util/is_swappable_with/value.cc: Disable PCH.
	* testsuite/20_util/is_unbounded_array/value.cc: Likewise.
	* testsuite/20_util/move_only_function/cons.cc: Likewise.
	* testsuite/20_util/move_only_function/version.cc: Likewise.
	* testsuite/20_util/optional/monadic/and_then.cc: Likewise.
	* testsuite/20_util/optional/requirements.cc: Likewise.
	* testsuite/20_util/optional/version.cc: Likewise.
	* testsuite/20_util/owner_less/void.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/version.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/array.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/overwrite.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/version.cc: Likewise.
	* testsuite/20_util/time_point_cast/rounding.cc: Likewise.
	* testsuite/20_util/to_chars/constexpr.cc: Likewise.
	* testsuite/20_util/to_chars/result.cc: Likewise.
	* testsuite/20_util/to_chars/version.cc: Likewise.
	* testsuite/20_util/to_underlying/1.cc: Likewise.
	* testsuite/20_util/to_underlying/version.cc: Likewise.
	* testsuite/20_util/tuple/apply/1.cc: Likewise.
	* testsuite/20_util/tuple/cons/constexpr_allocator_arg_t.cc:
	Likewise.
	* testsuite/20_util/tuple/make_from_tuple/1.cc: Likewise.
	* testsuite/20_util/tuple/p2321r2.cc: Likewise.
	* testsuite/20_util/tuple/tuple_element_t.cc: Likewise.
	* testsuite/20_util/unique_ptr/cons/constexpr_c++20.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc:
	Likewise.
	* testsuite/20_util/unreachable/1.cc: Likewise.
	* testsuite/20_util/unreachable/version.cc: Likewise.
	* testsuite/20_util/unwrap_reference/1.cc: Likewise.
	* testsuite/20_util/unwrap_reference/3.cc: Likewise.
	* testsuite/20_util/variant/constexpr.cc: Likewise.
	* testsuite/20_util/variant/version.cc: Likewise.
	* testsuite/20_util/variant/visit_inherited.cc: Likewise.
	* testsuite/20_util/void_t/1.cc: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/char/constexpr.cc:
	Likewise.
	* testsuite/21_strings/basic_string/cons/wchar_t/constexpr.cc:
	Likewise.
	* testsuite/21_strings/basic_string/erasure.cc: Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/char/to_string_float.cc:
	Likewise.
	* testsuite/21_strings/basic_string/numeric_conversions/version.cc:
	Likewise.
	* testsuite/21_strings/basic_string/version.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string_view/operations/copy/char/constexpr.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/21_strings/char_traits/requirements/version.cc:
	Likewise.
	* testsuite/23_containers/array/comparison_operators/constexpr.cc:
	Likewise.
	* testsuite/23_containers/array/creation/1.cc: Likewise.
	* testsuite/23_containers/array/creation/2.cc: Likewise.
	* testsuite/23_containers/array/element_access/constexpr_c++17.cc:
	Likewise.
	* testsuite/23_containers/array/requirements/constexpr_fill.cc:
	Likewise.
	* testsuite/23_containers/array/requirements/constexpr_iter.cc:
	Likewise.
	* testsuite/23_containers/deque/erasure.cc: Likewise.
	* testsuite/23_containers/forward_list/erasure.cc: Likewise.
	* testsuite/23_containers/list/erasure.cc: Likewise.
	* testsuite/23_containers/map/erasure.cc: Likewise.
	* testsuite/23_containers/queue/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/span/1.cc: Likewise.
	* testsuite/23_containers/span/2.cc: Likewise.
	* testsuite/23_containers/stack/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/operations/1.cc:
	Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/operations/1.cc:
	Likewise.
	* testsuite/23_containers/vector/cons/constexpr.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.
	* testsuite/23_containers/vector/requirements/version.cc:
	Likewise.
	* testsuite/24_iterators/insert_iterator/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/1.cc:
	Remove redundant checks already tested elsewhere.
	* testsuite/25_algorithms/constexpr_macro.cc: Likewise.
	* testsuite/25_algorithms/cpp_lib_constexpr.cc: Likewise.
	* testsuite/25_algorithms/fold_left/1.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-2.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-3.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-4.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-5.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/bit_cast.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/version.cc: Likewise.
	* testsuite/26_numerics/bit/header-2.cc: Likewise.
	* testsuite/26_numerics/bit/header.cc: Likewise.
	* testsuite/26_numerics/complex/1.cc: Likewise.
	* testsuite/26_numerics/complex/2.cc: Likewise.
	* testsuite/26_numerics/endian/2.cc: Likewise.
	* testsuite/26_numerics/endian/3.cc: Likewise.
	* testsuite/26_numerics/gcd/1.cc: Likewise.
	* testsuite/26_numerics/lcm/1.cc: Likewise.
	* testsuite/26_numerics/lerp/1.cc: Likewise.
	* testsuite/26_numerics/lerp/version.cc: Likewise.
	* testsuite/26_numerics/midpoint/integral.cc: Likewise.
	* testsuite/26_numerics/midpoint/version.cc: Likewise.
	* testsuite/26_numerics/numbers/1.cc: Likewise.
	* testsuite/26_numerics/numbers/2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/native_handle/char/1.cc:
	Likewise.
	* testsuite/27_io/basic_filebuf/native_handle/version.cc:
	Likewise.
	* testsuite/27_io/basic_ofstream/open/char/noreplace.cc:
	Likewise.
	* testsuite/27_io/basic_ofstream/open/wchar_t/noreplace.cc:
	Likewise.
	* testsuite/27_io/basic_syncbuf/1.cc: Likewise.
	* testsuite/27_io/basic_syncbuf/2.cc: Likewise.
	* testsuite/27_io/basic_syncstream/1.cc: Likewise.
	* testsuite/27_io/basic_syncstream/2.cc: Likewise.
	* testsuite/27_io/spanstream/1.cc: Likewise.
	* testsuite/27_io/spanstream/version.cc: Likewise.
	* testsuite/29_atomics/atomic/cons/value_init.cc: Likewise.
	* testsuite/29_atomics/atomic/lock_free_aliases.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/1.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: Likewise.
	* testsuite/30_threads/barrier/1.cc: Likewise.
	* testsuite/30_threads/barrier/2.cc: Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/1.cc:
	Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/2.cc:
	Likewise.
	* testsuite/30_threads/jthread/1.cc: Likewise.
	* testsuite/30_threads/jthread/version.cc: Likewise.
	* testsuite/30_threads/latch/1.cc: Likewise.
	* testsuite/30_threads/latch/2.cc: Likewise.
	* testsuite/30_threads/scoped_lock/requirements/typedefs.cc:
	Likewise.
	* testsuite/30_threads/semaphore/1.cc: Likewise.
	* testsuite/30_threads/semaphore/2.cc: Likewise.
	* testsuite/30_threads/stop_token/1.cc: Likewise.
	* testsuite/30_threads/stop_token/2.cc: Likewise.
	* testsuite/experimental/feat-char8_t.cc: Likewise.
	* testsuite/experimental/iterator/ostream_joiner.cc: Likewise.
	* testsuite/experimental/numeric/gcd.cc: Likewise.
	* testsuite/experimental/scopeguard/uniqueres.cc: Likewise.
	* testsuite/std/concepts/1.cc: Likewise.
	* testsuite/std/concepts/2.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_const/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk_by/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/enumerate/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/join_with/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/slide/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/stride/1.cc: Likewise.
	* testsuite/std/ranges/cartesian_product/1.cc: Likewise.
	* testsuite/std/ranges/headers/ranges/synopsis.cc: Likewise.
	* testsuite/std/ranges/repeat/1.cc: Likewise.
	* testsuite/std/ranges/version_c++23.cc: Likewise.
	* testsuite/std/ranges/zip/1.cc: Likewise.
	* testsuite/std/time/syn_c++20.cc: Likewise.
	* testsuite/experimental/feat-cxx14.cc: Likewise. Include
	<algorithm> and <iterator>.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
2023-11-16 08:06:59 +00:00
Jonathan Wakely
7c02efd45f libstdc++: Fix broken tests for <complex.h>
When I added these tests I gave them .h file extensions, so they've
never been run.

They need to use the no_pch option, so that they only test the
<complex.h> header and don't get <complex> via <bits/stdc++.h>.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/headers/complex.h/std_c++11.h: Moved to...
	* testsuite/26_numerics/headers/complex.h/std_c++11.cc: ...here.
	* testsuite/26_numerics/headers/complex.h/std_c++98.h: Moved to...
	* testsuite/26_numerics/headers/complex.h/std_c++98.cc: ...here.
	Check macro first and then #undef.
	* testsuite/26_numerics/headers/complex.h/std_gnu++11.h: Moved to...
	* testsuite/26_numerics/headers/complex.h/std_gnu++11.cc: ...here.
2023-11-11 00:41:09 +00:00
Nathaniel Shead
0b880466e9 libstdc++: Add missing functions to <cmath> [PR79700]
This patch adds the -f and -l variants of the C99 <math.h> functions to
<cmath> under namespace std (so std::sqrtf, std::fabsl, etc.) for C++11
and up.

libstdc++-v3/ChangeLog:

	PR libstdc++/79700
	* include/c_global/cmath (acosf, acosl, asinf, asinl, atanf)
	(atanl, atan2f, atan2l, ceilf, ceill, cosf, cosl, coshf, coshl)
	(expf, expl, fabsf, fabsl, floorf, floorl, fmodf, fmodl, frexpf)
	(frexpl, ldexpf, ldexpl, logf, logl, log10f, log10l, modff)
	(modfl, powf, powl, sinf, sinl, sinhf, sinhl, sqrtf, sqrtl, tanf)
	(tanl, tanhf, tanhl): Add using-declarations in namespace std.
	* testsuite/26_numerics/headers/cmath/equivalent_functions.cc:
	New test.
	* testsuite/26_numerics/headers/cmath/functions_std_c++17.cc:
	Add checks for existence of above names.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2023-11-11 00:41:08 +00:00
Patrick Palka
6e92a6a2a7 c++: non-dependent assignment checking [PR63198, PR18474]
This patch makes us recognize and check non-dependent simple assigments
ahead of time, like we already do for compound assignments.  This means
the templated representation of such assignments will now usually have
an implicit INDIRECT_REF (due to the reference return type), which the
-Wparentheses code needs to handle.  As a drive-by improvement, this
patch also makes maybe_convert_cond issue -Wparentheses warnings ahead
of time, and removes a seemingly unnecessary suppress_warning call in
build_x_modify_expr.

On the libstdc++ side, some tests were attempting to modify a data
member from a uninstantiated const member function, which this patch
minimally fixes by making the data member mutable.

	PR c++/63198
	PR c++/18474

gcc/cp/ChangeLog:

	* semantics.cc (maybe_convert_cond): Look through implicit
	INDIRECT_REF when deciding whether to issue a -Wparentheses
	warning, and consider templated assignment expressions as well.
	(finish_parenthesized_expr): Look through implicit INDIRECT_REF
	when suppressing -Wparentheses warning.
	* typeck.cc (build_x_modify_expr): Check simple assignments
	ahead time too, not just compound assignments.  Give the second
	operand of MODOP_EXPR a non-null type so that it's not considered
	always instantiation-dependent.  Don't call suppress_warning.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/static_assert15.C: Expect diagnostic for
	non-constant static_assert condition.
	* g++.dg/expr/unary2.C: Remove xfails.
	* g++.dg/template/init7.C: Make initializer type-dependent to
	preserve intent of test.
	* g++.dg/template/recurse3.C: Likewise for the erroneous
	statement.
	* g++.dg/template/non-dependent26.C: New test.
	* g++.dg/warn/Wparentheses-32.C: New test.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/discard_block_engine/cons/seed_seq2.cc:
	Make data member seed_seq::called mutable.
	* testsuite/26_numerics/random/independent_bits_engine/cons/seed_seq2.cc:
	Likewise.
	* testsuite/26_numerics/random/linear_congruential_engine/cons/seed_seq2.cc:
	Likewise.
	* testsuite/26_numerics/random/mersenne_twister_engine/cons/seed_seq2.cc:
	Likewise.
	* testsuite/26_numerics/random/shuffle_order_engine/cons/seed_seq2.cc:
	Likewise.
	* testsuite/26_numerics/random/subtract_with_carry_engine/cons/seed_seq2.cc:
	Likewise.
	* testsuite/ext/random/simd_fast_mersenne_twister_engine/cons/seed_seq2.cc:
	Likewise.
2023-09-18 14:47:52 -04:00
Jonathan Wakely
8ccae1639f libstdc++: Remove dg-options "-std=gnu++20" from remaining tests
The testsuite will automatically select C++20 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++23
and C++26 as well.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/coroutines/95917.cc: Remove dg-options
	-std=gnu++2a.
	* testsuite/18_support/coroutines/hash.cc: Likewise.
	* testsuite/18_support/coroutines/lwg3460.cc: Likewise.
	* testsuite/18_support/destroying_delete.cc: Likewise.
	* testsuite/18_support/source_location/1.cc: Likewise.
	* testsuite/18_support/source_location/consteval.cc: Likewise.
	* testsuite/18_support/source_location/version.cc: Likewise.
	* testsuite/19_diagnostics/error_category/operators/three_way.cc:
	Likewise.
	* testsuite/19_diagnostics/error_code/operators/three_way.cc:
	Likewise.
	* testsuite/19_diagnostics/error_condition/operators/three_way.cc:
	Likewise.
	* testsuite/19_diagnostics/stacktrace/output.cc: Likewise.
	* testsuite/26_numerics/adjacent_difference/lwg2055.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/has_single_bit.cc:
	Likewise.
	* testsuite/28_regex/iterators/regex_iterator/lwg3719.cc:
	Likewise.
	* testsuite/28_regex/iterators/regex_token_iterator/lwg3719.cc:
	Likewise.
	* testsuite/28_regex/sub_match/compare_c++20.cc: Likewise.
	* testsuite/experimental/filesystem/iterators/106201.cc:
	Likewise.
	* testsuite/experimental/scopeguard/exit.cc: Likewise.
	* testsuite/experimental/scopeguard/uniqueres.cc: Likewise.
2023-09-16 00:10:46 +01:00
Jonathan Wakely
bb2dd7619f libstdc++: Remove dg-options "-std=gnu++20" from 26_numerics tests
The testsuite will automatically select C++20 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++23
and C++26 as well.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/accumulate/constexpr.cc: Remove
	dg-options -std=gnu++2a.
	* testsuite/26_numerics/accumulate/lwg2055.cc: Likewise.
	* testsuite/26_numerics/adjacent_difference/constexpr.cc:
	Likewise.
	* testsuite/26_numerics/bit/bit.cast/105027.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/bit_cast.cc: Likewise.
	* testsuite/26_numerics/bit/bit.cast/version.cc: Likewise.
	* testsuite/26_numerics/bit/bit.count/countl_one.cc: Likewise.
	* testsuite/26_numerics/bit/bit.pow.two/bit_ceil_neg.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/lwg3656.cc: Likewise.
	* testsuite/26_numerics/bit/bit.rotate/rotl.cc: Likewise.
	* testsuite/26_numerics/bit/bit.rotate/rotr.cc: Likewise.
	* testsuite/26_numerics/bit/header-2.cc: Likewise.
	* testsuite/26_numerics/bit/header.cc: Likewise.
	* testsuite/26_numerics/complex/1.cc: Likewise.
	* testsuite/26_numerics/complex/2.cc: Likewise.
	* testsuite/26_numerics/complex/comparison_operators/more_constexpr.cc:
	Likewise.
	* testsuite/26_numerics/complex/operators/more_constexpr.cc:
	Likewise.
	* testsuite/26_numerics/complex/requirements/more_constexpr.cc:
	Likewise.
	* testsuite/26_numerics/complex/value_operations/more_constexpr.cc:
	Likewise.
	* testsuite/26_numerics/endian/1.cc: Likewise.
	* testsuite/26_numerics/endian/2.cc: Likewise.
	* testsuite/26_numerics/endian/3.cc: Likewise.
	* testsuite/26_numerics/exclusive_scan/constexpr.cc: Likewise.
	* testsuite/26_numerics/inclusive_scan/constexpr.cc: Likewise.
	* testsuite/26_numerics/inner_product/constexpr.cc: Likewise.
	* testsuite/26_numerics/inner_product/lwg2055.cc: Likewise.
	* testsuite/26_numerics/iota/constexpr.cc: Likewise.
	* testsuite/26_numerics/lerp/1.cc: Likewise.
	* testsuite/26_numerics/lerp/constexpr.cc: Likewise.
	* testsuite/26_numerics/lerp/version.cc: Likewise.
	* testsuite/26_numerics/midpoint/floating.cc: Likewise.
	* testsuite/26_numerics/midpoint/integral.cc: Likewise.
	* testsuite/26_numerics/midpoint/pointer.cc: Likewise.
	* testsuite/26_numerics/midpoint/pointer_neg.cc: Likewise.
	* testsuite/26_numerics/midpoint/version.cc: Likewise.
	* testsuite/26_numerics/numbers/1.cc: Likewise.
	* testsuite/26_numerics/numbers/2.cc: Likewise.
	* testsuite/26_numerics/numbers/3.cc: Likewise.
	* testsuite/26_numerics/numbers/float128.cc: Likewise.
	* testsuite/26_numerics/numbers/nonfloat_neg.cc: Likewise.
	* testsuite/26_numerics/partial_sum/constexpr.cc: Likewise.
	* testsuite/26_numerics/partial_sum/lwg2055.cc: Likewise.
	* testsuite/26_numerics/random/concept.cc: Likewise.
	* testsuite/26_numerics/reduce/constexpr.cc: Likewise.
	* testsuite/26_numerics/slice/compare.cc: Likewise.
	* testsuite/26_numerics/transform_exclusive_scan/constexpr.cc:
	Likewise.
	* testsuite/26_numerics/transform_inclusive_scan/constexpr.cc:
	Likewise.
	* testsuite/26_numerics/transform_reduce/constexpr.cc: Likewise.
2023-09-16 00:10:45 +01:00
Jonathan Wakely
7810fb3a14 libstdc++: Remove dg-options "-std=gnu++23" from remaining tests
The testsuite will automatically select C++23 for these tests now, and
removing the hardcoded -std option allows them to be tested for C++26
as well.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/headers/limits/synopsis_cxx23.cc: Remove
	dg-options.
	* testsuite/18_support/headers/stdfloat/types_std.cc: Likewise.
	* testsuite/18_support/type_info/constexpr.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/current.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/entry.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: Likewise.
	* testsuite/19_diagnostics/stacktrace/version.cc: Likewise.
	* testsuite/20_util/aligned_storage/deprecated-2b.cc: Likewise.
	* testsuite/20_util/aligned_union/deprecated-2b.cc: Likewise.
	* testsuite/20_util/bitset/access/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/cons/constexpr_c++23.cc: Likewise.
	* testsuite/20_util/bitset/count/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/ext/constexpr.cc: Likewise.
	* testsuite/20_util/bitset/operations/constexpr_c++23.cc:
	Likewise.
	* testsuite/20_util/bitset/version.cc: Likewise.
	* testsuite/20_util/from_chars/8.cc: Likewise.
	* testsuite/20_util/from_chars/constexpr.cc: Likewise.
	* testsuite/20_util/function/cons/deduction_c++23.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/4.cc: Likewise.
	* testsuite/20_util/function_objects/invoke/dangling_ref.cc:
	Likewise.
	* testsuite/20_util/is_scoped_enum/value.cc: Likewise.
	* testsuite/20_util/is_scoped_enum/version.cc: Likewise.
	* testsuite/20_util/move_only_function/call.cc: Likewise.
	* testsuite/20_util/move_only_function/cons.cc: Likewise.
	* testsuite/20_util/move_only_function/move.cc: Likewise.
	* testsuite/20_util/move_only_function/version.cc: Likewise.
	* testsuite/20_util/optional/monadic/and_then.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else.cc: Likewise.
	* testsuite/20_util/optional/monadic/or_else_neg.cc: Likewise.
	* testsuite/20_util/optional/monadic/pr109242.cc: Likewise.
	* testsuite/20_util/optional/monadic/transform.cc: Likewise.
	* testsuite/20_util/pair/p2321r2.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value.cc: Likewise.
	* testsuite/20_util/reference_from_temporary/value2.cc:
	Likewise.
	* testsuite/20_util/reference_from_temporary/version.cc:
	Likewise.
	* testsuite/20_util/to_chars/constexpr.cc: Likewise.
	* testsuite/20_util/to_chars/float128_c++23.cc: Likewise.
	* testsuite/20_util/to_chars/float16_c++23.cc: Likewise.
	* testsuite/20_util/to_chars/version.cc: Likewise.
	* testsuite/20_util/to_underlying/1.cc: Likewise.
	* testsuite/20_util/to_underlying/version.cc: Likewise.
	* testsuite/20_util/tuple/p2321r2.cc: Likewise.
	* testsuite/20_util/unique_ptr/assign/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/comparison/constexpr.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/cons/constexpr_c++20.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/modifiers/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/specialized_algorithms/constexpr.cc: Likewise.
	* testsuite/20_util/unreachable/1.cc: Likewise.
	* testsuite/20_util/unreachable/version.cc: Likewise.
	* testsuite/20_util/uses_allocator/lwg3677.cc: Likewise.
	* testsuite/21_strings/basic_string/capacity/char/resize_and_overwrite.cc: Likewise.
	* testsuite/21_strings/basic_string/operations/contains/char.cc:
	Likewise.
	* testsuite/21_strings/basic_string/operations/contains/nonnull.cc: Likewise.
	* testsuite/21_strings/basic_string/operations/contains/wchar_t.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc: Likewise.
	* testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/nonnull.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/wchar_t.cc: Likewise.
	* testsuite/23_containers/queue/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/stack/cons_from_iters.cc: Likewise.
	* testsuite/23_containers/vector/bool/element_access/1.cc:
	Likewise.
	* testsuite/24_iterators/const_iterator/1.cc: Likewise.
	* testsuite/25_algorithms/contains/1.cc: Likewise.
	* testsuite/25_algorithms/contains_subrange/1.cc: Likewise.
	* testsuite/25_algorithms/find_last/1.cc: Likewise.
	* testsuite/25_algorithms/find_last_if/1.cc: Likewise.
	* testsuite/25_algorithms/find_last_if_not/1.cc: Likewise.
	* testsuite/25_algorithms/fold_left/1.cc: Likewise.
	* testsuite/25_algorithms/fold_right/1.cc: Likewise.
	* testsuite/25_algorithms/iota/1.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: Likewise.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: Likewise.
	* testsuite/26_numerics/complex/ext_c++23.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc:
	Likewise.
	* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc:
	Likewise.
	* testsuite/26_numerics/numbers/4.cc: Likewise.
	* testsuite/27_io/basic_ostream/inserters_other/char/volatile_ptr.cc: Likewise.
	* testsuite/27_io/filesystem/path/native/conv_c++23.cc:
	Likewise.
	* testsuite/27_io/spanstream/1.cc: Likewise.
	* testsuite/27_io/spanstream/2.cc: Likewise.
	* testsuite/27_io/spanstream/version.cc: Likewise.
	* testsuite/29_atomics/atomic_float/requirements_cxx23.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: Likewise.
	* testsuite/30_threads/packaged_task/cons/deduction_c++23.cc:
	Likewise.
	* testsuite/experimental/filesystem/path/native/conv_c++23.cc:
	Likewise.
	* testsuite/std/ranges/adaptors/adjacent/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/adjacent_transform/1.cc:
	Likewise.
	* testsuite/std/ranges/adaptors/as_const/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/as_rvalue/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/chunk_by/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/enumerate/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/join_with/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/lwg3715.cc: Likewise.
	* testsuite/std/ranges/adaptors/slide/1.cc: Likewise.
	* testsuite/std/ranges/adaptors/stride/1.cc: Likewise.
	* testsuite/std/ranges/cartesian_product/1.cc: Likewise.
	* testsuite/std/ranges/range_adaptor_closure.cc: Likewise.
	* testsuite/std/ranges/repeat/1.cc: Likewise.
	* testsuite/std/ranges/version_c++23.cc: Likewise.
	* testsuite/std/ranges/zip/1.cc: Likewise.
	* testsuite/std/ranges/zip_transform/1.cc: Likewise.
2023-09-15 21:57:40 +01:00
Jonathan Wakely
270e702eda libstdc++: Remove unnecessary dg-options and outdated comment
It's no longer true that 1.0if has type float _Complex when GNU
extensions are enabled, so remove the hardcoded -std option.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/complex/literals/types.cc: Remove
	dg-options and add target selector instead.
2023-09-04 16:24:35 +01:00
Jonathan Wakely
4bbe1414e1 libstdc++: Add { target c++98_only } to tests
These test behaviour only seen with -std=c++03 so the target selector
should match.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/bitset/107037.cc: Add c++98_only selector.
	* testsuite/26_numerics/complex/56111.cc: Likewise.
2023-09-04 16:24:34 +01:00
Nathaniel Shead
5ebe5bcf8b c++: Improve location information in constant evaluation
This patch updates 'input_location' during constant evaluation to ensure
that errors in subexpressions that lack location information still
provide accurate diagnostics.

By itself this change causes some small regressions in diagnostic
quality for circumstances where errors used 'input_location' but the
location of the parent subexpression doesn't make sense, so this patch
also includes a small diagnostic improvement to fix the most egregious
case.

gcc/cp/ChangeLog:

	* constexpr.cc (modifying_const_object_error): Find the source
	location of the const object's declaration.
	(cxx_eval_constant_expression): Update input_location to the
	location of the currently evaluated expression, if possible.

libstdc++-v3/ChangeLog:

	* testsuite/25_algorithms/equal/constexpr_neg.cc: Update diagnostic
	locations.
	* testsuite/26_numerics/gcd/105844.cc: Likewise.
	* testsuite/26_numerics/lcm/105844.cc: Likewise.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/constexpr-48089.C: Update diagnostic locations.
	* g++.dg/cpp0x/constexpr-70323.C: Likewise.
	* g++.dg/cpp0x/constexpr-70323a.C: Likewise.
	* g++.dg/cpp0x/constexpr-delete2.C: Likewise.
	* g++.dg/cpp0x/constexpr-diag3.C: Likewise.
	* g++.dg/cpp0x/constexpr-ice20.C: Likewise.
	* g++.dg/cpp0x/constexpr-mutable3.C: Likewise.
	* g++.dg/cpp0x/constexpr-recursion.C: Likewise.
	* g++.dg/cpp0x/overflow1.C: Likewise.
	* g++.dg/cpp1y/constexpr-89285.C: Likewise.
	* g++.dg/cpp1y/constexpr-89481.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const14.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const16.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const18.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const19.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const21.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const22.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const3.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const4.C: Likewise.
	* g++.dg/cpp1y/constexpr-tracking-const7.C: Likewise.
	* g++.dg/cpp1y/constexpr-union5.C: Likewise.
	* g++.dg/cpp1y/pr68180.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda6.C: Likewise.
	* g++.dg/cpp1z/constexpr-lambda8.C: Likewise.
	* g++.dg/cpp2a/bit-cast11.C: Likewise.
	* g++.dg/cpp2a/bit-cast12.C: Likewise.
	* g++.dg/cpp2a/bit-cast14.C: Likewise.
	* g++.dg/cpp2a/constexpr-98122.C: Likewise.
	* g++.dg/cpp2a/constexpr-dynamic17.C: Likewise.
	* g++.dg/cpp2a/constexpr-init1.C: Likewise.
	* g++.dg/cpp2a/constexpr-new12.C: Likewise.
	* g++.dg/cpp2a/constexpr-new3.C: Likewise.
	* g++.dg/cpp2a/constinit10.C: Likewise.
	* g++.dg/cpp2a/is-corresponding-member4.C: Likewise.
	* g++.dg/ext/constexpr-vla2.C: Likewise.
	* g++.dg/ext/constexpr-vla3.C: Likewise.
	* g++.dg/ubsan/pr63956.C: Likewise.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
2023-07-25 21:45:10 -04:00
Thomas Rodgers
3162ca09db libstdc++: Synchronize PSTL with upstream
This patch rebases the C++17 parallel algorithms implementation (pstl)
against the current upstream version, commit 843c12d6a.

This version does not currently include the recently added OpenMP
backend, that will be considered for a future version.

libstdc++-v3/ChangeLog:
	* include/pstl/algorithm_fwd.h: Synchronize with upstream.
	* include/pstl/algorithm_impl.h: Likewise.
	* include/pstl/execution_defs.h: Likewise.
	* include/pstl/execution_impl.h: Likewise.
	* include/pstl/glue_algorithm_impl.h: Likewise.
	* include/pstl/glue_execution_defs.h: Likewise.
	* include/pstl/glue_memory_impl.h: Likewise.
	* include/pstl/glue_numeric_impl.h: Likewise.
	* include/pstl/memory_impl.h: Likewise.
	* include/pstl/numeric_fwd.h: Likewise.
	* include/pstl/numeric_impl.h: Likewise.
	* include/pstl/parallel_backend.h: Likewise.
	* include/pstl/parallel_backend_serial.h: Likewise.
	* include/pstl/parallel_backend_tbb.h: Likewise.
	* include/pstl/parallel_impl.h: Likewise.
	* include/pstl/pstl_config.h: Likewise.
	* include/pstl/unseq_backend_simd.h: Likewise.
	* include/pstl/utils.h: Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/pstl/uninitialized_fill_destroy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/fill.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/generate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/remove_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/swap_ranges.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/transform_binary.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/transform_unary.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/adjacent_find.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/for_each.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/mismatch.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/includes.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/is_sorted.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/minmax_element.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/set.cc:
	Likewise.
	* testsuite/25_algorithms/pstl/alg_sorting/sort.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/reduce.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/scan.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc:
	Likewise.
	* testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc:
	Likewise.
	* testsuite/util/pstl/test_utils.h:
	Likewise.
2023-06-26 11:34:43 -07:00
Jonathan Wakely
ae12aced97 libstdc++: Fix some tests that fail with -fexcess-precision=standard
libstdc++-v3/ChangeLog:

	* testsuite/20_util/duration/cons/2.cc: Use values that aren't
	affected by rounding.
	* testsuite/20_util/from_chars/5.cc: Cast arithmetic result to
	double before comparing for equality.
	* testsuite/20_util/from_chars/6.cc: Likewise.
	* testsuite/20_util/variant/86874.cc: Use values that aren't
	affected by rounding.
	* testsuite/25_algorithms/lower_bound/partitioned.cc: Compare to
	original value instead of to floating-point-literal.
	* testsuite/26_numerics/random/discrete_distribution/cons/range.cc:
	Cast arithmetic result to double before comparing for equality.
	* testsuite/26_numerics/random/piecewise_constant_distribution/cons/range.cc:
	Likewise.
	* testsuite/26_numerics/random/piecewise_linear_distribution/cons/range.cc:
	Likewise.
	* testsuite/26_numerics/valarray/transcend.cc (eq): Check that
	the absolute difference is less than 0.01 instead of comparing
	to two decimal places.
	* testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc:
	Cast arithmetic result to double before comparing for equality.
	* testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc:
	Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc:
	Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc:
	Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc:
	Likewise.
	* testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc:
	Likewise.
	* testsuite/ext/random/hoyt_distribution/cons/parms.cc: Likewise.
2023-06-07 16:51:59 +01:00
Jonathan Wakely
f8403c4304 libstdc++: Fix PSTL test that fails in C++20
This test fails in C++20 and later due to a warning:

warning: C++20 says that these are ambiguous, even though the second is reversed:
note: candidate 1: 'bool MyClass::operator==(const MyClass&)'
note: candidate 2: 'bool MyClass::operator==(const MyClass&)' (reversed)
note: try making the operator a 'const' member function
FAIL: 26_numerics/pstl/numeric_ops/transform_reduce.cc (test for excess errors)

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc:
	Add const to equality operator.
2023-06-01 16:54:24 +01:00
Jonathan Wakely
1f378f6dd3 libstdc++: Stop using _GLIBCXX_USE_C99_MATH_TR1 in <cmath>
Similar to the three commits r14-908, r14-909 and r14-910, the
_GLIBCXX_USE_C99_MATH_TR1 macro is misleading when it is also used for
<cmath>, not only for <tr1/cmath> headers. It is also wrong, because the
configure checks for TR1 use -std=c++98 and a target might define the
C99 features for C++11 but not for C++98.

Add separate configure checks for the <math.h> functions using
-std=c++11 for the checks. Use the new macro defined by those checks in
the C++11-specific parts of <cmath>, and in <complex>, <random> etc.

The check that defines _GLIBCXX_NO_C99_ROUNDING_FUNCS is only needed for
the C++11 <cmath> checks, so remove that from GLIBCXX_CHECK_C99_TR1 and
only do it for GLIBCXX_ENABLE_C99.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_ENABLE_C99): Add checks for C99 math
	functions and define _GLIBCXX_USE_C99_MATH_FUNCS. Move checks
	for C99 rounding functions to here.
	(GLIBCXX_CHECK_C99_TR1): Remove checks for C99 rounding
	functions from here.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* include/bits/random.h: Use _GLIBCXX_USE_C99_MATH_FUNCS instead
	of _GLIBCXX_USE_C99_MATH_TR1.
	* include/bits/random.tcc: Likewise.
	* include/c_compatibility/math.h: Likewise.
	* include/c_global/cmath: Likewise.
	* include/ext/random: Likewise.
	* include/ext/random.tcc: Likewise.
	* include/std/complex: Likewise.
	* testsuite/20_util/from_chars/4.cc: Likewise.
	* testsuite/20_util/from_chars/8.cc: Likewise.
	* testsuite/26_numerics/complex/proj.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/60401.cc: Likewise.
	* testsuite/26_numerics/headers/cmath/types_std_c++0x.cc:
	Likewise.
	* testsuite/lib/libstdc++.exp (check_v3_target_cstdint):
	Likewise.
	* testsuite/util/testsuite_random.h: Likewise.
2023-05-31 21:01:16 +01:00
Jakub Jelinek
883f1e25dc libstdc++: Fix up some <cmath> templates [PR109883]
As can be seen on the following testcase, for
std::{atan2,fmod,pow,copysign,fdim,fmax,fmin,hypot,nextafter,remainder,remquo,fma}
if one operand type is std::float{16,32,64,128}_t or std::bfloat16_t and
another one some integral type or some other floating point type which
promotes to the other operand's type, we can end up with endless recursion.
This is because of a declaration ordering problem in <cmath>, where the
float, double and long double overloads of those functions come before
the templates which use __gnu_cxx::__promote_{2,3}, but the
std::float{16,32,64,128}_t and std::bfloat16_t overloads come later in the
file.  If the result of those promotions is _Float{16,32,64,128} or
__gnu_cxx::__bfloat16_t, say std::pow(_Float64, int) calls
std::pow(_Float64, _Float64) and the latter calls itself.

The following patch fixes that by moving those templates later in the file,
so that the calls from those templates see also the other overloads.

I think other templates in the file like e.g. isgreater etc. shouldn't be
a problem, because those just use __builtin_isgreater etc. in their bodies.

2023-05-17  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/109883
	* include/c_global/cmath (atan2, fmod, pow): Move
	__gnu_cxx::__promote_2 using templates after _Float{16,32,64,128} and
	__gnu_cxx::__bfloat16_t overloads.
	(copysign, fdim, fmax, fmin, hypot, nextafter, remainder, remquo):
	Likewise.
	(fma): Move __gnu_cxx::__promote_3 using template after
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads.

	* testsuite/26_numerics/headers/cmath/constexpr_std_c++23.cc: New test.
2023-05-17 21:21:23 +02:00
Jonathan Wakely
af595613ac libstdc++: Fix std::abs(__float128) for -NaN and -0.0 [PR109758]
The current implementation of this non-standard overload of std::abs
incorrectly returns a negative value for negative NaNs and negative
zero, because x < 0 is false in both cases.

Use fabsl(long double) or fabsf128(_Float128) if those do the right
thing.  Otherwise, use __builtin_signbit(x) instead of x < 0 to detect
negative inputs. This assumes that __builtin_signbit handles __float128
correctly, but that seems to be true for all of GCC, clang and icc.

libstdc++-v3/ChangeLog:

	PR libstdc++/109758
	* include/bits/std_abs.h (abs(__float128)): Handle negative NaN
	and negative zero correctly.
	* testsuite/26_numerics/headers/cmath/109758.cc: New test.
2023-05-11 12:16:21 +01:00
Jonathan Wakely
abb958ada1 libstdc++: Add assertions to std::mask_array operations [PR62196]
Add assertions to diagnose incorrect uses of valarray masks.

The assignment operators of std::mask_array do not have any explicit
preconditions in the standard, but the assignment operator
valarray<T>::operator=(const mask_array<T>&) requires the lengths to
match, so it seems consistent to also require that when the operands are
reversed.  In support of that interpretation, libstdc++ has undefined
behaviour if the right-hand operand has more elements than are selected
by the mask, and libc++ has undefined behaviour if it has fewer
elements. Our std::mask_array stores the number of selected elements as
_M_sz so it's easy to add an assertion that checks it.

For the valarray::operator[] that takes a valarray<bool> mask,
[valarray.sub] in the standard says: "In each case the selected
element(s) shall exist." This makes it undefined to have a mask that
refers to out-of-range elements. We can easily check this too.

libstdc++-v3/ChangeLog:

	PR libstdc++/62196
	* include/bits/mask_array.h (mask_array): Add assertions to
	assignment operators.
	* include/std/valarray (valarray::operator[](valarray<bool>)):
	Add assertions.
	* testsuite/26_numerics/valarray/mask-1_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-2_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-3_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-4_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-5_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-6_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-7_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask-8_neg.cc: New test.
	* testsuite/26_numerics/valarray/mask.cc: New test.
2023-03-14 10:28:38 +00:00
Jakub Jelinek
83ffe9cde7 Update copyright years. 2023-01-16 11:52:17 +01:00
Jonathan Wakely
c775e2b81f libstdc++: Replace non-ASCII character in comment
This has an unnecessary UTF-8 non-breaking space.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
	Replace non-ASCII character.
2022-11-28 15:22:40 +00:00
Jonathan Wakely
a64775a0ed libstdc++: Make 16-bit std::subtract_with_carry_engine work [PR107466]
This implements the proposed resolution of LWG 3809, so that
std::subtract_with_carry_engine can be used with a 16-bit result_type.
Currently this produces a narrowing error when instantiating the
std::linear_congruential_engine to create the initial state. It also
truncates the default_seed constant when passing it as a result_type
argument.

Change the type of the constant to uint_least32_t and pass 0u when the
default_seed should be used.

libstdc++-v3/ChangeLog:

	PR libstdc++/107466
	* include/bits/random.h (subtract_with_carry_engine): Use 32-bit
	type for default seed. Use 0u as default argument for
	subtract_with_carry_engine(result_type) constructor and
	seed(result_type) member function.
	* include/bits/random.tcc (subtract_with_carry_engine): Use
	32-bit type for default seed and engine used for initial state.
	* testsuite/26_numerics/random/subtract_with_carry_engine/cons/lwg3809.cc:
	New test.
2022-11-28 15:02:04 +00:00
Jonathan Wakely
4581328022 libstdc++: Change return type of std::bit_width to int (LWG 3656)
libstdc++-v3/ChangeLog:

	* doc/html/manual/bugs.html: Regenerate.
	* doc/xml/manual/intro.xml: Document LWG 3656 change.
	* include/std/bit (__bit_width, bit_width): Return int.
	* testsuite/26_numerics/bit/bit.pow.two/lwg3656.cc: New test.
2022-11-25 00:22:01 +00:00
Jonathan Wakely
fbad7a74aa libstdc++: Fix tests with non-const operator==
These tests fail in strict -std=c++20 mode but their equality ops don't
need to be non-const, it looks like an accident.

This fixes two FAILs with -std=c++20:
FAIL: 20_util/tuple/swap.cc (test for excess errors)
FAIL: 26_numerics/valarray/87641.cc (test for excess errors)

libstdc++-v3/ChangeLog:

	* testsuite/20_util/tuple/swap.cc (MoveOnly::operator==): Add
	const qualifier.
	* testsuite/26_numerics/valarray/87641.cc (X::operator==):
	Likewise.
2022-11-11 04:00:58 +00:00
Jakub Jelinek
29ef50b6bc libstdc++-v3: Some std::*float*_t charconv and i/ostream overloads
The following patch adds the easy part of <charconv>, <istream> and
<ostream> changes for extended floats.
In particular, for the first one only overloads where the _Float* has
the same format as float/double/long double and for the latter two
everything but the _GLIBCXX_HAVE_FLOAT128_MATH case.
For charconv, I'm not really familiar with it, I'm pretty sure
we need new libstdc++.so.6 side implementation of from_chars for
{,b}float16_t and for to_chars not really sure but for unspecified precision
if it should emit minimum characters that to_chars then can unambiguously
parse, I think it is less than in the float case.  For float128_t
{to,from}_chars I think we even have it on the library side already, just
ifdefed for powerpc64le only.
For i/o stream operator<</>>, not sure what is better, if not providing
anything at all, or doing what we in the end do if user doesn't override
the virtual functions, or use {to,from}_chars under the hood, something
else?
Besides this, the patch adds some further missed
// { dg-options "-std=gnu++2b" }
spots, I've also noticed I got the formatting wrong in some testcases
by not using spaces around VERIFY conditions and elsewhere by having
space before ( for calls.
The testsuite coverage is limited, I've added test for from_chars because
it was easy to port, but not really sure what to do about to_chars, it has
for float/double huge testcases which would be excessive to repeat.
And for i/ostream not really sure what exactly is worth testing.

2022-11-01  Jakub Jelinek  <jakub@redhat.com>

	* include/std/charconv (from_chars, to_chars): Add _Float{32,64,128}
	overloads for cases where those types match {float,double,long double}.
	* include/std/istream (basic_istream::operator>>): Add
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads.
	* include/std/ostream (basic_ostream::operator<<): Add
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t overloads.
	* testsuite/20_util/from_chars/8.cc: New test.
	* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test):
	Formatting fixes.
	* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: Add
	dg-options "-std=gnu++2b".
	(test_functions, main): Formatting fixes.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc:
	Add dg-options "-std=gnu++2b".
2022-11-01 13:34:51 +01:00
Jakub Jelinek
db55f1dda2 libstdc++-v3: <complex> support for extended floating point types
The following patch adds <complex> support for extended floating point
types.
C++23 removes the float/double/long double specializations from the spec
and instead adds explicit(bool) specifier on the converting constructor.
The patch uses that for converting constructor of the base template as well
as the float/double/long double specializations's converting constructors
(e.g. so that it handles convertion construction also from complex of extended
floating point types).  Copy ctor was already defaulted as the spec now
requires.
The patch also adds partial specialization for the _Float{16,32,64,128}
and __gnu_cxx::__bfloat16_t types because the base template doesn't use
__complex__ but a pair of floating point values.
The g++.dg/cpp23/ testcase verifies explicit(bool) works correctly.

2022-10-31  Jakub Jelinek  <jakub@redhat.com>

gcc/testsuite/
	* g++.dg/cpp23/ext-floating12.C: New test.
libstdc++-v3/
	* include/std/complex (complex::complex converting ctor): For C++23
	use explicit specifier with constant expression.  Explicitly cast
	both parts to _Tp.
	(__complex_abs, __complex_arg, __complex_cos, __complex_cosh,
	__complex_exp, __complex_log, __complex_sin, __complex_sinh,
	__complex_sqrt, __complex_tan, __complex_tanh, __complex_pow): Add
	__complex__ _Float{16,32,64,128} and __complex__ decltype(0.0bf16)
	overloads.
	(complex<float>::complex converting ctor,
	complex<double>::complex converting ctor,
	complex<long double>::complex converting ctor): For C++23 implement
	as template with explicit specifier with constant expression
	and explicit casts.
	(__complex_type): New template.
	(complex): New partial specialization for types with extended floating
	point types.
	(__complex_acos, __complex_asin, __complex_atan, __complex_acosh,
	__complex_asinh, __complex_atanh): Add __complex__ _Float{16,32,64,128}
	and __complex__ decltype(0.0bf16) overloads.
	(__complex_proj): Likewise.  Add template for complex of extended
	floating point types.
	* include/bits/cpp_type_traits.h (__is_floating): Specialize for
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t.
	* testsuite/26_numerics/complex/ext_c++23.cc: New test.
2022-10-31 20:15:27 +01:00
Jakub Jelinek
cbf56503d5 libstdc++: Small extended float support tweaks
The following patch
1) enables the std::float128_t overloads for x86 with glibc 2.26+
2) makes std::nextafter(std::float16_t, std::float16_t) and
   std::nextafter(std::bfloat16_t, std::bfloat16_t) constexpr
3) adds (small) testsuite coverage for that

2022-10-21  Jakub Jelinek  <jakub@redhat.com>

	* config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH):
	Uncomment.
	* include/c_global/cmath (nextafter(_Float16, _Float16)): Make it constexpr.
	If std::__is_constant_evaluated() call __builtin_nextafterf16.
	(nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)): Similarly
	but call __builtin_nextafterf16b.
	* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Add
	static assertions to test constexpr nextafter.
2022-10-31 16:49:04 +01:00
Jakub Jelinek
ba281da28d libstdc++-v3: Implement {,b}float16_t nextafter and some fixes [PR106652]
The following patch implements nextafter for std::{,b}float16_t,
though right now only without constexpr support, and adds a testcase for it.
The testcase unfortunately relevealed I've screwed up testing of my last
patch.  I've tested earlier version of the patch with
--target_board=unix/-std=c++23
but didn't test the final version with that RUNTESTFLAGS, so missed
an invalid call to std::sph_neumann (too many arguments) in the test.
And, I've made a typo in the guard for numeric_limits (the reason
for the guard is I wanted to avoid defining a large macro that nothing
will then use because the std::{,b}float*_t types are C++23 only) and
so numeric_limits wasn't specialized for the types at all but
testsuite/18_support/headers/limits/synopsis_cxx23.cc test didn't
detect that.
In the nextafter implementation I'm calling __builtin_nextafterf
to get various required side-effects for nextafter from 0/-0, or from max
to inf or from min to largest subnormal to avoid needing to set errno
inline, or use inline asm specific for each processor to force math
evaluation barriers.  Dunno if
  #ifdef __INT16_TYPE__
    using __float16_int_type = __INT16_TYPE__;
  #else
    using __float16_int_type = short int;
  #endif
isn't too ugly, perhaps we could just blindly use short int and hope
or even assert it has the same size as _Float16 or __gnu_cxx::__bfloat16_t?
Only aarch64, arm, csky, gcn, x86, nvptx and riscv support these types
and all of them have 16-bit short (I think the only target with some
other short size is avr with certain command line switches where both
short and int are 8-bit, but such mode isn't compatible with C and C++
requirements).

2022-10-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106652
	* include/std/limits: Fix a typo, 202202L -> 202002L.
	(numeric_limits::<_Float16>::radix, numeric_limits::<_Float32>::radix,
	numeric_limits::<_Float64>::radix, numeric_limits::<_Float128>::radix,
	numeric_limits::<__gnu_cxx::__bfloat16_t>::radix): Use __FLT_RADIX__
	macro instead of type specific macros.
	* include/c_global/cmath (nextafter(_Float16, _Float16)): New
	overload.
	(nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t)):
	Likewise.
	* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc
	(test_functions): Uncomment nextafter test.  Fix up sph_neumann call.
	* testsuite/26_numerics/headers/cmath/nextafter_c++23.cc: New test.
2022-10-19 11:26:17 +02:00
Jakub Jelinek
a23225fb4f libstdc++: Partial library support for std::float{16,32,64,128}_t and std::bfloat16_t
The following patch is partial support for std::float{16,32,64,128}_t
and std::bfloat16_t in libstdc++.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html
says that <ostream>, <istream>, <charconv> and <complex>
need changes toom, but that isn't implemented so far.
In <cmath> the only thing missing I'm aware of is
std::nextafter std::float16_t and std::bfloat16_t overloads (I think
we probably need to implement that out of line somewhere, or inline? - might
need inline asm barriers) and std::nexttoward overloads (those are
intentional, you said there is a LWG issue about that).
Also, this patch has the glibc 2.26+ std::float128_t support for platforms
where long double isn't IEEE quad format temporarily disabled
because it depends on
https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603665.html
changes which aren't in yet.

The patch also doesn't include any testcases to cover the <type_traits>
changes, it isn't clear to me where to put that.

2022-10-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/106652
	* include/std/stdfloat: New file.
	* include/std/numbers (__glibcxx_numbers): Define and use it
	for __float128 explicit instantiations as well as
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t.
	* include/std/atomic (atomic<_Float16>, atomic<_Float32>,
	atomic<_Float64>, atomic<_Float128>, atomic<__gnu_cxx::__bfloat16_t>):
	New explicit instantiations.
	* include/std/type_traits (__is_floating_point_helper<_Float16>,
	__is_floating_point_helper<_Float32>,
	__is_floating_point_helper<_Float64>,
	__is_floating_point_helper<_Float128>,
	__is_floating_point_helper<__gnu_cxx::__bfloat16_t>): Likewise.
	* include/std/limits (__glibcxx_concat3_, __glibcxx_concat3,
	__glibcxx_float_n): Define.
	(numeric_limits<_Float16>, numeric_limits<_Float32>,
	numeric_limits<_Float64>, numeric_limits<_Float128>,
	numeric_limits<__gnu_cxx::__bfloat16_t>): New explicit instantiations.
	* include/bits/std_abs.h (abs): New overloads for
	_Float{16,32,64,128} and __gnu_cxx::__bfloat16_t.
	* include/bits/c++config (_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128): Define
	if long double is IEEE quad.
	(__gnu_cxx::__bfloat16_t): New using.
	* include/c_global/cmath (acos, asin, atan, atan2, ceil, cos, cosh,
	exp, fabs, floor, fmod, frexp, ldexp, log, log10, modf, pow, sin,
	sinh, sqrt, tan, tanh, fpclassify, isfinite, isinf, isnan, isnormal,
	signbit, isgreater, isgreaterequal, isless, islessequal,
	islessgreater, isunordered, acosh, asinh, atanh, cbrt, copysign, erf,
	erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb, lgamma,
	llrint, llround, log1p, log2, logb, lrint, lround, nearbyint,
	nextafter, remainder, rint, round, scalbln, scalbn, tgamma, trunc,
	lerp): New overloads with _Float{16,32,64,128} or
	__gnu_cxx::__bfloat16_t types.
	* config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH):
	Prepare for definition if glibc 2.26 and later implements *f128 APIs
	but comment out the actual definition for now.
	* include/ext/type_traits.h (__promote<_Float16>, __promote<_Float32>,
	__promote<_Float64>, __promote<_Float128>,
	__promote<__gnu_cxx::__bfloat16_t>): New specializations.
	* include/Makefile.am (std_headers): Add stdfloat.
	* include/Makefile.in: Regenerated.
	* include/precompiled/stdc++.h: Include stdfloat.
	* testsuite/18_support/headers/stdfloat/types_std.cc: New test.
	* testsuite/18_support/headers/limits/synopsis_cxx23.cc: New test.
	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c++23.cc:
	New test.
	* testsuite/26_numerics/headers/cmath/functions_std_c++23.cc: New test.
	* testsuite/26_numerics/numbers/4.cc: New test.
	* testsuite/29_atomics/atomic_float/requirements_cxx23.cc: New test.
2022-10-18 11:37:13 +02:00
Arsen Arsenović
7cc9022f8d libstdc++: Disable hosted-only tests [PR103626]
PR libstdc++/103626 - _GLIBCXX_HOSTED should respect -ffreestanding

libstdc++-v3/ChangeLog:

	PR libstdc++/103626
	* testsuite/17_intro/headers/c++1998/stdc++_assert_neg.cc:
	Require ET hosted.
	* testsuite/18_support/aligned_alloc/aligned_alloc.cc: Likewise.
	* testsuite/18_support/new_nothrow.cc: Likewise.
	* testsuite/20_util/allocator/105975.cc: Likewise.
	* testsuite/20_util/allocator/14176.cc: Likewise.
	* testsuite/20_util/allocator/64135.cc: Likewise.
	* testsuite/20_util/allocator/89510.cc: Likewise.
	* testsuite/20_util/allocator/lwg3190.cc: Likewise.
	* testsuite/20_util/allocator/overaligned.cc: Likewise.
	* testsuite/20_util/allocator/rebind_c++20.cc: Likewise.
	* testsuite/20_util/allocator/requirements/constexpr.cc:
	Likewise.
	* testsuite/20_util/allocator/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/20_util/allocator/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/allocator/requirements/typedefs_c++20.cc:
	Likewise.
	* testsuite/20_util/allocator/void.cc: Likewise.
	* testsuite/20_util/allocator_traits/header-2.cc: Likewise.
	* testsuite/20_util/allocator_traits/header.cc: Likewise.
	* testsuite/20_util/allocator_traits/members/92878_92947.cc:
	Likewise.
	* testsuite/20_util/allocator_traits/members/pointers.cc:
	Likewise.
	* testsuite/20_util/allocator_traits/requirements/typedefs.cc:
	Likewise.
	* testsuite/20_util/bad_function_call/cons_virtual_derivation.cc:
	Likewise.
	* testsuite/20_util/bind/42593.cc: Likewise.
	* testsuite/20_util/bitset/access/dr396.cc: Likewise.
	* testsuite/20_util/bitset/access/to_string.cc: Likewise.
	* testsuite/20_util/bitset/cons/16020.cc: Likewise.
	* testsuite/20_util/bitset/cons/dr1325-2.cc: Likewise.
	* testsuite/20_util/bitset/cons/dr396.cc: Likewise.
	* testsuite/20_util/bitset/debug/invalidation/1.cc: Likewise.
	* testsuite/20_util/bitset/ext/15361.cc: Likewise.
	* testsuite/20_util/bitset/operations/13838.cc: Likewise.
	* testsuite/20_util/bitset/operations/96303.cc: Likewise.
	* testsuite/20_util/bitset/version.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/56383.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/89303.cc: Likewise.
	* testsuite/20_util/enable_shared_from_this/members/assign.cc:
	Likewise.
	* testsuite/20_util/enable_shared_from_this/members/const.cc:
	Likewise.
	* testsuite/20_util/enable_shared_from_this/members/reinit.cc:
	Likewise.
	* testsuite/20_util/enable_shared_from_this/members/unique_ptr.cc:
	Likewise.
	* testsuite/20_util/enable_shared_from_this/members/weak_from_this.cc:
	Likewise.
	* testsuite/20_util/enable_shared_from_this/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/forward/1.cc: Likewise.
	* testsuite/20_util/forward/1_neg.cc: Likewise.
	* testsuite/20_util/function/1.cc: Likewise.
	* testsuite/20_util/function/10.cc: Likewise.
	* testsuite/20_util/function/2.cc: Likewise.
	* testsuite/20_util/function/3.cc: Likewise.
	* testsuite/20_util/function/4.cc: Likewise.
	* testsuite/20_util/function/43397.cc: Likewise.
	* testsuite/20_util/function/48541.cc: Likewise.
	* testsuite/20_util/function/5.cc: Likewise.
	* testsuite/20_util/function/58569.cc: Likewise.
	* testsuite/20_util/function/6.cc: Likewise.
	* testsuite/20_util/function/60594.cc: Likewise.
	* testsuite/20_util/function/65760.cc: Likewise.
	* testsuite/20_util/function/69222.cc: Likewise.
	* testsuite/20_util/function/7.cc: Likewise.
	* testsuite/20_util/function/77322.cc: Likewise.
	* testsuite/20_util/function/8.cc: Likewise.
	* testsuite/20_util/function/9.cc: Likewise.
	* testsuite/20_util/function/91456.cc: Likewise.
	* testsuite/20_util/function/assign/move.cc: Likewise.
	* testsuite/20_util/function/assign/move_target.cc: Likewise.
	* testsuite/20_util/function/cmp/cmp_neg.cc: Likewise.
	* testsuite/20_util/function/cons/55320.cc: Likewise.
	* testsuite/20_util/function/cons/57465.cc: Likewise.
	* testsuite/20_util/function/cons/72820.cc: Likewise.
	* testsuite/20_util/function/cons/addressof.cc: Likewise.
	* testsuite/20_util/function/cons/callable.cc: Likewise.
	* testsuite/20_util/function/cons/deduction.cc: Likewise.
	* testsuite/20_util/function/cons/lwg2774.cc: Likewise.
	* testsuite/20_util/function/cons/move.cc: Likewise.
	* testsuite/20_util/function/cons/move_target.cc: Likewise.
	* testsuite/20_util/function/cons/noexcept.cc: Likewise.
	* testsuite/20_util/function/cons/non_copyconstructible.cc:
	Likewise.
	* testsuite/20_util/function/cons/refqual.cc: Likewise.
	* testsuite/20_util/function/cons/70692.cc: Likewise.
	* testsuite/20_util/function/cons/deduction_c++23.cc: Likewise.
	* testsuite/20_util/function/invoke/forwarding.cc: Likewise.
	* testsuite/20_util/function/invoke/move_only.cc: Likewise.
	* testsuite/20_util/function/null_pointer_comparisons.cc:
	Likewise.
	* testsuite/20_util/function/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/function/target_no_rtti.cc: Likewise.
	* testsuite/20_util/function_objects/83607.cc: Likewise.
	* testsuite/20_util/function_objects/mem_fn/adl.cc: Likewise.
	* testsuite/20_util/headers/cstdlib/functions_std.cc: Likewise.
	* testsuite/20_util/headers/functional/types_std_c++0x.cc:
	Likewise.
	* testsuite/20_util/headers/memory/types_std_c++0x.cc: Likewise.
	* testsuite/20_util/is_function/35637.cc: Likewise.
	* testsuite/20_util/move/1.cc: Likewise.
	* testsuite/20_util/move_only_function/call.cc: Likewise.
	* testsuite/20_util/move_only_function/cons.cc: Likewise.
	* testsuite/20_util/move_only_function/move.cc: Likewise.
	* testsuite/20_util/move_only_function/version.cc: Likewise.
	* testsuite/20_util/owner_less/cmp.cc: Likewise.
	* testsuite/20_util/owner_less/noexcept.cc: Likewise.
	* testsuite/20_util/owner_less/void.cc: Likewise.
	* testsuite/20_util/pointer_safety/1.cc: Likewise.
	* testsuite/20_util/scoped_allocator/65279.cc: Likewise.
	* testsuite/20_util/scoped_allocator/69293_neg.cc: Likewise.
	* testsuite/20_util/scoped_allocator/construct_pair.cc:
	Likewise.
	* testsuite/20_util/scoped_allocator/dr2586.cc: Likewise.
	* testsuite/20_util/scoped_allocator/requirements/explicit_instantiation.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/assign/assign.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/auto_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/auto_ptr_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/auto_ptr_rvalue.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/assign/dr541.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/move.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/sfinae.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/shared_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/assign/unique_ptr_lvalue_neg.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/assign/unique_ptr_rvalue.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/atomic/1.cc: Likewise.
	* testsuite/20_util/shared_ptr/atomic/2.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/1.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/reinterpret.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/rval.cc: Likewise.
	* testsuite/20_util/shared_ptr/comparison/42925.cc: Likewise.
	* testsuite/20_util/shared_ptr/comparison/86537.cc: Likewise.
	* testsuite/20_util/shared_ptr/comparison/cmp.cc: Likewise.
	* testsuite/20_util/shared_ptr/comparison/cmp_c++20.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/comparison/dr1401.cc: Likewise.
	* testsuite/20_util/shared_ptr/comparison/less.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/39405.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/43820_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/46910.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/51365.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/52924.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/55123.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/58659.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/58839.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/61036.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/79467.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/80229.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/alias-rval.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/alias.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/array.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/auto_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/auto_ptr_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/copy.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/deduction.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/default.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/lwg2802.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/lwg3548.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/move.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/cons/nullptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/pointer.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_array.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_1.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/cons/void_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/weak_ptr.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/36949.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/58594-no-rtti.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/58594.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/87278.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/92878_92947.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/99006.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/dr402.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/dr925.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/make.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/no_rtti.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/overwrite.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/private.cc: Likewise.
	* testsuite/20_util/shared_ptr/creation/single_allocation.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/single_allocation_no_rtti.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/creation/version.cc: Likewise.
	* testsuite/20_util/shared_ptr/dest/dest.cc: Likewise.
	* testsuite/20_util/shared_ptr/hash/1.cc: Likewise.
	* testsuite/20_util/shared_ptr/misc/24595.cc: Likewise.
	* testsuite/20_util/shared_ptr/misc/42019.cc: Likewise.
	* testsuite/20_util/shared_ptr/misc/get_deleter.cc: Likewise.
	* testsuite/20_util/shared_ptr/misc/swap.cc: Likewise.
	* testsuite/20_util/shared_ptr/modifiers/reset.cc: Likewise.
	* testsuite/20_util/shared_ptr/modifiers/reset_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/modifiers/reset_sfinae.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/modifiers/swap.cc: Likewise.
	* testsuite/20_util/shared_ptr/modifiers/swap_neg.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/array.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/bool_conv.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/get.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/owner_before.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/observers/unique.cc: Likewise.
	* testsuite/20_util/shared_ptr/observers/use_count.cc: Likewise.
	* testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/requirements/weak_type.cc:
	Likewise.
	* testsuite/20_util/specialized_algorithms/construct_at/95788.cc:
	Likewise.
	* testsuite/20_util/temporary_buffer.cc: Likewise.
	* testsuite/20_util/tuple/48476.cc: Likewise.
	* testsuite/20_util/tuple/cons/90700.cc: Likewise.
	* testsuite/20_util/tuple/cons/96803.cc: Likewise.
	* testsuite/20_util/tuple/cons/allocator_with_any.cc: Likewise.
	* testsuite/20_util/tuple/cons/allocators.cc: Likewise.
	* testsuite/20_util/tuple/cons/constexpr_allocator_arg_t.cc:
	Likewise.
	* testsuite/20_util/tuple/cons/explicit_construct.cc: Likewise.
	* testsuite/20_util/tuple/p2321r2.cc: Likewise.
	* testsuite/20_util/unique_ptr/creation/92878_92947.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/array.cc: Likewise.
	* testsuite/20_util/unique_ptr/creation/array_neg.cc: Likewise.
	* testsuite/20_util/unique_ptr/creation/constexpr.cc: Likewise.
	* testsuite/20_util/unique_ptr/creation/for_overwrite.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/for_overwrite__neg.cc:
	Likewise.
	* testsuite/20_util/unique_ptr/creation/single.cc: Likewise.
	* testsuite/20_util/uses_allocator/69293_neg.cc: Likewise.
	* testsuite/20_util/uses_allocator/92878_92947.cc: Likewise.
	* testsuite/20_util/uses_allocator/uninitialized_construct.cc:
	Likewise.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise.
	* testsuite/20_util/weak_ptr/cons/deduction.cc: Likewise.
	* testsuite/20_util/weak_ptr/cons/noexcept_move_construct.cc:
	Likewise.
	* testsuite/20_util/weak_ptr/lock/1.cc: Likewise.
	* testsuite/20_util/weak_ptr/observers/owner_before.cc:
	Likewise.
	* testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/21_strings/basic_string/version.cc: Likewise.
	* testsuite/21_strings/basic_string_view/operations/contains/char/2.cc:
	Likewise.
	* testsuite/21_strings/c_strings/char/69626.cc: Likewise.
	* testsuite/21_strings/char_traits/requirements/version.cc:
	Likewise.
	* testsuite/23_containers/vector/requirements/version.cc:
	Likewise.
	* testsuite/24_iterators/back_insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/front_insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/insert_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/istream_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/92285.cc: Likewise.
	* testsuite/24_iterators/istreambuf_iterator/cons/sentinel.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/istreambuf_iterator/requirements/dr445.cc:
	Likewise.
	* testsuite/24_iterators/ostream_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/24_iterators/ostreambuf_iterator/requirements/base_classes.cc:
	Likewise.
	* testsuite/25_algorithms/constexpr_macro.cc: Likewise.
	* testsuite/25_algorithms/equal/constrained.cc: Likewise.
	* testsuite/25_algorithms/headers/cstdlib/functions_std.cc:
	Likewise.
	* testsuite/25_algorithms/inplace_merge/1.cc: Likewise.
	* testsuite/25_algorithms/lexicographical_compare/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/make_heap/movable.cc: Likewise.
	* testsuite/25_algorithms/pstl/feature_test-4.cc: Likewise.
	* testsuite/25_algorithms/random_shuffle/1.cc: Likewise.
	* testsuite/25_algorithms/random_shuffle/moveable.cc: Likewise.
	* testsuite/25_algorithms/random_shuffle/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/sort/35588.cc: Likewise.
	* testsuite/25_algorithms/stable_partition/1.cc: Likewise.
	* testsuite/25_algorithms/stable_partition/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/mem_check.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/moveable.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/25_algorithms/stable_partition/requirements/explicit_instantiation/pod.cc:
	Likewise.
	* testsuite/25_algorithms/stable_sort/1.cc: Likewise.
	* testsuite/26_numerics/complex/2.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/13943.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/2190.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/60401.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/dr2192.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/dr2192_neg.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/dr2735.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/functions_std.cc:
	Likewise.
	* testsuite/26_numerics/headers/cstdlib/macros.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/types_std.cc: Likewise.
	* testsuite/26_numerics/headers/cstdlib/types_std_c++0x.cc:
	Likewise.
	* testsuite/26_numerics/lerp/version.cc: Likewise.
	* testsuite/26_numerics/midpoint/version.cc: Likewise.
	* testsuite/27_io/basic_syncbuf/2.cc: Likewise.
	* testsuite/27_io/basic_syncstream/2.cc: Likewise.
	* testsuite/27_io/fpos/14320-1.cc: Likewise.
	* testsuite/27_io/fpos/14320-2.cc: Likewise.
	* testsuite/27_io/fpos/14320-3.cc: Likewise.
	* testsuite/27_io/fpos/14320-4.cc: Likewise.
	* testsuite/27_io/spanstream/version.cc: Likewise.
	* testsuite/29_atomics/atomic/lwg3220.cc: Likewise.
	* testsuite/29_atomics/atomic/operators/51811.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/1.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc: Likewise.
	* testsuite/29_atomics/atomic/wait_notify/2.cc: Likewise.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: Likewise.
	* testsuite/30_threads/barrier/2.cc: Likewise.
	* testsuite/30_threads/condition_variable_any/stop_token/2.cc:
	Likewise.
	* testsuite/30_threads/jthread/version.cc: Likewise.
	* testsuite/30_threads/latch/2.cc: Likewise.
	* testsuite/30_threads/semaphore/2.cc: Likewise.
	* testsuite/30_threads/stop_token/2.cc: Likewise.
	* testsuite/abi/pr42230.cc: Likewise.
	* testsuite/ext/shared_ptr/1.cc: Likewise.
	* testsuite/libstdc++-xmethods/shared_ptr.cc: Likewise.
	* testsuite/std/ranges/adaptors/lazy_split_neg.cc: Likewise.
	* testsuite/std/ranges/adaptors/p1739.cc: Likewise.
	* testsuite/std/ranges/iota/lwg3292_neg.cc: Likewise.
	* testsuite/std/ranges/p2325.cc: Likewise.
2022-10-03 15:44:01 +01:00
Alexandre Oliva
3e3744d37e libstdc++: testsuite: complex proj requirements
The template version of complex::proj returns its argument without
testing for infinities, and that's all we have when neither C99
complex nor C99 math functions are available, and it seems too hard to
do better without isinf and copysign.

I suppose just calling them and expecting users will supply
specializations as needed has been ruled out, and so has refraining
from defining it when it can't be implemented correctly.

It's pointless to run the proj.cc test under these circumstances, so
arrange for it to be skipped.  In an unusual way, after trying to
introduce dg-require tests for ccomplex-or-cmath, and found their
results to be misleading due to variations across -std=* versions.


for  libstdc++-v3/ChangeLog

	* testsuite/26_numerics/complex/proj.cc: Skip test in the
	circumstances in which the implementation of proj is known to
	be broken.
2022-06-27 10:34:18 -03:00
Jonathan Wakely
78fd15fd4a libstdc++: Simplify test by not using std::log2
This test uses std::log2 without including <cmath>, but it doesn't need
to use it at all. Just get the number of digits from numeric_limits
instead.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/random_device/entropy.cc: Use
	numeric_limits<unsigned>::digits.
2022-06-23 12:00:01 +01:00
Jonathan Wakely
671970a562 libstdc++: Make std::lcm and std::gcd detect overflow [PR105844]
When I fixed PR libstdc++/92978 I introduced a regression whereby
std::lcm(INT_MIN, 1) and std::lcm(50000, 49999) would no longer produce
errors during constant evaluation. Those calls are undefined, because
they violate the preconditions that |m| and the result can be
represented in the return type (which is int in both those cases). The
regression occurred because __absu<unsigned>(INT_MIN) is well-formed,
due to the explicit casts to unsigned in that new helper function, and
the out-of-range multiplication is well-formed, because unsigned
arithmetic wraps instead of overflowing.

To fix 92978 I made std::gcm and std::lcm calculate |m| and |n|
immediately, yielding a common unsigned type that was used to calculate
the result. That was partly correct, but there's no need to use an
unsigned type. Doing so only suppresses the overflow errors so the
compiler can't detect them. This change replaces __absu with __abs_r
that returns the common type (not its corresponding unsigned type). This
way we can detect overflow in __abs_r when required, while still
supporting the most-negative value when it can be represented in the
result type. To detect LCM results that are out of range of the result
type we still need explicit checks, because neither constant evaluation
nor UBsan will complain about unsigned wrapping for cases such as
std::lcm(500000u, 499999u). We can detect those overflows efficiently by
using __builtin_mul_overflow and asserting.

libstdc++-v3/ChangeLog:

	PR libstdc++/105844
	* include/experimental/numeric (experimental::gcd): Simplify
	assertions. Use __abs_r instead of __absu.
	(experimental::lcm): Likewise. Remove use of __detail::__lcm so
	overflow can be detected.
	* include/std/numeric (__detail::__absu): Rename to __abs_r and
	change to allow signed result type, so overflow can be detected.
	(__detail::__lcm): Remove.
	(gcd): Simplify assertions. Use __abs_r instead of __absu.
	(lcm): Likewise. Remove use of __detail::__lcm so overflow can
	be detected.
	* testsuite/26_numerics/gcd/gcd_neg.cc: Adjust dg-error lines.
	* testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
	* testsuite/26_numerics/gcd/105844.cc: New test.
	* testsuite/26_numerics/lcm/105844.cc: New test.
2022-06-10 15:24:29 +01:00
Jonathan Wakely
e3b8b4f781 libstdc++: Reduce <random> test iterations for simulators
Some of these tests take several minutes on a simulator like cris-elf,
so we can conditionally run fewer iterations. The testDiscreteDist
helper already supports custom sizes so we just need to make use of that
when { target simulator } matches.

The relevant code is sufficiently tested on other targets, so we're not
losing anything by only running a small number of iterators for sims.

libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/bernoulli_distribution/operators/values.cc:
	Run fewer iterations for simulator targets.
	* testsuite/26_numerics/random/binomial_distribution/operators/values.cc:
	Likewise.
	* testsuite/26_numerics/random/discrete_distribution/operators/values.cc:
	Likewise.
	* testsuite/26_numerics/random/geometric_distribution/operators/values.cc:
	Likewise.
	* testsuite/26_numerics/random/negative_binomial_distribution/operators/values.cc:
	Likewise.
	* testsuite/26_numerics/random/poisson_distribution/operators/values.cc:
	Likewise.
	* testsuite/26_numerics/random/uniform_int_distribution/operators/values.cc:
	Likewise.
2022-05-20 15:47:49 +01:00
Jonathan Wakely
42991a9116 libstdc++: Simplify std::normal_distribution equality operator
libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (operator==): Only check
	normal_distribution::_M_saved_available once.
	* testsuite/26_numerics/random/normal_distribution/operators/equal.cc:
	Check equality after state changes.
	* testsuite/26_numerics/random/pr60037-neg.cc: Adjust dg-error
	lineno.
2022-05-06 23:54:09 +01:00
Jonathan Wakely
909ef4e272 libstdc++: Fix deserialization for std::normal_distribution [PR105502]
This fixes a regression in std::normal_distribution deserialization that
caused the object to be left unchanged if the __state_avail value read
from the stream was false.

libstdc++-v3/ChangeLog:

	PR libstdc++/105502
	* include/bits/random.tcc
	(operator>>(basic_istream<C,T>&, normal_distribution<R>&)):
	Update state when __state_avail is false.
	* testsuite/26_numerics/random/normal_distribution/operators/serialize.cc:
	Check that deserialized object equals serialized one.
2022-05-06 23:54:09 +01:00
Jonathan Wakely
4894d69a1f libstdc++: Add missing constraints to std::bit_cast [PR105027]
Our std::bit_cast was relying on the compiler to check for errors inside
__builtin_bit_cast, instead of checking them as constraints. That means
std::bit_cast was not SFINAE-friendly.

This fix uses a requires-clause, so for old versions of Clang without
concepts support the function will still be unconstrained. At some point
in future we can remove the #ifdef __cpp_concepts check and rely on all
compilers having full concepts support in C++20 mode.

libstdc++-v3/ChangeLog:

	PR libstdc++/105027
	* include/std/bit (bit_cast): Add constraints.
	* testsuite/26_numerics/bit/bit.cast/105027.cc: New test.
2022-03-23 12:17:16 +00:00
Jakub Jelinek
7adcbafe45 Update copyright years. 2022-01-03 10:42:10 +01:00
Jakub Jelinek
7393fa8b1d libstdc++: Implement std::byteswap for C++23
This patch attempts to implement P1272R4 (except for the std::bit_cast
changes in there which seem quite unrelated to this and will need to be
fixed on the compiler side).
While at least for GCC __builtin_bswap{16,32,64,128} should work fine
in constant expressions, I wonder about other compilers, so I'm using
a fallback implementation for constexpr evaluation always.
If you think that is unnecessary, I can drop the
__cpp_if_consteval >= 202106L &&
if !consteval
  {
and
  }
and reformat.
The fallback implementation is an attempt to make it work even for integral
types that don't have number of bytes divisible by 2 or when __CHAR_BIT__
is e.g. 16.

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

	* include/std/bit (__cpp_lib_byteswap, byteswap): Define.
	* include/std/version (__cpp_lib_byteswap): Define.
	* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: New test.
	* testsuite/26_numerics/bit/bit.byteswap/version.cc: New test.
2021-11-28 16:33:33 +01:00
Jonathan Wakely
a04b73e15b libstdc++: Replace hyphens in effective target keywords
An effective target like foo-bar-baz will match a target selector of
*-*-* and cause problems in the testsuite. Several libstdc++ et keywords
are of the form foo-bar, which could still be a problem for *-*
selectors.

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

libstdc++-v3/ChangeLog:

	* testsuite/lib/libstdc++.exp: Rename effective target keywords
	to avoid dashes in the name.
	* testsuite/*: Update effective targe keywords.
2021-11-24 13:20:26 +00:00
Jason Merrill
87c2080b05 c++: Add -fimplicit-constexpr
With each successive C++ standard the restrictions on the use of the
constexpr keyword for functions get weaker and weaker; it recently occurred
to me that it is heading toward the same fate as the C register keyword,
which was once useful for optimization but became obsolete.  Similarly, it
seems to me that we should be able to just treat inlines as constexpr
functions and not make people add the extra keyword everywhere.

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

gcc/c-family/ChangeLog:

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

gcc/cp/ChangeLog:

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

libstdc++-v3/ChangeLog:

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

gcc/testsuite/ChangeLog:

	* lib/g++-dg.exp: Handle "impcx".
	* lib/target-supports.exp
	(check_effective_target_implicit_constexpr): New.
	* g++.dg/abi/abi-tag16.C:
	* g++.dg/abi/abi-tag18a.C:
	* g++.dg/abi/guard4.C:
	* g++.dg/abi/lambda-defarg1.C:
	* g++.dg/abi/mangle26.C:
	* g++.dg/cpp0x/constexpr-diag3.C:
	* g++.dg/cpp0x/constexpr-ex1.C:
	* g++.dg/cpp0x/constexpr-ice5.C:
	* g++.dg/cpp0x/constexpr-incomplete2.C:
	* g++.dg/cpp0x/constexpr-memfn1.C:
	* g++.dg/cpp0x/constexpr-neg3.C:
	* g++.dg/cpp0x/constexpr-specialization.C:
	* g++.dg/cpp0x/inh-ctor19.C:
	* g++.dg/cpp0x/inh-ctor30.C:
	* g++.dg/cpp0x/lambda/lambda-mangle3.C:
	* g++.dg/cpp0x/lambda/lambda-mangle5.C:
	* g++.dg/cpp1y/auto-fn12.C:
	* g++.dg/cpp1y/constexpr-loop5.C:
	* g++.dg/cpp1z/constexpr-lambda7.C:
	* g++.dg/cpp2a/constexpr-dtor3.C:
	* g++.dg/cpp2a/constexpr-new13.C:
	* g++.dg/cpp2a/constinit11.C:
	* g++.dg/cpp2a/constinit12.C:
	* g++.dg/cpp2a/constinit14.C:
	* g++.dg/cpp2a/constinit15.C:
	* g++.dg/cpp2a/spaceship-constexpr1.C:
	* g++.dg/cpp2a/spaceship-eq3.C:
	* g++.dg/cpp2a/udlit-class-nttp-neg2.C:
	* g++.dg/debug/dwarf2/auto1.C:
	* g++.dg/debug/dwarf2/cdtor-1.C:
	* g++.dg/debug/dwarf2/lambda1.C:
	* g++.dg/debug/dwarf2/pr54508.C:
	* g++.dg/debug/dwarf2/pubnames-2.C:
	* g++.dg/debug/dwarf2/pubnames-3.C:
	* g++.dg/ext/is_literal_type3.C:
	* g++.dg/ext/visibility/template7.C:
	* g++.dg/gcov/gcov-12.C:
	* g++.dg/gcov/gcov-2.C:
	* g++.dg/ipa/devirt-35.C:
	* g++.dg/ipa/devirt-36.C:
	* g++.dg/ipa/devirt-37.C:
	* g++.dg/ipa/devirt-44.C:
	* g++.dg/ipa/imm-devirt-1.C:
	* g++.dg/lookup/builtin5.C:
	* g++.dg/lto/inline-crossmodule-1_0.C:
	* g++.dg/modules/enum-1_a.C:
	* g++.dg/modules/fn-inline-1_c.C:
	* g++.dg/modules/pmf-1_b.C:
	* g++.dg/modules/used-1_c.C:
	* g++.dg/tls/thread_local11.C:
	* g++.dg/tls/thread_local11a.C:
	* g++.dg/tm/pr46653.C:
	* g++.dg/ubsan/pr70035.C:
	* g++.old-deja/g++.other/delete6.C:
	* g++.dg/modules/pmf-1_a.H:
	Adjust for implicit constexpr.
2021-11-15 18:50:07 -05:00
Jonathan Wakely
95e8fcd3d5 libstdc++: Make test print which random_device tokens work
libstdc++-v3/ChangeLog:

	* testsuite/26_numerics/random/random_device/cons/token.cc:
	Print results of random_device_available checks.
2021-11-09 15:12:29 +00:00
Jonathan Wakely
3439657b02 libstdc++: Support getentropy and arc4random in std::random_device
This adds additional "getentropy" and "arc4random" tokens to
std::random_device. The former is supported on Glibc and OpenBSD (and
apparently wasm), and the latter is supported on various BSDs.

libstdc++-v3/ChangeLog:

	* acinclude.m4 (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM):
	Define.
	* configure.ac (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM):
	Use them.
	* config.h.in: Regenerate.
	* configure: Regenerate.
	* src/c++11/random.cc (random_device): Add getentropy and
	arc4random as sources.
	* testsuite/26_numerics/random/random_device/cons/token.cc:
	Check new tokens.
	* testsuite/26_numerics/random/random_device/entropy.cc:
	Likewise.
2021-11-09 14:40:33 +00:00