Commit Graph

5830 Commits

Author SHA1 Message Date
Jonathan Wakely
45477b791d libstdc++: Add platform wait functions for FreeBSD [PR120527]
This defines __platform_wait, __platform_notify, and
__platform_wait_until for FreeBSD, making use of the _umtx_op syscall.

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

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

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

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

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

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

libstdc++-v3/ChangeLog:

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

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

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

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

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

	PR libstdc++/119745

libstdc++-v3/ChangeLog:

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

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

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

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

libstdc++-v3/ChangeLog:

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

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-16 12:34:18 +01:00
Patrick Palka
0852c2d9d7 libstdc++/regex: Avoid -Wunused-parameter warnings in _Executor
Now that _Executor is non-recursive most subroutines no longer use their
_Match_mode parameter (previously it was just passed to recursive _M_dfs
calls).  For now, just make them unnamed to avoid warnings.

libstdc++-v3/ChangeLog:

	* include/bits/regex_executor.tcc (_Executor::_M_rep_once_more):
	Make unnused _Match_mode parameter unnamed.
	(_Executor::_M_handle_repeat): Likewise.
	(_Executor::_M_handle_subexpr_begin): Likewise.
	(_Executor::_M_handle_subexpr_end): Likewise.
	(_Executor::_M_handle_line_begin_assertion): Likewise.
	(_Executor::_M_handle_line_end_assertion): Likewise.
	(_Executor::_M_handle_match): Likewise.
	(_Executor::_M_handle_backref): Likewise.
	(_Executor::_M_handle_alternative): Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-12 15:17:57 -05:00
Tomasz Kamiński
b58cf25443 libstdc++: Make function_ref non-dangling for stateless wrappers
This patch makes the function_ref non-dangling for the stateless
wrappers:
* any functor for which operator() selected for arguments is static,
* standard functors, including pre-C++20 ones.
In other words, any function_ref fr, that is constructed from stateless
wrapper w, can be still called after the object w is destroyed, e.g.:
  std::function_ref<bool(int, int)> fr(std::ranges::less{});
  fr(1, 2); // OK, previously UB because fr referred to already destroyed
            // temporary
As function_ref's operator() is not constexpr, we test the change by checking
if the above declaration can be made constexpr, as such variable cannot contain
dangling pointer values.

We adjust the function_ref generic constructor from any functor, to use more
specialized invoker:
* _S_static (newly added) if the called operator() overload is static,
  after changes r16-5624-g0ea9d760fbf44c, this covers all post-c++20 functors;
* _S_nttp<_Fd{}> for pre-C++20 standard functors.
In both above cases the value of _M_ptrs is ignored and simply set to nullptr.

This follows same technique (checking _Fd::operator()(args...)), and support
the same set of types, as for one used for the transform views iterators in
r16-5625-g9ed821d107f7a1.

As after this change we provide well-defined behavior for the code, that
previous was undefined, this changes is pure quality-of-implementation.
As illustrated by the test cases, it has observable side effects, where
non-longer dangling constructs can be used to define constexpr function_ref.
However, the standard does not define when the constructors defined constexpr
are actually usable at compile time, and the already have precedent in form
of SSO string for validity such constructs being implementation specific.

libstdc++-v3/ChangeLog:

	* include/bits/funcref_impl.h (function_ref::function_ref(_Fn&&)):
	Use _S_static and _S_nttp invokers.
	* include/bits/funcwrap.h (_Base_invoker::_S_static):
	Define.
	* include/bits/stl_function.h (std::__is_std_op_template)
	(std::__is_std_op_wrapper) [__cplusplus > 201703L]:
	Moved from std/ranges.
	* include/std/ranges (__detail::__is_std_op_template)
	(__detail::__is_std_op_wrapper): Moved to bits/stl_function.h.
	* testsuite/20_util/function_ref/dangling.cc: New test.
	* testsuite/20_util/function_ref/dangling_neg.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-11 17:54:09 +01:00
Jonathan Wakely
fba29a5e4e libstdc++: Optimize std::regex_traits lookup functions
Optimize regex_traits::lookup_collatename and
regex_traits::lookup_classname.

For lookup_collatename we can hoist the static array into a
non-dependent function, then call that for the regex_traits<char>
specialization without performing any narrowing operations via the ctype
facet. For the regex_traits<wchar_t> specialization we populate a
std::string for the narrowed result, and call the non-dependent function.

For lookup_classname we can avoid the static array entirely, replacing
the iteration over that array with a nested switch that implements a
kind of manually-unrolled trie, only match one char at a time until we
either match a full string or get a mismatch. This avoids narrowing the
entire input and storing it in a temporary string. This improves
performance by 2-3x for -O2 and below (the benefit is much smaller for
-O3).

We can also check the input length for random access iterators, and
reject any strings longer than "xdigit" without doing any work at all.
For silly cases like [:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:]
this gives a 100x improvement.

libstdc++-v3/ChangeLog:

	* include/bits/regex.tcc (__detail::__lookup_collatename): New
	function.
	(regex_traits::lookup_collatename): Use new function. Elide
	redundant narrowing via ctype facet for regex_traits<char>.
	(regex_traits::lookup_classname): Replace lookup table with
	handwritten prefix match.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-11 11:00:03 +00:00
Jonathan Wakely
49d219a5d7 libstdc++: Fix std::regex_traits::lookup_classname [PR124015]
This fixes a bug in regex_traits::lookup_classname(f, l, true) where the
result was always ctype_base::alpha for any input sequence [f, l) that
has the ctype_base::lower or ctype_base::upper bits set. For targets
that define alpha as lower|upper (rather than having a distinct bit for
alpha) this bug meant that all masks which have lower or upper bits set
were replaced with alpha when the icase parameter is true. This has the
effect that trying to do a case insensitive match for [:alnum:],
[:graph:], or [:print:] was equivalent to matching [:alpha:] instead,
which is obviously not correct.

Based on inspection of the ctype_base.h files under the config/os
directory, the bug appears to affect newlib, picolibc, qnx and vxworks.

libstdc++-v3/ChangeLog:

	PR libstdc++/124015
	* include/bits/regex.tcc (regex_traits::lookup_classname): Fix
	handling of icase parameter.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-11 11:00:03 +00:00
Tomasz Kamiński
6b550d69fe libstdc++: Allow constant initialization of std::atomic of types with padding [PR123875]
Currently for the types T that contains padding bits, std::atomic<T>(T)
constructor was not usable at compile-time in C++14 or later modes. This
regression caused by use of __builtin_clear_padding introduced in
r13-2548-g157236dbd62164.

This leads to two regressions when switching from C++11 to C++14
standard (or switching from GCC-12 to later version for C++14 standard),
where for type X that contains padding
* constexpr std::atomic<X> cx(X(...)) becomes ill-formed,
* std::atomic<X> gx(X(...)) with static storage duration, switch from
  static to dynamic initialization.
The latter breakage is silent and may introduced very hard to localize
order of initialization issues.

This patch mitigates above issue by not invoking the __builtin_clear_padding,
during constant initialization (std::__is_constant_evaluated() is false).
This is considered to be safe, as:
* for objects with static storage duration, padding bits are already
  cleared by zero-initialization
* for constexpr objects with non-static storage duration, there is no
  API that would allow user to observe padding bits on const atomic objects

To elaborate on the second point, values of padding bits in atomic can
be observed by:
* The compare_exchange_weak/compare_exchange_strong operations are mutating,
  so cannot be invoked on const objects.
* As atomic<X> is not required to store actual object of type X,
  observing its object representation does (via bitcast, memcpy), does
  not provide values of object representation of X. Furthermore, the
  operations are defined only for trivially_copyable types, and atomic
  specializations meets above requirement only due to bug in libstdc++
  (see PR67572).

Note that above will no longer hold, and the solution will need to be
revisited during implementation of C++26 paper P3309R3: constexpr
atomic and atomic_ref (it will be possible to call compare_exchange
during constant evaluation).

	PR libstdc++/123875

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (__atomic_impl::__clear_padding):
	Use if constexpr unconditionally.
	(__atomic_float<_Fp>::__atomic_float(_Fp)): Skip __clear_padding
	call for constant evaluation.
	* include/std/atomic (atomic<_Tp>::atomic(_Tp)): Likewise.
	* testsuite/29_atomics/atomic/cons/static_zero_padding.cc: New test.

Reviewed-by: Patrick Palka  <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-10 11:51:03 +01:00
Jonathan Wakely
0912dfcd1e libstdc++: Fix incorrect noexcept on string::compare overloads [PR123991]
These compare overloads throw when the pos index is out of range, not
only when the const T& parameter throws on conversion to string_view.

Remove the incorrect conditional noexcept-specifier from the two
overloads that can throw.

libstdc++-v3/ChangeLog:

	PR libstdc++/123991
	* include/bits/basic_string.h (compare(size_type, size_type, T)):
	Remove noexcept-specifier.
	(compare(size_type, size_type, T, size_type, size_type)):
	Likewise.
	* include/bits/cow_string.h (compare(size_type, size_type, T)):
	Remove noexcept-specifier.
	(compare(size_type, size_type, T, size_type, size_type)):
	Likewise.
	* testsuite/21_strings/basic_string/operations/compare/char/123991.cc:
	New test.
	* testsuite/21_strings/basic_string/operations/compare/wchar_t/123991.cc:
	New test.

Reviewed-by: Nathan Myers <nmyers@redhat.com>
2026-02-10 10:05:30 +00:00
Patrick Palka
d3af40eefa libstdc++/regex: Remove now unused __dfs_mode template parameter
This mechanical patch removes _Executor's __dfs_mode template parameter.
In passing we can also get rid of the _V2 inline namespace because this
removal alone achieve the goal of the inline namespace which is to make
all of _Executor's member function signatures different from the
previous (GCC < 16) recursive implementation, allowing for safe mixing
of the two incompatible implementations.

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (_Executor): Remove __dfs_mode template
	parameter and _V2 inline namespace.
	* include/bits/regex.tcc (__regex_algo_impl): Adjust after
	__dfs_mode template parameter removal.
	* include/bits/regex_executor.h (_Executor): Remove __dfs_mode
	parameter and _V2 inline namespace.
	* include/bits/regex_executor.tcc (_Executor): Likewise.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-09 20:04:12 -05:00
Patrick Palka
c49ce07bf0 libstdc++/regex: Replace __dfs_mode template parameter with run-time flag
That _Executor's __dfs_mode flag is a template parameter means
__regex_algo_impl has to instantiate two different (but largely the
same) versions of _Executor even though the BFS version is rarely used.
And it seems the compiler has trouble DCEing the unused version of
_Executor, which needlessly increases code size and burdens the optimizer.

This patch replaces the template parameter with a run-time data member
_M_search_mode.  We in turn need to inline the _Executor::_State_info
member functions and data members into _Executor so that they depend on
the run-time instead of compile-time flag.  This means _Executor is
three pointers bigger in DFS mode (due to the unused _M_match_queue and
_M_visited_states members), which we can reduce to one pointer if we
really want to, but that doesn't seem ver worthwhile.

The __dfs_mode template parameter is now unused but not yet removed,
that'll be done in the next patch.

After this patch, both code size and run time for the microbenchmark

    for (int i = 0; i < 10000; i++)
      regex_match(string(200, 'a'), regex("(a|b|c)*"));

decreases by about 15% each (with -O2).  Compile time/memory use decreases
by 5-10%.

libstdc++-v3/ChangeLog:

	* include/bits/regex.tcc (__regex_algo_impl): Pass __use_dfs
	parameter to _Executor's constructor.
	* include/bits/regex_executor.h (_Executor::_Search_mode): New.
	(_Executor::_Executor): Add __use_dfs parameter and initialize
	_M_search_mode.  Adjust after inlining _State_info members into
	_Executor.
	(_Executor::~_Executor): Free _M_visted_states.
	(_Executor::_M_main): Adjust after renaming _M_main_dispatch
	overloads to _M_main_dfs and _M_main_bfs.
	(_Executor::_State_info): Remove.
	(_Executor::_M_visited): Inlined from _State_info.
	(_Executor::_M_get_sol_pos): Likewise.
	(_Executor::_M_states): Remove.
	(_Executor::_M_start): Inlined from _State_info.
	(_Executor::_M_sol_pos): Likewise.
	(_Executor::_M_match_queue): Likewise.
	(_Executor::_M_search_mode): New.
	* include/bits/regex_executor.tcc (_Executor::_M_main_dispatch):
	Renamed to...
	(_Executor::_M_main_dfs, _Executor::_M_main_bfs): ... these.
	(_Executor::_M_*): Adjust after _M_states removal.
	(_Executor::_M_lookhead): Also adjust _Executor constructor
	call.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-09 20:04:00 -05:00
Jonathan Wakely
a53eaa2690 libstdc++: Fix doxygen comment for std::out_ptr [PR124024]
libstdc++-v3/ChangeLog:

	PR libstdc++/124024
	* include/bits/out_ptr.h (out_ptr): Fix doxygen comment to refer
	to the right function.
	(inout_ptr): Improve markup in doxygen comment.
2026-02-09 20:43:16 +00:00
Tomasz Kamiński
9b85fcc00e libstdc++: Update guards on __heterogeneous_hash_key and __heterogeneous_tree_key
The r16-7359-gae04c1afd1526a changed __heterogeneous_key to be
defined if __glibcxx_associative_heterogeneous_erasure, but missed
guards on derived __heterogeneous_hash_key and __heterogeneous_tree_key
concept.

libstdc++-v3/ChangeLog:

	* include/bits/hashtable.h (std::__heterogeneous_hash_key)
	[__glibcxx_associative_heterogeneous_erasure]: Changed guard.
	* include/bits/stl_tree.h (std::__heterogeneous_tree_key)
	[__glibcxx_associative_heterogeneous_erasure]: Likewise.
	* include/bits/stl_function.h: Add comment with C++ version
	for __glibcxx_associative_heterogeneous_erasure guard.
2026-02-06 14:06:46 +01:00
Nathan Myers
ae04c1afd1 libstdc++: fix C++17 regression in concept __heterogeneous_key (2nd)
The commit 3f79055504 defined a
concept __heterogeneous_key using a name not defined in C++17.
This is fixed by guarding the definition behind a name defined
in C++23 the earliest Standard that uses the definition.

https://gcc.gnu.org/pipermail/gcc-patches/2026-February/707814.html

libstdc++-v3/ChangeLog
	* include/bits/stl_function.h (concept __heterogeneous_key):
	Guard with __glibcxx_associative_heterogeneous_erasure
2026-02-06 05:41:28 -05:00
Nathan Myers
786e316de5 libstdc++: fix C++17 regression in concept __heterogeneous_key
The commit 3f79055504 defined a
concept using a name not defined in C++17. This is fixed by
using an older name.

https://gcc.gnu.org/pipermail/gcc-patches/2026-February/707814.html

libstdc++-v3/ChangeLog
	* include/bits/stl_function.h (__heterogeneous_key): Use
	C++17-defined remove_cvref<>::type instead.
2026-02-06 03:25:21 -05:00
Caolán McNamara
d78b2b6c01 libstdc++: make __collatenames array const in regex.tcc
libstdc++-v3/ChangeLog:

	* include/bits/regex.tcc (regex_traits::lookup_collatename):
	Make __collatenames array const.

Signed-off-by: Caolán McNamara <caolanm@gmail.com>
2026-02-05 16:48:41 +00:00
Nathan Myers
3f79055504 libstdc++: container erasure overloads (P2077) [PR117404]
Remaining to do:
 * Add new declarations in debug headers too.

Implement C++23 P2077R3 "Heterogeneous erasure overloads for
associative containers". Adds template overloads for members
erase and extract to address elements using an alternative key
type, such as string_view for a container of strings, without
need to construct an actual key object.

The new overloads enforce concept __heterogeneous_tree_key or
__heterogeneous_hash_key to verify the function objects provided
meet requirements, and that the key supplied is not an iterator
or the native key.

libstdc++-v3/ChangeLog:
	PR libstdc++/117404
	* include/bits/version.def (associative_heterogeneous_erasure):
	Define.
	* include/bits/version.h: Regenerate.
	* include/std/map: Request new feature from version.h.
	* include/std/set: Same.
	* include/std/unordered_map: Same.
	* include/std/unordered_set: Same.
	* include/bits/stl_map.h (extract, erase): Define overloads.
	* include/bits/stl_set.h: Same.
	* include/bits/stl_multimap.h: Same.
	* include/bits/stl_multiset.h: Same.
	* include/bits/unordered_map.h: Same, 2x.
	* include/bits/unordered_set.h: Same, 2x.
	* include/bits/stl_function.h (concepts __not_container_iterator,
	__heterogeneous_key): Define.
	* include/bits/hashtable.h (_M_find_before_node, _M_locate, extract):
	Delegate to more-general _tr version.
	(_M_find_before_node_tr, _M_locate_tr, _M_extract_tr, _M_erase_tr):
	Add new members to support a heterogeneous key argument.
	(_M_erase_some): Add new helper function.
	(concept __heterogeneous_hash_key): Define.
	* include/bits/stl_tree.h (_M_lower_bound_tr, _M_upper_bound_tr,
	_M_erase_tr, _M_extract_tr): Add new members to support a
	heterogeneous key argument.
	(concept __heterogeneous_tree_key): Define.
	* testsuite/23_containers/map/modifiers/hetero/erase.cc: New test.
	* testsuite/23_containers/multimap/modifiers/hetero/erase.cc: Same.
	* testsuite/23_containers/multiset/modifiers/hetero/erase.cc: Same.
	* testsuite/23_containers/set/modifiers/hetero/erase.cc: Same.
	* testsuite/23_containers/unordered_map/modifiers/hetero/erase.cc: Same.
	* testsuite/23_containers/unordered_multimap/modifiers/hetero/erase.cc:
	Same.
	* testsuite/23_containers/unordered_multiset/modifiers/hetero/erase.cc:
	Same.
	* testsuite/23_containers/unordered_set/modifiers/hetero/erase.cc: Same.
2026-02-04 17:39:51 -05:00
Marek Polacek
7197d0cce7 libstdc++, c++/reflection: mark {,de}allocate constexpr
[allocator.members] says that allocator::{,de}allocate should be
constexpr but currently we don't mark them as such.  I had to
work around that in the Reflection code, but it would be better to
clean this up.  (I see no allocation_result so I'm not changing that.)

gcc/cp/ChangeLog:

	* constexpr.cc (is_std_allocator): Don't check for __new_allocator.
	(is_std_allocator_allocate): Make static.
	* cp-tree.h (is_std_allocator_allocate): Remove declaration.
	* reflect.cc (check_out_of_consteval_use): Don't call
	is_std_allocator_allocate.
	(check_consteval_only_fn): Likewise.

libstdc++-v3/ChangeLog:

	* include/bits/new_allocator.h (__new_allocator::allocate,
	__new_allocator::deallocate): Add missing constexpr.

Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-03 15:15:52 -05:00
Jakub Jelinek
4a514ea759 libstdc++: Define __cpp_lib_define_static [PR123921]
I've totally missed the P3491R3 paper (define_static_{string,object,array})
comes with its own feature test macro - __cpp_lib_define_static 202506
which should appear in <version> and <meta>.
The paper contains 3 parts, std::is_string_literal,
std::meta::reflect_constant_{string,array} and
std::define_static_{string,object,array}.
The first part is implementable without reflection, the third part in theory
would be also implementable without reflection but usually will be (and in
libstdc++ is) implemented using reflection, and the middle part is really
part of reflection.  So dunno how useful this FTM actually is, maybe just
for cases where some implementation does implement reflection and doesn't
implement this paper for a while.

Anyway, the FTM is in C++26 draft, so this patch adds it, with the same
condition as __cpp_lib_reflection.

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

	PR libstdc++/123921
	* include/bits/version.def (define_static): New with the
	same values as reflection.
	* include/bits/version.h: Regenerate.
	* include/std/meta: Define also __glibcxx_want_define_static before
	including bits/version.h.

	* g++.dg/reflect/feat2.C: Add also test for __cpp_lib_define_static.
	* g++.dg/reflect/feat3.C: New test.
2026-02-03 14:22:46 +01:00
Patrick Palka
8978da072f libstdc++/regex: Zero-initialize _ExecutorFrame flags
Prevents uninitialized read bugs, and it's also just natural to assume
flags are initially cleared rather than uninitialized.

In passing rename the _M_end flag to _M_subexpr_end to make it distinct
from _Executor::_M_end.

libstdc++-v3/ChangeLog:

	* include/bits/regex_executor.tcc (_ExecutorFrameBase):
	Zero-initialize _M_byte0.
	(_ExecutorFrameBase::_M_end): Rename to ...
	(_ExecutorFrameBase::_M_subexpr_end): ... this.
	(_Executor::_M_handle_subexpr_begin): Remove now redundant
	clearing of _M_subexpr_end.
	(_Executor::_M_handle_subexpr_end): Adjust after renaming.
	(_Executor::_M_dfs) <case _S_fopcode_restore_cur_results>:
	Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-02 15:14:20 -05:00
Patrick Palka
bdd45f4eee libstdc++/regex: Suppress -Wpedantic warning about anonymous structs
Fixes some modules testsuite compilation errors.

libstdc++-v3/ChangeLog:

	* include/bits/regex_executor.tcc (_ExecutorFrameBase): Add
	#pragma GCC diagnostic to suppress -Wpedantic warning about
	anonymous structs.
2026-01-30 21:01:08 -05:00
Patrick Palka
a8a1183d58 libstdc++/regex: add [[gnu::always_inline]] to _Executor::_M_node
The compiler understandably doesn't know that _M_node only ever has a
single call site, _M_dfs, (and is not directly called from other library
headers or user code) and so decides not to inline it.  So use the
always_inline attribute to force the inlining.  This seems sufficient to
make all _M_dfs subroutines get inlined away, and speeds up the executor
by 30% on some microbenchmarks.

libstdc++-v3/ChangeLog:

	* include/bits/regex_executor.tcc (__detail::_Executor::_M_node)
	[__OPTIMIZE__]: Add [[gnu::always_inline]] attribute.  Declare
	inline.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-01-30 13:16:20 -05:00
Patrick Palka
ead66d5f22 libstdc++/regex: Defer _M_current restoration to backtracking nodes [PR86164]
The incrementing of the current input string position (_M_current) is
done by _M_handle_match, which also makes sure to restore it afterwards,
via a restore_current frame.  But restoring _M_current is naturally only
necessary when backtracking is involved, not after every single match.

So this patch moves the responsibility of saving/restoring _M_current
from _M_handle_match to the branching nodes _M_handle_alternative and
_M_handle_repeat.  This is done by storing _M_current within the
fallback_next, fallback_rep_once_more and posix_alternative frames.
In turn we can get rid of the now unused restore_current frame kind.

This reduces the maximum size of the _M_frames stack by 15% for

  regex_match(string(200000, 'a'), "(a|b|c)*")

	PR libstdc++/86164

libstdc++-v3/ChangeLog:

	* include/bits/regex_executor.tcc (__detail::_ExecutorFrameOpcode):
	Remove _S_fopcode_restore_current.
	(__detail::_Executor::_M_handle_repeat): Pass _M_current when
	pushing a fallback_next or fallback_rep_once_more frame.
	(__detail::_Executor::_M_handle_match): Don't push a
	restore_current frame.
	(__detail::_Executor::_M_handle_backref): Likewise and simplify
	accordingly.
	(__detail::_Executor::_M_handle_alternative): Pass _M_current when
	pushing a fallback_next or posix_alternative frame.
	(__detail::_Executor::_M_dfs) <case _S_fopcode_fallback_next>:
	Restore _M_current.
	<case _S_fopcode_fallback_rep_once_more>: Likewise.
	<case _S_fopcode_posix_alternative>: Likewise.
	<case _S_fopcode_restore_current>: Remove.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-01-30 12:29:17 -05:00
Patrick Palka
158ad5f969 libstdc++/regex: Make DFS executor non-recursive [PR86164]
This patch replaces the recursive implementation of the DFS executor
with an iterative one using an explicit heap-based stack.  System
stack usage of the executor is now constant with respect to input size
rather than linear, avoding stack overflow errors when processing
long inputs.

	PR libstdc++/86164

libstdc++-v3/ChangeLog:

	* include/bits/regex.h (__detail::_Executor): Use inline
	namespace _V2.
	* include/bits/regex_executor.h (__detail::_ExecutorFrame):
	Declare.
	(__detail::_Executor): Use inline namespace _V2.
	(__detail::_Executor::_M_node): Declare.
	(__detail::_Executor::_M_frames): New data member.
	* include/bits/regex_executor.tcc (__detail::_ExecutorFrameOpcode):
	New.
	(__detail::_ExecutorFrameBase): New.
	(__detail::_ExecutorFrame): New.
	(__detail::_Executor): Use inline namespace _V2.
	(__detail::_Executor::_M_rep_once_more): Replace recursive
	_M_dfs calls with an _S_opcode_next frame push, and any work
	after such calls with an appropriate frame push.
	(__detail::_M_handle_repeat): Likewise.
	(__detail::_M_handle_subexpr_begin): Likewise.
	(__detail::_M_handle_subexpr_end): Likewise.
	(__detail::_M_handle_line_begin_assertion): Likewise.
	(__detail::_M_handle_line_end_assertion): Likewise.
	(__detail::_M_handle_word_boundary): Likewise.
	(__detail::_M_handle_subexpr_lookahead): Likewise.
	(__detail::_M_handle_match): Likewise.
	(__detail::_M_handle_backref): Likewise.
	(__detail::_M_handle_accept): Likewise.
	(__detail::_M_handle_alternative): Likewise.
	(__detail::_M_node): Factored out from _M_dfs.
	(__detail::_M_dfs): Push an initial frame to _M_frames that
	visits the starting node and pass this stack each subroutine.
	Pop the latest _ExecutorFrame from _M_frames and handle
	appropriately according to its _ExecutorFrameOpcode.  Loop until
	_M_frames is empty.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-01-30 12:23:40 -05:00
Jonathan Wakely
74e0bb3faa libstdc++: Disable false positive middle end warnings in std::shared_ptr [PR122197]
Speculative devirtualization in GCC 16 causes some false positive
warnings for unreachable paths. Use diagnostic pragmas to suppress
those warnings until the regression is fixed.

libstdc++-v3/ChangeLog:

	PR tree-optimization/122197
	* include/bits/shared_ptr_base.h (~_Sp_counted_deleter): Use
	diagnostic pragam to disable -Wfree-nonheap-object false
	positive.
	(~_Sp_counted_ptr_inplace): Likewise for -Warray-bounds false
	positive.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-28 10:28:09 +00:00
Soumya AR
68a1218c18 libstdc++: Implement std::atomic::fetch_min/max
This patch extends libstdc++ to implement C++26's atomic fetch min/max
operations.

The __atomic_fetch_minmaxable concept checks if __atomic_fetch_min and
__atomic_fetch_max builtins are implemented by the compiler. If not, fall back
to a CAS loop.

This patch was bootstrapped and regtested on aarch64-linux-gnu and
x86_64-linux-gnu, no regression.

Signed-off-by: Soumya AR <soumyaa@nvidia.com>

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h:
	Add fetch_min and fetch_max memberfunctions.
	* include/bits/version.def:
	Add __cpp_lib_atomic_min_max feature test macro.
	* include/bits/version.h (defined): Regenerate.
	* include/std/atomic: Extend for fetch_min/max non-member functions.
	* src/c++23/std.cc.in: Export atomic_fetch_min, atomic_fetch_max,
	atomic_fetch_min_explicit, atomic_fetch_max_explicit.
	* testsuite/29_atomics/atomic_integral/nonmembers_fetch_minmax.cc:
	New test.
	* testsuite/29_atomics/atomic_ref/integral_fetch_minmax.cc: New test.
2026-01-28 10:57:37 +05:30
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