]> git.ipfire.org Git - thirdparty/gcc.git/commit
libsdc++: Restore check for validity of std::get for elements_view.
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 24 Apr 2026 13:10:41 +0000 (15:10 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 24 Apr 2026 14:59:38 +0000 (16:59 +0200)
commit490eca9b76ec201356d6defacaa8231a64a2102d
treedae042fff01be815f9e13c5bed33af375f4b220e
parent3f6d37193c7987ee9362c073dd5da6f7419c87b3
libsdc++: Restore check for validity of std::get for elements_view.

Resolves LWG3797, "elements_view insufficiently constrained".

When P2165R4 updated __has_tuple_element in C++23 to reuse __tuple_like
concept, it dropped the requirement of validity of get, assuming that for
tuple_like type with size of N, get<I> on lvalue is well-formed for any I < N.
This however does not hold for ranges::subrange (tuple-like of size 2) with
move-only iterator, for which get can only be applied on rvalue. In consequence
constrains allowed instantiating elements_view for range of such subrange,
but instantiating it's iterator lead to hard error from iterator_category
computation.

This patch applies the requirements on validity of get also in C++23 and
later standard modes.

libstdc++-v3/ChangeLog:

* include/std/ranges (__detail::__has_tuple_element): Check
if std::get<_Nm>(__t) returns referenceable type also for C++23
and later.
* testsuite/std/ranges/adaptors/elements.cc: Add test covering
vector of ranges::subrange with move-only iterator.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/elements.cc