STL icon indicating copy to clipboard operation
STL copied to clipboard

`<algorithm>`: `ranges::minmax` accidentally constructed `remove_cvref_t<iter_reference_t<I>>`

Open hewillk opened this issue 2 years ago • 1 comments

https://github.com/microsoft/STL/blob/1c59a205787f4fdcd9c20decc8fa6dfa9096d394/stl/inc/algorithm#L10108-L10116

The last auto _Prev = *_UFirst; indicates that we constructed remove_cvref_t<iter_reference_t<I>> from iter_reference_t<I>, which is not guaranteed to be well-formed by the function's constraints. I believe we should do _Vty _Prev(*_UFirst); instead.

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

hewillk avatar Oct 18 '23 09:10 hewillk

Good catch - we talked about this at the weekly maintainer meeting and agree that this is a bug.

This also indicates that we have missing test coverage of ranges algorithms with this scenario.

StephanTLavavej avatar Oct 18 '23 21:10 StephanTLavavej