public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101587] New: uninitialized_copy/move incorrectly uses std::min
@ 2021-07-23  2:09 hewillk at gmail dot com
  2021-07-23  8:33 ` [Bug libstdc++/101587] ranges::uninitialized_copy/move " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2021-07-23  2:09 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-07-23 12:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23  2:09 [Bug libstdc++/101587] New: uninitialized_copy/move incorrectly uses std::min hewillk at gmail dot com
2021-07-23  8:33 ` [Bug libstdc++/101587] ranges::uninitialized_copy/move " redi at gcc dot gnu.org
2021-07-23  9:04 ` redi at gcc dot gnu.org
2021-07-23  9:16 ` redi at gcc dot gnu.org
2021-07-23  9:56 ` hewillk at gmail dot com
2021-07-23 10:34 ` redi at gcc dot gnu.org
2021-07-23 11:50 ` hewillk at gmail dot com
2021-07-23 12:12 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).