Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWG-3769 basic_const_iterator::operator== causes infinite constraint recursion #3459

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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