libstdc++: Move [[nodiscard]] attributes again [PR101782]

Where I moved these nodiscard attributes to made them apply to the
function type, not to the function. This meant they no longer generated
the desired -Wunused-result warnings, and were ill-formed with Clang
(but only a pedwarn with GCC).

Clang also detected ill-formed attributes in <queue> which this fixes.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/101782
	* include/bits/ranges_base.h (ranges::begin, ranges::end)
	(ranges::rbegin, ranges::rend, ranges::size, ranges::ssize)
	(ranges::empty, ranges::data): Move attribute after the
	declarator-id instead of at the end of the declarator.
	* include/bits/stl_iterator.h (__gnu_cxx::__normal_iterator):
	Move attributes back to the start of the function declarator,
	but move the requires-clause to the end.
	(common_iterator): Move attribute after the declarator-id.
	* include/bits/stl_queue.h (queue): Remove ill-formed attributes
	from friend declaration that are not definitions.
	* include/std/ranges (views::all, views::filter)
	(views::transform, views::take, views::take_while,
	views::drop) (views::drop_while, views::join,
	views::lazy_split) (views::split, views::counted,
	views::common, views::reverse) (views::elements): Move
	attributes after the declarator-id.
This commit is contained in:
Jonathan Wakely 2021-08-05 16:46:00 +01:00
parent 4739344d36
commit c8b024fa4b
4 changed files with 33 additions and 60 deletions

View File

@ -111,8 +111,7 @@ namespace ranges
requires is_array_v<remove_reference_t<_Tp>> || __member_begin<_Tp>
|| __adl_begin<_Tp>
constexpr auto
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
{
if constexpr (is_array_v<remove_reference_t<_Tp>>)
{
@ -163,8 +162,7 @@ namespace ranges
requires is_bounded_array_v<remove_reference_t<_Tp>>
|| __member_end<_Tp> || __adl_end<_Tp>
constexpr auto
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
{
if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
{
@ -268,9 +266,8 @@ namespace ranges
template<__maybe_borrowed_range _Tp>
requires __member_rbegin<_Tp> || __adl_rbegin<_Tp> || __reversable<_Tp>
constexpr auto
operator()(_Tp&& __t) const
operator()[[nodiscard]](_Tp&& __t) const
noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
{
if constexpr (__member_rbegin<_Tp>)
return __t.rbegin();
@ -327,9 +324,8 @@ namespace ranges
template<__maybe_borrowed_range _Tp>
requires __member_rend<_Tp> || __adl_rend<_Tp> || __reversable<_Tp>
constexpr auto
operator()(_Tp&& __t) const
operator()[[nodiscard]](_Tp&& __t) const
noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
{
if constexpr (__member_rend<_Tp>)
return __t.rend();
@ -417,8 +413,7 @@ namespace ranges
requires is_bounded_array_v<remove_reference_t<_Tp>>
|| __member_size<_Tp> || __adl_size<_Tp> || __sentinel_size<_Tp>
constexpr auto
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
{
if constexpr (is_bounded_array_v<remove_reference_t<_Tp>>)
return extent_v<remove_reference_t<_Tp>>;
@ -438,8 +433,7 @@ namespace ranges
template<typename _Tp>
requires requires (_Tp& __t) { _Size{}(__t); }
constexpr auto
operator()(_Tp&& __t) const noexcept(noexcept(_Size{}(__t)))
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(noexcept(_Size{}(__t)))
{
auto __size = _Size{}(__t);
using __size_type = decltype(__size);
@ -498,8 +492,7 @@ namespace ranges
requires __member_empty<_Tp> || __size0_empty<_Tp>
|| __eq_iter_empty<_Tp>
constexpr bool
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp&>())
{
if constexpr (__member_empty<_Tp>)
return bool(__t.empty());
@ -540,8 +533,7 @@ namespace ranges
template<__maybe_borrowed_range _Tp>
requires __member_data<_Tp> || __begin_data<_Tp>
constexpr auto
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>())
[[nodiscard]]
operator()[[nodiscard]](_Tp&& __t) const noexcept(_S_noexcept<_Tp>())
{
if constexpr (__member_data<_Tp>)
return __t.data();

View File

@ -1118,21 +1118,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cpp_lib_three_way_comparison
template<typename _IteratorL, typename _IteratorR, typename _Container>
requires requires (_IteratorL __lhs, _IteratorR __rhs)
{ { __lhs == __rhs } -> std::convertible_to<bool>; }
[[nodiscard]]
constexpr bool
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
noexcept(noexcept(__lhs.base() == __rhs.base()))
[[nodiscard]]
requires requires {
{ __lhs.base() == __rhs.base() } -> std::convertible_to<bool>;
}
{ return __lhs.base() == __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container>
[[nodiscard]]
constexpr std::__detail::__synth3way_t<_IteratorR, _IteratorL>
operator<=>(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
noexcept(noexcept(std::__detail::__synth3way(__lhs.base(), __rhs.base())))
[[nodiscard]]
{ return std::__detail::__synth3way(__lhs.base(), __rhs.base()); }
#else
// Forward iterator requirements
@ -1985,9 +1986,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _It2, sentinel_for<_It> _Sent2>
requires sentinel_for<_Sent, _It2>
friend bool
operator==(const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
[[nodiscard]]
operator== [[nodiscard]] (const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
{
switch(__x._M_index << 2 | __y._M_index)
{
@ -2008,9 +2008,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _It2, sentinel_for<_It> _Sent2>
requires sentinel_for<_Sent, _It2> && equality_comparable_with<_It, _It2>
friend bool
operator==(const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
[[nodiscard]]
operator== [[nodiscard]] (const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
{
switch(__x._M_index << 2 | __y._M_index)
{
@ -2032,9 +2031,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<sized_sentinel_for<_It> _It2, sized_sentinel_for<_It> _Sent2>
requires sized_sentinel_for<_Sent, _It2>
friend iter_difference_t<_It2>
operator-(const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
[[nodiscard]]
operator- [[nodiscard]] (const common_iterator& __x,
const common_iterator<_It2, _Sent2>& __y)
{
switch(__x._M_index << 2 | __y._M_index)
{

View File

@ -107,18 +107,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
template<typename _Tp1, typename _Seq1>
_GLIBCXX_NODISCARD
friend bool
operator==(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&);
template<typename _Tp1, typename _Seq1>
_GLIBCXX_NODISCARD
friend bool
operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&);
#if __cpp_lib_three_way_comparison
template<typename _Tp1, three_way_comparable _Seq1>
[[nodiscard]]
friend compare_three_way_result_t<_Seq1>
operator<=>(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&);
#endif

View File

@ -1127,9 +1127,8 @@ namespace views::__adaptor
|| __detail::__can_ref_view<_Range>
|| __detail::__can_subrange<_Range>
constexpr auto
operator()(_Range&& __r) const
operator() [[nodiscard]] (_Range&& __r) const
noexcept(_S_noexcept<_Range>())
[[nodiscard]]
{
if constexpr (view<decay_t<_Range>>)
return std::forward<_Range>(__r);
@ -1554,8 +1553,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Pred>
requires __detail::__can_filter_view<_Range, _Pred>
constexpr auto
operator()(_Range&& __r, _Pred&& __p) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const
{
return filter_view(std::forward<_Range>(__r), std::forward<_Pred>(__p));
}
@ -1932,8 +1930,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Fp>
requires __detail::__can_transform_view<_Range, _Fp>
constexpr auto
operator()(_Range&& __r, _Fp&& __f) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Fp&& __f) const
{
return transform_view(std::forward<_Range>(__r), std::forward<_Fp>(__f));
}
@ -2114,8 +2111,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Tp>
requires __detail::__can_take_view<_Range, _Tp>
constexpr auto
operator()(_Range&& __r, _Tp&& __n) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Tp&& __n) const
{
return take_view(std::forward<_Range>(__r), std::forward<_Tp>(__n));
}
@ -2242,8 +2238,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Pred>
requires __detail::__can_take_while_view<_Range, _Pred>
constexpr auto
operator()(_Range&& __r, _Pred&& __p) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const
{
return take_while_view(std::forward<_Range>(__r), std::forward<_Pred>(__p));
}
@ -2363,8 +2358,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Tp>
requires __detail::__can_drop_view<_Range, _Tp>
constexpr auto
operator()(_Range&& __r, _Tp&& __n) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Tp&& __n) const
{
return drop_view(std::forward<_Range>(__r), std::forward<_Tp>(__n));
}
@ -2452,8 +2446,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Pred>
requires __detail::__can_drop_while_view<_Range, _Pred>
constexpr auto
operator()(_Range&& __r, _Pred&& __p) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Pred&& __p) const
{
return drop_while_view(std::forward<_Range>(__r),
std::forward<_Pred>(__p));
@ -2815,8 +2808,7 @@ namespace views::__adaptor
template<viewable_range _Range>
requires __detail::__can_join_view<_Range>
constexpr auto
operator()(_Range&& __r) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r) const
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 3474. Nesting join_views is broken because of CTAD
@ -3267,8 +3259,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Pattern>
requires __detail::__can_lazy_split_view<_Range, _Pattern>
constexpr auto
operator()(_Range&& __r, _Pattern&& __f) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Pattern&& __f) const
{
return lazy_split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f));
}
@ -3476,8 +3467,7 @@ namespace views::__adaptor
template<viewable_range _Range, typename _Pattern>
requires __detail::__can_split_view<_Range, _Pattern>
constexpr auto
operator()(_Range&& __r, _Pattern&& __f) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r, _Pattern&& __f) const
{
return split_view(std::forward<_Range>(__r), std::forward<_Pattern>(__f));
}
@ -3498,8 +3488,7 @@ namespace views::__adaptor
{
template<input_or_output_iterator _Iter>
constexpr auto
operator()(_Iter __i, iter_difference_t<_Iter> __n) const
[[nodiscard]]
operator() [[nodiscard]] (_Iter __i, iter_difference_t<_Iter> __n) const
{
if constexpr (random_access_iterator<_Iter>)
return subrange(__i, __i + __n);
@ -3620,8 +3609,7 @@ namespace views::__adaptor
requires __detail::__already_common<_Range>
|| __detail::__can_common_view<_Range>
constexpr auto
operator()(_Range&& __r) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r) const
{
if constexpr (__detail::__already_common<_Range>)
return views::all(std::forward<_Range>(__r));
@ -3743,8 +3731,7 @@ namespace views::__adaptor
|| __detail::__is_reversible_subrange<remove_cvref_t<_Range>>
|| __detail::__can_reverse_view<_Range>
constexpr auto
operator()(_Range&& __r) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r) const
{
using _Tp = remove_cvref_t<_Range>;
if constexpr (__detail::__is_reverse_view<_Tp>)
@ -4142,8 +4129,7 @@ namespace views::__adaptor
template<viewable_range _Range>
requires __detail::__can_elements_view<_Nm, _Range>
constexpr auto
operator()(_Range&& __r) const
[[nodiscard]]
operator() [[nodiscard]] (_Range&& __r) const
{
return elements_view<all_t<_Range>, _Nm>{std::forward<_Range>(__r)};
}