]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use hidden friends for __normal_iterator operators
authorJonathan Wakely <jwakely@redhat.com>
Wed, 27 Nov 2024 20:58:29 +0000 (20:58 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 2 Jul 2025 17:16:40 +0000 (18:16 +0100)
commit6596f5ab7465336d8466f2310cb612ae1bfbc7f3
tree9032e271fcbe3749c9153aab9ae1ff519b6c2fa7
parent57d30924e2b3887a1aedc6102daa67bc3272ace7
libstdc++: Use hidden friends for __normal_iterator operators

As suggested by Jason, this makes all __normal_iterator operators into
friends so they can be found by ADL and don't need to be separately
exported in module std.

The operator<=> comparing two iterators of the same type is removed
entirely, instead of being made a hidden friend. That overload was added
by r12-5882-g2c7fb16b5283cf to deal with unconstrained operator
overloads found by ADL, as defined in the testsuite_greedy_ops.h header.
We don't actually test that case as there's no unconstrained <=> in that
header, and it doesn't seem reasonable for anybody to define such an
operator<=> in C++20 when they should constrain their overloads properly
(e.g. using a requires-clause). The homogeneous operator<=> overloads
added for reverse_iterator and move_iterator could also be removed, but
that's not part of this commit.

I also had to reorder the __attribute__((always_inline)) and
[[nodiscard]] attributes on the pre-c++20 operators, because Clang won't
allow [[foo]] after __attribute__((bar)) on a friend function:

<source>:4:36: error: an attribute list cannot appear here
    4 |     __attribute__((always_inline)) [[nodiscard]] friend bool
      |                                    ^~~~~~~~~~~~~

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (__normal_iterator): Make all
non-member operators hidden friends, except ...
(operator<=>(__normal_iterator<I,C>, __normal_iterator<I,C>)):
Remove.
* src/c++11/string-inst.cc: Remove explicit instantiations of
operators that are no longer templates.
* src/c++23/std.cc.in (__gnu_cxx): Do not export operators for
__normal_iterator.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/src/c++11/string-inst.cc
libstdc++-v3/src/c++23/std.cc.in