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

<algorithm>: ranges::inplace_merge accidentally constructed remove_cvref_t<iter_rvalue_reference_t<I>> #4108

Closed
hewillk opened this issue Oct 19, 2023 · 2 comments · Fixed by #4841
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges

Comments

@hewillk
Copy link
Contributor

hewillk commented Oct 19, 2023

This is basically a sibling of #4102.

STL/stl/inc/algorithm

Lines 7614 to 7630 in 1c59a20

template <bidirectional_iterator _It>
void _Rotate_one_right(_It _First, _It _Mid, _It _Last) {
// exchanges the range [_First, _Mid) with [_Mid, _Last)
_STL_INTERNAL_CHECK(_RANGES next(_Mid) == _Last);
auto _Temp = _RANGES iter_move(_Mid);
_RANGES _Move_backward_common(_First, _STD move(_Mid), _STD move(_Last));
*_First = _STD move(_Temp);
}
template <bidirectional_iterator _It>
void _Rotate_one_left(_It _First, _It _Mid, _It _Last) {
// exchanges the range [_First, _Mid) with [_Mid, _Last)
_STL_INTERNAL_CHECK(_RANGES next(_First) == _Mid);
auto _Temp = _RANGES iter_move(_First);
auto _Result = _RANGES _Move_unchecked(_STD move(_Mid), _STD move(_Last), _STD move(_First));
*_Result.out = _STD move(_Temp);
}

auto _Temp = _RANGES iter_move(_Mid) unexpectedly constructed remove_cvref_t<iter_reference_t<I>>.

Contrived testcase: https://godbolt.org/z/b7YqKPMej

@frederick-vs-ja
Copy link
Contributor

It seems that we should use iter_value_t<_It> _Temp(_RANGES iter_move(_First));.

@StephanTLavavej StephanTLavavej added bug Something isn't working ranges C++20/23 ranges labels Oct 25, 2023
@StephanTLavavej
Copy link
Member

Agreed. As in #4102 (comment) this also indicates missing test coverage.

@StephanTLavavej StephanTLavavej changed the title <algorithm>: ranges::inplace_merge accidentally constructed remove_cvref_t<iter_rvalue_reference_t <I>> <algorithm>: ranges::inplace_merge accidentally constructed remove_cvref_t<iter_rvalue_reference_t<I>> Aug 1, 2024
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants