[PATCH] libstdc++: Fix attribute order on __normal_iterator friends [PR120949]
Tomasz Kaminski
tkaminsk@redhat.com
Tue Jul 8 12:25:58 GMT 2025
On Sat, Jul 5, 2025 at 1:27 AM Jonathan Wakely <jwakely@redhat.com> wrote:
> In r16-1911-g6596f5ab746533 I claimed to have reordered some attributes
> for compatibility with Clang, but it looks like I got the Clang
> restriction backwards and put them all in the wrong order.
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/120949
> * include/bits/stl_iterator.h (__normal_iterator): Fix order of
> always_inline and nodiscard attributes for Clang compatibility.
> ---
>
> Tested x86_64-linux, and tested lightly with Clang.
>
LGTM.
I have also checked that this is indeed an order that is accepted by clang.
The fact that this restriction is only put on hidden friends is strange.
>
> libstdc++-v3/include/bits/stl_iterator.h | 30 +++++++++++++-----------
> 1 file changed, 16 insertions(+), 14 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/stl_iterator.h
> b/libstdc++-v3/include/bits/stl_iterator.h
> index a7188f46f6db..75e794f6c020 100644
> --- a/libstdc++-v3/include/bits/stl_iterator.h
> +++ b/libstdc++-v3/include/bits/stl_iterator.h
> @@ -1211,7 +1211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> #else
> // Forward iterator requirements
> template<typename _Iter>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1220,7 +1220,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() == __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1229,7 +1229,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> { return __lhs.base() == __rhs.base(); }
>
> template<typename _Iter>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1238,7 +1238,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() != __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1248,15 +1248,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
> // Random access iterator requirements
> template<typename _Iter>
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> _GLIBCXX_CONSTEXPR
> + _GLIBCXX_CONSTEXPR
> inline bool
> operator<(const __normal_iterator& __lhs,
> const __normal_iterator<_Iter, _Container>& __rhs)
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() < __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX20_CONSTEXPR
> bool
> @@ -1265,15 +1266,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> { return __lhs.base() < __rhs.base(); }
>
> template<typename _Iter>
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> _GLIBCXX_CONSTEXPR
> + _GLIBCXX_CONSTEXPR
> bool
> operator>(const __normal_iterator& __lhs,
> const __normal_iterator<_Iter, _Container>& __rhs)
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() > __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1282,7 +1284,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> { return __lhs.base() > __rhs.base(); }
>
> template<typename _Iter>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1291,7 +1293,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() <= __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1300,7 +1302,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> { return __lhs.base() <= __rhs.base(); }
>
> template<typename _Iter>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1309,7 +1311,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() >= __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> bool
> @@ -1341,7 +1343,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> #endif
> { return __lhs.base() - __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> difference_type
> @@ -1349,7 +1351,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> _GLIBCXX_NOEXCEPT
> { return __lhs.base() - __rhs.base(); }
>
> - __attribute__((__always_inline__)) _GLIBCXX_NODISCARD
> + _GLIBCXX_NODISCARD __attribute__((__always_inline__))
> friend
> _GLIBCXX_CONSTEXPR
> __normal_iterator
> --
> 2.50.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250708/6e2bf28a/attachment.htm>
More information about the Libstdc++
mailing list