Commit Graph

5873 Commits

Author SHA1 Message Date
Jonathan Wakely
fa4754797c libstdc++: Optionally define std::print functions non-inline [PR124410]
We don't want to export std::vprint_unicode etc. from libstdc++.so yet,
but we can give users the option of improving compile times by getting
the definitions of the std::print internals from libstdc++exp.a instead.

This commit adds a macro, _GLIBCXX_NO_INLINE_PRINT, which disables the
inline definitions of std::vprint_unicode etc. so that extern
definitions in libstdc++exp.a can be used instead.

With this change compiling a helloworld using std::print goes from 8s to
under 2s with trunk. For release branches with --enable-checking=release
we should see even faster times. The object file size is also
dramatically smaller, because there's just a single call to an extern
function instead of instantiating the entire std::print and std::format
implementation inline.

libstdc++-v3/ChangeLog:

	PR libstdc++/124410
	* doc/html/*: Regenerate.
	* doc/xml/manual/using.xml (_GLIBCXX_NO_INLINE_PRINT): Document
	macro.
	* include/Makefile.am: Add bits/print.h and bits/ostream_print.h
	headers.
	* include/Makefile.in: Regenerate.
	* include/std/ostream (vprint_nonunicode, vprint_unicode): Move
	definitions to new bits/ostream_print.h header.
	* include/std/print (__format::_File_sink, vprint_nonunicode)
	(vprint_nonunicode_buffered, vprint_unicode)
	(vprint_unicode_buffered): Move definitions to new bits/print.h
	header.
	* src/c++23/print.cc: Include new headers to define symbols for
	inline print functions.
	* include/bits/ostream_print.h: New file.
	* include/bits/print.h: New file.
2026-04-17 13:43:49 +01:00
Elena Tyuleneva
1bb8dc29aa libstdc++: Fix philox_engine counter increment carry
The philox counter increment that happens in
philox_engine::_M_transition(), applies +1 to _M_x[0] before the bitwise
OR with (_M_x[1] << __w), so the carry from _M_x[0] is merged into the
_M_x[1] portion rather than being added to it. This causes the counter
to cycle prematurely and never advance past {0, 0, 1, 2^w - 1}.

Fix by changing operations order, which results in forming the
full-width value from _M_x[1]:_M_x[0] and then adding 1 on both the n ==
4 and n == 2 paths.

libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (philox_engine::_M_transtiion): Fix
	counter increment to propagate carry correctly.
	* testsuite/26_numerics/random/philox_engine/operators/counter_carry.cc:
	New test.

Signed-off-by: Elena Tyuleneva <elena.tyuleneva@intel.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2026-04-15 17:51:49 +01:00
Jonathan Wakely
caeab8f359 libstdc++: Fix philox2x64 case for 32-bit targets
While testing a patch for std::philox_engine I noticed that
instantiating std::philox_engine with n=2 and w=64 fails on targets
without __int128, because it relies on an implicit conversion from the
intermediate counter type to the result type. When w=64 and the target
doesn't support __int128, we use the __rand_uint128 class type for the
intermediate counter values, but that does not support implicit
conversion to integral types.

This adds the necessary casts to make the conversions explicit.

libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (philox_engine::_M_transition): Cast
	intermediate values to result_type for n=2 case.
2026-04-15 17:43:22 +01:00
Matthias Kretz
17e0482487 libstdc++: Implement LWG4403: CTAD misses difference type casting
libstdc++-v3/ChangeLog:

	* include/bits/simd_vec.h (basic_vec deduction guide): Explicit
	cast to simd-size-type from range size type.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
2026-04-15 09:40:55 +02:00
Tomasz Kamiński
62d243c91c libstdc++: Define __cpp_lib_stdbit_h and __cpp_lib_stdckdint_h feature test macros.
This implements LWG4550: Need new feature test macros for <stdckdint.h>
and <stdbit.h>.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (stdbit_h, stdckdint_h): Define.
	* include/bits/version.h: Regenerate.
	* include/c_compatibility/stdbit.h (__cpp_lib_stdbit_h): Define
	and use it in guards.
	* include/c_compatibility/stdckdint.h (__cpp_lib_stdckdint_h):
	Define and use it in guards.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-14 17:09:26 +02:00
Tomasz Kamiński
9c0a9b700e libstdc++: Runtime fallback for constant_wrapper subscript and call operators.
This implements P3978R3: constant_wrapper should unwrap on call and subscript.

The operator() and operator[] are now fallback to calling corresponding
operation on value, if either arguments are not constant_wrapper like, or
the result of the invocation is not usable as non-type template argument
(non-constant). The call operator is also now defined in terms of invoke,
to support member pointers.

The noexcept specification is simplified, by observing that creating a
default constructed (constant_wrapper<value(....)>{}) is never throwing
operation. Nested requires expr is used for short-circuting, and thus
avoid checking viability of the operation on the value with
constant_wrapper only (see PoisonedAdd, PoisonedIndex in tests).

libstdc++-v3/ChangeLog:

	* include/bits/version.def (constant_wrapped): Updated to 202603L.
	* include/bits/version.h: Regenerate.
	* include/bits/utility.h (_CwOperators::operator())
	(_CwOperators:operator[]): Delete, they are now provided by...
	(constant_wrapper::operator(), constant_wrapper::operator[]):
	Define.
	* testsuite/20_util/constant_wrapper/generic.cc: Add additional
	test cases for invoke and subscript.
	* testsuite/20_util/constant_wrapper/version.cc: Update tested
	value.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-14 14:20:59 +02:00
Matthias Wippich
6159bfcf8b libstdc++: Implement structured binding support for integer_sequence
This implements P1789R3 Library Support for Expansion Statements.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p1789r3.pdf

libstdc++-v3/ChangeLog:

	* include/bits/utility.h (std::tuple_size, std::tuple_element):
	Add partial specializations for integer_sequence.
	(std::get(integer_sequence<_Tp, _Idx...>)): Define.
	* include/bits/version.def (integer_sequence): Bump to 202511L.
	* include/bits/version.h: Regenerate.
	* testsuite/20_util/integer_sequence/tuple_access.cc: New test.
	* testsuite/20_util/integer_sequence/tuple_access_neg.cc: New test.
	* testsuite/experimental/feat-cxx14.cc: Updated check for
	__cpp_lib_integer_sequence value.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Ivan Lazaric <ivan.lazaric1@gmail.com>
Signed-off-by: Matthias Wippich <mfwippich@gmail.com>
2026-04-14 12:29:24 +02:00
François Dumont
f1561d3569 libstdc++: [_Hashtable] Use std::addressof in post-C++11 code
There is no need to use std::__addressof in post-C++11 code.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h: Replace usages of std::__addressof with
	std::addressof.
	* include/bits/hashtable_policy.h: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-04-13 22:29:22 +02:00
Tomasz Kamiński
8beabc8851 libstdc++: Define __cpp_lib_replaceable_contract_violation_handler.
This implements P3886R0: Wording for AT1-057, by defining the
__cpp_lib_replaceable_contract_violation_handler. The macro is defined
only if contracts are supported (i.e. under same conditions as
__cpp_lib_contracts).

GCC supports providing custom violation handler by providing an separate
defintion of handle_contract_violation. This is supported on the targets
that uses ELF format, so the macro is defined for with non-zero value
for them.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (replaceable_contract_violation_handler)
	[(__cplusplus > 202302L) && (__cpp_contracts >= 202502L)]:
	Define to 202603 for ELF targets, and 0 otherwise.
	* include/bits/version.h: Regenerate.
	* include/std/contracts: Define
	__cpp_lib_replaceable_contract_violation_handler.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-13 12:57:58 +02:00
Tomasz Kamiński
2979e67af1 libstdc++: Update __cpp_lib_function_ref value for P3948R1.
SG-10 agreed on using 202604L value for paper P3961R0 that
also updates __cpp_lib_function_ref macro.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (function_ref): Bump to 202603L.
	* include/bits/version.h: Regenerate.
	* testsuite/20_util/function_ref/assign.cc: Remove repeated
	check for feature test macro.
	* testsuite/20_util/function_ref/cons.cc: Updated checked
	value.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-13 11:49:33 +02:00
Tomasz Kamiński
30e3fa6191 libstdc++: Rename views::to_input to views::as_input.
This patch implements P3828R1: Rename the to_input view to as_input.

The paper suggest renaming the feature test macro without changing the
value and this patch follows.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (ranges_to_input): Rename to...
	(ranges_as_input): Rename from ranges_as_input.
	* include/bits/version.h: Regenerate.
	* include/std/ranges (ranges::to_input_view, views::to_input)
	(__detail::__can_to_input, views::_ToInput): Rename to...
	(ranges::as_input_view, views::as_input, __detail::__can_as_input)
	(views::_AsInput): Rename from above...
	* src/c++23/std.cc.in: Rename views::to_input and to_input_view
	export.
	* testsuite/25_algorithms/contains/1.cc: Replace views::to_input
	with views::as_input.
	* testsuite/std/ranges/adaptors/to_input/1.cc: Move to...
	* testsuite/std/ranges/adaptors/as_input/1.cc: ...here, and replace
	views::to_input with views::as_input.

gcc/testsuite/ChangeLog:

	* g++.dg/reflect/range_args.C: Replace views::to_input with
	views::as_input.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-10 08:08:00 +02:00
Tomasz Kamiński
bd29a35496 libstdc++: Remove span constructor from initializer_list.
Following LWG4520 resolution from paper
P4144R1 Remove span’s initializer_list constructor for C++26.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (span_initializer_list): Remove.
	* include/bits/version.h: Regenerate.
	* include/std/span (span::span(initializer_list<value_type>)):
	Remove.
	* testsuite/23_containers/span/init_list_cons.cc: Removed.
	* testsuite/23_containers/span/init_list_cons_neg.cc: Removed.
	* testsuite/23_containers/inplace_vector/copy.cc: Replace span
	with initializer_list in eq helper.
	* testsuite/23_containers/inplace_vector/erasure.cc: Likewise.
	* testsuite/23_containers/inplace_vector/move.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-10 08:02:37 +02:00
Tomasz Kamiński
c6a5424313 libstdc++: Add default template parameters for uninitialized_fill(_n).
This implements P3217R0 and adds default argument for the value type
templater parameter for uninitialized_fill, uninitialized_fill_n and
their ranges counterpart.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_uninitialized.h
	(__uninitialized_fill_fn::operator())
	(__uninitialized_fill_fn_n::operator()): Add default argument
	for _Tp parameter.
	* include/bits/stl_uninitialized.h (std::unitialized_fill)
	(std::unitialized_fill_n): Likewise.
	* include/pstl/glue_memory_defs.h (std::unitialized_fill)
	(std::unitialized_fill_n): Likewise.
	* include/bits/version.def (algorithm_default_value_type):
	Bump to 202603.
	* include/bits/version.h: Regenerate.
	* testsuite/25_algorithms/default_template_value.cc:
	Test for new algorithms.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-10 07:59:24 +02:00
Matthias Kretz
52b44d966e libstdc++: Remove non_type and replace it with constant_wrapper in function_ref
This implements P3948R1: constant_wrapper is the only tool needed
for passing constant expressions via function arguments.

This changes function_ref from nontype_t to constant_wrapper and
implements the ambiguity check (static_asert in function_ref
from constant_wrapper constructor).

In addition to P3948R1 this also includes the (forgotten) deduction
guide changes suggested in the draft PR [1].

[1] https://github.com/cplusplus/draft/pull/8878

libstdc++-v3/ChangeLog:

	* include/bits/funcref_impl.h (function_ref::function_ref):
	Change nontype_t parameter to constant_wrapper, and adjust
	accordingly. Add static_assert detecting ambigous semantics.
	(function_ref::operator=): Detect constant_wrapper rather than
	nontype_t.
	* include/bits/funcwrap.h (function_ref): Change nontype_t
	parameter to constant_wrapper in deduction guides.
	* include/bits/utility.h (std::nontype_t, std::nontype)
	(std::__is_nontype_v): Remove.
	(std::__is_constant_wrapper_v): Define.
	* src/c++23/std.cc.in (std::nontype_t, std::nontype):
	Remove exports.
	* testsuite/20_util/function_ref/cw_cons_neg.cc: New tests
	for ambiguity check.
	* testsuite/20_util/function_ref/assign.cc: Replace nontype_t
	with constant_wrapper and nontype with std::cw.
	* testsuite/20_util/function_ref/call.cc: Likewise.
	* testsuite/20_util/function_ref/cons.cc: Likewise.
	* testsuite/20_util/function_ref/cons_neg.cc: Likewise.
	* testsuite/20_util/function_ref/dangling.cc: Likewise.
	* testsuite/20_util/function_ref/deduction.cc: Likewise.
	* testsuite/20_util/function_ref/mutation.cc: Likewise.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-08 13:22:20 +02:00
Tomasz Kamiński
58564c85c5 libstdc++: Move constant_wrapper from <type_traits> to <utility>
Change placement of constant_wrapper and related classes per
P3978R3: constant_wrapper should unwrap on call and subscript.

libstdc++-v3/ChangeLog:

	* include/bits/utility.h (std::_CwFixedValue, std::_ConstExprParam)
	(std::_CwOperators, std::constant_wrapper): Moved from...
	* include/std/type_traits (std::_CwFixedValue, std::_ConstExprParam)
	(std::_CwOperators, std::constant_wrapper): Moved to bits/utility.h.
	Disable __cpp_lib_constant_wrapper defintion.
	* include/std/utility: Define __cpp_lib_constant_wrapper.
	* testsuite/20_util/constant_wrapper/adl.cc: Updated header includes.
	* testsuite/20_util/constant_wrapper/ex.cc: Likewise.
	* testsuite/20_util/constant_wrapper/generic.cc: Likewise.
	* testsuite/20_util/constant_wrapper/instantiate.cc: Likewise.
	* testsuite/20_util/constant_wrapper/op_comma_neg.cc: Likewise.
	* testsuite/20_util/constant_wrapper/other_wrappers.cc: Likewise.
	* testsuite/20_util/constant_wrapper/version.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-08 08:33:11 +02:00
Tomasz Kamiński
395e5cef29 libstdc++: Export explicit instantiations for C++20 members of std::string
The C++20 standard added new starts_with and ends_with members to
std::basic_string, which were not previously instantiated in the library.
This meant that the extern template declarations had to be disabled for
C++20 mode. With this patch the new members are instantiated in the
library and so the explicit instantiation declarations can be used for
C++20.

Furthermore, basic_string default constructor is now constrained with
is_default_constructible_v<_Alloc> constrains, that is included in
mangled name, so we also need to instantiate and export it.

The new members added by C++23 are still not exported, and so the
explicit instantiation declarations are still disabled for C++23.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver (GLIBCXX_3.4): Make string exports
	less greedy.
	(GLIBCXX_3.4.35): Export basic_string default constructor and
	starts_with and ends_with members.
	* include/bits/basic_string.h: Update __cpluplus checks for C++20.
	* include/bits/cow_string.h: Likewise.
	* include/bits/basic_string.tcc: Declare explicit instantiations
	for C++20 as well as earlier dialects.
	* src/c++20/Makefile.am: Add cow-string-inst.cc and
	string-inst.cc source files.
	* src/c++20/Makefile.in: Regenerate.
	* src/c++20/string-inst.cc: New file defining explicit
	instantiations for basic_string default constructor and starts_with,
	ends_with methods added in C++20
	* src/c++20/cow-string-inst.cc: Version of above for cow-stings.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-07 19:25:27 +02:00
Matthias Kretz
1cfdd868ce libstdc++: Require SSE2 for std::simd [PR124722]
Without SSE2 double precision uses excess precision, leading to test
failures. For now, std::simd remains a tech preview that simply is
disabled without SSE2.

libstdc++-v3/ChangeLog:

	PR libstdc++/124722
	* include/bits/version.def: Check for __SSE2__ rather than x86.
	* include/bits/version.h: Regenerate.
	* testsuite/std/simd/arithmetic.cc: Build with -msse2.
	* testsuite/std/simd/arithmetic_expensive.cc: Likewise.
	* testsuite/std/simd/creation.cc: Likewise.
	* testsuite/std/simd/creation_expensive.cc: Likewise.
	* testsuite/std/simd/loads.cc: Likewise.
	* testsuite/std/simd/loads_expensive.cc: Likewise.
	* testsuite/std/simd/mask.cc: Likewise.
	* testsuite/std/simd/mask2.cc: Likewise.
	* testsuite/std/simd/mask2_expensive.cc: Likewise.
	* testsuite/std/simd/mask_expensive.cc: Likewise.
	* testsuite/std/simd/reductions.cc: Likewise.
	* testsuite/std/simd/reductions_expensive.cc: Likewise.
	* testsuite/std/simd/shift_left.cc: Likewise.
	* testsuite/std/simd/shift_left_expensive.cc: Likewise.
	* testsuite/std/simd/shift_right.cc: Likewise.
	* testsuite/std/simd/shift_right_expensive.cc: Likewise.
	* testsuite/std/simd/simd_alg.cc: Likewise.
	* testsuite/std/simd/simd_alg_expensive.cc: Likewise.
	* testsuite/std/simd/sse_intrin.cc: Likewise.
	* testsuite/std/simd/stores.cc: Likewise.
	* testsuite/std/simd/stores_expensive.cc: Likewise.
	* testsuite/std/simd/traits_common.cc: Likewise.
	* testsuite/std/simd/traits_math.cc: Likewise.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
2026-04-06 20:10:24 +02:00
Jakub Jelinek
1e38d1a4f4 c++, libstdc++: Implement P3856R8 - New reflection metafunction - is_structural_type
This patch attempts to implement this paper, adds a new trait, builtin trait
and metafunction.

2026-04-03  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
	* cp-trait.def (__builtin_is_structural): New trait.
	* semantics.cc (trait_expr_value): Handle CPTK_IS_STRUCTURAL.
	(finish_trait_expr): Likewise.
	* constraint.cc (diagnose_trait_expr): Likewise.
	* metafns.gperf (enum metafn_code): Add METAFN_IS_STRUCTURAL_TYPE.
	(is_structural_type): New metafn.
	* metafns.h: Regenerate.
	* reflect.cc (eval_is_structural_type): New function.
	(process_metafunction): Handle METAFN_IS_STRUCTURAL_TYPE.
gcc/testsuite/
	* g++.dg/reflect/type_trait14.C: New test.
	* g++.dg/reflect/eh1.C: Add test for is_structural_type.
	* g++.dg/reflect/eh2.C: Likewise.
libstdc++-v3/
	* include/bits/version.def (is_structural): New.
	* include/bits/version.h: Regenerate.
	* include/std/type_traits (__glibcxx_want_is_structural): Define.
	(std::is_structural): New type trait.
	(std::is_structural_v): New type trait variable template.
	* include/std/meta (std::meta::is_structural_type): New declaration.
	* src/c++23/std.cc.in: Export std::is_structural, std::is_structural_v
	and std::meta::is_structural_type.
	* testsuite/20_util/is_structural/requirements/explicit_instantiation.cc: New test.
	* testsuite/20_util/is_structural/requirements/typedefs.cc: New test.
	* testsuite/20_util/is_structural/value.cc: New test.
	* testsuite/20_util/variable_templates_for_traits.cc: Test
	is_structural_v.

Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-04-03 20:52:55 +02:00
Tomasz Kamiński
8b95d5f5b2 libstdc++: Updated inplace_vector::try_ functions per P3981R2 and P4022R0.
This paper removes the try_append_range from inplace_vector and changes the
return type of try_emplace_back and try_push_back to optional<_Tp&> per:
P4022R0: Remove try_append_range from inplace_vector for now.
P3981R2: Better return types in std::inplace_vector and std::exception_ptr_cast.

The test are also expanded to cover type Y, that is convertible to optional<Y&>,
and require return type to be constructed using in_place.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (inplace_vector): Bump to 202603.
	* include/bits/version.h: Regenerate.
	* include/std/inplace_vector (inplace_vector::try_emplace_back)
	(inplace_vector::try_push_back): Change return type to optional<_Tp&>
	and adjust implementation accordingly.
	(inplace_vector::try_append_range): Remove.
	* include/debug/inplace_vector (inplace_vector::try_emplace_back)
	(inplace_vector::try_push_back, inplace_vector::try_append_range):
	Likewise.
	* testsuite/23_containers/inplace_vector/modifiers/single_insert.cc:
	Updated check for the optional<T&> return. Added test for type
	convertible to optional<T&>
	* testsuite/23_containers/inplace_vector/debug/invalidation/try_emplace_back.cc:
	Use has_value() to check if engaged optional is returned.
	* testsuite/23_containers/inplace_vector/debug/invalidation/try_push_back.cc:
	Likewise.
	* testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc:
	Remove try_append_range tests.
	* testsuite/23_containers/inplace_vector/debug/invalidation/try_append_range.cc:
	Removed.
	* testsuite/23_containers/inplace_vector/version.cc: Updated expected
	feature test macro value.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 15:50:16 +02:00
Jonathan Wakely
74b665e0f0 libstdc++: Simplify documentation of match_flag_type::format_default
This combines the $n and $nn items into one, which is more consistent
with the EcmaScript docs.

libstdc++-v3/ChangeLog:

	* include/bits/regex_constants.h (format_default): Simplify
	description of $n in Doxygen comment.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:58 +01:00
Jonathan Wakely
d61f795de9 libstdc++: Minor tweak to Doxygen comment for std::pair
It doesn't necessarily hold objects, it can hold references too.

libstdc++-v3/ChangeLog:

	* include/bits/stl_pair.h (pair): Adjust Doxygen comment.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:57 +01:00
Jonathan Wakely
3c16bcabff libstdc++: Fix Doxygen comments on chrono::floor etc.
libstdc++-v3/ChangeLog:

	* include/bits/chrono.h (floor, ceil, round): Fix Doxygen
	comments to use correct parameter name and describe return value
	more accurately.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:57 +01:00
Jonathan Wakely
bc8c59ad3a libstdc++: Rename parameters of unordered erase(K&&) members
This fixes some Doxygen warnings caused by inconsistent parameter names,
which do not match the names used in the Doxygen comments:

include/bits/unordered_map.h:899: warning: argument '__x' of command @param is not found in the argument list of std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::erase(_Kt &&__key)
include/bits/unordered_map.h:899: warning: The following parameter of std::unordered_map::erase(_Kt &&__key) is not documented:
  parameter '__key'

libstdc++-v3/ChangeLog:

	* include/bits/unordered_map.h (unordered_map::erase(K&&)):
	Change parameter name to __x.
	* include/bits/unordered_set.h (unordered_set::erase(K&&))
	(unordered_multiset::erase(K&&)): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:56 +01:00
Jonathan Wakely
0c2c94b1d1 libstdc++: Fix Doxygen grouping
libstdc++-v3/ChangeLog:

	* include/bits/ostream.h (operator<<): Do not include deleted
	overloads in @{ group.
	* include/bits/stl_queue.h (priority_queue): Add @{ group around
	constructors.
	* include/bits/unordered_map.h: Remove stray @{. Move #endif to
	encompass @} that is within the #if group.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:56 +01:00
Jonathan Wakely
6cfeaa2a6d libstdc++: Remove Doxygen @return on void functions
With the latest version of Doxygen this gives a warning about using
@return on a function that returns void. Stating it explicitly adds very
little value, anybody can see from the signature that a function returns
void.

libstdc++-v3/ChangeLog:

	* include/bits/move.h (swap): Remove @return from Doxygen
	comment.
	* include/bits/stl_algo.h (inplace_merge, shuffle)
	(random_shuffle, partial_sort, nth_element, sort)
	(stable_sort): Likewise.
	* include/bits/stl_algobase.h (iter_swap, fill): Likewise.
	* include/bits/stl_deque.h (_Deque_base::_M_initialize_map)
	(deque::_M_range_initialize, deque::_M_fill_initialize):
	Likewise.
	* include/bits/stl_iterator_base_funcs.h (advance): Likewise.
	* include/bits/stl_numeric.h (iota): Likewise.
	* include/bits/stl_tempbuf.h (return_temporary_buffer):
	Likewise.
	* include/bits/stl_uninitialized.h (uninitialized_fill):
	Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:56 +01:00
Jonathan Wakely
9b3957cd59 libstdc++: Fix errors in Doxygen markup
libstdc++-v3/ChangeLog:

	* doc/doxygen/doxygroups.cc: Define variable_templates group.
	* include/bits/binders.h: Fix @file name.
	* include/bits/formatfwd.h: Add missing @cond
	* include/bits/forward_list.h: Add closing backtick in comment.
	* include/bits/out_ptr.h (out_ptr, inout_ptr): Fix names in
	@param comments.
	* include/bits/regex_constants.h: Escape backtick in comment.
	* include/bits/stl_map.h: Add missing @{.
	* include/bits/stl_set.h: Likewise.
	* include/bits/stl_pair.h: Move declaration of complex into #if
	group where it's used. Fix nesting of @cond and @endcond in #if
	groups.
	* include/std/functional: Move @cond inside #if group.
	* include/std/type_traits: Likewise.
	* libsupc++/exception: Fix typo'd backtick.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:55 +01:00
Jonathan Wakely
8be7d5deb0 libstdc++: Use __cpp_lib_map_try_emplace feature test macro
Check the relevant macro for insert_or_assign members, instead of just
checking the value of __cplusplus.

Also use Doxygen grouping to make docs for try_emplace apply to all
three overloads.

libstdc++-v3/ChangeLog:

	* include/bits/stl_map.h (map::try_emplace): Move #endif and use
	Doxygen's @{ to document all three overloads.
	(map::insert_or_assign): Use relevant feature test macro.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 13:59:53 +01:00
Tomasz Kamiński
c00c750ba2 libstdc++: Rename std::strided_slice to std::extent_slice.
This is last change proposed in P3982R2, so we bump submdspan
value.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (submdspan): Update to 202603,
	and list all papers in comment.
	* include/bits/version.h: Regenerate.
	* include/std/mdspan: Replaced std::strided_stride to
	std::extent_slice, __is_strided_slice to __is_extent_slice,
	_SliceKind::__unit_strided_slice to __unit_stride_slice.
	* src/c++23/std.cc.in (std::extent_slice): Replaced
	std::strided_slice to std::extent_slice.
	* testsuite/23_containers/mdspan/submdspan/canonical_slices.cc:
	Replaced all occurences of strided_slice to extent_slice.
	* testsuite/23_containers/mdspan/submdspan/canonical_slices_neg.cc:
	Likewise.
	* testsuite/23_containers/mdspan/submdspan/strided_slice.cc: Move to...
	* testsuite/23_containers/mdspan/submdspan/extent_slice.cc: ...here
	and handle rename.
	* testsuite/23_containers/mdspan/submdspan/strided_slice_neg.cc: Move to...
	* testsuite/23_containers/mdspan/submdspan/extent_slice_neg.cc: ...here
	and handle rename.
	* testsuite/23_containers/mdspan/submdspan/selections/testcases.h:
	Replaced all occurences of strided_slice to extent_slice.
	* testsuite/23_containers/mdspan/submdspan/subextents.cc: Likewise.
	* testsuite/23_containers/mdspan/submdspan/subextents_neg.cc:
	Likewise.
	* testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc:
	Likewise.
	* testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-02 09:58:44 +02:00
François Dumont
c0b659db1a libstdc++: [_GLIBCXX_DEBUG] Fix COW string valid range check
In revision 698a6af5dc the _GLIBCXX_DEBUG code
for the Library Defect 438 has been removed as starting in C++11 the iterator
type is constrained through the _RequireInputIter requirement.

But the COW basic_string implementation used when _GLIBCXX_USE_CXX11_ABI=0 is
missing the _RequireInputIter constraint on a number of methods resulting in test
failures.

For the moment move the culprit __glibcxx_requires_valid_range call in the COW
basic_string implementation in a method where the iterator type has already been
checked.

libstdc++-v3/ChangeLog:

	* include/bits/cow_string.h
	(basic_string::replace(iterator, iterator, _InputIte, _InputIte)): Move
	__glibcxx_requires_valid_range to...
	(basic_string::_M_replace_dispatch(iterator, iterator, _InputIte,
	_InputIte, __fase_type)): ...here.
	* testsuite/21_strings/basic_string/debug/append_neg.cc: New test case.
	* testsuite/21_strings/basic_string/debug/assign_neg.cc: New test case.
	* testsuite/21_strings/basic_string/debug/construct_neg.cc: New test case.
	* testsuite/21_strings/basic_string/debug/insert_neg.cc: New test case.
	* testsuite/21_strings/basic_string/debug/replace_neg.cc: New test case.

Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-04-01 18:59:24 +02:00
Patrick Palka
d60b69a2eb libstdc++: Implement P3725R3 Filter View Extensions for Safer Use
This implements the recently approved C++26 paper P3725R3, which
we treat as a Defect Report against C++20.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (ranges_filter): Define for C++20.
	* include/bits/version.h: Regenerate.
	* include/std/ranges: Provide __cpp_lib_ranges_filter.
	(filter_view::_Iterator): Add _Const template parameter.
	(filter_view::_Iterator::_S_iter_concept): Return
	input_iterator_tag if _Const.
	(filter_view::_Iterator::_Parent): New.
	(filter_view::_Iterator::_Base): New.
	(filter_view::_Iterator::_Vp_iter): Replace with ...
	(filter_view::_Iterator::_Base_iter): ... this.
	(filter_view::_Iterator::_M_current): Adjust to consider _Const.
	(filter_view::_Iterator::_M_parent): Likewise.
	(filter_view::_Iterator::value_type): Likewise.
	(filter_view::_Iterator::difference_type): Likewise.
	(filter_view::_Iterator::_Iterator): Likewise.  Add
	const-converting overload.
	(filter_view::_Iterator::base): Adjust to consider _Const.
	(filter_view::_Iterator::operator*): Likewise.
	(filter_view::_Iterator::operator->): Likewise.
	(filter_view::_Iterator::operator++): Likewise.
	(filter_view::_Iterator::operator--): Likewise.
	(filter_view::_Iterator::iter_move): Likewise.
	(filter_view::_Iterator::iter_swap): Likewise.
	(filter_view::_Sentinel): Add _Const template parameter.
	(filter_view::_Sentinel::_Parent): New.
	(filter_view::_Sentinel::_Base): New.
	(filter_view::_Sentinel::_M_end): Adjust to consider _Const.
	(filter_view::_Sentinel::_Sentinel): Likewise.  Add
	const-converting overload.
	(filter_view::_Sentinel::base): Adjust to consider _Const.
	(filter_view::_Sentinel::operator==): Likewise.  Inline the
	helper member function __equal.
	(filter_view::begin): Adjust return type of non-const overload.
	New const overload.
	(filter_view::end): Likewise.
	* testsuite/std/ranges/adaptors/filter.cc: Verify value of
	__cpp_lib_ranges_filter.
	(test08): New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-04-01 11:34:24 -04:00
Jonathan Wakely
bd87cdb896 libstdc++: Rename std::runtime_format for C++26 (P3953R3)
Last week in Croydon we approved P3953R3 to rename std::runtime_format
for C++26. The rationale is that with compile-time std::format, the name
std::runtime_format doesn't make sense. It's std::dynamic_format now
instead.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_S_empty_fs)
	(__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_D_x)
	(__formatter_chrono::_M_F, __formatter_chrono::_M_subsecs)
	(__formatter_chrono_info::_M_format_to): Use
	_Dynamic_format_string instead of _Runtime_format_string.
	* include/bits/version.def (format): Bump value.
	* include/bits/version.h: Regenerate.
	* include/std/format (_Runtime_format_string): Rename to
	_Dynamic_format_string.
	(runtime_format): Rename to dynamic_format.
	* include/std/print (println): Adjust comment to refer to
	dynamic_format instead of runtime_format.
	* testsuite/std/format/runtime_format.cc: Move to...
	* testsuite/std/format/dynamic_format.cc: ...here.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-01 12:51:16 +01:00
Jonathan Wakely
c9525a7902 libstdc++: Rename saturation arithmetic for C++26 (P4052R0)
Last week in Croydon we approved P4052R0 to rename std::add_sat etc. for
C++26

libstdc++-v3/ChangeLog:

	* include/bits/sat_arith.h (add_sat, sub_sat, mul_sat, div_sat)
	(saturate_cast): Rename to saturating_xxx as per P4052R0.
	* include/bits/version.def (saturation_arithmetic): Bump value.
	* include/bits/version.h: Regenerate.
	* testsuite/26_numerics/saturation/add.cc: Use new name.
	* testsuite/26_numerics/saturation/cast.cc: Likewise.
	* testsuite/26_numerics/saturation/div.cc: Likewise.
	* testsuite/26_numerics/saturation/extended.cc: Likewise.
	* testsuite/26_numerics/saturation/mul.cc: Likewise.
	* testsuite/26_numerics/saturation/sub.cc: Likewise.
	* testsuite/26_numerics/saturation/version.cc: Check for updated
	value.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-04-01 12:51:13 +01:00
Tomasz Kamiński
63ea5ff289 libstdc++: Change atomic_ref::address return type to cv void*.
This implements with P3936R1 Safer atomic_ref::address with
the bump to __cpp_lib_atomic_ref feture test macro.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (__atomic_ref_base::_Address_return_t):
	Define.
	(__atomic_ref_base::address): Change return type to _Address_return_t.
	* include/bits/version.def (atomic_ref): Bump to 202603.
	* include/bits/version.h: Regenerate.
	* testsuite/29_atomics/atomic_ref/address.cc: Update check for
	return type.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-30 18:01:13 +02:00
Nathan Myers
8df8a196f7 libstdc++: Delete superseded comment
A comment referring to nothing remained in a patch.

libstdc++-v3/ChangeLog:
	* include/bits/stl_tree.h: Delete comment.
2026-03-27 11:37:39 -04:00
Matthias Kretz
8be0893fd9 libstdc++: Implement [simd] for C++26
This implementation differs significantly from the
std::experimental::simd implementation. One goal was a reduction in
template instantiations wrt. what std::experimental::simd did.

Design notes:

- bits/vec_ops.h contains concepts, traits, and functions for working
  with GNU vector builtins that are mostly independent from std::simd.
  These could move from std::simd:: to std::__vec (or similar). However,
  we would then need to revisit naming. For now we kept everything in
  the std::simd namespace with __vec_ prefix in the names. The __vec_*
  functions can be called unqualified because they can never be called
  on user-defined types (no ADL). If we ever get simd<UDT> support this
  will be implemented via bit_cast to/from integral vector
  builtins/intrinsics.

- bits/simd_x86.h extends vec_ops.h with calls to __builtin_ia32_* that
  can only be used after uttering the right GCC target pragma.

- basic_vec and basic_mask are built on top of register-size GNU vector
  builtins (for now / x86). Any larger vec/mask is a tree of power-of-2
  #elements on the "first" branch. Anything non-power-of-2 that is
  smaller than register size uses padding elements that participate in
  element-wise operations. The library ensures that padding elements
  lead to no side effects. The implementation makes no assumption on the
  values of these padding elements since the user can bit_cast to
  basic_vec/basic_mask.

Implementation status:

- The implementation is prepared for more than x86 but is x86-only for
  now.

- Parts of [simd] *not* implemented in this patch:

  - std::complex<floating-point> as vectorizable types
  - [simd.permute.dynamic]
  - [simd.permute.mask]
  - [simd.permute.memory]
  - [simd.bit]
  - [simd.math]
  - mixed operations with vec-mask and bit-mask types
  - some conversion optimizations (open questions wrt. missed
    optimizations in the compiler)

- This patch implements P3844R3 "Restore simd::vec broadcast from int",
  which is not part of the C++26 WD draft yet. If the paper does not get
  accepted the feature will be reverted.

- This patch implements D4042R0 "incorrect cast between simd::vec and
simd::mask via conversion to and from impl-defined vector types" (to be
published once the reported LWG issue gets a number).

- The standard feature test macro __cpp_lib_simd is not defined yet.

Tests:

- Full coverage requires testing
  1. constexpr,
  2. constant-propagating inputs, and
  3. unknown (to the optimizer) inputs
  - for all vectorizable types
  * for every supported width (1–64 and higher)
  + for all possible ISA extensions (combinations)
  = with different fast-math flags
  ... leading to a test matrix that's far out of reach for regular
  testsuite builds.

- The tests in testsuite/std/simd/ try to cover all of the API. The
  tests can be build in every combination listed above. Per default only
  a small subset is built and tested.

- Use GCC_TEST_RUN_EXPENSIVE=something to compile the more expensive
  tests (constexpr and const-prop testing) and to enable more /
  different widths for the test type.

- Tests can still emit bogus -Wpsabi warnings (see PR98734) which are
  filtered out via dg-prune-output.

Benchmarks:

- The current implementation has been benchmarked in some aspects on
  x86_64 hardware. There is more optimization potential. However, it is
  not always clear whether optimizations should be part of the library
  if they can be implemented in the compiler.

- No benchmark code is included in this patch.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add simd headers.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def (simd): New.
	* include/bits/version.h: Regenerate.
	* include/bits/simd_alg.h: New file.
	* include/bits/simd_details.h: New file.
	* include/bits/simd_flags.h: New file.
	* include/bits/simd_iterator.h: New file.
	* include/bits/simd_loadstore.h: New file.
	* include/bits/simd_mask.h: New file.
	* include/bits/simd_mask_reductions.h: New file.
	* include/bits/simd_reductions.h: New file.
	* include/bits/simd_vec.h: New file.
	* include/bits/simd_x86.h: New file.
	* include/bits/vec_ops.h: New file.
	* include/std/simd: New file.
	* testsuite/std/simd/arithmetic.cc: New test.
	* testsuite/std/simd/arithmetic_expensive.cc: New test.
	* testsuite/std/simd/create_tests.h: New file.
	* testsuite/std/simd/creation.cc: New test.
	* testsuite/std/simd/creation_expensive.cc: New test.
	* testsuite/std/simd/loads.cc: New test.
	* testsuite/std/simd/loads_expensive.cc: New test.
	* testsuite/std/simd/mask2.cc: New test.
	* testsuite/std/simd/mask2_expensive.cc: New test.
	* testsuite/std/simd/mask.cc: New test.
	* testsuite/std/simd/mask_expensive.cc: New test.
	* testsuite/std/simd/reductions.cc: New test.
	* testsuite/std/simd/reductions_expensive.cc: New test.
	* testsuite/std/simd/shift_left.cc: New test.
	* testsuite/std/simd/shift_left_expensive.cc: New test.
	* testsuite/std/simd/shift_right.cc: New test.
	* testsuite/std/simd/shift_right_expensive.cc: New test.
	* testsuite/std/simd/simd_alg.cc: New test.
	* testsuite/std/simd/simd_alg_expensive.cc: New test.
	* testsuite/std/simd/sse_intrin.cc: New test.
	* testsuite/std/simd/stores.cc: New test.
	* testsuite/std/simd/stores_expensive.cc: New test.
	* testsuite/std/simd/test_setup.h: New file.
	* testsuite/std/simd/traits_common.cc: New test.
	* testsuite/std/simd/traits_impl.cc: New test.
	* testsuite/std/simd/traits_math.cc: New test.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
2026-03-21 12:44:15 +01:00
Jakub Jelinek
1c73a21caf libstdc++: Uglify another variable name
This is needed to make the latest version of the uglification plugin
I'm about to send PASS.

2026-03-18  Jakub Jelinek  <jakub@redhat.com>

	* include/bits/regex_compiler.h (_Compiler::_M_pop): Uglify ret
	variable name.
2026-03-18 15:40:51 +01:00
Jonathan Wakely
62dec39dbd libstdc++: Fix some non-uglified names
Jakub wrote a plugin which identified some non-reserved names being used
in our headers. The "count" one is actually a reserved name (there's
std::set::count and std::count and std::bitset::count) but we might as
well uglify it when used as a function parameter name. I think the "ext"
ones must have happened when moving function definitions from fs_path.cc
to fs_path.h and I forgot to change them.

The __cond::wait and __cond::wait_recursive member functions are using
non-reserved names, so that should be changed too, but this patch
doesn't fix that. I don't think we use the __gnu_cxx::__cond type in any
headers, so maybe that should just be moved into libsupc++/guard.cc or a
new header which is not installed and only used while building the
library.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_duration::_S_subseconds):
	Uglify subs variable name.
	* include/bits/fs_path.h (path::stem, path::extension)
	(path::has_stem, path::has_extension): Uglify ext parameter
	name.
	* include/ext/concurrence.h (__cond::wait, __cond::wait_recursive):
	Uglify mutex parameter names.
	* include/pstl/glue_algorithm_defs.h (generate_n): Uglify count
	parameter name.
	* include/std/ranges (zip_transform_view): Uglify Rs template
	parameter name.
	(__cartesian_is_sized_sentinel): Uglify FirstSent template
	parameter name.
	* include/tr1/riemann_zeta.tcc: Uglify max_size variable name.
2026-03-17 21:49:43 +00:00
Jonathan Wakely
892451e7b6 libstdc++: Optimize __uninitialized_copy_a for std::deque iterators [PR124463]
I reimplemented uninitialized_copy and uninitialized_move in
r15-4473-g3abe751ea86e34 so that they no longer delegate to std::copy,
but that meant that they were no longer optimized for std::deque
iterators, leading to performance regressions for operations on a
std::deque with trivial element types. This adds new overloads of
__uninitialized_copy_a and __uninitialized_move_a to handle std::deque
iterators, restoring the lost performance.

There are also overloads of std::fill for deque iterators which are no
longer used for std::uninitialized_fill. This does not add replacements
for those, so there will still be lost performance for std::deque
operations that depend on std::uninitialized_fill. Similarly, inserting
or assigning from istreambuf_iterator into a std::deque no longer uses
the std::copy overloads for those types, and that isn't fixed by this
patch either.

libstdc++-v3/ChangeLog:

	PR libstdc++/124463
	* include/bits/deque.tcc (__uninitialized_copy_a): Define
	overloads for input and output iterators being std::deque
	iterators, and for only the output iterator being a std::deque
	iterator.
	(__uninitialized_move_a): Overload for input and output
	iterators being std::deque iterators.
	* include/bits/stl_uninitialized.h (__uninitialized_copy_a)
	(__uninitialized_move_a): Declare overloads for std::deque
	iterators.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-17 21:49:14 +00:00
Jonathan Wakely
c351a240ad libstdc++: Make ranges::distance work with volatile iterators (LWG 4242)
This implements LWG 4242 which was approved in Sofia 2025.

I don't think the change from static_cast<const decay_t<I>&> to just
static_cast<decay_t<I>> is observable, but it doesn't hurt. What fixes
the problem identified in the issue is the is_array_v check, which
avoids the static_cast entirely for volatile-qualified iterators.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (distance(It&&, Sent)): Only decay
	arrays to pointers when the type is actually an array, as per
	LWG 4242.
	* testsuite/24_iterators/range_operations/distance.cc: Add test
	for LWG 4242.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-16 22:04:23 +00:00
Jonathan Wakely
f60dbb5796 libstdc++: Improve diagnostics for std::allocator<incomplete type>
Using requires { sizeof(T); } in __new_allocator::allocate gives a
better diagnostic when the static_assert fails.

We can also reduce the total number of diagnostics due to invalid
sizeof(T) and alignof(T) by using the same requires-expression to make
the body of the function a discarded statement when the static_assert
already failed. This fixes a regression in diagnostic quality due to
making __new_allocator::allocate constexpr in r16-7271-g7197d0cce70525,
which caused a cascade of seven errors instead of just one for
std::allocator<incomplete-type>().allocate(1).

libstdc++-v3/ChangeLog:

	* include/bits/allocator.h (allocator::allocate): Use specific
	feature test macro for constexpr allocate and deallocate. Make
	consteval path a discarded statement if sizeof(T) is ill-formed.
	* include/bits/new_allocator.h (__new_allocator::allocate): Use
	requires-expression for static_cast. Make function body a
	discarded stament if sizeof(T) is ill-formed. Use if-constexpr
	for alignment checks.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-16 15:17:45 +00:00
Jonathan Wakely
7738be342c libstdc++: Do not use projection for ranges::replace default args (LWG 4444)
Implement the resolution of LWG 444, accepted in Kona 2025.

The new value to be assigned to the matching elements should default to
the value type of the range, not the type returned by the projection.
The type returned by the projection is only used to find the matching
elements, and might not be assignable to the value type at all.

libstdc++-v3/ChangeLog:

	* include/bits/ranges_algo.h (__replace_fn, __replace_if_fn):
	Change default template argument for type of new value, as per
	LWG 4444.
	* testsuite/25_algorithms/replace/lwg4444.cc: New test.
	* testsuite/25_algorithms/replace_if/lwg4444.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-10 18:22:28 +00:00
Nathan Myers
02926c0abb libstdc++: Add allocate_at_least (P0401) [PR118030]
Implement proposals adopted for C++23:
P0401R6, "Providing size feedback in the Allocator interface"
P2652R2, "Disallow User Specialization of allocator_traits".

This is the minimal conforming implementation, i.e. without the
useful parts. Useful parts, to come in future patches, would
include giving access to any extra storage reserved, and use of
it in vector, string, and other contiguous containers.

libstdc++-v3/ChangeLog:
	PR libstdc++/118030
	* include/bits/alloc_traits.h (allocate_at_least (2x)): Define.
	* include/bits/allocator.h (allocate_at_least): Define.
	* include/std/memory (__glibcxx_want_allocate_at_least): Define.
	* include/bits/memoryfwd.h (allocation_result): Define, #include
	<bits/version.h> first so that will work.
	* include/bits/version.def (allocate_at_least): Add.
	* include/bits/version.h: Regenerate.
	* testsuite/20_util/allocator/allocate_at_least.cc: New test.
	* testsuite/20_util/allocator/allocate_at_least_neg.cc: New test.
2026-03-10 13:38:23 -04:00
Jonathan Wakely
57f353300f libstdc++: Use specific feature test macro for #if in <string>
libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h: Check __glibcxx_to_string instead
	of __cplusplus.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-10 10:33:45 +00:00
Jonathan Wakely
45477b791d libstdc++: Add platform wait functions for FreeBSD [PR120527]
This defines __platform_wait, __platform_notify, and
__platform_wait_until for FreeBSD, making use of the _umtx_op syscall.

The Linux versions of those functions only support 32-bit integers, but
the FreeBSD versions use the syscall for both 32-bit and 64-bit types,
as the _umtx_op supports both.

We also need to change __spin_impl because it currently assumes the
waitable at args._M_obj is always a __platform_wait_t. Because FreeBSD
supports waiting on both 32-bit and 64-bit integers, we need a
platform-specific function for loading a value from _M_obj.  This adds a
new __platform_load function, which does an atomic load of the right
size. The Linux definition just loads an int, but for FreeBSD it depends
on _M_obj_size. We also need a generic version of the function for
platforms without __platform_wait, because __spin_impl is always used,
even when the __waitable_state contains a condition_variable.

libstdc++-v3/ChangeLog:

	PR libstdc++/120527
	* include/bits/atomic_wait.h [__FreeBSD__] (__platform_wait_t):
	Define typedef.
	[__FreeBSD__] (__platform_wait_uses_type): Define variable
	template.
	* src/c++20/atomic.cc (__platform_load): New function.
	[__FreeBSD__] (_GLIBCXX_HAVE_PLATFORM_WAIT, __platform_wait)
	(__platform_notify, __platform_wait_until): Define.
	(__detail::__spin_impl): Use __platform_load.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-09 16:44:11 +00:00
Tomasz Kamiński
468124a1aa libstdc++: Remove unnecessary string in filesystem::path formatter
libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h (std::formatter<filesystem::path, _CharT>):
	Format _Utf_view directly via __formatter_str::_M_format_range.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-06 11:35:24 +01:00
Nathan Myers
94d5ca4583 libstdc++: container heterogeneous insertion (P2363) [PR117402]
Implements P2353R5 "Extending associative containers with the
remaining heterogeneous overloads". Adds overloads templated on
heterogeneous key types for several members of associative
containers, particularly insertions:

                      /-- unordered --\
 set  map  mset mmap set  map  mset mmap
  @    .    .    .    @    .    .    .    insert
  .    @    .    .    .    @    .    .    op[], at, try_emplace,
                                            insert_or_assign
  .    .    .    .    @    @    @    @    bucket

(Nothing is added to the multiset or multimap tree containers.)
All the insert*() and try_emplace() members also get a hinted
overload.  The at() members get const and non-const overloads.

The new overloads enforce concept __heterogeneous_tree_key or
__heterogeneous_hash_key, as in P2077, to enforce that the
function objects provided meet requirements, and that the key
supplied is not an iterator or the native key. Insertions
implicitly construct the required key_type object from the
argument, by move where permitted.

libstdc++-v3/ChangeLog:
	PR libstdc++/117402
	* include/bits/stl_map.h (operator[], at (2x), try_emplace (2x),
	insert_or_assign (2x)): Add overloads.
	* include/bits/unordered_map.h (operator[], at (2x),
	try_emplace (2x), insert_or_assign (2x), bucket (2x)): Add overloads.
	* include/bits/stl_set.h (insert (2x)): Add overloads.
	* include/bits/unordered_set.h (insert (2x), bucket (2x)): Add overloads.
	* include/bits/hashtable.h (_M_bucket_tr, _M_insert_tr): Define.
	* include/bits/hashtable_policy.h (_M_at_tr (2x)): Define.
	* include/bits/stl_tree.h (_M_emplace_here, _M_get_insert_unique_pos_tr,
	_M_get_insert_hint_unique_pos_tr): Define new heterogeneous insertion
	code path for set and map.
	* include/bits/version.def (associative_heterogeneous_insertion):
	Define.
	* include/bits/version.h: Regenerate.
	* include/std/map (__glibcxx_want_associative_heterogeneous_insertion):
	Define macro.
	* include/std/set: Same.
	* include/std/unordered_map: Same.
	* include/std/unordered_set: Same.
	* testsuite/23_containers/map/modifiers/hetero/insert.cc: New tests.
	* testsuite/23_containers/set/modifiers/hetero/insert.cc: Same.
	* testsuite/23_containers/unordered_map/modifiers/hetero/insert.cc:
	Same.
	* testsuite/23_containers/unordered_multimap/modifiers/hetero/insert.cc:
	Same.
	* testsuite/23_containers/unordered_multiset/modifiers/hetero/insert.cc:
	Same.
	* testsuite/23_containers/unordered_set/modifiers/hetero/insert.cc:
	Same.
2026-03-04 03:59:15 -05:00
Jonathan Wakely
f48b123580 libstdc++: Reference C++11 standard more precisely in regex comments
libstdc++-v3/ChangeLog:

	* include/bits/regex_compiler.h: Adjust comments so that
	standard references are specific to C++11.
2026-03-03 12:05:49 +00:00
Yuao Ma
0772974fec libstdc++: complete P0493R5 with pointer support
Previous implementations of fetch_min/max only supported integers, not
handling pointers. To complete the paper, we need to implement support
for pointers as well. This patch adds the missing functionality and
test cases.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (__atomic_base<_PTp*>::fetch_min,
	__atomic_base<_PTp*>::fetch_max,
	__atomic_ref<_Pt, false, false, true>::fetch_min,
	__atomic_ref<_Pt, false, false, true>::fetch_max): Define new
	functions.
	* include/std/atomic (atomic<_Tp*>::fetch_min,
	atomic<_Tp*>::fetch_max): Likewise.
	(atomic_fetch_min_explicit, atomic_fetch_max_explicit,
	atomic_fetch_min, atomic_fetch_max): Change parameter from
	__atomic_base<_ITp>* to atomic<_Tp>*.
	* testsuite/29_atomics/atomic/pointer_fetch_minmax.cc: New test.
	* testsuite/29_atomics/atomic_ref/pointer_fetch_minmax.cc: New
	test.
2026-02-26 21:11:07 +08:00
Tomasz Kamiński
716ec14c57 libstdc++: Implement rvalue overload for basic_string::substr() [PR119745]
This paper implement the changes from P2438R2 basic_string::substr() &&
paper into C++26. The additional substr and constructor overload are
implemented only for SSO string, as they require mutating the content
(if reused), and thus would require copy of the string anyway for COW
strings. (In consequence allocators implicitly constructible from int
remain ambiguous for C++11 ABI strings, see r16-7497-gfa1149534d8580).

In addition to cases when the allocators are not compatible (equal),
this patch does not reuse (transfer) allocator storage, if the selected
substring fits inside the SSO buffer, so we do not risk keeping large
chunk of memory for few characters. (This also covers cases when the
source stored the content in the local buffer).

As this additional overloads are meant to be optimization, in contrast
to move constructor, the source is left unmodified if the allocation
is not transferred. This avoid introducing a write (of null terminator)
to previously untouched, heap allocated, memory.

Separate overloads for substr(size_type __pos, size_type __n) and
substr(size_type __pos == 0), that delegate to corresponding constructor,
are provided to avoid the check of __n against the length() in the later
case.

Finally, the signatures of existing substr() overload are not modified
(no longer required since C++20), which avoid any impact on the ABI.

	PR libstdc++/119745

libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h (basic_string::_M_construct)
	[__cplusplus >= 202302L]: Declare.
	(basic_string::basic_string(basic_string&&, size_type, const _Alloc&))
	(basic_string(basic_string&&, size_type, size_type, const _Alloc&))
	(basic_string::substr(size_type, size_type) &&)
	(basic_string::substr(size_type) &&) [__cplusplus >= 202302L]: Define.
	* include/bits/basic_string.tcc (basic_string::_M_construct)
	[__cplusplus >= 202302L]: Define.
	* testsuite/21_strings/basic_string/operations/substr/rvalue.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-16 18:26:35 +01:00
Ivan Lazaric
642020ab7e libstdc++: implement formatter for std::filesystem::path
This patch implements formatting for std::filesystem::path from P2845R8,
and defines the feature test macro __cpp_lib_format_path to 202403L,
provided only in <filesystem>.

Formatting options are performed (if applicable) in order:
'g', '?', transcoding, fill-and-align & width

The standard specifies transcoding behaviour only when literal encoding
is UTF-8, leaving all other cases implementation defined.
Current implementation of filesystem::path assumes:
* char encoding is UTF-8
* wchar_t encoding is either UTF-32 or UTF-16

libstdc++-v3/ChangeLog:

	* include/bits/fs_path.h: Include bits/formatfwd.h.
	(std::formatter<filesystem::path, _CharT>): Define.
	* include/bits/version.def (format_path): Define.
	* include/bits/version.h: Regenerate.
	* include/std/filesystem: Expose __cpp_lib_format_path.
	* testsuite/std/format/fs_path.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-16 12:34:18 +01:00