Commit Graph

5472 Commits

Author SHA1 Message Date
Jonathan Wakely
ca97c87758 libstdc++: Add <spanstream> declarations to <iosfwd> [PR105284]
libstdc++-v3/ChangeLog:

	PR libstdc++/105284
	* include/std/iosfwd: Add declarations for <spanstream> class
	templates and typedefs.
	* include/std/spanstream (basic_spanbuf, basic_ispanstream)
	(basic_ospanstream, basic_spanstream): Remove default template
	arguments.
	* testsuite/27_io/headers/iosfwd/synopsis.cc: Add <spanstream>
	declarations.
	* testsuite/27_io/headers/iosfwd/types.cc: Check <spanstream>
	default arguments.
2022-05-10 16:40:22 +01:00
Jonathan Wakely
1807e07825 libstdc++: Add <syncstream> declarations to <iosfwd> [PR105284]
libstdc++-v3/ChangeLog:

	PR libstdc++/105284
	* include/std/iosfwd: Add declarations for <synstream> class
	templates and typedefs.
	* include/std/syncstream (basic_syncbuf, basic_osyncstream):
	Remove default template arguments.
	* testsuite/27_io/headers/iosfwd/synopsis.cc: New test.
	* testsuite/27_io/headers/iosfwd/types.cc: New test.
2022-05-10 16:40:22 +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
aa8bdfee1d libstdc++: Fix test that fails on Solaris [PR104731]
On Solaris the dirent::d_name member is a single char, causing this test
to fail with warnings about buffer overflow. Change the test to use a
union with additional space for writing a string to the d_name member.

libstdc++-v3/ChangeLog:

	PR libstdc++/104731
	* testsuite/27_io/filesystem/iterators/error_reporting.cc:
	Use a trailing char array as storage for dirent::d_name.
2022-05-06 14:51:35 +01:00
Jonathan Wakely
b6b6600678 libstdc++: Fixes for tests that fail with -fno-rtti
This disables a use of dynamic_cast that is not valid for -fno-rtti and
adjusts some tests so they don't FAIL with -fno-rtti. Some tests are
skipped completely, and others just make use of typeid conditional on
the __cpp_rtti macro. A couple of tests were using typeid to verify
typedefs denote the right type, which can be done at compile-time using
templates instead.

libstdc++-v3/ChangeLog:

	* include/experimental/memory_resource [!__cpp_rtti]
	(__resource_adaptor_imp::do_is_equal): Do not use dynamic_cast
	when RTTI is disabled.
	* testsuite/17_intro/freestanding.cc: Require RTTI.
	* testsuite/18_support/exception/38732.cc: Likewise.
	* testsuite/18_support/exception_ptr/rethrow_exception.cc:
	Likewise.
	* testsuite/18_support/nested_exception/68139.cc: Likewise.
	* testsuite/18_support/nested_exception/rethrow_if_nested.cc:
	Likewise.
	* testsuite/18_support/type_info/103240.cc: Likewise.
	* testsuite/18_support/type_info/fundamental.cc: Likewise.
	* testsuite/18_support/type_info/hash_code.cc: Likewise.
	* testsuite/20_util/any/assign/emplace.cc: Likewise.
	* testsuite/20_util/any/cons/in_place.cc: Likewise.
	* testsuite/20_util/any/misc/any_cast.cc: Likewise.
	* testsuite/20_util/any/observers/type.cc: Likewise.
	* testsuite/20_util/function/1.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/5.cc: Likewise.
	* testsuite/20_util/function/6.cc: Likewise.
	* testsuite/20_util/function/7.cc: Likewise.
	* testsuite/20_util/function/8.cc: Likewise.
	* testsuite/20_util/polymorphic_allocator/resource.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/1.cc: Likewise.
	* testsuite/20_util/shared_ptr/casts/rval.cc: Likewise.
	* testsuite/20_util/shared_ptr/cons/unique_ptr_deleter_ref_2.cc:
	Likewise.
	* testsuite/20_util/shared_ptr/misc/get_deleter.cc: Likewise.
	* testsuite/20_util/typeindex/comparison_operators.cc: Likewise.
	* testsuite/20_util/typeindex/comparison_operators_c++20.cc:
	Likewise.
	* testsuite/20_util/typeindex/hash.cc: Likewise.
	* testsuite/20_util/typeindex/hash_code.cc: Likewise.
	* testsuite/20_util/typeindex/name.cc: Likewise.
	* testsuite/22_locale/ctype/is/string/89728_neg.cc: Likewise.
	* testsuite/22_locale/global_templates/standard_facet_hierarchies.cc:
	Likewise.
	* testsuite/22_locale/global_templates/user_facet_hierarchies.cc:
	Likewise.
	* testsuite/22_locale/locale/13630.cc: Check type without using
	RTTI.
	* testsuite/23_containers/array/requirements/non_default_constructible.cc:
	Require RTTI.
	* testsuite/27_io/basic_ostream/emit/1.cc: Likewise.
	* testsuite/27_io/fpos/14320-1.cc: Check type without using RTTI.
	* testsuite/27_io/fpos/mbstate_t/12065.cc: Require RTTI.
	* testsuite/27_io/ios_base/failure/dual_abi.cc: Likewise.
	* testsuite/experimental/any/misc/any_cast.cc: Likewise.
	* testsuite/experimental/any/observers/type.cc: Likewise.
	* testsuite/experimental/memory_resource/resource_adaptor.cc:
	Likewise.
	* testsuite/lib/libstdc++.exp (check_effective_target_rtti):
	Define new proc.
	* testsuite/tr1/3_function_objects/function/1.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/2.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/3.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/4.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/5.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/6.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/7.cc: Likewise.
	* testsuite/tr1/3_function_objects/function/8.cc: Likewise.
	* testsuite/tr2/bases/value.cc: Likewise.
	* testsuite/tr2/direct_bases/value.cc: Likewise.
	* testsuite/util/exception/safety.h [!__cpp_rtti]: Don't print
	types without RTTI.
2022-05-05 21:13:58 +01:00
Jonathan Wakely
ef8d5ac08b libstdc++: Simplify std::array accessors [PR104719]
This removes the __array_traits::_S_ref and __array_traits::_S_ptr
accessors, which only exist to make the special case of std::array<T, 0>
syntactically well-formed.

By changing the empty type used as the std::array<T, 0>::_M_elems data
member to support operator[] and conversion to a pointer, we can write
code using the natural syntax. The indirection through _S_ref and
_S_ptr is removed for the common case, and a function call is only used
for the special case of zero-size arrays.

The invalid member access for zero-sized arrays is changed to use
__builtin_trap() instead of a null dereference. This guarantees a
runtime error if it ever gets called, instead of undefined behaviour
that is likely to get optimized out as unreachable.

libstdc++-v3/ChangeLog:

	PR libstdc++/104719
	* include/std/array (__array_traits::_S_ref): Remove.
	(__array_traits::_S_ptr): Remove.
	(__array_traits<T, 0>::_Type): Define operator[] and operator T*
	to provide an array-like API.
	(array::_AT_Type): Remove public typeef.
	(array::operator[], array::at, array::front, array::back): Use
	index operator to access _M_elems instead of _S_ref.
	(array::data): Use implicit conversion from _M_elems to pointer.
	(swap(array&, array&)): Use __enable_if_t helper.
	(get<I>): Use index operator to access _M_elems.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc:
	Adjust dg-error line numbers.
2022-05-04 16:24:56 +01:00
Alexandre Oliva
25389f3de4 [PR105324] libstdc++: testsuite: pr105324 requires FP from_char
The floating-point overloads of from_char are only declared if
_GLIBCXX_HAVE_USELOCALE is #defined as nonzero.  That's exposed from
charconv as __cpp_lib_to_chars >= 201611L, so guard the test body with
that.


for  libstdc++-v3/ChangeLog

	PR c++/105324
	* testsuite/20_util/from_chars/pr105324.cc: Guard test body
	with conditional for floating-point overloads of from_char.
2022-05-03 14:57:15 -03:00
Patrick Palka
576f975cab libstdc++: case-sensitivity in hexfloat std::from_chars [PR105441]
The hexfloat parser for binary32/64 added in r12-6645-gcc3bf3404e4b1c
overlooked that the exponent part can also begin with an uppercase 'P'.

	PR libstdc++/105441

libstdc++-v3/ChangeLog:

	* src/c++17/floating_from_chars.cc (__floating_from_chars_hex):
	Also accept 'P' as the start of the exponent.
	* testsuite/20_util/from_chars/7.cc: Add corresponding testcase.
2022-05-02 07:00:48 -04:00
Jonathan Wakely
4e117418fb libstdc++: Fix error reporting in filesystem::copy [PR99290]
The recursive calls to filesystem::copy should stop if any of them
reports an error.

libstdc++-v3/ChangeLog:

	PR libstdc++/99290
	* src/c++17/fs_ops.cc (fs::copy): Pass error_code to
	directory_iterator constructor, and check on each iteration.
	* src/filesystem/ops.cc (fs::copy): Likewise.
	* testsuite/27_io/filesystem/operations/copy.cc: Check for
	errors during recursion.
	* testsuite/experimental/filesystem/operations/copy.cc:
	Likewise.
2022-04-28 13:33:48 +01:00
Jonathan Wakely
a849584587 libstdc++: Add pretty printer for std::atomic
For the atomic specializations for shared_ptr and weak_ptr we can reuse
the existing SharedPointerPrinter, with a small tweak.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (SharedPointerPrinter): Add
	support for atomic<shared_ptr<T>> and atomic<weak_ptr<T>>.
	(StdAtomicPrinter): New printer.
	(build_libstdcxx_dictionary): Register new printer.
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Test std::atomic.
	* testsuite/libstdc++-prettyprinters/cxx20.cc: Test atomic smart
	pointers.
2022-04-27 15:48:32 +01:00
Jonathan Wakely
41ccd683f0 libstdc++: Add std::atomic<shared_ptr>(nullptr_t) constructor (LWG 3661)
This DR was approved at the February 2022 plenary.

libstdc++-v3/ChangeLog:

	* include/bits/shared_ptr_atomic.h (atomic<shared_ptr>): Add
	constructor for constant initialization from nullptr_t.
	* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc:
	Check for new constructor.
2022-04-26 13:22:18 +01:00
Jonathan Wakely
e3c5e8360b libstdc++: Define std::hash<std::filesystem::path> (LWG 3657)
This DR was approved at the February 2022 plenary.

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (hash<filesystem::path>): Define.
	* testsuite/27_io/filesystem/path/nonmember/hash_value.cc:
	Check std::hash specialization.
2022-04-26 13:22:18 +01:00
Jonathan Wakely
2fbdcf5e58 libstdc++: Implement constexpr std::unique_ptr for C++23 (P2273R3)
libstdc++-v3/ChangeLog:

	* include/bits/ptr_traits.h (__cpp_lib_constexpr_memory): Define
	conditionally.
	* include/bits/unique_ptr.h (__cpp_lib_constexpr_memory):
	Define for C++23.
	(default_delete, default_delete<T[]>, __uniq_ptr_impl)
	(unique_ptr, unique_ptr<T[], D>): Add constexpr to all member
	functions.
	* include/std/version (__cpp_lib_constexpr_memory): Define new
	value for C++23.
	* testsuite/20_util/unique_ptr/assign/constexpr.cc: New test.
	* testsuite/20_util/unique_ptr/comparison/constexpr.cc: New test.
	* testsuite/20_util/unique_ptr/cons/constexpr_c++20.cc: New test.
	* testsuite/20_util/unique_ptr/creation/constexpr.cc: New test.
	* testsuite/20_util/unique_ptr/modifiers/constexpr.cc: New test.
	* testsuite/20_util/unique_ptr/specialized_algorithms/constexpr.cc:
	New test.
2022-04-25 16:16:33 +01:00
Jonathan Wakely
a5cee0480c libstdc++: Add deduction guides for std::packaged_task [PR105375]
This change was LWG 3117.

The test is copied from 20_util/function/cons/deduction.cc

libstdc++-v3/ChangeLog:

	PR libstdc++/105375
	* include/std/future (packaged_task): Add deduction guides.
	* testsuite/30_threads/packaged_task/cons/deduction.cc: New test.
2022-04-25 16:16:33 +01:00
Philipp Fent
71999fde2a libstdc++: Add pretty printer for std::initializer_list
Re-using the std::span printer, this now shows the contents of the
initializer list instead of the pointer and length members.

Signed-off-by: Philipp Fent <fent@in.tum.de>

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdSpanPrinter._iterator):
	Rename as iterator.
	(StdInitializerListPrinter): Define new printer.
	(build_libstdcxx_dictionary): Register new printer.
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Check printer for
	initializer_list.
2022-04-25 13:32:04 +01:00
Thomas W Rodgers
7c21556daf libstdc++: Make atomic notify_one and notify_all non-const
<recording this here for future reference>
PR102994 "atomics: std::atomic<ptr>::wait is not marked const" raises the
issue that the current libstdc++ implementation marks the notify members
const, the implementation strategy used by libstdc++, as well as libc++
and the Microsoft STL, do not require the atomic to be mutable (it is hard
to conceive of a desirable implementation approach that would require it).
The original paper proposing the wait/notify functionality for atomics
(p1185) also had these members marked const for the first three revisions,
but that was changed without explanation in r3 and subsequent revisions of
the paper.

After raising the issue to the authors of p1185 and the author of the
libc++ implementation, the consensus seems to be "meh, it's harmless" so
there seems little appetite for an LWG issue to revisit the subject.

This patch changes the libstdc++ implementation to be in agreement with
the standard by removing const from those notify_one/notify_all members.

libstdc++-v3/ChangeLog:

	PR libstdc++/102994
	* include/bits/atomic_base.h (atomic_flag::notify_one,
	notify_all): Remove const qualification.
	(__atomic_base::notify_one, notify_all): Likewise.
	* include/std/atomic (atomic<bool>::notify_one, notify_all):
	Likewise.
	(atomic::notify_one, notify_all): Likewise.
	(atomic<T*>::notify_one, notify_all): Likewise.
	(atomic_notify_one, atomic_notify_all): Likewise.
	* testsuite/29_atomics/atomic/wait_notify/102994.cc: Adjust test
	to account for change in notify_one/notify_all signature.
2022-04-22 15:53:41 -07:00
Jonathan Wakely
cf37107522 libstdc++: Remove bogus assertion in std::from_chars [PR105324]
I'm not sure what I was thinking when I added this assertion, maybe it
was supposed to be alignment == 1 (which is what the pmr::string actually
uses). The simplest fix is to just remove the assertion.

The assertion is no longer enabled by default on trunk, but it's still
there for the --enablke-libstdcxx-debug build, and is still wrong. The
fix is needed on the gcc-11 branch.

libstdc++-v3/ChangeLog:

	PR libstdc++/105324
	* src/c++17/floating_from_chars.cc (buffer_resource::do_allocate):
	Remove assertion.
	* testsuite/20_util/from_chars/pr105324.cc: New test.
2022-04-21 11:31:51 +01:00
Jonathan Wakely
67ded3a1f5 libstdc++: Fix macro checked by test
The macro being tested here is wrong, but just happens to have the same
value as the one supposed to be tests.

libstdc++-v3/ChangeLog:

	* testsuite/21_strings/basic_string_view/operations/copy/char/constexpr.cc:
	Check correct feature test macro.
2022-04-20 13:54:57 +01:00
Philipp Fent
fdb3f82fb3 libstdc++: Add pretty printer for std::span
This improves the debug output for C++20 spans.

Before:
{static extent = 18446744073709551615, _M_ptr = 0x7fffffffb9a8, _M_extent = {_M_extent_value = 2}}
Now with StdSpanPrinter:
std::span of length 2 = {1, 2}

Signed-off-by: Philipp Fent <fent@in.tum.de>

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdSpanPrinter): Define.
	* testsuite/libstdc++-prettyprinters/cxx20.cc: Test it.
2022-04-19 14:18:33 +01:00
Patrick Palka
7e76cef873 libstdc++: Avoid double-deref of __first in ranges::minmax [PR104858]
PR libstdc++/104858

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__minmax_fn): Avoid dereferencing
	__first twice at the start.
	* testsuite/25_algorithms/minmax/constrained.cc (test06): New test.
2022-04-15 14:41:14 -04:00
Jonathan Wakely
d2f8208e9a libstdc++: Fix missing and incorrect feature test macros [PR105269]
libstdc++-v3/ChangeLog:

	PR libstdc++/105269
	* include/bits/stl_vector.h (__cpp_lib_constexpr_vector):
	Define.
	* include/c_compatibility/stdatomic.h (__cpp_lib_stdatomic_h):
	Define.
	* include/std/optional (__cpp_lib_optional): Define new value
	for C++23.
	(__cpp_lib_monadic_optional): Remove.
	* include/std/version (__cpp_lib_constexpr_vector): Define.
	(__cpp_lib_stdatomic_h): Define.
	(__cpp_lib_optional): Define new value for C++23.
	(__cpp_lib_monadic_optional): Remove.
	* testsuite/20_util/optional/monadic/and_then.cc: Adjust.
	* testsuite/20_util/optional/requirements.cc: Adjust for C++23.
	* testsuite/20_util/optional/version.cc: Likewise.
	* testsuite/23_containers/vector/cons/constexpr.cc: Check
	feature test macro.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/20_util/optional/monadic/version.cc: Removed.
	* testsuite/23_containers/vector/requirements/version.cc: New test.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: New test.
2022-04-14 11:02:37 +01:00
Jonathan Wakely
2ce0f5185b libstdc++: Reduce memory usage in std::stacktrace::current
This adds an alternative callback for use in the overload of
basic_stacktrace::current that takes a max_depth parameter. The new
callback will not allow the container to grow past the initial capacity,
which is set to the specified maximum depth.  This avoids allocating
memory for hundreds of frames only to discard them again because of a
small maximum depth limit.

For larger maximum depths the normal callback is used, with a smaller
initial capacity that can grow as needed. The container will be resized
to the given max depth after the entire backtrace has been produced
(relying on the fact that std::stacktrace_entry objects are trivially
destructible to elide their destruction).

Currently the value for "larger" limits is 128, so a max depth <= 128
will allocate capacity for exactly that many frames. A larger max depth
(or an unspecified max depth) will use an initial capacity of 64 frames
and grow as needed. Since each frame is only a uintptr_t value it might
be reasonable to increase the first value so that memory usage can be
capped for larger maximum depths.

This change also delays the creation of the libbacktrace state until we
actually need it, so that the state is not created if allocation fails.

libstdc++-v3/ChangeLog:

	* include/std/stacktrace (basic_stacktrace::current): Replace
	calls to _M_reserve and _S_curr_cb with call to _M_prepare.
	Check return value of backtrace_simple when max depth given.
	(basic_stacktrace::_M_reserve): Remove.
	(basic_stacktrace::_S_curr_cb): Remove.
	(basic_stacktrace::_M_prepare(size_type)): New function to
	reserve initial capacity and return callback.
	(basic_stacktrace::_Impl::_M_allocate): Remove check for 0 < n
	and remove redundant zeroing of _M_frames and _M_capacity.
	(basic_stacktrace::_Impl::_M_push_back): Add [[unlikely]]
	attribute. Assign _Impl instead of swapping.
	* testsuite/19_diagnostics/stacktrace/current.cc: New test.
2022-04-12 22:38:31 +01:00
Jonathan Wakely
73da9ec556 libstdc++: Fix std::basic_stacktrace special members [PR105031]
The PR points out that there is a non-constant condition used for an
if-constexpr statement, but there are several other problems with the
copy, move and swap members of std::basic_stacktrace.

libstdc++-v3/ChangeLog:

	PR libstdc++/105031
	* include/std/stacktrace (basic_stacktrace::basic_stacktrace):
	Fix allocator usage in constructors.
	(basic_stacktrace::operator=(const basic_stacktrace&)): Do not
	try to reallocate using const allocator.
	(basic_stacktrace::operator=(basic_stacktrace&&)): Fix
	if-constexpr with non-constant condition. Do not allocate new
	storage if allocator propagates. Do not set _M_size if
	allocation fails.
	(basic_stacktrace::swap(basic_stacktrace&)): Fix typo. Add
	assertion that non-propagating allocators are equal.
	* testsuite/19_diagnostics/stacktrace/stacktrace.cc: New test.
2022-04-11 17:59:50 +01:00
Jonathan Wakely
bdb9639ee9 libstdc++: Improve behaviour of std::stacktrace::current
This prevents inlining the current() function to guarantee that it is
present in the stacktrace, then tells libbacktrace to skip that frame.

To avoid overflow in the int argument to __glibcxx_backtrace_simple, we
need to check if the skip parameter exceeds INT_MAX (which is possible
for 16-bit targets where short and int have the same width). We also
need to limit the size of the returned value to the max_depth parameter,
which was missing previously.

This also fixes basic_stacktrace::max_size() to not exceed the maximum
size supported by the allocator, which might be smaller than the maximum
value of size_type.

libstdc++-v3/ChangeLog:

	* include/std/stacktrace (basic_stacktrace::current): Duplicate
	implementation into each overload. Add noinline attribute and
	skip current frame.
	(basic_stacktrace::max_size()): Call _Impl::_S_max_size.
	(basic_stacktrace::_S_curr_cb()): New function defining lambda.
	(basic_stacktrace::_Impl::_S_max_size): New function defining
	maximum size in terms of allocator and size_type.
	(basic_stacktrace::_Impl::_M_allocate): Check against
	max_size().
	* testsuite/19_diagnostics/stacktrace/entry.cc: Call function
	for non-constexpr checks. Check line number is correct.
2022-04-11 17:59:08 +01:00
Jonathan Wakely
c62b0f731b libstdc++: Move stacktrace tests to 19_diagnostics directory
This matches where the feature is defined in the current draft.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/stacktrace/entry.cc: Moved to...
	* testsuite/19_diagnostics/stacktrace/entry.cc: ...here.
	* testsuite/20_util/stacktrace/synopsis.cc: Moved to...
	* testsuite/19_diagnostics/stacktrace/synopsis.cc: ...here.
	* testsuite/20_util/stacktrace/version.cc: Moved to...
	* testsuite/19_diagnostics/stacktrace/version.cc: ...here.
2022-04-11 15:53:22 +01:00
Jonathan Wakely
7b4495d3c4 libstdc++: Fix constraints on std::expected<void, E> constructor [PR105153]
libstdc++-v3/ChangeLog:

	PR libstdc++/105153
	* include/std/expected
	(expected<void,E>::expected(expected<U,G>&&)): Fix constraints.
	* testsuite/20_util/expected/cons.cc: Check constructor.
2022-04-08 18:30:07 +01:00
Jonathan Wakely
0dfaf56252 libstdc++: Fix std::expected<void, E>::swap(expected&) [PR105154]
libstdc++-v3/ChangeLog:

	PR libstdc++/105154
	* include/std/expected (expected<void, E>::swap): Set
	_M_has_value to false for objects that previously had a value.
	* testsuite/20_util/expected/swap.cc: Fix test to check void
	specialization.
2022-04-08 18:30:06 +01:00
Jonathan Wakely
29e355d0d6 libstdc++: Fix std::bad_expected_access constructor [PR105146]
libstdc++-v3/ChangeLog:

	PR libstdc++/105146
	* include/std/expected (bad_expected_access): Move constructor
	parameter.
	* testsuite/20_util/expected/bad.cc: New test.
2022-04-08 18:30:06 +01:00
Hans-Peter Nilsson
2dda1094a7 libstdc++-v3 expected: Correct minimal-size test in requirements.cc
Without this, for a target where alignment and structure-sizes are by
default byte-aligned, such as cris-elf, you'll see, in libstdc++.log:

/X/gcc/libstdc++-v3/testsuite/20_util/expected/requirements.cc:127: error: static assertion failed
/X/gcc/libstdc++-v3/testsuite/20_util/expected/requirements.cc:127: note: the comparison reduces to '(5 == 2)'
compiler exited with status 1
FAIL: 20_util/expected/requirements.cc (test for excess errors)
Excess errors:
/X/gcc/libstdc++-v3/testsuite/20_util/expected/requirements.cc:127: error: static assertion failed

The intent of that line is to check that the object is not larger than
necessary.

libstdc++-v3/:
	* testsuite/20_util/expected/requirements.cc: Correct minimal-size
	test.
2022-04-07 04:19:21 +02:00
Jonathan Wakely
babaabbcc8 libstdc++: Implement std::unreachable() for C++23 (P0627R6)
This defines std::unreachable as an assertion for debug mode, a trap
when _GLIBCXX_ASSERTIONS is defined, and __builtin_unreachable()
otherwise.

The reason for only using __builtin_trap() in the second case is to
avoid the overhead of setting up a call to __glibcxx_assert_fail that
should never happen.

UBsan can detect if __builtin_unreachable() is executed, so if a feature
test macro for that sanitizer is added, we could change just use
__builtin_unreachable() when the sanitizer is enabled.

While thinking about what the debug assertion failure should print, I
noticed that the __glibcxx_assert_fail function doesn't check for null
pointers. This adds a check so we don't try to print them if null.

libstdc++-v3/ChangeLog:

	* include/std/utility (unreachable): Define for C++23.
	* include/std/version (__cpp_lib_unreachable): Define.
	* src/c++11/debug.cc (__glibcxx_assert_fail): Check for valid
	arguments. Handle only the function being given.
	* testsuite/20_util/unreachable/1.cc: New test.
	* testsuite/20_util/unreachable/version.cc: New test.
2022-04-01 13:17:18 +01:00
Jonathan Wakely
95768878c7 testsuite: Disable tests for C++23 that depend on std::unexpected
These tests depend on unexpected handlers, which are no longer declared
for C++23 mode. Adjust the target specifier so they don't run.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/noexcept06.C: Disable for C++23.

libstdc++-v3/ChangeLog:

	* testsuite/18_support/exception/38732.cc: Disable for C++23.
	* testsuite/18_support/headers/exception/synopsis.cc: Likewise.
	* testsuite/18_support/unexpected_handler.cc: Likewise.
2022-03-29 20:30:43 +01:00
Jonathan Wakely
567eb37c76 libstdc++: Fix typos in comments in tests
libstdc++-v3/ChangeLog:

	* testsuite/20_util/optional/monadic/and_then.cc: Fix typo.
	* testsuite/20_util/optional/monadic/transform.cc: Likewise.
	* testsuite/22_locale/codecvt/always_noconv/char/1.cc: Likewise.
	* testsuite/22_locale/codecvt/encoding/char/1.cc: Likewise.
	* testsuite/22_locale/codecvt/in/char/1.cc: Likewise.
	* testsuite/22_locale/codecvt/max_length/char/1.cc: Likewise.
	* testsuite/22_locale/codecvt/out/char/1.cc: Likewise.
	* testsuite/22_locale/codecvt/unshift/char/1.cc: Likewise.
2022-03-28 12:20:42 +01:00
Jonathan Wakely
b78e0ce28b libstdc++: Define std::expected for C++23 (P0323R12)
Because this adds a new class template called std::unexpected, we have
to stop declaring the std::unexpected() function (which was deprecated
in C++11 and removed in C++17).

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in: Add new header.
	* include/Makefile.am: Likewise.
	* include/Makefile.in: Regenerate.
	* include/precompiled/stdc++.h: Add new header.
	* include/std/version (__cpp_lib_expected): Define.
	* libsupc++/exception [__cplusplus > 202002] (unexpected)
	(unexpected_handler, set_unexpected): Do not declare for C++23.
	* include/std/expected: New file.
	* testsuite/20_util/expected/assign.cc: New test.
	* testsuite/20_util/expected/cons.cc: New test.
	* testsuite/20_util/expected/illformed_neg.cc: New test.
	* testsuite/20_util/expected/observers.cc: New test.
	* testsuite/20_util/expected/requirements.cc: New test.
	* testsuite/20_util/expected/swap.cc: New test.
	* testsuite/20_util/expected/synopsis.cc: New test.
	* testsuite/20_util/expected/unexpected.cc: New test.
	* testsuite/20_util/expected/version.cc: New test.
2022-03-27 18:50:31 +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
Hans-Peter Nilsson
5d2233f403 libstdc++-v3 testsuite: Call fesetround(FE_DOWNWARD) only if defined
Without this, for a typical soft-float target such as cris-elf, after
commit r12-7676-g5a4e208022e704 you'll see, in libstdc++.log:
...
FAIL: 20_util/from_chars/6.cc (test for excess errors)
Excess errors:
/home/hp/tmp/auto0321/gcc/libstdc++-v3/testsuite/20_util/from_chars/6.cc:33: error: 'FE_DOWNWARD' was not declared in this scope

UNRESOLVED: 20_util/from_chars/6.cc compilation failed to produce executable
...

It appears to be a side-effect of that commit changing the
way __cpp_lib_to_chars is defined.  (On the bright side,
./7.cc now passes since that commit.)

TFM, specifically fenv(3), says that "Each of the macros
FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW,
FE_UNDERFLOW is defined when the implementation supports
handling of the corresponding exception".

A git-grep shows that this was the only place using a FE_ macro
unconditionally.

libstdc++-v3:
	* testsuite/20_util/from_chars/6.cc (test01) [FE_DOWNWARD]:
	Conditionalize call to fesetround.
2022-03-22 22:53:02 +01:00
Jonathan Wakely
7a42b1fa1a libstdc++: Simplify constraints for std::any construction [PR104242]
Partially revert r12-4190-g6da36b7d0e43b6f9281c65c19a025d4888a25b2d
because using __and_<..., is_copy_constructible<T>> when T is incomplete
results in an error about deriving from is_copy_constructible<T> when
that is incomplete. I don't know how to fix that, so this simply
restores the previous constraint which worked in this case (even though
I think it's technically undefined to use is_copy_constructible<T> with
incomplete T). This doesn't restore exactly what we had before, but uses
the is_copy_constructible_v and __is_in_place_type_v variable templates
instead of the ::value member.

libstdc++-v3/ChangeLog:

	PR libstdc++/104242
	* include/std/any (any(T&&)): Revert change to constraints.
	* testsuite/20_util/any/cons/104242.cc: New test.
2022-03-18 15:40:03 +00:00
Jonathan Wakely
ac73c944ea libstdc++: Reduce header dependencies from PSTL headers [PR92546]
This avoids including the whole of <functional> in <algorithm>, as the
<pstl/glue_algorithm_defs.h> header only actually needs std::pair.

This also avoids including <iterator> in <pstl/utils.h>, which only
needs <type_traits>, std::bad_alloc, and std::terminate (which can be
repalced with std::__terminate). This matters less, because
<pstl/utils.h> is only included by the <pstl/*_impl.h> headers and they
all use <iterator> anyway, and are only included by <execution>.

libstdc++-v3/ChangeLog:

	PR libstdc++/92546
	* include/pstl/glue_algorithm_defs.h: Replace <functional> with
	<bits/stl_pair.h>.
	* include/pstl/utils.h: Replace <iterator> with <type_traits>.
	(__pstl::__internal::__except_handler): Use std::__terminate
	instead of std::terminate.
	* src/c++17/fs_path.cc: Include <array>.
	* testsuite/25_algorithms/adjacent_find/constexpr.cc: Include
	<functional>.
	* testsuite/25_algorithms/binary_search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/clamp/constrained.cc: Likewise.
	* testsuite/25_algorithms/equal/constrained.cc: Likewise.
	* testsuite/25_algorithms/for_each/constrained.cc: Likewise.
	* testsuite/25_algorithms/includes/constrained.cc: Likewise.
	* testsuite/25_algorithms/is_heap/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_heap_until/constexpr.cc: Likewise.
	* testsuite/25_algorithms/is_permutation/constrained.cc: Include
	<iterator>.
	* testsuite/25_algorithms/is_sorted/constexpr.cc: Include
	<functional>.
	* testsuite/25_algorithms/is_sorted_until/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lexicographical_compare/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/lexicographical_compare/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/lexicographical_compare_three_way/1.cc:
	Include <array>.
	* testsuite/25_algorithms/lower_bound/constexpr.cc: Include
	<functional>.
	* testsuite/25_algorithms/max/constrained.cc: Likewise.
	* testsuite/25_algorithms/max_element/constrained.cc: Likewise.
	* testsuite/25_algorithms/min/constrained.cc: Likewise.
	* testsuite/25_algorithms/min_element/constrained.cc: Likewise.
	* testsuite/25_algorithms/minmax_element/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/mismatch/constexpr.cc: Likewise.
	* testsuite/25_algorithms/move/93872.cc: Likewise.
	* testsuite/25_algorithms/move_backward/93872.cc: Include
	<iterator>.
	* testsuite/25_algorithms/nth_element/constexpr.cc: Include
	<functional>.
	* testsuite/25_algorithms/partial_sort/constexpr.cc: Likewise.
	* testsuite/25_algorithms/partial_sort_copy/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/search/constexpr.cc: Likewise.
	* testsuite/25_algorithms/search_n/constrained.cc: Likewise.
	* testsuite/25_algorithms/set_difference/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_difference/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/set_intersection/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_intersection/constrained.cc:
	Likewise.
	* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc:
	Likewise.
	* testsuite/25_algorithms/set_union/constexpr.cc: Likewise.
	* testsuite/25_algorithms/set_union/constrained.cc: Likewise.
	* testsuite/25_algorithms/sort/constexpr.cc: Likewise.
	* testsuite/25_algorithms/sort_heap/constexpr.cc: Likewise.
	* testsuite/25_algorithms/transform/constrained.cc: Likewise.
	* testsuite/25_algorithms/unique/constexpr.cc: Likewise.
	* testsuite/25_algorithms/unique/constrained.cc: Likewise.
	* testsuite/25_algorithms/unique_copy/constexpr.cc: Likewise.
	* testsuite/25_algorithms/upper_bound/constexpr.cc: Likewise.
	* testsuite/std/ranges/adaptors/elements.cc: Include <vector>.
	* testsuite/std/ranges/adaptors/lazy_split.cc: Likewise.
	* testsuite/std/ranges/adaptors/split.cc: Likewise.
2022-03-18 10:16:36 +00:00
Jonathan Wakely
78ef40ecdc libstdc++: Fix comment in testsuite utility
libstdc++-v3/ChangeLog:

	* testsuite/util/testsuite_character.h: Fix comment.
2022-03-17 12:23:56 +00:00
Jonathan Wakely
2f26b26721 libstdc++: Fix symbol versioning for Solaris 11.3 [PR103407]
The new std::from_chars implementation means that those symbols are now
defined on Solaris 11.3, which lacks uselocale. They were not present in
gcc-11, but the linker script gives them the GLIBCXX_3.4.29 symbol
version because that is the version where they appeared for systems with
uselocale.

This makes the version for those symbols depend on whether uselocale is
available or not, so that they get version GLIBCXX_3.4.30 on targets
where they weren't defined in gcc-11.

In order to avoid needing separate ABI baseline files for Solaris 11.3
and 11.4, the ABI checker program now treats the floating-point
std::from_chars overloads as undesignated if they are not found in the
baseline symbols file. This means they can be left out of the SOlaris
baseline without causing the check-abi target to fail.

libstdc++-v3/ChangeLog:

	PR libstdc++/103407
	* config/abi/pre/gnu.ver: Make version for std::from_chars
	depend on HAVE_USELOCALE macro.
	* testsuite/util/testsuite_abi.cc (compare_symbols): Treat
	std::from_chars for floating-point types as undesignated if
	not found in the baseline symbols file.
2022-03-16 21:16:53 +00:00
Jonathan Wakely
5706a5db88 libstdc++: Use non-debug vector in constexpr test [PR104748]
The std::__debug::vector isn't usable in constant expressions, so this
test fails in debug mode. Until the debug vector is fixed we can just
make the test use the non-debug one.

libstdc++-v3/ChangeLog:

	PR libstdc++/104748
	* testsuite/std/ranges/adaptors/all.cc: Use non-debug vector for
	constexpr test.
2022-03-03 22:28:48 +00:00
Jonathan Wakely
64cdf49962 libstdc++: Fix test failure on AIX
This fixes a test failure due to a non-reserved name in an AIX system
header (included via <pthread.h>). That name clashes with one of the
names we check our own headers for, so skip checking that name on AIX.

libstdc++-v3/ChangeLog:

	* testsuite/17_intro/names.cc (func): Undef on AIX.
2022-03-03 22:25:44 +00:00
Jonathan Wakely
9805965e35 libstdc++: Implement std::strong_order for floating-point types [PR96526]
This removes a FIXME in <compare>, defining the total order for
floating-point types. I originally opened PR96526 to request a new
compiler built-in to implement this, but now that we have std::bit_cast
it can be done entirely in the library.

The implementation is based on the glibc definitions of totalorder,
totalorderf, totalorderl etc.

I think this works for all the types that satisfy std::floating_point
today, and should also work for the types expected to be added by P1467
except for std::bfloat16_t. It also supports some additional types that
don't currently satisfy std::floating_point, such as __float80, but we
probably do want that to satisfy the concept for non-strict modes.

libstdc++-v3/ChangeLog:

	PR libstdc++/96526
	* libsupc++/compare (strong_order): Add missing support for
	floating-point types.
	* testsuite/18_support/comparisons/algorithms/strong_order_floats.cc:
	New test.
2022-03-03 22:24:45 +00:00
Patrick Palka
5e1b17f038 libstdc++: Implement P2415R2 changes to viewable_range / views::all
This implements the wording changes in P2415R2 "What is a view?", which
is a DR for C++20.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__detail::__is_initializer_list):
	Define.
	(viewable_range): Adjust as per P2415R2.
	* include/bits/ranges_cmp.h (__cpp_lib_ranges): Adjust value.
	* include/std/ranges (owning_view): Define as per P2415R2.
	(enable_borrowed_range<owning_view>): Likewise.
	(views::__detail::__can_subrange): Replace with ...
	(views::__detail::__can_owning_view): ... this.
	(views::_All::_S_noexcept): Sync with operator().
	(views::_All::operator()): Use owning_view instead of subrange
	as per P2415R2.
	* include/std/version (__cpp_lib_ranges): Adjust value.
	* testsuite/std/ranges/adaptors/all.cc (test06): Adjust now that
	views::all uses owning_view instead of subrange.
	(test08): New test.
	* testsuite/std/ranges/adaptors/lazy_split.cc (test09): Adjust
	now that rvalue non-view non-borrowed ranges are viewable.
	* testsuite/std/ranges/adaptors/split.cc (test06): Likewise.
2022-02-22 09:37:58 -05:00
Jonathan Wakely
12a88e6e20 libstdc++: Deprecate non-standard std::vector<bool>::insert(pos) [PR104559]
The SGI STL and pre-1998 drafts of the C++ standard had a default
argument for vector<bool>::insert(iterator, const bool&) which was
remove by N1051. The default argument is still present in libstdc++ for
some reason. There are no tests verifying it as an extension, so I don't
think it has been kept intentionally.

This removes the default argument but adds an overload without the
second parameter, and adds the deprecated attribute to it. This allows
any code using it to keep working (for now) but with a warning.

libstdc++-v3/ChangeLog:

	PR libstdc++/104559
	* doc/xml/manual/evolution.xml: Document deprecation.
	* doc/html/manual/api.html: Regenerate.
	* include/bits/stl_bvector.h (insert(const_iterator, const bool&)):
	Remove default argument.
	(insert(const_iterator)): New overload with deprecated attribute.
	* testsuite/23_containers/vector/bool/modifiers/insert/104559.cc:
	New test.
2022-02-17 23:44:25 +00:00
Jonathan Wakely
36100e0e95 libstdc++: Make std::error_code printer more robust
This attempts to implement a partial workaround for the GDB bug
https://sourceware.org/bugzilla/show_bug.cgi?id=28856 which causes GDB
to crash when printing a frame with a std::error_code argument.

By recognising the known error categories defined in the library and
hardcoding their names we do not need to call cat->name() on the
category.  This has the additional benefit of also working when
debugging a core file rather than a running process. For those known
categories we can also cast the int value to the corresponding error
code enum (e.g. future_errc) so that we show an enumerator instead of
just an integer.

For program-defined categories we just use the name of the dynamic type
to identify the category, and print the value as an integer. Once the
GDB bug is fixed and the virtual name() function can be called safely,
that would be preferable. For now it's better to have an imperfect
printer that doesn't crash GDB.

This rewritten StdErrorCodePrinter needs gdb.Value.dynamic_type, so is
only registered if that is supported, which means GDB 7.7 and later.

libstdc++-v3/ChangeLog:

	* python/libstdcxx/v6/printers.py (StdErrorCodePrinter): Replace
	code that call cat->name() on std::error_category objects.
	Identify known categories by symbol name and use a hardcoded
	name. Print error code values as enumerators where appopriate.
	* testsuite/libstdc++-prettyprinters/cxx11.cc: Adjust expected
	name of custom category. Check io_errc and future_errc errors.
2022-02-17 22:22:14 +00:00
Jonathan Wakely
6cfb7ffb65 libstdc++: Add missing constexpr to uses-allocator construction utilities [PR104542]
libstdc++-v3/ChangeLog:

	PR libstdc++/104542
	* include/bits/uses_allocator_args.h (make_obj_using_allocator)
	(uninitialized_construct_using_allocator): Add constexpr.
	* testsuite/20_util/uses_allocator/make_obj.cc: Check constexpr.
	* testsuite/20_util/uses_allocator/uninitialized_construct.cc: New test.
2022-02-15 12:49:34 +00:00
Jonathan Wakely
3d50dede07 libstdc++: Fix stream extraction of IEEE128 long double [PR100912]
The std::__convert_from_v helper that formats double and long double
values into a char buffer was not being duplicated for the two long
double ABIs. This resulted in an ODR violation inside the library, where
some callers needed it to use snprintf to format __ibm128 values and
other callers needed it to use __snprintfieee128 to format __ieee128
values. The linker discarded one of the definitions, leaving one set of
callers using the wrong code.

This puts __convert_from_v in the __gnu_cxx_ieee128 inline namespace
when long double is __ieee128, so that there are two different
definitions of the function.

The std::money_put::__do_put overload for __ibm128 values needs a
different fix, because that is defined when long double is __ieee128 and
so would call the one in the inline namespace. That can be fixed by just
inlining the code directly into the function and using an asm alias to
call the right version of snprintf for the __ibm128 format. The code to
do that can be simpler than __convert_from_v because if we're defining
the ALT128_COMPAT symbols we know that we have a recent glibc and so we
can assume that uselocale and snprintf are supported.

libstdc++-v3/ChangeLog:

	PR libstdc++/100912
	* config/locale/gnu/c_locale.h (__convert_from_v): Use inline
	namespace for IEEE128 long double mode.
	* config/os/gnu-linux/ldbl-ieee128-extra.ver: Add new symbol
	version and export __gnu_cxx_ieee128::__convert_from_v.
	* include/bits/locale_facets_nonio.tcc (money_put::__do_put):
	Make __ibm128 overload use snprintf directly
	* testsuite/util/testsuite_abi.cc: Add new symbol version.
	Remove stable IEEE128/LDBL versions.
2022-02-14 17:19:08 +00:00
Jonathan Wakely
220d85fdf0 libstdc++: Fix typo in pragma
libstdc++-v3/ChangeLog:

	* testsuite/20_util/unsynchronized_pool_resource/allocate.cc:
	Fix typo.
2022-02-14 12:46:04 +00:00
Jonathan Wakely
9a56779dbc libstdc++: Fix FAIL: 20_util/temporary_buffer.cc for C++14
The std::get_temporary_buffer function is deprecated since C++17, but
the test was expecting a warning for C++14 as well.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/temporary_buffer.cc: Fix dg-warning target
	selector.
2022-02-11 21:42:22 +00:00