https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101587
Bug ID: 101587 Summary: uninitialized_copy/move incorrectly uses std::min Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- ranges_uninitialized.h#L269: if constexpr (sized_sentinel_for<_ISent, _Iter> && sized_sentinel_for<_OSent, _Out> && is_trivial_v<_OutType> && is_nothrow_assignable_v<_OutType&, iter_reference_t<_Iter>>) { auto __d1 = __ilast - __ifirst; auto __d2 = __olast - __ofirst; return ranges::copy_n(std::move(__ifirst), std::min(__d1, __d2), __ofirst); } We should make sure that __d1 and __d2 are the same types before calling std::min, the same goes for uninitialized_copy_n/move_n. #include <memory> #include <ranges> int main() { auto r = std::views::iota(0l, 5l); std::array<long, 5> o; std::ranges::uninitialized_copy(r, o); } https://godbolt.org/z/fj7hM8qdx