2829 Commits
Author SHA1 Message Date
Nathan Myers 2bfaa218b0 libstdc++: bitset _GLIBCXX_ASSERTIONS op[] fixes
C++11 forbids a compound statement, as seen in the definition
of __glibcxx_assert(), in a constexpr function. This patch
open-codes the assertion in `bitset<>::operator[] const` for
C++11 to fix a failure in `g++.old-deja/g++.martin/bitset1.C`.

Also, it adds `{ dg-do compile }` in another test to suppress
a spurious UNRESOLVED complaint.

libstdc++-v3/ChangeLog:
	* include/std/bitset (operator[]() const): Customize bounds
	check for C++11 case.
	* testsuite/20_util/bitset/access/subscript_const_neg.cc:
	Suppress UNRESOLVED complaint.
2026-03-06 07:12:23 -05:00
Nathan Myers 1b404c5744 libstdc++: bitset subscript check when _GLIBCXX_ASSERTIONS [PR118341]
Changes in v3:
 - Delete redundant "dg" annotations.

Changes in v2:
 - Rejigger testing.
 - Add tests for regular bitset<>::op[].

Perform __glibcxx_assert bounds check on indices to bitset<>::op[]
for const and non-const overloads.

Also, add previously neglected regular tests for bitset<>::op[].

libstdc++-v3/ChangeLog
	PR libstdc++/118341
	* include/std/bitset (operator[] (2x)): Add assertion.
	* testsuite/20_util/bitset/access/118341_neg1.cc: New test.
	* testsuite/20_util/bitset/access/118341_neg2.cc: Same.
	* testsuite/20_util/bitset/access/118341_smoke.cc: Same.
	* testsuite/20_util/bitset/access/subscript.cc: Same.
	* testsuite/20_util/bitset/access/subscript_const_neg.cc: Same.
2026-03-05 13:23:36 -05:00
Tomasz KamińskiandIvan Lazaric 7793e34adf libstdc++: Remove UB in _Arg_value union alternative assignment
The _Arg_value::_M_set method, initialized the union member, by
assigning to reference to that member produced by _M_get(*this).
However, per language rules, such assignment has undefined behavior,
if alternative was not already active, same as for any object not
within its lifetime.

To address above, we modify _M_set to use placement new for the class
types, and invoke _S_access with two arguments for all other types.
The _S_access (rename of _S_get) is modified to assign the value of
the second parameter (if provided) to the union member. Such direct
assignments are treated specially in the language (see N5032
[class.union.general] p5), and will start lifetime of trivially default
constructible alternative.

libstdc++-v3/ChangeLog:

	* include/std/format (_Arg_value::_M_get): Rename to...
	(_Arg_value::_M_access): Modified to accept optional
	second parameter that is assigned to value.
	(_Arg_value::_M_get): Handle rename.
	(_Arg_value::_M_set): Use construct_at for basic_string_view,
	handle, and two-argument _S_access for other types.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Ivan Lazaric <ivan.lazaric1@gmail.com>
Co-authored-by: Ivan Lazaric <ivan.lazaric1@gmail.com>
2026-03-05 11:55:59 +01:00
Tomasz Kamiński afa58609ba libstdc++: Store basic_format_arg::handle in __format::_Arg_value
This patch changes the type of _M_handle member of __format::_Arg_value
from __format::_HandleBase union member to basic_format_arg<_Context>::handle.
This allows handle to be stored (using placement new) inside _Arg_value at
compile time, as type _M_handle member now matches stored object.

In addition to above, to make handle usable at compile time, we adjust
the _M_func signature to match the stored function, avoiding the need
for reinterpret cast.

To avoid a cycling dependency, where basic_format_arg<_Context> requires
instantiating _Arg_value<_Context> for its _M_val member, that in turn
requires basic_format_arg<_Context>::handle, we define handle as nested
class inside _Arg_value and change basic_format_arg<_Context>::handle
to alias for it.

Finally, the handle(_Tp&) constructor is now constrained to not accept
handle itself, as otherwise it would be used instead of copy-constructor
when constructing from handle&.

As _Arg_value is already templated on _Context, this change should not lead
to additional template instantiations.

libstdc++-v3/ChangeLog:

	* include/std/format (__Arg_value::handle): Define, extracted
	with modification from basic_format_arg::handle.
	(_Arg_value::_Handle_base): Remove.
	(_Arg_value::_M_handle): Change type to handle.
	(_Arg_value::_M_get, _Arg_value::_M_set): Check for handle
	type directly, and return result unmodified.
	(basic_format_arg::__formattable): Remove.
	(basic_format_arg::handle): Replace with alias to
	_Arg_value::handle.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-05 11:11:02 +01:00
Jonathan Wakely 47339c8f8a libstdc++: Change comment on #endif to match #if condition [PR124363]
I changed the #if in r8-3123-gc6888c62577671 but didn't make the
corresponding change to the #endif.

libstdc++-v3/ChangeLog:

	PR libstdc++/124363
	* include/std/string_view: Adjust comment on #endif to match #if
	condition.
2026-03-04 11:59:39 +00: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
Arthur O'Dwyer 300f170835 libstdc++: Make std::expected nodiscard [PR119197]
The new test includes two lines that currently do not warn because of
GCC compiler bug PR85973; the lines that do warn are the more
important cases.

	PR libstdc++/119197

libstdc++-v3/ChangeLog:

	* include/std/expected (expected, expected<void, E>): Add
	[[nodiscard]] to class.
	* testsuite/20_util/expected/119197.cc: New test.

Signed-off-by: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Reviewed-by: Nathan Myers <ncm@cantrip.org>
2026-03-03 16:13:23 +00:00
Jonathan Wakely 28e4005c42 libstdc++: Adjust indentation of std::atomic<T*> wait/notify members
libstdc++-v3/ChangeLog:

	* include/std/atomic (atomic<T*>::wait, atomic<T*>::notify_one)
	(atomic<T*>::notify_all): Fix indentation.
2026-03-03 16:11:58 +00:00
Tomasz Kamiński bfc2b87f82 libstdc++: Add #pragma to slience null-dereference warning in istreambuf_iterator::operator++ [PR105580]
The warning was produced by following sequence, given an istream_iterator<char>
it, such that *it will result in hitting EoF in it->_M_get(), and thus clearing
_M_sbuf, the subsequent call to ++it, will result in _M_sbuf->sbumpc() call on
null pointer. This is however an false-positive, as in such situation
it == istream_iteator() returns true, and the iterator should not be
incremented in first place.

This patch sliences the issue, by disabling the "-Wnull-dereference" using
GCC diagnostic pragmas. To work correctly the pragmas needs to be placed around
streambuf functions on which the issue originating from istreambuf_iterator are
reported.

	PR libstdc++/105580

libstdc++-v3/ChangeLog:

	* include/std/streambuf (streambuf::gptr, streambuf::egptr)
	(streambuf::gbump): Surround with pragma disabling -Wnull-dereference.
	* testsuite/24_iterators/istreambuf_iterator/105580.cc: Remove check for
	warning being emitted.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-03-02 11:21:51 +01: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 66e60479e9 libstdc++: Harmonize mdspan operator[] and at methods.
This patch changes the implementation of operator[], to follow similar
pattern as at, where we normalize argument types and forward to single
overload. The conversion now uses __mdspan::__index_type_cast, instead
of static_assert. This introduces asserts assuring that conversion is
is value preserving.

Finally, __is_multi_index is implemented as local lambda, avoiding
the need to create a local array with copies of the arguments.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__is_multi_index): Removed,
	replaced with local lambda in mdspan::operator[].
	(__mdspan::operator[]): Implement in terms of single overload
	accepting index_type. Use __mdspan::__index_type_cast for type
	conversion.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-23 13:01:52 +01:00
Tomasz Kamiński 43f7452026 libstdc++: Implement mdspan::at member functions from P3383R3.
This patch implements P3383R3: mdspan.at().

The mdspan::at cast only non-integral types to the index_type, before
performing the checks. This allows to detect negative value of arguments,
even if the index type is unsigned, and other values that would overflow
index_type.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (mdspan::at, mdspan::__index_int_t):
	Define.
	* testsuite/23_containers/mdspan/at.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-23 12:57:16 +01:00
Tomasz Kamiński 918cf3a50d libstdc++: Rework constant_wrapper assignments and increments
This implements LWG4383 with LWG4500, LWG4523 follow-up corrections.

This patch changes the constant_wrapper assignments operator (including
compounds), increment and decrement to apply directly to value. In
consequence the operators are only supported for types, for which above
operations can be applied on const value.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (_CWOperators::operator++)
	(_CWOperators::operator--, _CWOperators::operator+=)
	(_CWOperators::operator-=, _CWOperators::operator*=)
	(_CWOperators::operator/=, _CWOperators::operator%=)
	(_CWOperators::operator&=, _CWOperators::operator|=)
	(_CWOperators::operator^=, _CWOperators::operator<<=)
	(_CWOperators::operator>>=, constant_wrapper::operator=):
	Adjust definitions to apply operator on value.
	* testsuite/20_util/constant_wrapper/generic.cc:
	Remove test_pseudo_mutator.
	* testsuite/20_util/constant_wrapper/instantiate.cc:
	Test that operators are not provided if wrapped type
	do not support them, or provide mutable operators.
2026-02-19 17:10:19 +01:00
Patrick Palka 8ba1e2077f libstdc++: Add [[no_unique_address]] to repeat_view::_M_value [PR121402]
PR libstdc++/121402

libstdc++-v3/ChangeLog:

	* include/std/ranges (repeat_view::_M_value): Add
	[[no_unique_address]].
	* testsuite/std/ranges/adaptors/sizeof.cc
	[__cpp_lib_ranges_repeat]: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-18 10:13:51 -05:00
Tomasz Kamiński 55b87e1b3a libstdc++: Rename std::submdspan_extents and std::submdspan_canonicalize_slices
This patch implements LWG 4491, addressing C++26 NB comments.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (std::submdspan_extents): Rename to...
	(std::subextents): Renamed from submdspan_extents.
	(std::submdspan_canonicalize_slices): Rename to...
	(std::canonical_slices): Renamed from submdspan_canonicalize_slices.
	* testsuite/23_containers/mdspan/submdspan/submdspan_canonicalize_slices.cc:
	Move to...
	* testsuite/23_containers/mdspan/submdspan/canonical_slices.cc: ...here.
	Updated calls to submdspan_canonicalize_slices.
	* testsuite/23_containers/mdspan/submdspan/submdspan_canonicalize_slices_neg.cc:
	Move to...
	* testsuite/23_containers/mdspan/submdspan/canonical_slices_neg.cc: ...here.
	Updated calls to submdspan_canonicalize_slices.
	* testsuite/23_containers/mdspan/submdspan/submdspan_extents.cc: Move to...
	* testsuite/23_containers/mdspan/submdspan/subextents.cc: ...here.
	Qualified and renamed calls to submdspan_extents.
	* testsuite/23_containers/mdspan/submdspan/submdspan_extents_neg.cc: Move to...
	* testsuite/23_containers/mdspan/submdspan/subextents_neg.cc: ...here.
	Qualified and renamed calls to submdspan_extents.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-16 15:24:22 +01:00
Ivan LazaricandJonathan Wakely 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
Jonathan Wakely 7bafcc3617 libstdc++: Make CTAD ignore tuple(const Types&...) constructor [PR121771]
This is similar to the r16-3536-g0bb0d1d2880d56 change for std::pair, so
that CTAD ignores the tuple(const Types&...) constructor and only uses
the tuple(Types...) -> tuple<Types...> deduction guide. This ensures
that the deduced type comes from the decayed argument types.

libstdc++-v3/ChangeLog:

	PR libstdc++/121771
	* include/std/tuple (tuple::tuple(const Elements&...)): Use
	type_identity_t to prevent constructor being used for CTAD.
	(tuple::tuple(allocator_arg_t, const A&, const Elements&...)):
	Likewise.
	* testsuite/20_util/tuple/cons/121771.cc: New test.

Reviewed-by: Ville Voutilainen <ville.voutilainen@gmail.com>
2026-02-13 09:06:31 +00:00
Jonathan Wakely db072f75e5 libstdc++: Fix fallback definitions of std::is_member_*_pointer
When the builtins aren't used we need a declaration of std::is_function
for the fallback definitions of std::is_member_function_pointer and
std::is_member_object_pointer.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (is_function): Declare before first
	use.
2026-02-12 19:36:16 +00:00
Patrick Palka 48f2e8aa6d libstdc++: Clear padding bits in std::atomic ctor in C++11 [PR114865]
After the front end change r16-7199 both GCC and Clang allow non-empty
constexpr constructor bodies in C++11 as an extension, so we can now
unconditionally enable the __builtin_clear_padding logic in std::atomic's
constructor.

	PR libstdc++/114865

libstdc++-v3/ChangeLog:

	* include/std/atomic (atomic<_Tp>::atomic(_Tp)) [C++11]:
	Enable __builtin_clear_padding logic.
	* testsuite/29_atomics/atomic/compare_exchange_padding.cc: Enable
	this test in earlier modes, including C++11.
	* testsuite/29_atomics/atomic/cons/zero_padding.cc [C++11]:
	Enable tests verifying cleared padding bits for a non-static-init
	std::atomic object.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-02-11 21:35:21 -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
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 269ce3de8c libstdc++: Fix ambiguity caused by new std::source_location constructor
The new constructor added for Contracts support was not explicit, so
caused ambiguities when arbitrary pointers were used in contexts which
could convert to std::source_location.

We don't actually need a constructor, the contract_violation::location()
function can just set the data member directly.

libstdc++-v3/ChangeLog:

	* include/std/contracts (contract_violation::location): Use
	source_location default constructor and then set _M_impl.
	* include/std/source_location (source_location(const void*)):
	Remove constructor.
	* testsuite/18_support/contracts/includes.cc: Move to...
	* testsuite/18_support/contracts/srcloc.cc: ...here. Test for
	ambiguity caused by new constructor.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-02-05 16:48:20 +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
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
Jonathan Wakely 57f571f728 libstdc++: Make std::expected trivially copy/move assignable (LWG 4026)
This is the subject of two NB comments on C++26 which seem likely to be
approved. We're allowed to make this change as QoI anyway, even if it
isn't approved for the standard, and it should apply to C++23 as well to
avoid ABI changes between C++23 and C++26.

As shown in the updates to the test, defaulted special members can have
noexcept(false) even if they would be noexcept(true) by default. The new
defaulted operator= overloads added by this commit have conditional
noexcept-specifiers that match the conditions of the non-trivial
assignments, propagating any noexcept(false) on trivial special members
of the T and E types. We could strengthen the noexcept for the trivial
operators, but propagating the conditions from the underlying types is
probably what users expect, if they've bothered to put noexcept(false)
on their defaulted special members.

libstdc++-v3/ChangeLog:

	* include/std/expected (__expected::__trivially_replaceable)
	(__expected::__usable_for_assign)
	(__expected::__usable_for_trivial_assign)
	(__expected::__can_reassign_type): New concepts.
	(expected::operator=): Adjust constraints
	on existing overloads and add defaulted overload.
	(expected<cv void, E>::operator=): Likewise.
	* testsuite/20_util/expected/requirements.cc: Check for trivial
	and nothrow properties of assignments.
2026-01-29 20:17:40 +00:00
Jonathan Wakely a111fd4d47 libstdc++: Fix use of feature test macro in <source_location>
libstdc++-v3/ChangeLog:

	* include/std/source_location: Check __glibcxx_contracts instead
	of __cpp_lib_contracts.
	* testsuite/18_support/contracts/includes.cc: New test.
2026-01-29 17:14:03 +00:00
Jonathan Wakely 95ed4da229 libstdc++: Fix non-ASCII characters in <contracts> header
This fixes:
FAIL: 17_intro/headers/c++1998/charset.cc  -std=gnu++26 (test for excess errors)

libstdc++-v3/ChangeLog:

	* include/std/contracts: Replace non-ASCII characters.
2026-01-29 12:13:43 +00:00
Jonathan Wakely f362763f62 libstdc++: Do not allow contract26.cc to build without -fcontracts
It seems prefereable to get a hard error if this file is built
incorrectly, rather than failing to define any symbols.

libstdc++-v3/ChangeLog:

	* src/experimental/contract26.cc: Use #error if built without
	contracts support enabled.
	* include/std/source_location: Remove stray whitespace.
2026-01-28 12:19:08 +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
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 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
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
Jakub Jelinek dc716fb66a libstdc++: Fix __cpp_impl_reflection comparisons
Last night when applying Marek's patchset for testing I've noticed I forgot
to change these 5 spots when changing the -freflection -std=c++26 predefined
value from 202500 which meant we implement some reflection, but not the
whole paper, to 202506 which is the https://eel.is/c++draft/tab:cpp.predefined.ft
value for it.

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

	* include/std/type_traits (std::is_reflection, std::is_fundamental,
	std::is_reflection_v, std::is_consteval_only): Compare
	__cpp_impl_reflection >= 202506L instead of 202500L.
	* testsuite/20_util/variable_templates_for_traits.cc: Likewise.
2026-01-15 16:34:14 +01:00
Marek PolacekandJakub Jelinek 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
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 a94bd31fd8 libstdc++: Fix std::basic_stringbuf::str()&& [PR123100]
When basic_stringbuf::setbuf has been called we need to copy the
contents of the buffer into _M_string first, before returning that.

libstdc++-v3/ChangeLog:

	PR libstdc++/123100
	* include/std/sstream (basic_stringbuf::str()&&): Handle the
	case where _M_string is not being used for the buffer.
	* testsuite/27_io/basic_stringbuf/str/char/123100.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-07 15:21:52 +00:00
Jonathan Wakely 5b20eefe0c libstdc++: Fix memory leak in std::barrier destructor [PR123378]
When I replaced the std::unique_ptr member in r16-997-gef632273a90657 I
should have added an explicit delete[] operation to replace the effects
of the unique_ptr destructor.

libstdc++-v3/ChangeLog:

	PR libstdc++/123378
	* include/std/barrier (~__tree_barrier_base): Define.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2026-01-07 15:20:45 +00:00
Jakub Jelinek 254a858ae7 Update copyright years. 2026-01-02 09:56:11 +01:00
Tomasz Kamiński b3c167b61f libstdc++: Use union to store non-trivially destructible types in C++17 mode [PR112591]
This patch disables use of specialization _Uninitialized<_Type, false> for
non-trivially destructible types by default in C++17, and fallbacks to
the  primary template, that stores the type in union directly. This makes the
ABI consistent between C++17 and C++20 (or later). This partial specialization
is no longer required after the changes introduced in r16-5961-g09bece00d0ec98.

This fixes non-conformance in C++17 mode where global variables of a variant
specialization type, were not statically-initialized for non-trivially
destructible types, even if initialization of the selected alternative could
be performed at compile time. For illustration, the following global variable
will be statically initialized after this change:
  std::variant<std::unique_ptr<T>, std::unique_ptr<U>> ptr;

This constitutes an ABI break, and changes the layout of the types, that uses
the same non-trivially copyable both as the base class, as alternative of the
variant object that is first member:
  struct EmptyNonTrivial { ~EmptyNonTrivial(); };
  struct Affected : EmptyNonTrivial {
    std::variant<EmptyNonTrivial, char> mem; // mem was at offset zero,
                                             // will use non-zero offset now
  };
After changes the layout of such types consistent with one used for empty types
with trivial destructor, or one used for any empty type in C++20 or later.

For programs affected by this change, it can be reverted in C++17 mode, by
defining _GLIBCXX_USE_VARIANT_CXX17_OLD_ABI. However, presence of this macro
has no effect in C++20 or later modes.

	PR libstdc++/112591

libstdc++-v3/ChangeLog:

	* include/std/variant (_Uninitialized::_M_get, __get_n)
	(_Uninitialized<_Type, false>): Add _GLIBCXX_USE_VARIANT_CXX17_OLD_ABI
	check to preprocessor guard.
	* testsuite/20_util/variant/112591.cc: Updated tests.
	* testsuite/20_util/variant/112591_compat.cc: New test.
	* testsuite/20_util/variant/constinit.cc: New test.
	* testsuite/20_util/variant/constinit_compat.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-19 22:50:38 +01:00
LIU HaoandJonathan Wakely 7ad39bc909 libstdc++: On Windows, retrieve thread-local variables via functions
For Windows, GCC can be configured with `--enable-tls` to enable native TLS.
The native TLS implementation has a limitation that it is incapable of
exporting thread-local variables from DLLs. Therefore, they are retrieved
via getter functions instead.

libstdc++-v3/ChangeLog:

	* config/os/mingw32-w64/os_defines.h (_GLIBCXX_NO_EXTERN_THREAD_LOCAL):
	New macro.
	* include/std/mutex [_GLIBCXX_NO_EXTERN_THREAD_LOCAL]
	(__get_once_callable, __get_once_call): Declare new functions.
	* src/c++11/mutex.cc [_GLIBCXX_NO_EXTERN_THREAD_LOCAL]
	(__get_once_callable, __get_once_call): Define.

Signed-off-by: LIU Hao <lh_mouse@126.com>
Co-authored-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-18 23:23:26 +00:00
Tomasz Kamiński b2fb18e470 libstdc++: Provide conversion between atomic_ref of similar types.
This patch implements the P3860R1 (accepted as DR against C++20) and LWG4472.

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

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

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

libstdc++-v3/ChangeLog:

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

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-17 06:28:07 +01:00
Jonathan Wakely 487bd3ba4f libstdc++: Optimize compilation time for signed/unsigned integer traits
Replace the O(n) definitions using __is_one_of with constant-time
checks that look for a static member in the __is_integral_helper class
template. That class template is already specialized for every signed
and unsigned integer type, so we don't need to define any additional
specializations. We can just add a static data member that says whether
the type is a signed integer type, an unsigned integer type, or neither.
The __is_signed_integer and __is_unsigned_integer traits can then
inspect that value.

The new enum type could be extended in future to distinguish the
character types (char, wchar_t, char8_t, char16_t, and char32_t) and
bool from non-integer types, but that isn't needed for now.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (_Integer_kind): New enum type.
	(__is_integral_helper::_S_kind): New static data member in
	primary template and each explicit specialization.
	(__is_signed_integer, __is_unsigned_integer): Use _S_kind
	instead of O(n) disjunction with is_same.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-16 22:19:10 +00:00
Jonathan Wakely f725f08262 libstdc++: Update tzdata to 2025c
Import the new 2025c tzdata.zi file and new leapseconds expiry date.

libstdc++-v3/ChangeLog:

	* include/std/chrono (chrono::__detail::__get_leap_second_info):
	Update expiry date for leap seconds list.
	* src/c++20/tzdb.cc (tzdb_list::_Node::_S_read_leap_seconds):
	Likewise.
	* src/c++20/tzdata.zi: Import new file from 2025c release.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-12-16 22:19:09 +00:00
Patrick Palka 1d29b68562 libstdc++: Implement P2408R5 C++20 iterators as inputs to STL algos
From the paper's abstract:

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

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

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

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

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

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

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

	PR libstdc++/113299

libstdc++-v3/ChangeLog:

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

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2025-12-16 11:22:58 -05:00
Luc Grosheintz 6b78e97a0c libstdc++: Make <mdspan> compatible with clang.
The submdspan feature broke compatibility with clang, due to a missing
'::template type'.

libstdc++-v3/ChangeLog:

	* include/std/mdspan (submdspan): Fix missing '::template'.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-12-12 20:22:17 +01:00
Jakub Jelinek 62c126db6b libstdc++: Implement C++26 P3378R2 - constexpr exception types
The following patch attempts to implement the C++26 P3378R2 - constexpr
exception types paper.

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

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

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

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

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

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

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

libstdc++-v3/ChangeLog:

	* include/bits/version.def: Add FTM.
	* include/bits/version.h: Regenerate.
	* include/std/flat_set: Add constexpr.
	* testsuite/23_containers/flat_multiset/1.cc: Add constexpr test.
	* testsuite/23_containers/flat_set/1.cc: Add constexpr test.
2025-12-11 22:24:42 +08:00
Luc Grosheintz f5d72af36d libstdc++: Implement submdspan_mapping for layout_right_padded. [PR110352]
Implements submdspan for layout_right_padded as described in P3663.

	PR libstdc++/110352

libstdc++-v3/ChangeLog:

	* include/std/mdspan
	(__mdspan::_SubMdspanMapping<_LayoutSide::__right, true>): Define.
	(layout_right_padded::submdspan_mapping): New friend function.
	* testsuite/23_containers/mdspan/submdspan/selections/right_padded.cc:
	Instantiate tests for layout_right_padded.
	* testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc:
	Ditto.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-12-09 17:12:58 +01:00
Luc Grosheintz 558ab7b638 libstdc++: Implement submdspan_mapping for layout_left_padded. [PR110352]
Implements submdspan for layout_left_padded as described in P3663.

	PR libstdc++/110352

libstdc++-v3/ChangeLog:

	* include/std/mdspan (__mdspan::__is_padded_mapping): Define.
	(__mdspan::_SubMdspanMapping): Add _Padded template parameter.
	(__mdspan::_SubMdspanMapping<_LayoutSide::__left, true>): Define.
	(__mdspan::__submdspan_mapping_impl): Updated _Trait alias.
	(layout_left_padded::submdspan_mapping): New friend method.
	* testsuite/23_containers/mdspan/layout_traits.h
	(LayoutTraits::layout_same_padded): New template type alias.
	* testsuite/23_containers/mdspan/submdspan/selections/left_padded.cc:
	Instantiate tests for layout_left_padded.
	* testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc:
	Ditto.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-12-09 17:08:01 +01:00
Luc Grosheintz 57d53be024 libstdc++: Implement submdspan_mapping for layout_stride. [PR110352]
Add submdspan_mapping for layout_stride as in P3663.

	PR libstdc++/110352

libstdc++-v3/ChangeLog:

	* include/std/mdspan (layout_stride::mapping::submdspan_mapping): New
	friend function.
	* testsuite/23_containers/mdspan/submdspan/selections/stride.cc:
	Instantiate tests for layout_stride.
	* testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc:
	Ditto.
	* testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc:
	Add tests for layout_stride.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
2025-12-09 13:49:32 +01:00