Commit Graph

5800 Commits

Author SHA1 Message Date
Nina Ranns
fbde291af6 libstdc++, contracts: Add base P2900R14 contracts support.
What we need to do here (and, of course, in the code synthesis
that produces the objects) needs to be interoperable with other
platforms that share ABI.  For the present, this means Itanium
and to interoperate with clang and libc++.

The model we have followed in the development is essentially the
same as the model used for the C++2a edition.  However there is some
concern that the read-only data footprint of this is potentially
high and alternate schemes are in discussion with the clang folks.

Since the layout of the violation object is ABI let's leave this
in experimental until an agreed solution is fixed.

Remove the cxx2a support at the same time, GCC no longer supports
this mode.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add contract include.
	* include/Makefile.in: Regenerate.
	* include/bits/version.def: Add ftm for contracts.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Add contracts header.
	* include/std/source_location: Befriend the contract_violation
	class so that we can initialise a source_location from an
	existing __impl *.
	* src/c++23/std.cc.in: Add contracts support.
	* src/experimental/Makefile.am: Add new contract violation
	implementation, remove the old one.
	* src/experimental/Makefile.in: Regenerate.
	* include/experimental/contract: Removed.
	* src/experimental/contract.cc: Removed.
	* include/std/contracts: New file.
	* src/experimental/contract26.cc: New file.
	* testsuite/18_support/contracts/invoke_default_cvh.cc: New test.
	* testsuite/18_support/contracts/invoke_default_cvh2.cc: New test.

Co-Authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-Authored-by: Ville Voutilainen <ville.voutilainen@gmail.com>
Signed-off-by: Nina Ranns <dinka.ranns@gmail.com>
2026-01-28 01:25:12 +00:00
Tomasz Kamiński
d7e5113e59 libstdc++: Explicitly call _Mo_base() in _Cpy_base copy-constructor [PR123758]
This silences the warning while preserving current (correct) behavior.

	PR libstdc++/123758

libstdc++-v3/ChangeLog:

	* include/bits/funcwrap.h (_Cpy_base(_Cpy_base const&)):
	Explicitly call _Mo_base() in initializer list.
2026-01-23 11:13:33 +01:00
Jakub Jelinek
23cd6f3bcb libstdc++: Disable __cpp_lib_reflection for old CXX ABI
Reflection currently doesn't work with -D_GLIBCXX_USE_CXX11_ABI=0.
The problem is that std::meta::exception currently uses under the
hood std::string and std::u8string and those aren't constexpr in
the old ABI.
While those members are in the standard exposition-only and so
we could make it to work by writing a custom class template that
just remembers const char{,8_t} * and size_t, there shouldn't be
many people trying to use C++26 features with the ABI that isn't
even compatible with C++11.

2026-01-20  Jakub Jelinek  <jakub@redhat.com>

	* include/bits/version.def (reflection): Add cxx11abi = yes;.
	* include/bits/version.h: Regenerate.
2026-01-20 12:01:07 +01:00
Tomasz Kamiński
8fad43b785 libstdc++: Use overload operator<=> when provided in relational functors [PR114153]
The implementation of less<> did not consider the possibility of t < u being
rewritten from overloaded operator<=>. This lead to situation when for t,u that:
* provide overload operator<=>, such that (t < u) is rewritten to (t <=> u) < 0,
* are convertible to pointers,
the expression std::less<>(t, u) would incorrectly result in call of
std::less<void*> on values converted to the pointers, instead of t < u.
The similar issues also occurred for greater<>, less_equal<>, greater_equal<>,
their range equivalents, and in three_way_compare for heterogeneous calls.

This patch addresses above, by also checking for free-functions and member
overloads of operator<=>, before falling back to pointer comparison. We do
not put any constraints on the return type of selected operator, in particular
in being one of the standard defined comparison categories, as the language
does not put any restriction of returned type, and if (t <=> u) is well
formed, (t op u) is interpreted as (t <=> u) op 0. If that later expression
is ill-formed, the expression using op also is (see included tests).

The relational operator rewrites try both order of arguments, t < u,
can be rewritten into operator<=>(t, u) < 0 or 0 < operator<=>(u, t), it
means that we need to test both operator<=>(T, U) and operator<=>(U, T)
if T and U are not the same types. This is now extracted into
__not_overloaded_spaceship helper concept, placed in <concepts>, to
avoid extending set of includes.

The compare_three_way functor defined in compare, already considers overloaded
operator<=>, however it does not consider reversed candidates, leading
to situation in which t <=> u results in 0 <=> operator<=>(u, t), while
compare_three_way{}(t, u) uses pointer comparison. This is also addressed by
using __not_overloaded_spaceship, that check both order of arguments.

Finally, as operator<=> is introduced in C++20, for std::less(_equal)?<>,
std::greater(_equal)?<>, we use provide separate __ptr_cmp implementation
in that mode, that relies on use of requires expression. We use a nested
requires clause to guarantee short-circuiting of their evaluation.
The operator() of aforementioned functors is reworked to use if constexpr,
in all standard modes (as we allow is as extension), eliminating the need
for _S_cmp function.

	PR libstdc++/114153

libstdc++-v3/ChangeLog:

	* include/bits/ranges_cmp.h (__detail::__less_builtin_ptr_cmp):
	Add __not_overloaded_spaceship spaceship check.
	* include/bits/stl_function.h (greater<void>::operator())
	(less<void>::operator(), greater_equal<void>::operator())
	(less_equal<void>::operator()): Implement using if constexpr.
	(greater<void>::__S_cmp, less<void>::__S_cmp)
	(greater_equal<void>::__ptr_comp, less_equal<void>::S_cmp):
	Remove.
	(greater<void>::__ptr_cmp, less<void>::__ptr_cmp)
	(greater_equal<void>::__ptr_comp, less_equal<void>::ptr_cmp): Change
	tostatic constexpr variable. Define in terms of requires expressions
	and __not_overloaded_spaceship check.
	* include/std/concepts: (__detail::__not_overloaded_spaceship):
	Define.
	* libsupc++/compare: (__detail::__3way_builtin_ptr_cmp): Use
	__not_overloaded_spaceship concept.
	* testsuite/20_util/function_objects/comparisons_pointer_spaceship.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-19 12:09:11 +01:00
Tomasz Kamiński
e9a62938be libstdc++: Fix std::erase_if for std::string with -D_GLIBCXX_USE_CXX11_ABI=0.
The __cow_string used with -D_GLIBCXX_USE_CXX11_ABI=0, does not provide
erase accepting const_iterator, so we adjust  __detail::__erase.if
(introduced in r16-6889-g3287) to call __cont.erase with mutable iterators.

libstdc++-v3/ChangeLog:

	* include/bits/erase_if.h (__detail::__erase_if): Pass mutable
	iterators to __cont.erase.
2026-01-19 10:17:47 +01:00
François Dumont
3287a5c617 libstdc++: Fix std::erase_if behavior for std::__debug containers
Complete fix of std::erase_if/std::erase for all std::__debug containers and
__gnu_debug::basic_string. Make sure that iterators erased by this function
will be properly detected as such by the debug container and so considered as
invalid.

Doing so introduce a new std::__detail::__erase_if function dealing, similarly
to std::__detail::__erase_node_if, with non-node containers.

libstdc++-v3/ChangeLog:

	* include/bits/erase_if.h (__detail::__erase_if): New.
	* include/debug/deque (std::erase_if<>(__debug::deque<>&, _Pred)): Use latter.
	* include/debug/inplace_vector (std::erase_if<>(__debug::inplace_vector<>&, _Pred)):
	Likewise.
	* include/debug/vector (std::erase_if<>(__debug::vector<>&, _Pred)): Likewise.
	* include/std/deque: Include erase_if.h.
	(std::erase_if<>(std::vector<>&, _Pred)): Adapt to use __detail::__erase_if.
	* include/std/inplace_vector (std::erase_if<>(std::inplace_vector<>&, _Pred)):
	Likewise.
	* include/std/string (std::erase_if<>(std::basic_string<>&, _Pred)): Likewise.
	* include/std/vector (std::erase_if<>(std::vector<>&, _Pred)): Likewise.
	* include/debug/forward_list
	(std::erase_if<>(__debug::forward_list<>&, _Pred)): New.
	(std::erase<>(__debug::forward_list<>&, const _Up&)): New.
	* include/debug/list
	(std::erase_if<>(__debug::list<>&, _Pred)): New.
	(std::erase<>(__debug::list<>&, const _Up&)): New.
	* include/debug/map (std::erase_if<>(__debug::map<>&, _Pred)): New.
	(std::erase_if<>(__debug::multimap<>&, _Pred)): New.
	* include/debug/set (std::erase_if<>(__debug::set<>&, _Pred)): New.
	(std::erase_if<>(__debug::multiset<>&, _Pred)): New.
	* include/debug/string
	(std::erase_if<>(__gnu_debug::basic_string<>&, _Pred)): New.
	(std::erase<>(__gnu_debug::basic_string<>&, const _Up&)): New.
	* include/debug/unordered_map
	(std::erase_if<>(__debug::unordered_map<>&, _Pred)): New.
	(std::erase_if<>(__debug::unordered_multimap<>&, _Pred)): New.
	* include/debug/unordered_set
	(std::erase_if<>(__debug::unordered_set<>&, _Pred)): New.
	(std::erase_if<>(__debug::unordered_multiset<>&, _Pred)): New.
	* include/std/forward_list (std::erase_if<>(std::forward_list<>&, _Pred)):
	Adapt to work exclusively for normal implementation.
	(std::erase<>(std::forward_list<>&, const _Up&)): Likewise.
	* include/std/list (std::erase_if<>(std::list<>&, _Pred)): Likewise.
	(std::erase<>(std::list<>&, const _Up&)): Likewise.
	* include/std/map (std::erase_if<>(std::map<>&, _Pred)): Likewise.
	(std::erase_if<>(std::multimap<>&, _Pred)): Likewise.
	Guard functions using __cpp_lib_erase_if.
	* include/std/set (std::erase_if<>(std::set<>&, _Pred)): Likewise.
	(std::erase_if<>(std::multiset<>&, _Pred)): Likewise.
	Guard functions using __cpp_lib_erase_if.
	* include/std/unordered_map
	(std::erase_if<>(std::unordered_map<>&, _Pred)): Likewise.
	(std::erase_if<>(std::unordered_multimap<>&, _Pred)): Likewise.
	Guard functions using __cpp_lib_erase_if.
	* include/std/unordered_set
	(std::erase_if<>(std::unordered_set<>&, _Pred)): Likewise.
	(std::erase_if<>(std::unordered_multiset<>&, _Pred)): Likewise.
	Guard functions using __cpp_lib_erase_if.
	* testsuite/21_strings/basic_string/debug/erase.cc: New test case.
	* testsuite/23_containers/forward_list/debug/erase.cc: New test case.
	* testsuite/23_containers/forward_list/debug/invalidation/erase.cc: New test case.
	* testsuite/23_containers/list/debug/erase.cc: New test case.
	* testsuite/23_containers/list/debug/invalidation/erase.cc: New test case.
	* testsuite/23_containers/map/debug/erase_if.cc: New test case.
	* testsuite/23_containers/map/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/multimap/debug/erase_if.cc: New test case.
	* testsuite/23_containers/multimap/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/multiset/debug/erase_if.cc: New test case.
	* testsuite/23_containers/multiset/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/set/debug/erase_if.cc: New test case.
	* testsuite/23_containers/set/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_map/debug/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_map/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_multimap/debug/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_multimap/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_multiset/debug/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_multiset/debug/invalidation/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_set/debug/erase_if.cc: New test case.
	* testsuite/23_containers/unordered_set/debug/invalidation/erase_if.cc: New test case.
2026-01-19 06:36:11 +01:00
Marek Polacek
4b0e94b394 c++: C++26 Reflection [PR120775]
This patch implements C++26 Reflection as specified by P2996R13, which allows
users to perform magic.  This patch also implements related papers:
Annotations for Reflection (P3394R4),
Splicing a base class subobject (P3293R3),
define_static_{string,object,array} (P3491R3),
Function Parameter Reflection (P3096R12).
(I already implemented consteval blocks back in July.)
(We do not yet implement P3795.)

We also implemented some CWG issues that had been approved in Kona;
e.g., CWG 3101, 3109, 3111, 3115, 3117.

All metafunctions are implemented in this patch.

The feature needs to be enabled by -std=c++26 -freflection.

Some stats: the v1 patch was over 51,200 LOC which were written in ~335
commits.  It came with over 400 tests with 11,722 static_asserts.  We still
had about 50 TODOs and FIXMEs in the code.
v2 consists of about 56,000 LOC which were created in 440 commits.  We
now have 446 tests with 40 TODOs remaining.
v3 brought another 77 commits, mostly clean-ups and various bug fixes.

I'd like to thank:
Jakub Jelinek, whose efforts can only be described as heroic and who
never ceases to amaze me even after nearly 15 years of working together,
he implemented many difficult metafunctions, annotations, mangling,
converted our metafunction dispatch to using gperf, and so on and on;
Jonathan Wakely for his libstdc++ patch review and generous & impeccable
advice even at odd hours; Dan Katz for his work on the Reflection papers,
writing Reflection tests for clang++ (many of which I've stolen^Wused),
for his advice, bug reports, and generally cheering me on; Jason Merrill
for his guidance, patch review, and, in fact, encouraging me to take on
this project in the first place; Michael Levine, Valentyn Yukhymenko, and
Alex Yesmanchyk for their nice contributions to Reflection; and Tomasz
Kamiński for providing test cases, finding bugs, and answering my C++
questions.

	PR c++/120775
	PR c++/123081
	PR c++/122634

gcc/ChangeLog:

	* attribs.cc (attribute_value_equal): Return false if either attribute
	is ATTR_UNIQUE_VALUE_P.
	(merge_attributes): Handle lists with ATTR_UNIQUE_VALUE_P values.
	* doc/invoke.texi: Document -freflection.
	* dwarf2out.cc (is_base_type) <case default>: Check
	TREE_CODE >= LAST_AND_UNUSED_TREE_CODE instead of is_cxx_auto.
	(gen_type_die_with_usage): For TREE_CODE >= LAST_AND_UNUSED_TREE_CODE
	trees use use DW_TAG_unspecified_type.
	* tree-core.h (struct tree_base): Update a comment.
	* tree.h (ATTR_UNIQUE_VALUE_P): Define.
	(BINFO_BASE_ACCESSES): Update the comment.

gcc/c-family/ChangeLog:

	* c-attribs.cc (attribute_takes_identifier_p): Return false for C++
	annotations.  Handle "old parm name".
	* c-cppbuiltin.cc (c_cpp_builtins): Define __cpp_impl_reflection.
	* c.opt (freflection): New.

gcc/cp/ChangeLog:

	* Make-lang.in: Add cp/reflect.o.  Add a rule for cp/metafns.h.
	* config-lang.in: Add reflect.cc.
	* constexpr.cc (constexpr_global_ctx): Add consteval_block and
	metafns_called members.  Initialize them.
	(cxx_constexpr_quiet_p): New.
	(cxx_constexpr_manifestly_const_eval): New.
	(cxx_constexpr_caller): New.
	(cxx_constexpr_consteval_block): New.
	(enum value_cat): Move into cp-tree.h.
	(cxx_eval_constant_expression): Move the declaration into cp-tree.h.
	No longer static.  Handle REFLECT_EXPR.  Handle conversion of
	a reflection to the meta::info type.
	(cxx_eval_cxa_builtin_fn): Override current_function_decl.
	(cxx_eval_builtin_function_call): Handle __builtin_is_string_literal.
	(is_std_allocator): Also check __new_allocator.
	(is_std_allocator_allocate): No longer static.
	(cxa_allocate_and_throw_exception): New.
	(cxx_eval_call_expression): Handle metafunctions.  Maybe set
	metafns_called.
	(reduced_constant_expression_p): Handle REFLECT_EXPR.
	(cxx_eval_binary_expression): Use compare_reflections for comparing
	reflections.
	(find_immediate_fndecl): Don't walk REFLECT_EXPR_P.
	(cxx_eval_outermost_constant_expr): Set global_ctx.consteval_block.
	Detect consteval-only smuggling.
	(potential_constant_expression_1): Return true for REFLECT_EXPR
	and SPLICE_EXPR.
	* constraint.cc (diagnose_trait_expr): Add CPTK_IS_CONSTEVAL_ONLY case.
	* cp-gimplify.cc (immediate_escalating_function_p): No longer static.
	(promote_function_to_consteval): Likewise.
	(cp_gimplify_expr) <case CALL_EXPR>: Detect any surviving consteval-only
	expressions.
	<case CP_BUILT_IN_IS_STRING_LITERAL>: Handle.
	(wipe_consteval_only_r): New.
	(cp_fold_immediate_r): Detect invalid uses of consteval-only types.
	Clear consteval-only DECL_EXPRs.
	(cp_genericize_r): Wipe consteval-only vars from BIND_EXPR_VARS and
	BLOCK_VARS.
	* cp-objcp-common.cc (cp_common_init_ts): Mark META_TYPE, SPLICE_SCOPE,
	SPLICE_EXPR, and REFLECT_EXPR.
	* cp-trait.def (IS_CONSTEVAL_ONLY): New trait.
	* cp-tree.def (REFLECT_EXPR, META_TYPE, SPLICE_EXPR, SPLICE_SCOPE): New
	trees.
	* cp-tree.h (enum cp_tree_index): Add CPTI_ANNOTATION_IDENTIFIER,
	CPTI_STD_META, and CPTI_META_INFO_TYPE.
	(std_meta_node): Define.
	(meta_info_type_node): Define.
	(annotation_identifier): Define.
	(REFLECTION_TYPE_P): Define.
	(REFLECT_EXPR_P): Define.
	(REFLECT_EXPR_HANDLE): Define.
	(enum reflect_kind): New.
	(REFLECT_EXPR_KIND): Define.
	(SET_REFLECT_EXPR_KIND): Define.
	(SPLICE_EXPR_EXPRESSION_P): Define.
	(SET_SPLICE_EXPR_EXPRESSION_P): Define.
	(SPLICE_EXPR_MEMBER_ACCESS_P): Define.
	(SET_SPLICE_EXPR_MEMBER_ACCESS_P): Define.
	(SPLICE_EXPR_ADDRESS_P): Define.
	(SET_SPLICE_EXPR_ADDRESS_P): Define.
	(SPLICE_SCOPE_EXPR): Define.
	(SPLICE_SCOPE_TYPE_P): Define.
	(WILDCARD_TYPE_P): Include SPLICE_SCOPE.
	(COMPONENT_REF_SPLICE_P): Define.
	(SCALAR_TYPE_P): Include REFLECTION_TYPE_P.
	(ENUM_BEING_DEFINED_P): Define.
	(OLD_PARM_DECL_P): Define.
	(MULTIPLE_NAMES_PARM_P): Define.
	(cp_preserve_using_decl): Declare.
	(DEF_OPERATOR, DEF_ASSN_OPERATOR): Include META.
	(struct ovl_op_info_t): Add meta_name member.
	(enum cp_built_in_function): Add CP_BUILT_IN_IS_STRING_LITERAL.
	(build_stub_type): Declare.
	(current_function_decl_without_access_scope): Declare.
	(dependent_namespace_p): Declare.
	(convert_reflect_constant_arg): Declare.
	(finish_base_specifier): Adjust declaration.
	(parsing_lambda_declarator): Declare.
	(fold_builtin_is_string_literal): Declare.
	(annotation_p): Declare.
	(finish_class_member_access_expr): Adjust declaration.
	(immediate_escalating_function_p): Declare.
	(promote_function_to_consteval): Declare.
	(is_std_allocator_allocate): Declare.
	(cxa_allocate_and_throw_exception): Declare.
	(enum value_cat): Define.
	(cxx_eval_constant_expression): Declare.
	(cxx_constexpr_quiet_p): Declare.
	(cxx_constexpr_manifestly_const_eval): Declare.
	(cxx_constexpr_caller): Declare.
	(cxx_constexpr_consteval_block): Declare.
	(init_reflection): Declare.
	(metafunction_p): Declare.
	(direct_base_parent): Declare.
	(process_metafunction): Declare.
	(get_reflection): Declare.
	(get_null_reflection): Declare.
	(splice): Declare.
	(check_out_of_consteval_use): Declare.
	(consteval_only_p): Declare.
	(compare_reflections): Declare.
	(valid_splice_type_p): Declare.
	(valid_splice_scope_p): Declare.
	(check_splice_expr): Declare.
	(make_splice_scope): Declare.
	(dependent_splice_p): Declare.
	(reflection_mangle_prefix): Declare.
	(check_consteval_only_fn): Declare.
	* cvt.cc (convert_to_void): Call check_out_of_consteval_use.
	* cxx-pretty-print.cc (cxx_pretty_printer::unary_expression): New
	REFLECT_EXPR case.
	(cxx_pretty_printer::expression): Likewise.
	(cxx_pretty_printer::simple_type_specifier): New META_TYPE case.
	(cxx_pretty_printer::type_id): Likewise.
	* decl.cc (duplicate_decls): Merge parameter names for Reflection.
	Maybe set OLD_PARM_DECL_P.
	(initialize_predefined_identifiers): Add "annotation ".
	(cxx_init_decl_processing): Add __builtin_is_string_literal.  Call
	init_reflection.
	(maybe_commonize_var): Do nothing for consteval_only_p.
	(check_initializer): Default-initialize std::meta::info.
	(make_rtl_for_nonlocal_decl): For consteval_only_p vars, set
	DECL_EXTERNAL and return early.
	(cp_finish_decl): Call check_out_of_consteval_use.  Don't go
	creating a varpool node for consteval_only_p.
	(get_tuple_size): Check the instantiation instead of the type.
	(grokfndecl): Call check_consteval_only_fn.
	(xref_basetypes): Stitch annotations onto BINFO_BASE_ACCESSES.
	(finish_enum_value_list): Clear ENUM_BEING_DEFINED_P.
	* decl2.cc (is_late_template_attribute): Handle all annotations as
	late.
	(cp_check_const_attributes): Don't handle annotations here.
	(maybe_make_one_only): Do nothing for consteval_only_p.
	(mark_needed): Likewise.
	(min_vis_expr_r): Handle reflections.
	(prune_vars_needing_no_initialization): Skip consteval_only_p.
	(no_linkage_error): Return early for metafunctions.
	(c_parse_final_cleanups): Don't write out consteval_only_p vars.  Avoid
	complaining about metafunctions.
	* error.cc (dump_type): New cases for CONST_DECL, META_TYPE, and
	SPLICE_SCOPE.
	(dump_type_prefix): New cases for META_TYPE and SPLICE_SCOPE.
	(dump_type_suffix): Likewise.
	(dump_decl): Dump SPLICE_EXPR.
	(dump_expr): Dump REFLECT_EXPR and SPLICE_EXPR.
	* init.cc (build_zero_init_1): Build a null reflection value.
	(perform_member_init): Call check_out_of_consteval_use.
	* lex.cc (DEF_OPERATOR, OPERATOR_TRANSITION): Update defines.
	* mangle.cc (write_type): Mangle META_TYPE.
	(write_expression): Handle REFLECT_EXPR.
	(write_reflection): New.
	(write_template_arg_literal): New REFLECT_EXPR case.
	(write_template_arg): Handle REFLECT_EXPR.
	* method.cc (build_stub_type): No longer static.
	* module.cc (trees_out::type_node): Handle META_TYPE.
	(trees_in::tree_node): Likewise.
	* name-lookup.cc (name_lookup::adl_type): std::meta is an associated
	namespace of std::meta::info.
	(strip_using_decl): Don't strip when cp_preserve_using_decl.
	(handle_namespace_attrs): Handle annotations.
	(do_namespace_alias): Handle SPLICE_EXPR.
	(lookup_qualified_name): When cp_preserve_using_decl, don't do
	OVL_FUNCTION.
	(finish_using_directive): Detect annotations on using directive.
	* operators.def: Update for META_NAME.
	* parser.cc: New cp_preserve_using_decl global.
	(enum required_token): Add RT_CLOSE_SPLICE.
	(get_required_cpp_ttype): Return CPP_CLOSE_SPLICE for RT_CLOSE_SPLICE.
	(cp_parser_next_tokens_start_splice_type_spec_p): New.
	(cp_parser_next_tokens_can_start_splice_scope_spec_p): New.
	(cp_parser_splice_specifier): New.
	(cp_parser_splice_type_specifier): New.
	(cp_parser_splice_expression): New.
	(cp_parser_splice_scope_specifier): New.
	(cp_parser_splice_spec_is_nns_p): New.
	(cp_parser_nth_token_starts_splice_without_nns_p): New.
	(cp_parser_primary_expression): Handle CPP_OPEN_SPLICE.  Give an
	error for ^^ outside reflection.
	(cp_parser_unqualified_id): Allow r.~typename [:R:].
	(cp_parser_nested_name_specifier_opt): Cope with splice-scope-specifier.
	(cp_parser_qualifying_entity): Parse splice-scope-specifier.
	(cp_parser_postfix_expression): Deal with [: :] after a typename.
	(cp_parser_postfix_dot_deref_expression): Parse & handle splices
	in a class member access.  Pass splice_p to
	finish_class_member_access_expr.
	(cp_parser_reflection_name): New.
	(cp_parser_reflect_expression): New.
	(cp_parser_unary_expression): Parse reflect-expression.
	(cp_parser_declaration): Parse splice-scope-specifier.
	(cp_parser_decomposition_declaration): Detect annotations on structured
	bindings.
	(cp_parser_decltype_expr): Parse splice-expression.
	(cp_parser_template_id): New parsed_templ argument.  If it's nonnull,
	don't parse the template name.  Turn an assert into a condition.
	(cp_parser_type_specifier): Handle typename [: :].
	(cp_parser_simple_type_specifier): Parse splice-type-specifier.
	(cp_parser_enum_specifier): Set ENUM_BEING_DEFINED_P.
	(cp_parser_namespace_alias_definition): Parse splice-specifier.
	(cp_parser_using_directive): Likewise.
	(cp_parser_type_id_1): New bool * parameter to distinguish between
	types and type aliases.  Set it.
	(cp_parser_type_id): Adjust the call to cp_parser_type_id_1.
	(cp_parser_template_type_arg): Likewise.
	(cp_parser_trailing_type_id): Likewise.
	(cp_parser_base_specifier): Handle annotations.  Maybe give an error
	for splice-scope-specifier.  Parse splice-type-specifier.  Pass
	annotations to finish_base_specifier.
	(cp_parser_annotation): New.
	(cp_parser_std_attribute_list): Detect mixing annotations and attributes
	in the same list.
	(cp_parser_annotation_list): New.
	(cp_parser_std_attribute_spec): Parse annotations.
	(cp_parser_skip_balanced_tokens): Also handle CPP_OPEN_SPLICE
	and CPP_CLOSE_SPLICE.
	(cp_parser_type_requirement): Parse splice-type-specifier.
	(cp_parser_lookup_name): Also consider dependent namespaces.  Don't
	call check_accessibility_of_qualified_id for USING_DECLs.
	(cp_parser_required_error): Handle RT_CLOSE_SPLICE.
	* pt.cc (current_function_decl_without_access_scope): New.
	(verify_unstripped_args_1): REFLECT_EXPR_P is OK.
	(iterative_hash_template_arg): Handle REFLECT_EXPR.
	(convert_nontype_argument): Maybe give an error for REFLECTION_TYPE_P.
	(for_each_template_parm_r): Handle SPLICE_SCOPE.
	(instantiate_class_template): Handle annotations.
	(tsubst_pack_index): Make static.
	(tsubst_decl): Handle NAMESPACE_DECL.
	(tsubst_splice_scope): New.
	(tsubst_splice_expr): New.
	(tsubst): Don't return early for NAMESPACE_DECL.   New META_TYPE case.
	Handle a splice-specifier that expanded into a NAMESPACE_DECL.  Handle
	SPLICE_SCOPE, SPLICE_EXPR, and TEMPLATE_ID_EXPR.
	(tsubst_scope): Also accept NAMESPACE_DECL.
	(tsubst_qualified_id): Check dependent_namespace_p.
	(tsubst_lambda_expr): Set LAMBDA_EXPR_CONSTEVAL_BLOCK_P.
	(tsubst_expr): Allow dependent_splice_p in an assert.  Check
	COMPONENT_REF_SPLICE_P and pass it to finish_class_member_access_expr.
	<case NAMESPACE_DECL>: Remove.
	New REFLECT_EXPR and SPLICE_EXPR cases.
	(unify): Handle META_TYPE.
	(instantiate_body): Call check_consteval_only_fn.
	(tsubst_enum): Set ENUM_BEING_DEFINED_P.
	(dependent_type_p_r): A splice-scope-specifier is dependent.
	(dependent_namespace_p): New.
	(value_dependent_expression_p): Handle REFLECT_EXPR.  Also handle
	[meta.reflection.access.context]/8.
	(type_dependent_expression_p): REFLECT_EXPR_P is not type-dependent.
	(convert_reflect_constant_arg): New.
	* search.cc (check_final_overrider): Adjust for CWG 3117.
	* semantics.cc (finish_base_specifier): Handle annotations.
	(parsing_lambda_declarator): No longer static.
	(finish_id_expression_1): Check dependent_namespace_p.
	(fold_builtin_is_string_literal): New.
	(trait_expr_value): Handle CPTK_IS_CONSTEVAL_ONLY.
	(finish_trait_expr): Likewise.
	* tree.cc (handle_annotation_attribute): New.
	(builtin_valid_in_constant_expr_p): Return true for
	CP_BUILT_IN_IS_STRING_LITERAL.
	(cp_tree_equal): Handle comparing REFLECT_EXPRs.
	(internal_attributes): Add "annotation ".
	(annotation_p): New.
	* typeck.cc (finish_class_member_access_expr): New splice_p argument.
	Handle dependent splices.  Implement splicing a base class subobject.
	Handle class member access using a splice-expression.
	(cp_build_binary_op): Handle comparing std::meta::infos.
	(check_return_expr): Call check_out_of_consteval_use.
	* metafns.gperf: New file.
	* metafns.h: New file.
	* reflect.cc: New file.

libcc1/ChangeLog:

	* libcp1plugin.cc (start_class_def): Update the call to
	finish_base_specifier.

libcpp/ChangeLog:

	* charset.cc (_cpp_destroy_iconv): Destroy narrow_cset_desc and
	utf8_cset_desc.
	(cpp_translate_string): New.
	(cpp_valid_identifier): New.
	* include/cpplib.h: Add OPEN_SPLICE, CLOSE_SPLICE, and REFLECT_OP to
	TTYPE_TABLE.
	(cpp_translate_string): Declare.
	(cpp_valid_identifier): Declare.
	* internal.h (struct cpp_reader): Add reverse_narrow_cset_desc and
	reverse_utf8_cset_desc fields.
	* lex.cc (_cpp_lex_direct): Emit CPP_CLOSE_SPLICE, CPP_REFLECT_OP,
	and CPP_OPEN_SPLICE tokens.

libstdc++-v3/ChangeLog:

	* include/Makefile.am (std_headers): Add ${std_srcdir}/meta.
	* include/Makefile.in: Regenerate.
	* include/bits/iterator_concepts.h (std::ranges::__access::__begin): Add
	constexpr.
	* include/bits/version.def (reflection): New.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Include <meta> for C++26.
	* include/std/meta: New file.
	* include/std/type_traits (std::is_reflection): New trait.
	(std::is_fundamental): Include is_reflection for C++26 -freflection.
	(std::is_reflection_v): New variable template.
	(std::is_consteval_only): New trait.
	(std::is_consteval_only_v): New variable template.
	* src/c++23/std.cc.in: Add <meta> exports.
	* testsuite/20_util/variable_templates_for_traits.cc: Add -freflection as
	dg-additional-options for C++26.  Add std::is_reflection_v test in that case.
	* testsuite/20_util/is_consteval_only/requirements/explicit_instantiation.cc: New test.
	* testsuite/20_util/is_consteval_only/requirements/typedefs.cc: New test.
	* testsuite/20_util/is_consteval_only/value.cc: New test.
	* testsuite/20_util/is_reflection/requirements/explicit_instantiation.cc: New test.
	* testsuite/20_util/is_reflection/requirements/typedefs.cc: New test.
	* testsuite/20_util/is_reflection/value.cc: New test.

gcc/testsuite/ChangeLog:

	* g++.dg/DRs/dr2581-1.C: Add -freflection.
	* g++.dg/DRs/dr2581-2.C: Likewise.
	* g++.dg/reflect/access_context1.C: New test.
	* g++.dg/reflect/access_context2.C: New test.
	* g++.dg/reflect/access_context3.C: New test.
	* g++.dg/reflect/adl1.C: New test.
	* g++.dg/reflect/alignment_of1.C: New test.
	* g++.dg/reflect/alignment_of2.C: New test.
	* g++.dg/reflect/annotations1.C: New test.
	* g++.dg/reflect/annotations2.C: New test.
	* g++.dg/reflect/annotations3.C: New test.
	* g++.dg/reflect/annotations4.C: New test.
	* g++.dg/reflect/annotations5.C: New test.
	* g++.dg/reflect/annotations6.C: New test.
	* g++.dg/reflect/annotations7.C: New test.
	* g++.dg/reflect/annotations8.C: New test.
	* g++.dg/reflect/anon1.C: New test.
	* g++.dg/reflect/anon2.C: New test.
	* g++.dg/reflect/anon3.C: New test.
	* g++.dg/reflect/bases_of1.C: New test.
	* g++.dg/reflect/bases_of2.C: New test.
	* g++.dg/reflect/bases_of3.C: New test.
	* g++.dg/reflect/bit_size_of1.C: New test.
	* g++.dg/reflect/bitfield1.C: New test.
	* g++.dg/reflect/can_substitute1.C: New test.
	* g++.dg/reflect/class1.C: New test.
	* g++.dg/reflect/class2.C: New test.
	* g++.dg/reflect/common_reference1.C: New test.
	* g++.dg/reflect/common_type1.C: New test.
	* g++.dg/reflect/compare1.C: New test.
	* g++.dg/reflect/compare10.C: New test.
	* g++.dg/reflect/compare2.C: New test.
	* g++.dg/reflect/compare3.C: New test.
	* g++.dg/reflect/compare4.C: New test.
	* g++.dg/reflect/compare5.C: New test.
	* g++.dg/reflect/compare6.C: New test.
	* g++.dg/reflect/compare7.C: New test.
	* g++.dg/reflect/compare8.C: New test.
	* g++.dg/reflect/compare9.C: New test.
	* g++.dg/reflect/compat1.C: New test.
	* g++.dg/reflect/complete1.C: New test.
	* g++.dg/reflect/constant_of1.C: New test.
	* g++.dg/reflect/constant_of2.C: New test.
	* g++.dg/reflect/constant_of3.C: New test.
	* g++.dg/reflect/constant_of4.C: New test.
	* g++.dg/reflect/constant_of5.C: New test.
	* g++.dg/reflect/constant_of6.C: New test.
	* g++.dg/reflect/constant_of7.C: New test.
	* g++.dg/reflect/constant_of8.C: New test.
	* g++.dg/reflect/constant_of9.C: New test.
	* g++.dg/reflect/crash1.C: New test.
	* g++.dg/reflect/crash10.C: New test.
	* g++.dg/reflect/crash11.C: New test.
	* g++.dg/reflect/crash12.C: New test.
	* g++.dg/reflect/crash13.C: New test.
	* g++.dg/reflect/crash14.C: New test.
	* g++.dg/reflect/crash15.C: New test.
	* g++.dg/reflect/crash16.C: New test.
	* g++.dg/reflect/crash17.C: New test.
	* g++.dg/reflect/crash18.C: New test.
	* g++.dg/reflect/crash2.C: New test.
	* g++.dg/reflect/crash3.C: New test.
	* g++.dg/reflect/crash4.C: New test.
	* g++.dg/reflect/crash5.C: New test.
	* g++.dg/reflect/crash6.C: New test.
	* g++.dg/reflect/crash7.C: New test.
	* g++.dg/reflect/crash8.C: New test.
	* g++.dg/reflect/crash9.C: New test.
	* g++.dg/reflect/data_member_spec1.C: New test.
	* g++.dg/reflect/data_member_spec2.C: New test.
	* g++.dg/reflect/data_member_spec3.C: New test.
	* g++.dg/reflect/data_member_spec4.C: New test.
	* g++.dg/reflect/dealias1.C: New test.
	* g++.dg/reflect/dealias2.C: New test.
	* g++.dg/reflect/dealias3.C: New test.
	* g++.dg/reflect/define_aggregate1.C: New test.
	* g++.dg/reflect/define_aggregate2.C: New test.
	* g++.dg/reflect/define_aggregate3.C: New test.
	* g++.dg/reflect/define_aggregate4.C: New test.
	* g++.dg/reflect/define_aggregate5.C: New test.
	* g++.dg/reflect/define_static_array1.C: New test.
	* g++.dg/reflect/define_static_array2.C: New test.
	* g++.dg/reflect/define_static_array3.C: New test.
	* g++.dg/reflect/define_static_array4.C: New test.
	* g++.dg/reflect/define_static_object1.C: New test.
	* g++.dg/reflect/define_static_object2.C: New test.
	* g++.dg/reflect/define_static_string1.C: New test.
	* g++.dg/reflect/dep1.C: New test.
	* g++.dg/reflect/dep10.C: New test.
	* g++.dg/reflect/dep11.C: New test.
	* g++.dg/reflect/dep2.C: New test.
	* g++.dg/reflect/dep3.C: New test.
	* g++.dg/reflect/dep4.C: New test.
	* g++.dg/reflect/dep5.C: New test.
	* g++.dg/reflect/dep6.C: New test.
	* g++.dg/reflect/dep7.C: New test.
	* g++.dg/reflect/dep8.C: New test.
	* g++.dg/reflect/dep9.C: New test.
	* g++.dg/reflect/diag1.C: New test.
	* g++.dg/reflect/diag2.C: New test.
	* g++.dg/reflect/diag3.C: New test.
	* g++.dg/reflect/diag4.C: New test.
	* g++.dg/reflect/display_string_of1.C: New test.
	* g++.dg/reflect/eh1.C: New test.
	* g++.dg/reflect/eh2.C: New test.
	* g++.dg/reflect/eh3.C: New test.
	* g++.dg/reflect/eh4.C: New test.
	* g++.dg/reflect/eh5.C: New test.
	* g++.dg/reflect/eh6.C: New test.
	* g++.dg/reflect/eh7.C: New test.
	* g++.dg/reflect/eh8.C: New test.
	* g++.dg/reflect/eh9.C: New test.
	* g++.dg/reflect/enumerators_of1.C: New test.
	* g++.dg/reflect/error1.C: New test.
	* g++.dg/reflect/error10.C: New test.
	* g++.dg/reflect/error2.C: New test.
	* g++.dg/reflect/error3.C: New test.
	* g++.dg/reflect/error4.C: New test.
	* g++.dg/reflect/error5.C: New test.
	* g++.dg/reflect/error6.C: New test.
	* g++.dg/reflect/error8.C: New test.
	* g++.dg/reflect/error9.C: New test.
	* g++.dg/reflect/expr1.C: New test.
	* g++.dg/reflect/expr10.C: New test.
	* g++.dg/reflect/expr11.C: New test.
	* g++.dg/reflect/expr12.C: New test.
	* g++.dg/reflect/expr13.C: New test.
	* g++.dg/reflect/expr14.C: New test.
	* g++.dg/reflect/expr2.C: New test.
	* g++.dg/reflect/expr3.C: New test.
	* g++.dg/reflect/expr4.C: New test.
	* g++.dg/reflect/expr5.C: New test.
	* g++.dg/reflect/expr6.C: New test.
	* g++.dg/reflect/expr7.C: New test.
	* g++.dg/reflect/expr8.C: New test.
	* g++.dg/reflect/expr9.C: New test.
	* g++.dg/reflect/extract1.C: New test.
	* g++.dg/reflect/extract2.C: New test.
	* g++.dg/reflect/extract3.C: New test.
	* g++.dg/reflect/extract4.C: New test.
	* g++.dg/reflect/extract5.C: New test.
	* g++.dg/reflect/extract6.C: New test.
	* g++.dg/reflect/extract7.C: New test.
	* g++.dg/reflect/extract8.C: New test.
	* g++.dg/reflect/extract9.C: New test.
	* g++.dg/reflect/feat1.C: New test.
	* g++.dg/reflect/feat2.C: New test.
	* g++.dg/reflect/has_c_language_linkage1.C: New test.
	* g++.dg/reflect/has_default_argument1.C: New test.
	* g++.dg/reflect/has_default_argument2.C: New test.
	* g++.dg/reflect/has_default_member_initializer1.C: New test.
	* g++.dg/reflect/has_ellipsis_parameter1.C: New test.
	* g++.dg/reflect/has_external_linkage1.C: New test.
	* g++.dg/reflect/has_external_linkage2.C: New test.
	* g++.dg/reflect/has_identifier1.C: New test.
	* g++.dg/reflect/has_identifier2.C: New test.
	* g++.dg/reflect/has_internal_linkage1.C: New test.
	* g++.dg/reflect/has_internal_linkage2.C: New test.
	* g++.dg/reflect/has_linkage1.C: New test.
	* g++.dg/reflect/has_module_linkage1.C: New test.
	* g++.dg/reflect/has_module_linkage2.C: New test.
	* g++.dg/reflect/has_parent1.C: New test.
	* g++.dg/reflect/has_template_arguments1.C: New test.
	* g++.dg/reflect/has_template_arguments2.C: New test.
	* g++.dg/reflect/has_template_arguments3.C: New test.
	* g++.dg/reflect/has_template_arguments4.C: New test.
	* g++.dg/reflect/identifier_of1.C: New test.
	* g++.dg/reflect/identifier_of2.C: New test.
	* g++.dg/reflect/init1.C: New test.
	* g++.dg/reflect/init10.C: New test.
	* g++.dg/reflect/init11.C: New test.
	* g++.dg/reflect/init12.C: New test.
	* g++.dg/reflect/init13.C: New test.
	* g++.dg/reflect/init14.C: New test.
	* g++.dg/reflect/init15.C: New test.
	* g++.dg/reflect/init16.C: New test.
	* g++.dg/reflect/init17.C: New test.
	* g++.dg/reflect/init2.C: New test.
	* g++.dg/reflect/init3.C: New test.
	* g++.dg/reflect/init4.C: New test.
	* g++.dg/reflect/init5.C: New test.
	* g++.dg/reflect/init6.C: New test.
	* g++.dg/reflect/init7.C: New test.
	* g++.dg/reflect/init8.C: New test.
	* g++.dg/reflect/init9.C: New test.
	* g++.dg/reflect/is_accessible1.C: New test.
	* g++.dg/reflect/is_accessible2.C: New test.
	* g++.dg/reflect/is_alias_template1.C: New test.
	* g++.dg/reflect/is_assignment1.C: New test.
	* g++.dg/reflect/is_bit_field1.C: New test.
	* g++.dg/reflect/is_class_member1.C: New test.
	* g++.dg/reflect/is_class_template1.C: New test.
	* g++.dg/reflect/is_complete_type1.C: New test.
	* g++.dg/reflect/is_complete_type2.C: New test.
	* g++.dg/reflect/is_concept1.C: New test.
	* g++.dg/reflect/is_const1.C: New test.
	* g++.dg/reflect/is_consteval_only1.C: New test.
	* g++.dg/reflect/is_constructible_type1.C: New test.
	* g++.dg/reflect/is_constructible_type2.C: New test.
	* g++.dg/reflect/is_constructor_template1.C: New test.
	* g++.dg/reflect/is_constuctor1.C: New test.
	* g++.dg/reflect/is_conversion_function1.C: New test.
	* g++.dg/reflect/is_conversion_function_template1.C: New test.
	* g++.dg/reflect/is_copy_assignment1.C: New test.
	* g++.dg/reflect/is_copy_constructor1.C: New test.
	* g++.dg/reflect/is_data_member_spec1.C: New test.
	* g++.dg/reflect/is_default_constructor1.C: New test.
	* g++.dg/reflect/is_defaulted1.C: New test.
	* g++.dg/reflect/is_defaulted2.C: New test.
	* g++.dg/reflect/is_deleted1.C: New test.
	* g++.dg/reflect/is_deleted2.C: New test.
	* g++.dg/reflect/is_destructor1.C: New test.
	* g++.dg/reflect/is_enumerable_type1.C: New test.
	* g++.dg/reflect/is_enumerator1.C: New test.
	* g++.dg/reflect/is_explicit1.C: New test.
	* g++.dg/reflect/is_explicit2.C: New test.
	* g++.dg/reflect/is_explicit_object_parameter1.C: New test.
	* g++.dg/reflect/is_final1.C: New test.
	* g++.dg/reflect/is_function1.C: New test.
	* g++.dg/reflect/is_function2.C: New test.
	* g++.dg/reflect/is_function3.C: New test.
	* g++.dg/reflect/is_function_parameter1.C: New test.
	* g++.dg/reflect/is_function_parameter2.C: New test.
	* g++.dg/reflect/is_function_template1.C: New test.
	* g++.dg/reflect/is_function_template2.C: New test.
	* g++.dg/reflect/is_function_type1.C: New test.
	* g++.dg/reflect/is_literal_operator1.C: New test.
	* g++.dg/reflect/is_literal_operator_template1.C: New test.
	* g++.dg/reflect/is_lrvalue_reference_qualified1.C: New test.
	* g++.dg/reflect/is_move_assignment1.C: New test.
	* g++.dg/reflect/is_move_constructor1.C: New test.
	* g++.dg/reflect/is_mutable_member1.C: New test.
	* g++.dg/reflect/is_namespace1.C: New test.
	* g++.dg/reflect/is_namespace_alias1.C: New test.
	* g++.dg/reflect/is_namespace_member1.C: New test.
	* g++.dg/reflect/is_noexcept1.C: New test.
	* g++.dg/reflect/is_noexcept2.C: New test.
	* g++.dg/reflect/is_noexcept3.C: New test.
	* g++.dg/reflect/is_noexcept4.C: New test.
	* g++.dg/reflect/is_nonstatic_data_member1.C: New test.
	* g++.dg/reflect/is_object1.C: New test.
	* g++.dg/reflect/is_object2.C: New test.
	* g++.dg/reflect/is_operator_function1.C: New test.
	* g++.dg/reflect/is_operator_function_template1.C: New test.
	* g++.dg/reflect/is_override1.C: New test.
	* g++.dg/reflect/is_pure_virtual1.C: New test.
	* g++.dg/reflect/is_special_member_function1.C: New test.
	* g++.dg/reflect/is_static_member1.C: New test.
	* g++.dg/reflect/is_string_literal1.C: New test.
	* g++.dg/reflect/is_structured_binding1.C: New test.
	* g++.dg/reflect/is_structured_binding2.C: New test.
	* g++.dg/reflect/is_template1.C: New test.
	* g++.dg/reflect/is_template2.C: New test.
	* g++.dg/reflect/is_type1.C: New test.
	* g++.dg/reflect/is_type_alias1.C: New test.
	* g++.dg/reflect/is_type_alias2.C: New test.
	* g++.dg/reflect/is_type_alias3.C: New test.
	* g++.dg/reflect/is_user_declared1.C: New test.
	* g++.dg/reflect/is_user_declared2.C: New test.
	* g++.dg/reflect/is_user_provided1.C: New test.
	* g++.dg/reflect/is_user_provided2.C: New test.
	* g++.dg/reflect/is_variable1.C: New test.
	* g++.dg/reflect/is_variable_template1.C: New test.
	* g++.dg/reflect/is_virtual1.C: New test.
	* g++.dg/reflect/is_volatile1.C: New test.
	* g++.dg/reflect/lex1.C: New test.
	* g++.dg/reflect/lex2.C: New test.
	* g++.dg/reflect/mangle1.C: New test.
	* g++.dg/reflect/member-visibility1.C: New test.
	* g++.dg/reflect/member-visibility2.C: New test.
	* g++.dg/reflect/member1.C: New test.
	* g++.dg/reflect/member10.C: New test.
	* g++.dg/reflect/member11.C: New test.
	* g++.dg/reflect/member12.C: New test.
	* g++.dg/reflect/member13.C: New test.
	* g++.dg/reflect/member14.C: New test.
	* g++.dg/reflect/member15.C: New test.
	* g++.dg/reflect/member16.C: New test.
	* g++.dg/reflect/member17.C: New test.
	* g++.dg/reflect/member18.C: New test.
	* g++.dg/reflect/member19.C: New test.
	* g++.dg/reflect/member2.C: New test.
	* g++.dg/reflect/member20.C: New test.
	* g++.dg/reflect/member3.C: New test.
	* g++.dg/reflect/member4.C: New test.
	* g++.dg/reflect/member5.C: New test.
	* g++.dg/reflect/member6.C: New test.
	* g++.dg/reflect/member7.C: New test.
	* g++.dg/reflect/member8.C: New test.
	* g++.dg/reflect/member9.C: New test.
	* g++.dg/reflect/members_of1.C: New test.
	* g++.dg/reflect/members_of2.C: New test.
	* g++.dg/reflect/members_of3.C: New test.
	* g++.dg/reflect/members_of4.C: New test.
	* g++.dg/reflect/members_of5.C: New test.
	* g++.dg/reflect/members_of6.C: New test.
	* g++.dg/reflect/members_of7.C: New test.
	* g++.dg/reflect/metafn-ptr1.C: New test.
	* g++.dg/reflect/ns1.C: New test.
	* g++.dg/reflect/ns2.C: New test.
	* g++.dg/reflect/ns3.C: New test.
	* g++.dg/reflect/ns4.C: New test.
	* g++.dg/reflect/ns5.C: New test.
	* g++.dg/reflect/ns6.C: New test.
	* g++.dg/reflect/null1.C: New test.
	* g++.dg/reflect/null2.C: New test.
	* g++.dg/reflect/null3.C: New test.
	* g++.dg/reflect/null4.C: New test.
	* g++.dg/reflect/null5.C: New test.
	* g++.dg/reflect/object_of1.C: New test.
	* g++.dg/reflect/object_of2.C: New test.
	* g++.dg/reflect/odr1.C: New test.
	* g++.dg/reflect/offset_of1.C: New test.
	* g++.dg/reflect/operator_of1.C: New test.
	* g++.dg/reflect/override1.C: New test.
	* g++.dg/reflect/p2996-1.C: New test.
	* g++.dg/reflect/p2996-10.C: New test.
	* g++.dg/reflect/p2996-11.C: New test.
	* g++.dg/reflect/p2996-12.C: New test.
	* g++.dg/reflect/p2996-13.C: New test.
	* g++.dg/reflect/p2996-14.C: New test.
	* g++.dg/reflect/p2996-15.C: New test.
	* g++.dg/reflect/p2996-16.C: New test.
	* g++.dg/reflect/p2996-17.C: New test.
	* g++.dg/reflect/p2996-18.C: New test.
	* g++.dg/reflect/p2996-19.C: New test.
	* g++.dg/reflect/p2996-2.C: New test.
	* g++.dg/reflect/p2996-20.C: New test.
	* g++.dg/reflect/p2996-21.C: New test.
	* g++.dg/reflect/p2996-3.C: New test.
	* g++.dg/reflect/p2996-4.C: New test.
	* g++.dg/reflect/p2996-5.C: New test.
	* g++.dg/reflect/p2996-6.C: New test.
	* g++.dg/reflect/p2996-7.C: New test.
	* g++.dg/reflect/p2996-8.C: New test.
	* g++.dg/reflect/p2996-9.C: New test.
	* g++.dg/reflect/p3394-1.C: New test.
	* g++.dg/reflect/p3491-1.C: New test.
	* g++.dg/reflect/p3491-2.C: New test.
	* g++.dg/reflect/p3491-3.C: New test.
	* g++.dg/reflect/pack-index1.C: New test.
	* g++.dg/reflect/parameters_of1.C: New test.
	* g++.dg/reflect/parameters_of2.C: New test.
	* g++.dg/reflect/parameters_of3.C: New test.
	* g++.dg/reflect/parameters_of4.C: New test.
	* g++.dg/reflect/parameters_of5.C: New test.
	* g++.dg/reflect/parameters_of6.C: New test.
	* g++.dg/reflect/parent_of1.C: New test.
	* g++.dg/reflect/parm1.C: New test.
	* g++.dg/reflect/parm2.C: New test.
	* g++.dg/reflect/parm3.C: New test.
	* g++.dg/reflect/parm4.C: New test.
	* g++.dg/reflect/pr122634-1.C: New test.
	* g++.dg/reflect/pr122634-2.C: New test.
	* g++.dg/reflect/qrn1.C: New test.
	* g++.dg/reflect/qrn2.C: New test.
	* g++.dg/reflect/range_args.C: New test.
	* g++.dg/reflect/reflect_constant1.C: New test.
	* g++.dg/reflect/reflect_constant2.C: New test.
	* g++.dg/reflect/reflect_constant3.C: New test.
	* g++.dg/reflect/reflect_constant4.C: New test.
	* g++.dg/reflect/reflect_constant5.C: New test.
	* g++.dg/reflect/reflect_constant6.C: New test.
	* g++.dg/reflect/reflect_constant7.C: New test.
	* g++.dg/reflect/reflect_constant8.C: New test.
	* g++.dg/reflect/reflect_constant9.C: New test.
	* g++.dg/reflect/reflect_constant_array1.C: New test.
	* g++.dg/reflect/reflect_constant_array2.C: New test.
	* g++.dg/reflect/reflect_constant_array3.C: New test.
	* g++.dg/reflect/reflect_constant_array4.C: New test.
	* g++.dg/reflect/reflect_constant_string1.C: New test.
	* g++.dg/reflect/reflect_constant_string2.C: New test.
	* g++.dg/reflect/reflect_function1.C: New test.
	* g++.dg/reflect/reflect_function2.C: New test.
	* g++.dg/reflect/reflect_object1.C: New test.
	* g++.dg/reflect/reflect_object2.C: New test.
	* g++.dg/reflect/reflect_object3.C: New test.
	* g++.dg/reflect/reflect_object4.C: New test.
	* g++.dg/reflect/return_type_of1.C: New test.
	* g++.dg/reflect/return_type_of2.C: New test.
	* g++.dg/reflect/serialize1.C: New test.
	* g++.dg/reflect/serialize2.C: New test.
	* g++.dg/reflect/size_of1.C: New test.
	* g++.dg/reflect/source_location_of1.C: New test.
	* g++.dg/reflect/source_location_of2.C: New test.
	* g++.dg/reflect/splice1.C: New test.
	* g++.dg/reflect/splice2.C: New test.
	* g++.dg/reflect/splice3.C: New test.
	* g++.dg/reflect/splice4.C: New test.
	* g++.dg/reflect/splice5.C: New test.
	* g++.dg/reflect/splice6.C: New test.
	* g++.dg/reflect/splice7.C: New test.
	* g++.dg/reflect/splicing-base1.C: New test.
	* g++.dg/reflect/splicing-base2.C: New test.
	* g++.dg/reflect/splicing-base3.C: New test.
	* g++.dg/reflect/splicing-base4.C: New test.
	* g++.dg/reflect/storage_duration1.C: New test.
	* g++.dg/reflect/storage_duration2.C: New test.
	* g++.dg/reflect/storage_duration3.C: New test.
	* g++.dg/reflect/subobjects_of1.C: New test.
	* g++.dg/reflect/substitute1.C: New test.
	* g++.dg/reflect/substitute2.C: New test.
	* g++.dg/reflect/symbol_of1.C: New test.
	* g++.dg/reflect/symbol_of2.C: New test.
	* g++.dg/reflect/template_arguments_of1.C: New test.
	* g++.dg/reflect/template_arguments_of2.C: New test.
	* g++.dg/reflect/template_arguments_of3.C: New test.
	* g++.dg/reflect/template_of1.C: New test.
	* g++.dg/reflect/template_of2.C: New test.
	* g++.dg/reflect/template_of3.C: New test.
	* g++.dg/reflect/tuple1.C: New test.
	* g++.dg/reflect/tuple2.C: New test.
	* g++.dg/reflect/type1.C: New test.
	* g++.dg/reflect/type10.C: New test.
	* g++.dg/reflect/type2.C: New test.
	* g++.dg/reflect/type3.C: New test.
	* g++.dg/reflect/type4.C: New test.
	* g++.dg/reflect/type5.C: New test.
	* g++.dg/reflect/type6.C: New test.
	* g++.dg/reflect/type7.C: New test.
	* g++.dg/reflect/type8.C: New test.
	* g++.dg/reflect/type9.C: New test.
	* g++.dg/reflect/type_of1.C: New test.
	* g++.dg/reflect/type_of2.C: New test.
	* g++.dg/reflect/type_rels1.C: New test.
	* g++.dg/reflect/type_trait1.C: New test.
	* g++.dg/reflect/type_trait10.C: New test.
	* g++.dg/reflect/type_trait11.C: New test.
	* g++.dg/reflect/type_trait12.C: New test.
	* g++.dg/reflect/type_trait13.C: New test.
	* g++.dg/reflect/type_trait2.C: New test.
	* g++.dg/reflect/type_trait3.C: New test.
	* g++.dg/reflect/type_trait4.C: New test.
	* g++.dg/reflect/type_trait5.C: New test.
	* g++.dg/reflect/type_trait6.C: New test.
	* g++.dg/reflect/type_trait8.C: New test.
	* g++.dg/reflect/type_trait9.C: New test.
	* g++.dg/reflect/u8display_string_of1.C: New test.
	* g++.dg/reflect/u8identifier_of1.C: New test.
	* g++.dg/reflect/u8symbol_of1.C: New test.
	* g++.dg/reflect/underlying_type1.C: New test.
	* g++.dg/reflect/using1.C: New test.
	* g++.dg/reflect/value_or_object1.C: New test.
	* g++.dg/reflect/variable_of1.C: New test.
	* g++.dg/reflect/variable_of2.C: New test.
	* g++.dg/reflect/variable_of3.C: New test.
	* g++.dg/reflect/variant1.C: New test.
	* g++.dg/reflect/variant2.C: New test.
	* g++.dg/reflect/vector1.C: New test.
	* g++.dg/reflect/visibility1.C: New test.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Signed-off-by: Valentyn Yukhymenko <vyuhimenko@bloomberg.net>
Signed-off-by: Alex Yesmanchyk <ayesmanchyk@bloomberg.net>
Signed-off-by: Michael Levine <mlevine55@bloomberg.net>
Reviewed-by: Jason Merrill <jason@redhat.com>
2026-01-15 10:17:43 -05:00
Tomasz Kamiński
76ad28b112 libstdc++: Fix handling iterators with proxy subscript in heap algorithms.
This patch replaces uses of subscripts in heap algorithms, that where introduced
in r16-4100-gaaeca77a79a9a8 with dereference of advanced iterators.

The Cpp17RandomAccessIterator requirements, allows operator[] to return any
type that is convertible to reference, however user-provided comparators are
required only to accept result of dereferencing the iterator (i.e. reference
directly). This is visible, when comparator defines operator() for which
template arguments can be deduduced from reference (which will fail on proxy)
or that accepts types convertible from reference (see included tests).

For test we introduce a new proxy_random_access_iterator_wrapper iterator
in testsuite_iterators.h, that returns a proxy type from subscript operator.
This is separate type (instead of additional template argument and aliases),
as it used for test that work with C++98.

libstdc++-v3/ChangeLog:

	* include/bits/stl_heap.h (std::__is_heap_until, std::__push_heap)
	(std::__adjust_heap): Replace subscript with dereference of
	advanced iterator.
	* testsuite/util/testsuite_iterators.h (__gnu_test::subscript_proxy)
	(__gnu_test::proxy_random_access_iterator_wrapper): Define.
	* testsuite/25_algorithms/sort_heap/check_proxy_brackets.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-13 19:14:26 +01:00
Jonathan Wakely
59bc37debf libstdc++: Improve comments on __wait_args::_M_setup_proxy_wait
libstdc++-v3/ChangeLog:

	* include/bits/atomic_wait.h (__wait_args): Improve comments.
	* src/c++20/atomic.cc (__wait_args::_M_setup_proxy_wait):
	Improve comment.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-12 11:38:58 +00:00
Yuao Ma
2226b67bbe libstdc++: constexpr flat_map and flat_multimap
This patch makes flat_map and flat_multimap constexpr as part of P3372R3.

libstdc++-v3/ChangeLog:

	* include/bits/version.def: Add FTM.
	* include/bits/version.h: Regenerate.
	* include/std/flat_map: Add constexpr.
	* testsuite/23_containers/flat_map/1.cc: Add constexpr test.
	* testsuite/23_containers/flat_multimap/1.cc: Add constexpr test.
2026-01-10 15:08:53 +08:00
Jonathan Wakely
5f02ba9258 libstdc++: Fix proxy wait detection in atomic wait
A failed assertion was observed with std::atomic<bool>::wait when the
loop in __atomic_wait_address is entered and calls _M_setup_wait a
second time, after waking from __wait_impl. When the first call to
_M_setup_wait makes a call to _M_setup_proxy_wait that function decides
that a proxy wait is needed for an object of type bool, and it updates
the _M_obj and _M_obj_size members to refer to the futex in the proxy
state, instead of referring to the bool object itself. The next time
_M_setup_wait is called it calls _M_setup_proxy_wait again but now it
sees _M_obj_size == sizeof(futex) and so this time decides a proxy wait
is *not* needed, and then fails the __glibcxx_assert(_M_obj == addr)
check.

The problem is that _M_setup_proxy_wait wasn't correctly handling the
case where it's called a second time, after the decision to use a proxy
wait has already been made. That can be fixed in _M_setup_proxy_wait by
checking if _M_obj != addr, which implies that a proxy wait has already
been set up by a previous call. In that case, _M_setup_proxy_wait should
only update _M_old to the latest value of the proxy _M_ver.

This change means that _M_setup_proxy_wait is safe to call repeatedly
for a proxy wait, and will only update _M_wait_state, _M_obj, and
_M_obj_size on the first call. On the second and subsequent calls, those
variables are already correctly set for the proxy wait so don't need to
be set again.

For non-proxy waits, calling _M_setup_proxy_wait more than once is safe,
but pessimizes performance. The caller shouldn't make a second call to
_M_setup_proxy_wait because we don't need to check again if a proxy wait
should be used (the answer won't change) and we don't need to load a
value from the proxy _M_ver.

However, it was difficult to detect the case of a non-proxy wait,
because _M_setup_wait doesn't know if it's being called the first time
(when _M_setup_proxy_wait is called to make the initial decision) or a
subsequent time (in which case _M_obj == addr implies a non-proxy wait
was already decided on). As a result, _M_setup_proxy_wait was being used
every time to see if it's a proxy wait. We can resolve this by splitting
the _M_setup_wait function into _M_setup_wait and _M_on_wake, where the
former is only called once to do the initial setup and the latter is
called after __wait_impl returns, to prepare to check the predicate and
possibly wait again.  The new _M_on_wake function can avoid unnecessary
calls to _M_setup_proxy_wait by checking _M_obj == addr to identify a
non-proxy wait.

The three callers of _M_setup_wait are updated to use _M_on_wake instead
of _M_setup_wait after waking from a waiting function. This change
revealed a latent performance bug in __atomic_wait_address_for which was
not passing __res to _M_setup_wait, so a new value was always loaded
even when __res._M_has_val was true. By splitting _M_on_wake out of
_M_setup_wait this problem became more obvious, because we no longer
have _M_setup_wait doing two different jobs, depending on whether it was
passed the optional third argument or not.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_timed_wait.h (__atomic_wait_address_until):
	Use _M_on_wake instead of _M_setup_wait after waking.
	(__atomic_wait_address_for): Likewise.
	* include/bits/atomic_wait.h (__atomic_wait_address): Likewise.
	(__wait_args::_M_setup_wait): Remove third parameter and move
	code to update _M_old to ...
	(__wait_args::_M_on_wake): New member function to update _M_old
	after waking, only calling _M_setup_proxy_wait if needed.
	(__wait_args::_M_store): New member function to update _M_old
	from a value, for non-proxy waits.
	* src/c++20/atomic.cc (__wait_args::_M_setup_proxy_wait): If
	_M_obj is not addr, only load a new value and return true.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-09 19:18:21 +00:00
Jonathan Wakely
9eb863f152 libstdc++: Ensure counting_semaphore::try_acquire_for times out [PR122878]
As noted in Bug 122878 comment 2, the _M_try_acquire_for implementation
doesn't reduce the remaining timeout each time it returns from an atomic
waiting function. This means that it can wait longer than requested, or
even loop forever. If there is a spurious wake from the timed waiting
function (__wait_until_impl) it will return indicating no timeout
occurred, which means the caller will check the value and potentially
sleep again. If spurious wakes happen every time, it will just keep
sleeping in a loop forever. This is observed to actually happen on
FreeBSD 14.0-STABLE where pthread_cond_timedwait gets a spurious wake
and so never times out.

The solution in this commit is to replace the implementation of
_M_try_acquire_for with a call to _M_try_acquire_until, converting the
relative timeout to an absolute timeout against the steady clock. This
is what ends up happening anyway, because we only have a
__wait_until_impl entry point into the library internals, so
__atomic_wait_address_for already converts the relative timeout to an
absolute timeout (except for the special case of a zero-value duration,
which only checks for an update while spinning for a finite number of
iterations, and doesn't sleep).

As noted in comment 4 of the PR, this requires some changes to
_M_try_acquire which was relying on the behaviour of _M_try_acquire_for
for zero-value durations.  That behaviour is desirable for
_M_try_acquire so that it can handle short-lived contention without
failing immediately. To preserve that behaviour of _M_try_acquire it is
changed to do its own loop and to call __atomic_wait_address_for
directly with a zero duration, to do the spinloop.

libstdc++-v3/ChangeLog:

	PR libstdc++/122878
	* include/bits/semaphore_base.h (_M_try_acquire): Replace
	_M_try_acquire_for call with explicit loop and call to
	__atomic_wait_address_for.
	(_M_try_acquire_for): Replace loop with call to
	_M_try_acquire_until.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-09 19:18:21 +00:00
Jonathan Wakely
a6c853112d libstdc++: Remove redundant return statement after static_assert(false)
Jakub's fix for PR c++/91388 means that we don't need an unreachable
return statement after static_assert(false).

libstdc++-v3/ChangeLog:

	* include/bits/atomic_wait.h (__wait_args::_M_setup_wait):
	Remove unreachable return statement.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-07 15:21:49 +00:00
Jakub Jelinek
f8c32184b8 libstdc++: Use gnu_inline attribute on constexpr exception methods [PR123183]
As mentioned in
https://gcc.gnu.org/pipermail/gcc-patches/2026-January/704712.html
in the gnu::constexpr_only thread, gnu::gnu_inline attribute actually
seems to work for most of what we need for C++26 constexpr exceptions
(i.e. when we want out of line bodies for C++ < 26 and need to use
constexpr for C++26, yet don't want for reasons mentioned in those
two PRs the bodies of those constexpr methods to be emitted inline).
Unfortunately clang++ doesn't handle it 100% properly and requires
the redundant inline keyword to make it work (even when the methods
are constexpr and thus implicilty inline), g++ doesn't require that,
so the patch adds also the redundant inline keywords and not just
the [[__gnu__::__gnu_inline__]] attribute.
This way if something wants to inline those functions it can, but
if their address is taken, we just rely on libstdc++.{so,a} to provide
those (which it does as before because those TUs are compiled with
older -std= modes).
The earlier r16-6477-gd5743234731 commit made sure gnu::gnu_inline
constexpr virtual methods can be key methods, so vtables and rtti can
be emitted only in the TU defining non-gnu_inline versions of those.

2026-01-07  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/123183
	PR libstdc++/123326
	* libsupc++/exception (std::bad_exception::~bad_exception(),
	std::bad_exception::what()): Add inline keyword and
	[[__gnu__::__gnu_inline__]] attribute to the C++26 constexpr
	exceptions definitions.
	* libsupc++/exception.h (std::exception::~exception(),
	std::exception::what()): Likewise.
	* libsupc++/exception_ptr.h (std::exception_ptr::exception_ptr(void*)):
	Likewise.
	* libsupc++/nested_exception.h
	(std::nested_exception::~nested_exception()): Likewise.
	* libsupc++/typeinfo (std::bad_cast::~bad_cast(),
	std::bad_cast::what(), std::bad_typeid::~bad_typeid(),
	std::bad_typeid::what()): Likewise.
	* include/bits/new_except.h (std::bad_alloc::~bad_alloc(),
	std::bad_alloc::what(),
	std::bad_array_new_length::~bad_array_new_length(),
	std::bad_array_new_length::what()): Likewise.
	* include/bits/stdexcept_except.h
	(std::logic_error::logic_error(const string&),
	std::logic_error::logic_error(const char*),
	std::logic_error::~logic_error(), std::logic_error::what(),
	std::domain_error::domain_error(const string&),
	std::domain_error::domain_error(const char*),
	std::invalid_argument::invalid_argument(const string&),
	std::invalid_argument::invalid_argument(const char*),
	std::length_error::length_error(const string&),
	std::length_error::length_error(const char*),
	std::out_of_range::out_of_range(const string&),
	std::out_of_range::out_of_range(const char*),
	std::runtime_error::runtime_error(const string&),
	std::runtime_error::runtime_error(const char*),
	std::runtime_error::~runtime_error(), std::runtime_error::what(),
	std::overflow_error::overflow_error(const string&),
	std::overflow_error::overflow_error(const char*),
	std::overflow_error::~overflow_error(),
	std::underflow_error::underflow_error(const string&),
	std::underflow_error::underflow_error(const char*),
	std::underflow_error::~underflow_error()): Likewise.
	(std::domain_error::~domain_error(),
	std::invalid_argument::~invalid_argument(),
	std::length_error::~length_error(),
	std::out_of_range::~out_of_range()): Likewise.  Also change
	_GLIBCXX_NOTHROW to noexcept on those definitions.
2026-01-07 15:07:33 +01:00
Jakub Jelinek
254a858ae7 Update copyright years. 2026-01-02 09:56:11 +01:00
Tomasz Kamiński
72430fff7b libstdc++: Use smallest possible integer for __generate_cannonical_any
If the span of the range R produced by uniform bit generator U passed to
generate_canonical is not power of two, we need to use algorithm that
requires computing power R^k that is greater than 2^d, where d is number
of digits in mantissa of _RealT. Previously we have used an integer type
that is has twice as many digits as d. This lead to situation that for
standard engines that produced such range (like std::minstd_rand0,
std::minstd_rand, std::ranlux24, ....) 256bit integer support was
required for 128bit floats. However, in this cases R^4 provides more
than d bits of precision, while requiring 124 bits.

We overestimate the number of required bits, by computing a value
l * bit_width(R) (log2(R) + 1), where l is value such that log2(R) * l >= d.
As R >= 2^log2(R), then R^l >= (2^log2(R))^l == 2^(log(R) * l) >= 2^d,
so k+1 >= l >= k. In consequence R^k is smaller R^l which require at most
l * bit_width(R). This is an overestimate, but difference should not be
higher than l bits.

We replace __gen_can_pow and __gen_can_rng_calls_needed with
__gen_canon_log(v, b), which computes the largest power of b that fits into v.
As such a number is smaller than v, the result will always fit in it's type.
Both the logarithm and the power value are returned using
__gen_canon_log_res struct.

libstdc++-v3/ChangeLog:

	* include/bits/random.h (__rand_uint128::operator>)
	(__rand_uint128::operator>=): Define.
	* include/bits/random.tcc (__generate_canonical_pow2):
	Adjust for use of __rand_uint128 in C++11.
	(__gen_can_pow, __gen_can_rng_calls_needed): Replace with
	__gen_canon_log.
	(__gen_canon_log_res, __gen_canon_log): Define.
	(__generate_canonical_any): Reworked how _UInt is determined.
	* testsuite/26_numerics/random/uniform_real_distribution/operators/gencanon_eng.cc:
	New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-19 15:44:44 +01:00
Jonathan Wakely
18c306b1f4 libstdc++: Fix chrono::parse to read from wide strings [PR123147]
When we extract wide characters and insert them into a stringstream to
be parsed as a floating-point value, we should use a stringstream of
char, not wchar_t.

libstdc++-v3/ChangeLog:

	PR libstdc++/123147
	* include/bits/chrono_io.h (_Parser::operator()) <%S>: Use a
	buffer of narrow characters to be parsed by std::from_chars.
	* testsuite/std/time/parse/parse.cc: Check wchar_t parsing.
2025-12-19 14:00:07 +00:00
Jonathan Wakely
0b22234b87 libstdc++: Fix some warnings seen during mingw-w64 bootstrap
libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_write): Add
	maybe_unused attribute to avoid -Wunused-parameter warning.
	* src/c++20/tzdb.cc (detect_windows_zone): Decay array to
	pointer to avoid -Warray-compare warning.
2025-12-18 23:40:43 +00:00
Jonathan Wakely
630c1bfbb5 libstdc++: Fix ranges::stable_sort handling of null buffer [PR123180]
The logic of the null pointer check got reversed when converting the
std::stable_sort code for ranges::stable_sort.

libstdc++-v3/ChangeLog:

	PR libstdc++/123180
	* include/bits/ranges_algo.h (__stable_sort_fn::operator()): Fix
	sense of null check. Replace typedef with alias-declaration.
	* testsuite/25_algorithms/stable_sort/123180.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-12-18 13:47:25 +00:00
Jonathan Wakely
9614fe95eb libstdc++: Fix up std::generate_canonical for 32-bit arches
Make use of __detail::_Select_uint_least_t<d>::type for
std::generate_canonical, so that we choose an appropriately sized
integer based on the number of bits needed, and so we have a 128-bit
integer type even on 32-bit targets (via the new __rand_uint128 class).

libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (__generate_canonical_pow2): Adjust
	comments. Remove _UInt template parameter and define it in the
	body using _Select_uint_least_t<__d>. Remove popcount call for
	getting the width of the _UInt type. Cast floating-point
	literal to _RealT.
	(__generate_canonical_any): Remove _UInt template parameter and
	define it in the body using _Select_uint_least_t<__d * 2>. Use
	direct-initialization for _UInt variables. Cast floating-point
	literal to _RealT.
	(generate_canonical): Remove unused typedef. Remove constexpr-if
	branches and remove unsigned type from template argument lists.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Reviewed-by: Nathan Myers <nmyers@redhat.com>
2025-12-18 10:44:36 +00:00
Jonathan Wakely
278eb0a081 libstdc++: Make __cpp_lib_constexpr_exceptions depend on cxx11 ABI
The COW std::string is not constexpr, so the <stdexcept> exception
classes can't be constexpr either when they're defined in terms of the
COW string.

While constexpr exceptions for <typeinfo>, <new>, and <exception>
classes would work, __cpp_constexpr_exceptions >= 202411L implies that
everything including <stdexcept> should work. So when we can't support
it fully, we shouldn't announce it.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (constexpr_exceptions): Add
	cxx11abi=yes.
	* include/bits/version.h: Regenerate.
	* testsuite/18_support/exception/version.cc: Require effectiove
	target cxx11_abi.
	* testsuite/18_support/exception_ptr/exception_ptr_cast.cc: Only
	check for constexpr support in cxx11 ABI.
	* testsuite/19_diagnostics/headers/stdexcept/version.cc: Require
	effective target cxx11_abi.
	* testsuite/19_diagnostics/logic_error/constexpr.cc: Likewise.
	* testsuite/19_diagnostics/runtime_error/constexpr.cc: Likewise.
	* testsuite/20_util/expected/version.cc: Only check for
	__cpp_lib_constexpr_exceptions macro for cxx11 ABI.
	* testsuite/20_util/optional/version.cc: Likewise.
	* testsuite/20_util/variant/version.cc: Likewise.

Reviewed-by: Jakub Jelinek <jakub@redhat.com>
2025-12-17 21:28:57 +00:00
Jonathan Wakely
12084561db libstdc++: Implement std::philox_engine for targets without __int128
This moves the __detail::_Select_uint_least_t<N>::type class to
namespace scope and extends it with more 128-bit arithmetic operations,
implemented in terms of uint64_t.

Now std::philox_engine can use _Select_uint_least_t<w*2>::type instead
of __uint128_t, so that it works on targets without 128-bit integers.
This also means that targets that do support __uint128_t only use it
when actually necessary, so that we use uint64_t when generating a
32-bit result (e.g. with std::philox4x32).

libstdc++-v3/ChangeLog:

	* include/bits/random.h [!__SIZEOF_INT128__] (__rand_uint128):
	Refactor and rename _Select_uint_least_t<128>::type to a new
	class. Make all members constexpr. Add new member functions for
	additional arithmetic and bitwise operations, and comparisons.
	(__detail::_Select_uint_least_t<>::type): Define as an alias of
	__rand_uint128.
	* include/bits/random.tcc (philox_engine::_M_mulhi): Use
	_Select_uint_least_t<w*2>::type instead of __uint128_t.
	(philox_engine::_M_transition): Likewise.
	* include/bits/version.def (philox_engine): Remove extra_cond.
	* include/bits/version.h: Regenerate.
	* testsuite/26_numerics/random/philox4x32.cc: Remove
	dg-require-cpp-feature-test directive.
	* testsuite/26_numerics/random/philox4x64.cc: Likewise.
	* testsuite/26_numerics/random/philox_engine/cons/copy.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/cons/default.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/cons/seed.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/operators/equal.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/operators/serialize.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/requirements/constants.cc:
	Likewise.
	* testsuite/26_numerics/random/philox_engine/requirements/typedefs.cc:
	Likewise.

Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-17 20:41:31 +00:00
Jonathan Wakely
8372629e97 libstdc++: Move new std::generate_canonical to inline namespace
This ensures that the new definition of std::generate_canonical has a
different mangled name from the old one, so that TUs compiled with GCC
16 will be sure to use the new definition, even if the linker also sees
a symbol instantiated from the old definition. We use the same _V2
inline namespace as used elsewhere (std::_V2::condition_variable,
std::_V2::__rotate, and std::chrono::_V2::system_clock), and use a macro
to add it conditionally so that it's not used for the ABI-unstable
gnu-versioned-namespace configuration.

We can simplify the 26_numerics/random/pr60037-neg.cc test to only use
one dg-error without a line number, so that it matches any of the three
relevant static_assert failures for this test: the one from _Adaptor in
<bits/random.h> and the ones from the new and old definitions of
std::generate_canonical in <bits/random.tcc>. Without this change, the
line number for the dg-error matching the <bits/random.tcc> error
depends on the _GLIBCXX_USE_OLD_GENERATE_CANONICAL macro, which is
awkward to depend on in the test (because DejaGnu sees all dg-error
directives, it doesn't care if they're guarded by #ifdef preprocessor
checks).

libstdc++-v3/ChangeLog:

	* include/bits/random.h [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL]
	(generate_canonical): Use inline namespace _V2.
	* include/bits/random.tcc [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL]
	(generate_canonical): Likewise.
	* testsuite/26_numerics/random/pr60037-neg.cc: Remove lineno so
	that one dg-error matches both diagnostics.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-17 13:24:01 +00:00
Jonathan Wakely
cf8dea631d libstdc++: Restore braces around body of if-statement
libstdc++-v3/ChangeLog:

	* include/bits/random.tcc [_GLIBCXX_USE_OLD_GENERATE_CANONICAL]
	(generate_canonical): Restore braces around statement.
2025-12-17 13:23:17 +00:00
Tomasz Kamiński
837c21e1aa libstdc++: Make declaration and definition of generate_canonical consistent.
The r16-6177-g866bc8a9214b1d introduced type-constraint on _Urbg template
parameter in __glibcxx_concepts, with was inconsistent with declaration in
bits/random.h and definition in bits/random.tcc causing the missing symbol
errors in tests.

Furthermore, this made the mangled name of generate_canonical in C++20
mode different from older standard and previous versions of GCC.

libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (generate_canonical)
	[!_GLIBCXX_USE_OLD_GENERATE_CANONICAL]: Use static_assert
	instead of type-constraint on template parameter.
	* testsuite/26_numerics/random/pr60037-neg.cc: Updated line
	of error.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-17 11:01:15 +01:00
Tomasz Kamiński
9fcb592224 libstdc++: Fixed failing dg-error in random/pr60037-neg.cc tests.
libstdc++-v3/ChangeLog:

	* include/bits/random.tcc (generate_canonical): Update
	error message to match pre-existing one in random.h.
	* testsuite/26_numerics/random/pr60037-neg.cc: Updated
	line for error message.
2025-12-17 10:42:24 +01:00
Jakub Jelinek
932d24f0c7 libstdc++: Fix up all_pedantic_errors.cc
On x86_64-linux I see
On x86_64-linux
FAIL: 17_intro/headers/c++1998/all_pedantic_errors.cc  -std=gnu++17 (test for excess errors)
Excess errors:
/home/jakub/src/gcc/obj20/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/random.tcc:3681: error: ISO C++ does not support '__int128' for 'type name' [-Wpedantic]
/home/jakub/src/gcc/obj20/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/random.tcc:3698: error: ISO C++ does not support '__int128' for 'type name' [-Wpedantic]
This fixes it by adding __extension__.

2025-12-17  Jakub Jelinek  <jakub@redhat.com>

	* include/bits/random.tcc (std::generate_canonical): Use
	__extension__ before __generate_canonical_{pow2,any} calls with
	unsigned __int128 template arguments.
2025-12-17 09:49:03 +01:00
Tomasz Kamiński
b2fb18e470 libstdc++: Provide conversion between atomic_ref of similar types.
This patch implements the P3860R1 (accepted as DR against C++20) and LWG4472.

The two constraints on the constructor (that T and U are similar types and
is_convertible_v<U*, T*>) are combined into a single check:
is_convertible_v<_Up(*)[1], _Tp(*)[1]>. While this check is not equivalent
for array of known bound to array of unknown bound conversions (T[N] to T[]),
this is irrelevant for atomic_ref, since instantiation with an array type is
ill-formed (due to the return type of load and other members).

The __atomic_ref_base constructor is modified to accept _Tp* instead of _Tp&.
This allows both the atomic_ref(atomic_ref<_Up> __other) and atomic_ref(_Tp& __t)
constructors to delegate to it. Furthermore, such approach does not require
dereferencing *__other._M_ptr, and thus avoid ADL-lookup for operator* and
issues related to it. The precondition check on alignment is moved specifically
to the atomic_ref(_Tp&) constructor, preventing redundant checks during atomic_ref
conversion.

A deleted atomic_ref(_Tp&&) constructor is introduced (per LWG4472).
This prevents the construction of atomic_ref<T> from atomic_ref<volatile T>
via the conversion operator.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h
	(__atomic_ref_base<const _Tp>::__atomic_ref_base): Accept
	pointer instead of reference. Remove precondition check and
	mark as noexcept.
	(__atomic_ref_base<_Tp>::__atomic_ref_base): Accept pointer
	insted of reference, and mark as noexcept.
	* include/std/atomic (atomic_ref::atomic_ref(_Tp&)): Add
	precondition check and take address of argument.
	(atomic_ref::atomic_ref(_Tp&&)): Define as deleted.
	(atomic_ref::atomic_ref(atomic_ref<_Up>)): Define.
	* include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count):
	Pass address to __atomic_ref constructor.
	* include/std/barrier (__tree_barrier_base::_M_arrive)
	(__tree_barrier::arrive): Pass address to __atomic_ref constructor.
	* testsuite/29_atomics/atomic_ref/ctor.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-17 06:28:07 +01:00
Jonathan Wakely
7a5ad55596 libstdc++: Do not optimize std::copy to memcpy for bool output [PR122907]
Copying narrow characters to a range of bool using std::copy cannot be
optimized to use std::memcpy. Assignment of an arbitrary integer to a
bool needs to convert all non-zero values to true, so is not a simple
memcpy-like or bit_cast-like operation. We currently get this wrong and
optimize it to memcpy, producing invalid bool values.

By making __memcpyable_integer<bool> false we disable memcpy
optimizations for heterogeneous std::copy and std::move calls where
either the source or destination type is bool. Copies where both types
are bool can still optimize to memcpy, because we don't check
__memcpyable_integer in that case.

This disables the memcpy optimization for bool as the source type,
which isn't actually necessary (the representation of bool in GCC is
0x00 or 0x01 and so copying bool to char is just a bit_cast). We don't
currently have a straightforward way to allow memcpy for bool to char
but disallow the inverse. This seems acceptable as using std::copy with
bool inputs and narrow character outputs is probably not common enough
for this to be an important optimization to do in the library code.

libstdc++-v3/ChangeLog:

	PR libstdc++/122907
	* include/bits/cpp_type_traits.h (__memcpyable_integer<bool>):
	Define as false.
	* testsuite/25_algorithms/copy/122907.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-12-16 22:19:09 +00:00
Nathan Myers
866bc8a921 libstdc++: New generate_canonical impl (P0952, LWG2524) [PR119739]
Implement P0952R2 "A new specification for
std::generate_canonical", fixing issue LWG 2524.

It has us start over, using new entropy, if the naïve generation
of a value in [0..1) comes up equal to 1.0, which occurs too
rarely for the change to measurably affect performance, but
does affect the number of calls to the underlying random bit
generator.

The old implementation is preserved, guarded by preprocessor
macro _GLIBCXX_USE_OLD_GENERATE_CANONICAL, for use where behavior
exactly matching previous runs is required.

The fix is extended to all of C++11 to 26. The public function
dispatches to variations optimized for requested bit depth `d`,
using minimal integer sizes for exact intermediate calculations.
It is faster than the old implementation, which computed a
floating-point logarithm, and performs all intermediate
calculations on integer types. It does not allow the IEEE half-
precision type `float16_t`, as its range is not large enough to
represent intermediate integer values specified, but does allow
`bfloat16_t`.

This implementation varies from the Standard in retaining in the
output mantissa as much as possible of the entropy obtained from
the provided random bit generator, not just the leading `d` bits
of randomness as specified, and in permitting use on floating
point types beyond float, double, and long double. The macro
_GLIBCXX_GENERATE_CANONICAL_STRICT may be defined to obtain the
exact Standard behavior.

This patch also adds tests for statistical properties, and adds
new static asserts on template argument requirements where
supported.  It adds tests using non-optimal RNGs that yield
values 0..999999 and 0..0x7ffffffe.

A test for the case addressed in LWG 2524 already appeared in
64351.cc.  This change amounts to a different resolution for
bugzilla PR64351 and LWG 2524.

libstdc++-v3/ChangeLog:
	PR libstdc++/119739
	* include/bits/random.tcc: Add generate_canonical impl for C++26.
	* testsuite/26_numerics/random/uniform_real_distribution/operators/64351.cc:
	Adapt test for both pre- and post- C++26.
	* testsuite/26_numerics/random/uniform_real_distribution/operators/gencanon.cc:
	Test for float and double from 32-bit RNG, including 1.0 do-over.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-16 14:11:48 -05:00
Patrick Palka
1d29b68562 libstdc++: Implement P2408R5 C++20 iterators as inputs to STL algos
From the paper's abstract:

  Change the iterator requirements for non-Ranges algorithms. For
  forward iterators and above that are constant iterators, instead of
  requiring that iterators meet certain Cpp17...Iterator requirements,
  require that the iterators model certain iterator concepts. This makes
  iterators from several standard views usable with non-Ranges
  algorithms that require forward iterators or above, such as the
  parallel overloads of most algorithms.

This patch narrowly implements P2408R5 in C++23 mode and C++20 mode
(as an extension).  "Narrowly" because just as in the paper, we don't
attempt to relax the requirements of mutable iterators even though it's
possible in theory.  Note that the PSTL algorithm requirements have
already been relaxed in r15-3650.  And we don't bother touching the
deprecated parallel mode algorithms under ./include/parallel.

The main workhorse of this paper is a new helper
__iterator_concept_or_category that replaces eligible uses of
__iterator_category and iterator_traits::iterator_category.  This new
helper considers both the iterator_concept and iterator_category of the
given iterator and returns the former if it's at least as strong as the
latter.  It's implemented in terms of the __promotable_iterator concept
added in r16-2588 that made std::advance etc aware of C++20 iterators.
Note that this helper doesn't check the actual C++20 iterator concepts
(which check syntactic requirements along with iterator_concept if it's
defined) and instead just checks for, and fully trusts, the
iterator_concept defined by the iterator type.  This is a slight
deviation from the paper but IMHO it's consistent with the existing
trusting of iterator_category and should be good enough in practice,
though it means C++20 iterators that don't define iterator_concept will
not be recognized as such by this helper even if they otherwise model
the std::foo_iterator concept.  (An undefined iterator_concept
effectively defaults to random_access_iterator_tag.)

Most of the changes made here are effectively optimizations that don't
have a semantic impact, e.g. for std::reduce.  I added tests for a
couple of algorithms where these changes are observable.

The new __iterator_concept_or_category helper can probably also be used
to fix PR100070 "Standard library container iterator-pair constructors
should check C++20 iterator concepts".

As a follow-up to this patch we should either remove the Boost-style
concept checks, or relax them accordingly.  It seems we're leaning
towards removing them outright; see this thread:
https://gcc.gnu.org/pipermail/libstdc++/2025-May/061568.html

As suggested by Tomasz, this patch also introduces a _GLIBCXX_ITER_MOVE
wrapper around ranges::iter_move that also converts to the iterator's
value type (and is usable before C++20 as well).

	PR libstdc++/113299

libstdc++-v3/ChangeLog:

	* include/bits/deque.tcc (__copy_move_a1): Constrain with
	__is_any_random_access_iter instead of __is_random_access_iter.
	(__copy_move_backward_a1): Likewise.
	(__equal_aux1): Likewise.
	* include/bits/stl_algo.h (__search_n): Use
	__iter_concept_or_category instead of __iterator_category
	or iterator_traits::iterator_category.
	(find_end): Likewise.
	(__is_permutation): Likewise.
	(for_each_n): Likewise.
	(unique_copy): Likewise, for constant iterators.
	(sample): Likewise, for constant iterators.
	* include/bits/stl_algobase.h (__copy_move_a1): Adjust
	deque-based forward declaration accordingly.
	(__copy_move_backward_a1): Likewise.
	(__equal_aux1): Likewise.
	(__lexicographical_compare_impl): Use
	__iter_concept_or_category instead of __iterator_category or
	iterator_traits::iterator_category.
	(__equal4): Likewise.
	* include/bits/stl_iterator_base_funcs.h
	(__iter_concept_or_category): New.
	(__is_any_random_access_iter): New.
	(_GLIBCXX_ITER_MOVE): New.
	* include/bits/stl_uninitialized.h (uninitialized_copy_n):
	Use __iterator_concept_or_category instead of
	__iterator_category for the constant iterator __first.
	(__uninitialized_copy_n_pair): Likewise.
	* include/bits/version.def (algorithm_iterator_requirements):
	Define.
	* include/bits/version.h: Regenerate.
	* include/std/algorithm: Provide the FTM
	__cpp_lib_algorithm_iterator_requirements.
	* include/std/memory: Likewise.
	* include/std/numeric: Likewise.  Include
	<bits/stl_iterator_base_funcs.h>.
	(reduce): Use __is_any_random_access_iter instead of
	__is_random_access_iter.
	(transform_reduce): Likewise.
	(inclusive_scan): Use _GLIBCXX_ITER_MOVE instead of std::move.
	* testsuite/25_algorithms/find_end/c++20_iter.cc: New test.
	* testsuite/25_algorithms/sample/c++20_iter.cc: New test.
	* testsuite/25_algorithms/search_n/c++20_iter.cc: New test.
	* testsuite/25_algorithms/unique_copy/c++20_iter.cc: New test.
	* testsuite/26_numerics/inclusive_scan/c++20_iter.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-16 11:22:58 -05:00
Jakub Jelinek
62c126db6b libstdc++: Implement C++26 P3378R2 - constexpr exception types
The following patch attempts to implement the C++26 P3378R2 - constexpr
exception types paper.

This is quite complicated, because most of these classes which should
be constexpr-ized use solely or mostly out of line definitions in
libstdc++, both for historical, code size and dual ABI reasons, so that
one can throw these as exceptions between TUs with old vs. new (or vice
versa) ABIs.
For this reason, logic_error/runtime_error and classes derived from it
have the old ABI std::string object inside of them and the exported
APIs from libstdc++.so.6 ensure the right thing.

Now, because new invoked during constant evaluation needs to be deleted
during the same constant evaluation and can't leak into the constant
expressions, I think we don't have to use COW strings under the hood
(which aren't constexpr I guess because of reference counting/COW) and
we can use something else, the patch uses heap allocated std::string
object (where __cow_constexpr_string class has just a pointer to that).
As I think we still want to hide the ugly details if !consteval in the
library, the patch exports 8 __cow_string class symbols (6 existing which
were previously just not exported and 2 new ones) and if !consteval
calls those through extern "C" _Zmangled_name symbols.  The functions
are always_inline.

And then logic_error etc. have for C++26 (precisely for
__cpp_lib_constexpr_exceptions >= 202502L) constexpr definitions of
cdtors/methods.  This results in slightly larger code (a few insns at most)
at runtime for C++26, e.g. instead of calling say some logic error
cdtor/method with 2 arguments it calls some __cow_string one with 2
arguments but + 8 bytes pointer additions on both.

The patch also removes the __throw_format_error forward declaration
which apparently wasn't needed for anything as all __throw_format_error
users were either in <format> or included <format> before the uses,
reverts the
https://gcc.gnu.org/pipermail/libstdc++/2025-July/062598.html
patch and makes sure __throw_* functions (only those for exception types
which the P3378R2 or P3068R5 papers made constexpr usable and there are
actually constexpr/consteval uses of those) are constexpr for C++26
constexpr exceptions.

The patch does that by splitting the bits/functexcept.h header:
1) bits/functexcept.h stays for the __throw_* functions which are (at
least for now) never constexpr (the <ios>, <system_error>, <future>
and <functional> std::exception derived classes) or are never used
or never used in constexpr/consteval contexts (<exception>, <typeinfo>
std::exception derived classes and std::range_error).
2) bits/new_{throw,except}.h for __throw_bad_alloc/__throw_bad_array_new_length
and std::bad_alloc/std::bad_array_new_length (where <new> includes
<bits/new_except.h> and <bits/new_throw.h> as well for the C++26 constexpr
exceptions case)
3) for the most complicated <stdexcept> stuff, one header
addition to bits/stdexcept.h one header for the __throw_logic_error etc.
forward declarations, one header for the __throw_logic_error etc.
definitions and one header without header guards which will
depending on __glibcxx_exc_in_string include one or the other because
<string> vs. <string_view> vs. <stdexcept> have heavy interdependencies

2025-12-11  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/121114
libstdc++-v3/
	* include/bits/version.def: Implement C++26 P3378R2 - constexpr
	exception types.
	(constexpr_exceptions): Change value from 1 to 202502, remove
	no_stdname and TODO comments.
	* include/bits/version.h: Regenerate.
	* src/c++11/cow-stdexcept.cc (__cow_string(const char*)): New
	ctor.
	(__cow_string::c_str()): New method.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.35): Export 8 __cow_string
	symbols.
	* include/bits/new_except.h: New file.
	* include/bits/new_throw.h: New file.
	* include/bits/stdexcept_throw.h: New file.
	* include/bits/stdexcept_throwdef.h: New file.
	* include/bits/stdexcept_throwfwd.h: New file.
	* include/std/stdexcept: Include bits/stdexcept_except.h and move
	everything after <string> include except for std::range_error into
	include/bits/stdexcept_except.h.
	(std::range_error): If __cpp_lib_constexpr_exceptions >= 202502L
	make all cdtors and methods constexpr.
	* include/bits/stdexcept_except.h: New file.
	* include/std/optional (__glibcxx_want_constexpr_exceptions): Define
	before including bits/version.h.
	(bad_optional_access::what): Make constexpr for
	__cpp_lib_constexpr_exceptions >= 202502L.
	(__throw_bad_optional_access): Likewise.
	* include/std/expected (__glibcxx_want_constexpr_exceptions): Define
	before including bits/version.h.
	(bad_expected_access): Make cdtors and all methods constexpr for
	__cpp_lib_constexpr_exceptions >= 202502L.
	* include/std/format (__glibcxx_want_constexpr_exceptions): Define
	before including bits/version.h.
	(_GLIBCXX_CONSTEXPR_FORMAT_ERROR): Define and undef later.
	(format_error): Use _GLIBCXX_CONSTEXPR_FORMAT_ERROR on ctors.
	* include/std/variant (__glibcxx_want_constexpr_exceptions): Define
	before including bits/version.h.
	(_GLIBCXX_CONSTEXPR_BAD_VARIANT_ACCESS): Define and undef later.
	(bad_variant_access): Use it on ctors and what() method.
	(__throw_bad_variant_access): Use it here too.
	* testsuite/18_support/exception/version.cc: Adjust expected
	__cpp_lib_constexpr_exceptions value.
	* testsuite/19_diagnostics/runtime_error/constexpr.cc: New test.
	* testsuite/19_diagnostics/headers/stdexcept/version.cc: New test.
	* testsuite/19_diagnostics/logic_error/constexpr.cc: New test.
	* testsuite/20_util/expected/observers.cc (test_value_throw): Change
	return type to bool from void, return true at the end, add test
	to dereference what() first character.  Make it constexpr for
	__cpp_lib_constexpr_exceptions >= 202502L and add static_assert.
	* testsuite/20_util/expected/version.cc: Add tests for
	__cpp_lib_constexpr_exceptions value.
	* testsuite/20_util/variant/constexpr.cc: For
	__cpp_lib_constexpr_exceptions >= 202502L include <string>.
	(test_get): New function if __cpp_lib_constexpr_exceptions >= 202502L,
	assert calling it is true.
	* testsuite/20_util/variant/version.cc: Add tests for
	__cpp_lib_constexpr_exceptions value.
	* testsuite/20_util/optional/constexpr/observers/3.cc: Include
	testsuite_hooks.h.
	(eat, test01): New functions.  Assert test01() is true.
	* testsuite/20_util/optional/version.cc: Add tests for
	__cpp_lib_constexpr_exceptions value.
	* include/std/future: Add #include <bits/functexcept.h>.
	* include/std/shared_mutex: Include <bits/new_throw.h>.
	* include/std/flat_map: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/std/syncstream: Remove <bits/functexcept.h> include.
	* include/std/flat_set: Likewise.
	* include/std/bitset: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/std/string_view: Don't include <bits/functexcept.h>, include
	<bits/stdexcept_throw.h> early if __glibcxx_exc_in_string is not
	defined and include <bits/stdexcept_throw.h> at the end of
	the header again if __glibcxx_exc_in_string is 2 and C++26 constexpr
	exceptions are enabled.
	(__glibcxx_exc_in_string): Define if __glibcxx_exc_in_string wasn't
	defined before including <bits/stdexcept_throw.h>.
	* include/std/array: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/std/inplace_vector: Likewise.
	* include/std/string: Include <bits/stdexcept_except.h> and
	<bits/stdexcept_throw.h> after bits/basic_string.tcc include if
	C++26 constexpr exceptions are enabled and include
	<bits/stdexcept_throw.h> instead of <bits/functexcept.h> early.
	(__glibcxx_exc_in_string): Define early to 1, undefine at the end.
	* include/std/deque: Include <bits/stdexcept_throw.h>.
	* include/bits/new_allocator.h: Include <bits/new_throw.h> instead
	of <bits/functexcept.h>.
	* include/bits/stl_algobase.h: Remove <bits/functexcept.h> include.
	* include/bits/stl_vector.h: Include <bits/stdexcept_throw.h> instead
	of <bits/functexcept.h>.
	* include/bits/memory_resource.h: Include <bits/new_throw.h> instead
	of <bits/functexcept.h>.
	* include/bits/functexcept.h: Guard everything after includes with
	#if _GLIBCXX_HOSTED.
	(__throw_bad_alloc, __throw_bad_array_new_length,  __throw_logic_error,
	__throw_domain_error, __throw_invalid_argument, __throw_length_error,
	__throw_out_of_range, __throw_out_of_range_fmt, __throw_runtime_error,
	__throw_overflow_error, __throw_underflow_error): Move declarations to
	other headers - <bits/new_throw.h> and <bits/stdexcept_throwfwd.h>.
	* include/bits/stl_map.h: Include <bits/stdexcept_throw.h> instead
	of <bits/functexcept.h>.
	* include/bits/hashtable_policy.h: Include <bits/stdexcept_throw.h>
	instead of <bits/functexcept.h>.
	* include/bits/formatfwd.h (std::__throw_format_error): Remove
	declaration.
	* include/bits/specfun.h: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/bits/basic_ios.h: Include <bits/functexcept.h>.
	* include/bits/locale_classes.h: Likewise.
	* include/tr1/cmath: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/tr1/memory: Remove <bits/functexcept.h> include.
	* include/tr1/array: Include <bits/stdexcept_throw.h>.
	* include/ext/vstring_util.h: Include <bits/stdexcept_throw.h> instead
	of <bits/functexcept.h>.
	* include/ext/bitmap_allocator.h: Include <bits/new_throw.h> instead
	of <bits/functexcept.h>.
	* include/ext/mt_allocator.h: Likewise.
	* include/ext/malloc_allocator.h: Likewise.
	* include/ext/debug_allocator.h: Include <bits/stdexcept_throw.h>
	instead of <bits/functexcept.h>.
	* include/ext/concurrence.h: Include <bits/exception_defines.h>
	instead of <bits/functexcept.h>.
	* include/ext/throw_allocator.h: Include <bits/new_throw.h> and
	<bits/stdexcept_throw.h> instead of <bits/functexcept.h>.
	* include/ext/string_conversions.h: Include <bits/stdexcept_throw.h>
	instead of <bits/functexcept.h>.
	* include/ext/pool_allocator.h: Include <bits/new_throw.h> instead
	of <bits/functexcept.h>.
	* include/ext/ropeimpl.h: Include <bits/stdexcept_throw.h> instead of
	<bits/functexcept.h>.
	* include/tr2/dynamic_bitset: Likewise.
	* include/experimental/optional: Include <bits/exception_defines.h>
	instead of <bits/functexcept.h>.
	* include/Makefile.am (bits_freestanding): Add
	${bits_srcdir}/{new,stdexcept}_{except,throw}.h
	and ${bits_srcdir}/stdexcept_throw{fwd,def}.h.
	* include/Makefile.in: Regenerate.
	* src/c++17/floating_from_chars.cc: Remove <bits/functexcept.h>
	include.
	* src/c++11/regex.cc: Likewise.
	* src/c++11/functexcept.cc: Likewise.
	* src/c++11/snprintf_lite.cc: Include <bits/stdexcept_throw.h> instead
	of <bits/functexcept.h>.
	* src/c++11/thread.cc: Include <bits/functexcept.h>.
	* testsuite/util/testsuite_hooks.h: Include <bits/stdexcept_throw.h>
	instead of <bits/functexcept.h>.
	* testsuite/util/io/verified_cmd_line_input.cc: Include
	<bits/exception_defines.h> instead of <bits/functexcept.h>.
	* testsuite/20_util/allocator/105975.cc: Expect different diagnostics
	for C++26.
	* testsuite/23_containers/inplace_vector/access/capacity.cc: Remove
	#error, guard if consteval { return; } with
	#ifndef __cpp_lib_constexpr_exceptions.
	* testsuite/23_containers/inplace_vector/access/elem.cc: Likewise.
	* testsuite/23_containers/inplace_vector/cons/1.cc: Likewise.
	* testsuite/23_containers/inplace_vector/cons/from_range.cc: Likewise.
	* testsuite/23_containers/inplace_vector/modifiers/single_insert.cc:
	Likewise.
	* testsuite/23_containers/inplace_vector/modifiers/assign.cc:
	Likewise.
	* testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc:
	Likewise.
	* libsupc++/new: Include <bits/new_except.h>.
	(std::bad_alloc, std::bad_array_new_length): Move defintion to
	<bits/new_except.h>.
libgomp/
	* omp.h.in: Include <bits/new_throw.h> instead of
	<bits/functexcept.h>.
gcc/testsuite/
	* g++.dg/tree-ssa/pr110819.C: Guard scan-tree-dump-not delete on
	c++23_down and add comment explaining why C++26 fails that.
	* g++.dg/tree-ssa/pr96945.C: Likewise.
	* g++.dg/tree-ssa/pr109442.C: Likewise.
	* g++.dg/tree-ssa/pr116868.C: Likewise.
	* g++.dg/tree-ssa/pr58483.C: Likewise.
2025-12-11 19:54:44 +01:00
Yuao Ma
bf9dd44a97 libstdc++: constexpr flat_set and flat_multiset
This patch makes flat_set and flat_multiset constexpr as part of P3372R3.

libstdc++-v3/ChangeLog:

	* include/bits/version.def: Add FTM.
	* include/bits/version.h: Regenerate.
	* include/std/flat_set: Add constexpr.
	* testsuite/23_containers/flat_multiset/1.cc: Add constexpr test.
	* testsuite/23_containers/flat_set/1.cc: Add constexpr test.
2025-12-11 22:24:42 +08:00
Jonathan Wakely
1dd44ebd5f libstdc++: Regenerate <bits/version.h>
Some pre-r16-4328-g71e95e871d62e4 comments sneaked back in with some
recent commits.

libstdc++-v3/ChangeLog:

	* include/bits/version.h: Regenerate.
2025-12-09 21:06:27 +00:00
Luc Grosheintz
e2026d74f6 libstdc++: Set __cpp_lib_submdspan to 202411.
The submdspan feature is complete and this commit sets the feature
testing macros accordingly. Also makes the feature testing macro
submdspan depend on constant_wrapper.

Also changes the value of the internal feature testing macro for padded
layouts to 202403.

libstdc++-v3/ChangeLog:

	* include/bits/version.def (padded_layouts): Set to 202403.
	(submdspan): Set to 202411 add dependency.
	* include/bits/version.h: Regenerate.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-12-09 17:38:56 +01:00
Jonathan Wakely
03562c1e02 libstdc++: Implement P2404R3 relaxations to comparable_with concepts [PR122946]
This implements the C++23 proposal P2404R3 "Move-only types for
equality_comparable_with, totally_ordered_with, and
three_way_comparable_with". As agreed with the maintainers of libc++ and
MSVC STL, we treat this as a DR for C++20. It allows reasonable code to
compile which wasn't originally allowed in C++20, and only affects some
obscure subsumption cases for valid C++20 code.

libstdc++-v3/ChangeLog:

	PR libstdc++/122946
	* include/bits/version.def (concepts): Set value to 202207.
	* include/bits/version.h: Regenerate.
	* include/std/concepts (__comparison_common_type_with_impl)
	(__comparison_common_type_with): New helper concepts.
	(equality_comparable_with): Use __comparison_common_type_with.
	* libsupc++/compare (three_way_comparable_with): Likewise.
	(__glibcxx_want_concepts): Define to get __cpp_lib_concepts
	here.
	* testsuite/std/concepts/concepts.compare/move_only.cc: New
	test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-08 18:55:02 +00:00
Jonathan Wakely
ea42e28cbc libstdc++: Extend __is_standard_integer to cover extended integer types
We have __is_signed_integer and __is_unsigned_integer traits which
should have been updated by r16-2190-g4faa42ac0dee2c when making
__int128 an extended integer type (for PR libstdc++/96710). Currently
they check whether the type is a signed integer type or an unsigned
integer type, or a cv-qualified version of one of those. This doesn't
match the standard's definition, which does not include cv-qualified
types. This change ensures that signed __int128 and unsigned __int128
are included in those traits in strict -std modes, and it removes the
use of remove_cv_t so that they are not true for cv-qualified types.
This makes the traits match the meaning of "signed integer type" and
"unsigned integer type" in the standard ([basic.fundamental]).

We also have an __is_standard_integer trait, which is true if either
__is_signed_integer or __is_unsigned_integer is true, but that's also
not a match for the definition in the standard. The definitions of
"signed integer type" and "unsigned integer type" include both standard
and extended integer types, so only saying "standard" in the trait name
is misleading (even before this change, because in non-strict -std modes
the __GLIBCXX_TYPE_INT_N_0 .. __GLIBCXX_TYPE_INT_N_3 types were always
included in the trait, and they aren't standard integer types).

This change renames __is_standard_integer to the more accurate
__is_signed_or_unsigned_integer. Because the set of signed and
unsigned integer types is the same as the set of standard and extended
integer types, the trait could instead have been renamed to
__is_standard_or_extended_integer. I think it's clearer and more
self-explanatory to avoid "standard and extended" and name it for the
signed and unsigned integer types.

N.B. we don't want to call it just __is_integer_type because the integer
types includes cv-qualified types and also bool and the character types
char, wchar_t, char16_t etc.

The consequences of redefining and renaming these traits are small, and
only positive.

Apart from the uses in the __is_standard_integer trait, the only other
uses of __is_signed_integer and __is_unsigned_integer are in <format>
and those uses are unaffected by this change to add 128-bit integers to
the traits. In both uses the type argument is already cv-unqualified,
and there is already explicit handling for 128-bit integers where that
is required.

The existing uses of __is_standard_integer can simply be changed to use
the new name. This does change the behaviour of those uses of the trait,
because the __is_signed_or_unsigned_integer trait now includes
128-bit integers in strict modes. However, that is a desirable change
that fixes some bugs. Specifically, the [utility.intcmp] functions such
as std::cmp_less and the [numeric.sat.arith] functions such as
std::add_sat did not support 128-bit integers in strict modes. Since the
standard says they should be enabled for all signed and unsigned integer
types (or equivalently, for all standard and extended integer types),
those functions should all support __int128 and unsigned __int128. That
is fixed by this change.  Additionally, the same changes in <charconv>,
<mdspan>, and <stdckdint.h> enable the use of 128-bit integers for those
APIs in strict modes.

Finally, this also make a drive-by fix to the enable_if constraints for
the integer overloads of std::from_chars. That used remove_cv_t and so
enabled the overload for lvalue arguments of type const char, which
won't work and should not be enabled.

libstdc++-v3/ChangeLog:

	* include/bits/intcmp.h: Replace all uses of
	__is_standard_integer with __is_signed_or_unsigned_integer.
	* include/bits/max_size_type.h: Fix outdated comment.
	* include/bits/sat_arith.h: Replace all uses of
	__is_standard_integer with __is_signed_or_unsigned_integer.
	* include/c_compatibility/stdckdint.h: Replace all uses of the
	__cv_unqual_signed_or_unsigned_integer_type concept with
	__is_signed_or_unsigned_integer.
	(__cv_unqual_signed_or_unsigned_integer_type): Remove.
	* include/ext/numeric_traits.h: Fix outdated comment.
	* include/std/charconv (from_chars): Replace use of
	__is_standard_integer with __is_signed_or_unsigned_integer.
	Do not enable for cv-qualified char.
	* include/std/mdspan: Likewise.
	* include/std/type_traits (__is_unsigned_integer): Include
	unsigned __int128 in type list.
	(__is_signed_integer): Include signed __int128 in type list.
	(__is_standard_integer): Rename to ...
	(__is_signed_or_unsigned_integer): ... this.
	* testsuite/23_containers/mdspan/extents/ctor_ints.cc: Test
	with 128-bit integers.
	* testsuite/23_containers/mdspan/submdspan/strided_slice.cc:
	Likewise.
	* testsuite/20_util/integer_comparisons/extended.cc: New test.
	* testsuite/26_numerics/saturation/extended.cc: New test.
	* testsuite/26_numerics/stdckdint/extended.cc: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-12-08 18:55:02 +00:00
Jonathan Wakely
c7136f5b37 libstdc++: Remove redundant diagnostic pragmas from <bits/iterator_concepts.h>
Since r16-2190-g4faa42ac0dee2c this header no longer mentions __int128
explicitly, because it's just handled like other integer types now. So
we don't need the diagnostic pragmas to disables pedwarns for referring
to __int128.

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h: Remove diagnostic pragmas.
2025-12-08 09:21:42 +00:00
Jonathan Wakely
5d8455b072 libstdc++: Move std::cmp_equal, std::cmp_less etc. to new file
This allows the [utility.intcmp] functions to be used without including
all of <utility>.

libstdc++-v3/ChangeLog:

	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/std/latch: Include <bits/intcmp.h> instead of
	<utility>.
	* include/std/utility: Include <bits/intcmp.h>.
	(cmp_equal, cmp_not_equal, cmp_less, cmp_greater)
	(cmp_less_equal, cmp_greater_equal, in_range): Move to ...
	* include/bits/intcmp.h: New file.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-08 09:15:50 +00:00
Jonathan Wakely
7a2d141876 libstdc++: std::atomic should use std::addressof
libstdc++-v3/ChangeLog:

	* include/bits/atomic_wait.h (__detail::__atomic_eq): Use
	std::addressof instead of &.
	* include/std/atomic (atomic::wait, atomic::notify_one)
	(atomic::notify_all): Likewise.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
2025-12-06 00:28:43 +00:00
Patrick Palka
d1ac432c5a libstdc++: Implement rest of P2655R3 common_reference of reference_wrapper
PR libstdc++/120446

libstdc++-v3/ChangeLog:

	* include/bits/refwrap.h (__detail::__is_ref_wrapper):
	Define as per P2655R3 for C++20.
	(__detail::__ref_wrap_common_reference_exists_with): Likewise.
	(basic_common_reference): Define partial specializations using
	the above as per P2655R3 for C++20.
	* include/bits/version.def (common_reference_wrapper): New.
	* include/bits/version.h: Regenerate.
	* include/std/functional (__glibcxx_want_common_reference_wrapper):
	Define.
	* testsuite/20_util/reference_wrapper/p2655r3.cc: New test.

Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-05 13:43:40 -05:00
Patrick Palka
a9fd651fbb libstdc++: Implement P2655R3 changes to common_reference bullet 1
We implement this paper as a DR against C++20 (as do MSVC and libc++).

	PR libstdc++/120446

libstdc++-v3/ChangeLog:

	* include/bits/version.def (common_reference): New.
	* include/bits/version.h: Regenerate.
	* include/std/type_traits (__glibcxx_want_common_reference):
	Define.
	(__common_reference_impl<T1, T2, 1>): Add pointer convertibility
	constraints as per P2655R3.
	* testsuite/20_util/common_reference/p2655r3.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-05 13:43:29 -05:00
Patrick Palka
b212314667 libstdc++: Use deducing this in std::bind_front even in C++20 [PR111327]
PR libstdc++/111327

libstdc++-v3/ChangeLog:

	* include/bits/binders.h (_Binder::operator())
	[_GLIBCXX_EXPLICIT_THIS_PARAMETER]: Also use deducing this in
	C++20 mode when possible.
	* testsuite/20_util/function_objects/bind_front/111327.cc:
	Expect error inside header even in C++20 mode.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-05 12:15:08 -05:00
Patrick Palka
101f968476 libstdc++: Introduce _GLIBCXX_EXPLICIT_THIS_PARAMETER internal FTM
This FTM is like __cpp_explicit_this_parameter but is also defined
in earlier C++ modes if deducing this is supported as an extension
by the compiler.  Currently only GCC supports this, Clang doesn't.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_EXPLICIT_THIS_PARAMETER):
	New.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-05 12:14:18 -05:00
Yuao Ma
6123cb8bfc libstdc++: implement P3044R2 - sub-string_view from string (string part)
libstdc++-v3/ChangeLog:

	* include/bits/basic_string.h: Add subview.
	* include/bits/cow_string.h: Add subview.
	* include/std/string: Add FTM.
	* testsuite/21_strings/basic_string/operations/subview/char.cc: New test.
	* testsuite/21_strings/basic_string/operations/subview/wchar_t.cc: New test.
2025-12-03 23:56:32 +08:00
Yuao Ma
475933164f libstdc++: implement P3044R2 - sub-string_view from string (string_view part)
libstdc++-v3/ChangeLog:

	* include/bits/version.def: Add string_subview FTM.
	* include/bits/version.h: Regenerate.
	* include/std/string_view: Add subview.
	* testsuite/21_strings/basic_string_view/operations/subview/char.cc: New test.
	* testsuite/21_strings/basic_string_view/operations/subview/wchar_t.cc: New test.
2025-12-03 23:55:06 +08:00
Jonathan Wakely
b4d61f1d83 libstdc++: Use chrono::nanoseconds for __wait_until_impl parameter
Use the chrono::nanoseconds typedef instead of the equivalent
__wait_clock_t::duration typedef, and add a comment explaining why we
use a duration not a time_point.

libstdc++-v3/ChangeLog:

	* include/bits/atomic_timed_wait.h (__wait_until_impl): Use
	chrono::nanoseconds for parameter.
	* src/c++20/atomic.cc (__wait_until_impl): Likewise.
2025-12-01 12:58:16 +00:00
Patrick Palka
2d3142c009 libstdc++: Correctly implement LWG 3946 changes to const_iterator_t [PR122842]
LWG 3946 made const_iterator_t/sentinel_t agree with ranges::cbegin/cend
by defining the aliases in terms of the CPOs, but I defined it the other
way around in an incorrect way that made the aliases not consider
range-ness of const T via __possibly_const_range.  This patch
reimplements the proposed resolution in a more obviously correct way,
mirroring the wording.

	PR libstdc++/122842

libstdc++-v3/ChangeLog:

	* include/bits/ranges_base.h (__access:_CBegin): Define in
	terms of const_iterator directly, not const_iterator_t.
	(__access::_CEnd): Likewise in terms of const_sentinel vs
	const_sentinel_t.
	(const_iterator_t): Move down definition and define in terms
	of ranges::cbegin as per LWG 3946.
	(const_sentinel_t): Likewise in terms of ranges::cend.
	* testsuite/24_iterators/const_iterator/1.cc (test02): Correct
	test for int[], std::array and std::vector.  Also test
	std::string.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-11-28 15:38:04 -05:00
Jonathan Wakely
d07b9e7fe4 libstdc++: Future-proof C++20 atomic wait/notify
This will allow us to extend atomic waiting functions to support a
possible future 64-bit version of futex, as well as supporting
futex-like wait/wake primitives on other targets (e.g. macOS has
os_sync_wait_on_address and FreeBSD has _umtx_op).

Before this change, the decision of whether to do a proxy wait or to
wait on the atomic variable itself was made in the header at
compile-time, which makes it an ABI property that would not have been
possible to change later.  That would have meant that
std::atomic<uint64_t> would always have to do a proxy wait even if Linux
gains support for 64-bit futex2(2) calls at some point in the future.
The disadvantage of proxy waits is that several distinct atomic objects
can share the same proxy state, leading to contention between threads
even when they are not waiting on the same atomic object, similar to
false sharing. It also result in spurious wake-ups because doing a
notify on an atomic object that uses a proxy wait will wake all waiters
sharing the proxy.

For types that are known to definitely not need a proxy wait (e.g. int
on Linux) the header can still choose a more efficient path at
compile-time. But for other types, the decision of whether to do a proxy
wait is deferred to runtime, inside the library internals. This will
make it possible for future versions of libstdc++.so to extend the set
of types which don't need to use proxy waits, without ABI changes.

The way the change works is to stop using the __proxy_wait flag that was
set by the inline code in the headers. Instead the __wait_args struct
has an extra pointer member which the library internals populate with
either the address of the atomic object or the _M_ver counter in the
proxy state. There is also a new _M_obj_size member which stores the
size of the atomic object, so that the library can decide whether a
proxy is needed. So for example if linux gains 64-bit futex support then
the library can decide not to use a proxy when _M_obj_size == 8.
Finally, the _M_old member of the __wait_args struct is changed to
uint64_t so that it has room to store 64-bit values, not just whatever
size the __platform_wait_t type is (which is a 32-bit int on Linux).
Similarly, the _M_val member of __wait_result_type changes to uint64_t
too.

libstdc++-v3/ChangeLog:

	* config/abi/pre/gnu.ver: Adjust exports.
	* include/bits/atomic_timed_wait.h (_GLIBCXX_HAVE_PLATFORM_TIMED_WAIT):
	Do not define this macro.
	(__atomic_wait_address_until_v, __atomic_wait_address_for_v):
	Adjust assertions to check that __platform_wait_uses_type is
	true.
	* include/bits/atomic_wait.h (__waitable): New concept.
	(__platform_wait_uses_type): Different separately for platforms
	with and without platform wait.
	(_GLIBCXX_HAVE_PLATFORM_WAIT): Do not define this macro.
	(__wait_value_type): New typedef.
	(__wait_result_type): Change _M_val to __wait_value_type.
	(__wait_flags): Remove __proxy_wait enumerator. Reduce range
	reserved for ABI version by the commented-out value.
	(__wait_args_base::_M_old): Change type to __wait_args_base.
	(__wait_args_base::_M_obj, __wait_args_base::_M_obj_size): New
	data members.
	(__wait_args::__wait_args): Set _M_obj and _M_obj_size on
	construction.
	(__wait_args::_M_setup_wait): Change void* parameter to deduced
	type. Adjust bit_cast to work for types of different sizes.
	(__wait_args::_M_load_proxy_wait_val): Remove function, replace
	with ...
	(__wait_args::_M_setup_proxy_wait): New function.
	(__wait_args::_S_flags_for): Do not set __proxy_wait flag.
	(__atomic_wait_address_v): Adjust assertion to check that
	__platform_wait_uses_type is true.
	* src/c++20/atomic.cc (_GLIBCXX_HAVE_PLATFORM_WAIT): Define here
	instead of in header. Check _GLIBCXX_HAVE_PLATFORM_WAIT instead
	of _GLIBCXX_HAVE_PLATFORM_TIMED_WAIT.
	(__platform_wait, __platform_notify, __platform_wait_until): Add
	unused parameter for _M_obj_size.
	(__spin_impl): Adjust for 64-bit __wait_args_base::_M_old.
	(use_proxy_wait): New function.
	(__wait_args::_M_load_proxy_wait_val): Replace with ...
	(__wait_args::_M_setup_proxy_wait): New function. Call
	use_proxy_wait to decide at runtime whether to wait on the
	pointer directly instead of using a proxy. If a proxy is needed,
	set _M_obj and _M_obj_size to refer to its _M_ver member. Adjust
	for change to type of _M_old.
	(__wait_impl): Wait on _M_obj unconditionally. Pass _M_obj_size
	to __platform_wait.
	(__notify_impl): Call use_proxy_wait to decide whether to notify
	on the address parameter or a proxy
	(__spin_until_impl): Adjust for change to type of _M_val.
	(__wait_until_impl): Wait on _M_obj unconditionally. Pass
	_M_obj_size to __platform_wait_until.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-11-27 09:43:46 +00:00
Jonathan Wakely
89552346e3 libstdc++: Fix std::counting_semaphore<> default max value
My recent (uncommitted) changes to support a 64-bit __platform_wait_t
for FreeBSD and Darwin revealed a problem in std::counting_semaphore.
When the default template argument is used and __platform_wait_t is a
64-bit type, the numeric_limits<__platform_wait_t>::max() value doesn't
fit in ptrdiff_t and so we get ptrdiff_t(-1), which fails a
static_assert in the class body.

The solution is to cap the value to PTRDIFF_MAX instead of allowing it
to go negative.

libstdc++-v3/ChangeLog:

	* include/bits/semaphore_base.h (__platform_semaphore::_S_max):
	Limit to PTRDIFF_MAX to avoid negative values.
	* testsuite/30_threads/semaphore/least_max_value.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-11-27 09:43:24 +00:00