]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: optional<T&> for function and unbounded array should not be range [PR122396]
authorTomasz Kamiński <tkaminsk@redhat.com>
Thu, 6 Nov 2025 14:22:12 +0000 (15:22 +0100)
committerTomasz Kamiński <tkaminsk@redhat.com>
Wed, 12 Nov 2025 08:24:09 +0000 (09:24 +0100)
commitd554b8a704bae6c3470fbf44a95559fc26bc75d1
tree7ad55ff766b36c8fa78dd9059dbbb870525a5a9e
parentb0e56bc6ad9fc54841070d676bc2bd9b5e2f8b6d
libstdc++: optional<T&> for function and unbounded array should not be range [PR122396]

This implements proposed resolution for LWG4308 [1].

For T denoting either function type or unbounded array, the optional<T&> no
longer exposes iterator, and viable begin/end members. The conditionally
provided iterator type, it is now defined in __optional_ref_base
base class.

Furthermore, range support for optional<T&> is now also guarded by
__cpp_lib_optional_range_support.

[1] https://cplusplus.github.io/LWG/issue4308

PR libstdc++/122396

libstdc++-v3/ChangeLog:

* include/std/optional (__optional_ref_base): Define.
(std::optional<_Tp&>): Inherit from __optional_ref_base<_Tp>.
(optional<_Tp&>::iterator): Move to base class.
(optional<_Tp&>::begin, optional<_Tp&>::end): Use deduced return
type and constrain accordingly.
* testsuite/20_util/optional/range.cc: Add test for optional<T&>.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/std/optional
libstdc++-v3/testsuite/20_util/optional/range.cc