Skip to content

Commit

Permalink
LWG-3769 basic_const_iterator::operator== causes infinite constrain…
Browse files Browse the repository at this point in the history
…t recursion (#3459)
  • Loading branch information
CaseyCarter authored Feb 14, 2023
1 parent 6b2fef2 commit be588ec
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -1932,72 +1932,74 @@ public:
}

template <sentinel_for<_Iter> _Sent>
_NODISCARD constexpr bool operator==(const _Sent& _Se) const // per LWG-3769
_NODISCARD constexpr bool operator==(const _Sent& _Se) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current == _Se))) /* strengthened */ {
return _Current == _Se;
}

_NODISCARD_FRIEND constexpr bool
operator<(const basic_const_iterator& _Left, const basic_const_iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current < _Right._Current))) // strengthened
_NODISCARD constexpr bool operator<(const basic_const_iterator& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current < _Right._Current))) // strengthened
requires random_access_iterator<_Iter>
{
return _Left._Current < _Right._Current;
return _Current < _Right._Current;
}

_NODISCARD_FRIEND constexpr bool
operator>(const basic_const_iterator& _Left, const basic_const_iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current > _Right._Current))) // strengthened
_NODISCARD constexpr bool operator>(const basic_const_iterator& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current > _Right._Current))) // strengthened
requires random_access_iterator<_Iter>
{
return _Left._Current > _Right._Current;
return _Current > _Right._Current;
}

_NODISCARD_FRIEND constexpr bool
operator<=(const basic_const_iterator& _Left, const basic_const_iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current <= _Right._Current))) // strengthened
_NODISCARD constexpr bool operator<=(const basic_const_iterator& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current <= _Right._Current))) // strengthened
requires random_access_iterator<_Iter>
{
return _Left._Current <= _Right._Current;
return _Current <= _Right._Current;
}

_NODISCARD_FRIEND constexpr bool
operator>=(const basic_const_iterator& _Left, const basic_const_iterator& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current >= _Right._Current))) // strengthened
_NODISCARD constexpr bool operator>=(const basic_const_iterator& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current >= _Right._Current))) // strengthened
requires random_access_iterator<_Iter>
{
return _Left._Current >= _Right._Current;
return _Current >= _Right._Current;
}

_NODISCARD_FRIEND constexpr auto operator<=>(const basic_const_iterator& _Left,
const basic_const_iterator& _Right) noexcept(noexcept(_Left._Current <=> _Right._Current)) // strengthened
_NODISCARD constexpr auto operator<=>(const basic_const_iterator& _Right) const
noexcept(noexcept(_Current <=> _Right._Current)) // strengthened
requires random_access_iterator<_Iter> && three_way_comparable<_Iter>
{
return _Left._Current <=> _Right._Current;
return _Current <=> _Right._Current;
}

template <_Bci_order<_Iter> _Other>
_NODISCARD_FRIEND constexpr bool operator<(const basic_const_iterator& _Left, const _Other& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current < _Right))) /* strengthened */ {
return _Left._Current < _Right;
_NODISCARD constexpr bool operator<(const _Other& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current < _Right))) /* strengthened */ {
return _Current < _Right;
}

template <_Bci_order<_Iter> _Other>
_NODISCARD_FRIEND constexpr bool operator>(const basic_const_iterator& _Left, const _Other& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current > _Right))) /* strengthened */ {
return _Left._Current > _Right;
_NODISCARD constexpr bool operator>(const _Other& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current > _Right))) /* strengthened */ {
return _Current > _Right;
}

template <_Bci_order<_Iter> _Other>
_NODISCARD_FRIEND constexpr bool operator<=(const basic_const_iterator& _Left, const _Other& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current <= _Right))) /* strengthened */ {
return _Left._Current <= _Right;
_NODISCARD constexpr bool operator<=(const _Other& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current <= _Right))) /* strengthened */ {
return _Current <= _Right;
}

template <_Bci_order<_Iter> _Other>
_NODISCARD_FRIEND constexpr bool operator>=(const basic_const_iterator& _Left, const _Other& _Right) noexcept(
noexcept(_Fake_copy_init<bool>(_Left._Current >= _Right))) /* strengthened */ {
return _Left._Current >= _Right;
_NODISCARD constexpr bool operator>=(const _Other& _Right) const
noexcept(noexcept(_Fake_copy_init<bool>(_Current >= _Right))) /* strengthened */ {
return _Current >= _Right;
}

template <_Bci_order_3way<_Iter> _Other>
_NODISCARD constexpr auto operator<=>(const _Other& _Right) const
noexcept(noexcept(_Current <=> _Right)) /* strengthened */ {
return _Current <=> _Right;
}

template <_Not_bci_order<_Iter> _Other>
Expand All @@ -2024,12 +2026,6 @@ public:
return _Left >= _Right._Current;
}

template <_Bci_order_3way<_Iter> _Other>
_NODISCARD_FRIEND constexpr auto operator<=>(const basic_const_iterator& _Left, const _Other& _Right) noexcept(
noexcept(_Left._Current <=> _Right)) /* strengthened */ {
return _Left._Current <=> _Right;
}

_NODISCARD_FRIEND constexpr basic_const_iterator operator+(const basic_const_iterator& _It,
const difference_type _Off) noexcept(noexcept(basic_const_iterator{_It._Current + _Off})) // strengthened
requires random_access_iterator<_Iter>
Expand All @@ -2052,15 +2048,15 @@ public:
}

template <sized_sentinel_for<_Iter> _Sent>
_NODISCARD constexpr difference_type operator-(const _Sent& _Se) const // per LWG-3769
_NODISCARD constexpr difference_type operator-(const _Sent& _Se) const
noexcept(noexcept(_Current - _Se)) /* strengthened */ {
return _Current - _Se;
}

template <_Not_a_const_iterator _Sent>
requires sized_sentinel_for<_Sent, _Iter>
_NODISCARD_FRIEND constexpr difference_type operator-(const _Sent& _Se, const basic_const_iterator& _It) noexcept(
noexcept(_Se - _It._Current)) /* strengthened */ { // per LWG-3769
noexcept(_Se - _It._Current)) /* strengthened */ {
return _Se - _It._Current;
}
};
Expand Down

0 comments on commit be588ec

Please sign in to comment.